/** * This method will not create a source data store if an equivalent one (i.e. same configuration * parameters) is found in the provided <code>sourceDataStoreMap</code>. * * @see AppSchemaDataAccessConfigurator#buildMappings(AppSchemaDataAccessDTO) * @param sourceDataStoreMap map holding the source data stores created so far, e.g. while * parsing App-Schema configuration files included by the one currently being processed */ public static Set<FeatureTypeMapping> buildMappings( AppSchemaDataAccessDTO config, DataAccessMap sourceDataStoreMap) throws IOException { AppSchemaDataAccessConfigurator mappingsBuilder; mappingsBuilder = new AppSchemaDataAccessConfigurator(config, sourceDataStoreMap); Set<FeatureTypeMapping> mappingObjects = mappingsBuilder.buildMappings(); return mappingObjects; }
/** * Takes a config object and creates a set of mappings. * * <p>In the process will parse xml schemas to geotools' Feature Model types and descriptors, * connect to source datastores and build the mapping objects from source FeatureTypes to the * target ones. * * @param config DOCUMENT ME! * @return a Set of {@link org.geotools.data.complex.FeatureTypeMapping} source to target * FeatureType mapping definitions * @throws IOException if any error occurs while creating the mappings */ public static Set<FeatureTypeMapping> buildMappings(AppSchemaDataAccessDTO config) throws IOException { return buildMappings(config, new DataAccessMap()); }
public DataAccess<FeatureType, Feature> createDataStore( Map params, boolean hidden, DataAccessMap sourceDataStoreMap) throws IOException { Set<FeatureTypeMapping> mappings; AppSchemaDataAccess dataStore; URL configFileUrl = (URL) AppSchemaDataAccessFactory.URL.lookUp(params); XMLConfigDigester configReader = new XMLConfigDigester(); AppSchemaDataAccessDTO config = configReader.parse(configFileUrl); // load related types that are mapped separately, and not visible on their own // this is when the related types are not feature types, so they don't appear // on getCapabilities, and getFeature also shouldn't return anything etc. List<String> includes = config.getIncludes(); for (Iterator<String> it = includes.iterator(); it.hasNext(); ) { params.put("url", buildIncludeUrl(configFileUrl, it.next())); // this will register the related data access, to enable feature chaining; // sourceDataStoreMap is passed on to keep track of the already created source data // stores // and avoid creating the same data store twice (this enables feature iterators sharing // the same transaction to re-use the connection instead of opening a new one for each // joined type) createDataStore(params, true, sourceDataStoreMap); } mappings = AppSchemaDataAccessConfigurator.buildMappings(config, sourceDataStoreMap); dataStore = new AppSchemaDataAccess(mappings, hidden); return dataStore; }
@Test public void testLoadMappingsConfig() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); final URL url = getClass().getResource(schemaBase + "mappedPolygons.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); }
/** * Test that mappings are loaded OK. * * @throws Exception */ @Test public void testLoadMappingsConfig() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); final URL url = getClass().getResource(schemaBase + "GeologicUnit.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); }
private AppSchemaDataAccess buildDataAccess(String mappingsFileName) throws Exception { // generate the path to a mappings-file in the resources directory String configFilePath = extendFilename(testDir.getPath(), mappingsFileName); URL configFileUrl = URLs.fileToUrl(new File(configFilePath)); // parse the mappings-file XMLConfigDigester configReader = new XMLConfigDigester(); AppSchemaDataAccessDTO config = configReader.parse(configFileUrl); // generate the set of mappings needed to build the application-schema datastore Set<FeatureTypeMapping> mappings; mappings = AppSchemaDataAccessConfigurator.buildMappings(config); AppSchemaDataAccess datastore = new AppSchemaDataAccess(mappings); return datastore; }
/** * Illustrates that if xlink namespace has not been declared in the app-schema mapping file,the * client property is set as if for href (in the no-name namespace). * * <p>This test shows correct behaviour by throwing an exception reporting the undeclared * namespace. * * @throws IllegalArgumentException */ @Test public void testGetClientProperties() throws IOException { try { XMLConfigDigester reader = new XMLConfigDigester(); URL url = getClass().getResource("/test-data/MappedFeatureMissingNamespaceXlink.xml"); AppSchemaDataAccessDTO config = reader.parse(url); AppSchemaDataAccessConfigurator.buildMappings(config); fail("No exception caught"); } catch (Exception ex) { assertSame(java.io.IOException.class, ex.getClass()); } } }
@Test public void testGetBounds() throws IOException { final String namespaceUri = "http://online.socialchange.net.au"; final String localName = "RoadSegment"; final Name typeName = Types.typeName(namespaceUri, localName); URL configUrl = getClass().getResource("/test-data/roadsegments.xml"); AppSchemaDataAccessDTO config = new XMLConfigDigester().parse(configUrl); Set<FeatureTypeMapping> mappings = AppSchemaDataAccessConfigurator.buildMappings(config); dataStore = new AppSchemaDataAccess(mappings); FeatureSource<FeatureType, Feature> source = dataStore.getFeatureSource(typeName); FeatureTypeMapping mapping = (FeatureTypeMapping) mappings.iterator().next(); FeatureSource<?, ?> mappedSource = mapping.getSource(); Envelope expected = getBounds(mappedSource); Envelope actual = getBounds(source); assertEquals(expected, actual); }
@Test public void testParseURL() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); URL url = XMLConfigDigester.class.getResource("/test-data/roadsegments.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); FeatureTypeMapping mapping = (FeatureTypeMapping) mappings.iterator().next(); assertEquals(8, mapping.getAttributeMappings().size()); assertNotNull(mapping.getTargetFeature()); assertNotNull(mapping.getSource()); // Map/*<String, Expression>*/idMappings = mapping.getIdMappings(); // assertEquals(idMappings.get("RoadSegment"), ExpressionBuilder.parse("getId()")); } }
config.setTypeMappings(mappings); AppSchemaDataAccess da = new AppSchemaDataAccess(AppSchemaDataAccessConfigurator.buildMappings(config)); assertNotNull(da); da.dispose(); config.setTypeMappings(mappings); assertTrue(config.getTypeMappings().containsAll(mappings)); da = new AppSchemaDataAccess(AppSchemaDataAccessConfigurator.buildMappings(config)); assertNotNull(da); da.dispose();
try { AppSchemaDataAccess da = new AppSchemaDataAccess(AppSchemaDataAccessConfigurator.buildMappings(config)); } catch (DataSourceException e) { assertTrue( try { AppSchemaDataAccess da = new AppSchemaDataAccess(AppSchemaDataAccessConfigurator.buildMappings(config)); } catch (DataSourceException e) { assertTrue( try { AppSchemaDataAccess da = new AppSchemaDataAccess(AppSchemaDataAccessConfigurator.buildMappings(config)); } catch (DataSourceException e) { assertTrue(
Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config);
Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config);
/** * Takes a config object and creates a set of mappings. * * <p> * In the process will parse xml schemas to geotools' Feature Model types and descriptors, * connect to source datastores and build the mapping objects from source FeatureTypes to the * target ones. * </p> * * @param config * DOCUMENT ME! * * @return a Set of {@link org.geotools.data.complex.FeatureTypeMapping} source to target * FeatureType mapping definitions * * @throws IOException * if any error occurs while creating the mappings */ public static Set<FeatureTypeMapping> buildMappings(AppSchemaDataAccessDTO config) throws IOException { AppSchemaDataAccessConfigurator mappingsBuilder; mappingsBuilder = new AppSchemaDataAccessConfigurator(config); Set<FeatureTypeMapping> mappingObjects = mappingsBuilder.buildMappings(); return mappingObjects; }
AppSchemaDataAccessConfigurator.buildMappings(config);
@Test public void testLoadMappingsConfig() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); final URL url = getClass().getResource(schemaBase + "mappedPolygons.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); }
/** * Test that mappings are loaded OK. * * @throws Exception */ @Test public void testLoadMappingsConfig() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); final URL url = getClass().getResource(schemaBase + "GeologicUnit.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); }
private AppSchemaDataAccess buildDataAccess(String mappingsFileName) throws Exception { // generate the path to a mappings-file in the resources directory String configFilePath = extendFilename(testDir.getPath(), mappingsFileName); URL configFileUrl = DataUtilities.fileToURL(new File(configFilePath)); // parse the mappings-file XMLConfigDigester configReader = new XMLConfigDigester(); AppSchemaDataAccessDTO config = configReader.parse(configFileUrl); // generate the set of mappings needed to build the application-schema datastore Set<FeatureTypeMapping> mappings; mappings = AppSchemaDataAccessConfigurator.buildMappings(config); AppSchemaDataAccess datastore = new AppSchemaDataAccess(mappings); return datastore; }
@Test public void testParseURL() throws Exception { XMLConfigDigester reader = new XMLConfigDigester(); URL url = XMLConfigDigester.class.getResource("/test-data/roadsegments.xml"); AppSchemaDataAccessDTO config = reader.parse(url); Set mappings = AppSchemaDataAccessConfigurator.buildMappings(config); assertNotNull(mappings); assertEquals(1, mappings.size()); FeatureTypeMapping mapping = (FeatureTypeMapping) mappings.iterator().next(); assertEquals(8, mapping.getAttributeMappings().size()); assertNotNull(mapping.getTargetFeature()); assertNotNull(mapping.getSource()); // Map/*<String, Expression>*/idMappings = mapping.getIdMappings(); // assertEquals(idMappings.get("RoadSegment"), ExpressionBuilder.parse("getId()")); }
@Test public void testGetBounds() throws IOException { final String namespaceUri = "http://online.socialchange.net.au"; final String localName = "RoadSegment"; final Name typeName = Types.typeName(namespaceUri, localName); URL configUrl = getClass().getResource("/test-data/roadsegments.xml"); AppSchemaDataAccessDTO config = new XMLConfigDigester().parse(configUrl); Set<FeatureTypeMapping> mappings = AppSchemaDataAccessConfigurator.buildMappings(config); dataStore = new AppSchemaDataAccess(mappings); FeatureSource<FeatureType, Feature> source = dataStore.getFeatureSource(typeName); FeatureTypeMapping mapping = (FeatureTypeMapping) mappings.iterator().next(); FeatureSource<?,?> mappedSource = mapping.getSource(); Envelope expected = getBounds(mappedSource); Envelope actual = getBounds(source); assertEquals(expected, actual); }