Search in sources :

Example 16 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class ModuleImport method getApplicationContext.

protected GenericApplicationContext getApplicationContext(final BeanDefinitionRegistry parentRegistry) {
    if (this.applicationContext == null) {
        this.applicationContext = new GenericApplicationContext();
        if (parentRegistry instanceof ResourceLoader) {
            final ResourceLoader resourceLoader = (ResourceLoader) parentRegistry;
            final ClassLoader classLoader = resourceLoader.getClassLoader();
            this.applicationContext.setClassLoader(classLoader);
        }
        AnnotationConfigUtils.registerAnnotationConfigProcessors(this.applicationContext, null);
        final DefaultListableBeanFactory beanFactory = this.applicationContext.getDefaultListableBeanFactory();
        final BeanFactory parentBeanFactory = (BeanFactory) parentRegistry;
        for (final String beanName : parentRegistry.getBeanDefinitionNames()) {
            final BeanDefinition beanDefinition = parentRegistry.getBeanDefinition(beanName);
            final String beanClassName = beanDefinition.getBeanClassName();
            if (beanClassName != null) {
                if (beanClassName.equals(AttributeMap.class.getName())) {
                    registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
                    this.beanNamesNotToExport.add(beanName);
                } else if (beanClassName.equals(MapFactoryBean.class.getName())) {
                    final PropertyValue targetMapClass = beanDefinition.getPropertyValues().getPropertyValue("targetMapClass");
                    if (targetMapClass != null) {
                        final Object mapClass = targetMapClass.getValue();
                        if (AttributeMap.class.getName().equals(mapClass)) {
                            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
                            this.beanNamesNotToExport.add(beanName);
                        }
                    }
                }
            }
        }
        beanFactory.addPropertyEditorRegistrar(this.resourceEditorRegistrar);
        final AttributesBeanConfigurer attributesConfig = new AttributesBeanConfigurer(this.applicationContext, this.parameters);
        this.applicationContext.addBeanFactoryPostProcessor(attributesConfig);
        for (final String beanName : this.importBeanNames) {
            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, beanName);
            this.beanNamesNotToExport.add(beanName);
        }
        for (final Entry<String, String> entry : this.importBeanAliases.entrySet()) {
            final String beanName = entry.getKey();
            final String aliasName = entry.getValue();
            registerTargetBeanDefinition(this.applicationContext, parentBeanFactory, beanName, aliasName);
            this.beanNamesNotToExport.add(aliasName);
        }
        final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(this.applicationContext);
        for (final Resource resource : this.resources) {
            beanReader.loadBeanDefinitions(resource);
        }
        this.applicationContext.refresh();
    }
    return this.applicationContext;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) AttributesBeanConfigurer(com.revolsys.spring.config.AttributesBeanConfigurer) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Resource(com.revolsys.spring.resource.Resource) PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AttributeMap(com.revolsys.collection.map.AttributeMap) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory)

Example 17 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class TestUtil method doTestGeometry.

public static void doTestGeometry(final Class<?> clazz, final String file) {
    boolean valid = true;
    final Resource resource = new ClassPathResource(file, clazz);
    try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
        int i = 0;
        for (final Record object : reader) {
            final int srid = object.getInteger("srid");
            final int axisCount = object.getInteger("axisCount");
            final double scaleXy = object.getInteger("scaleXy");
            final double scaleZ = object.getInteger("scaleZ");
            final double[] scales = { scaleXy, scaleXy, scaleZ };
            final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
            final String wkt = object.getValue("wkt");
            final Geometry geometry = geometryFactory.geometry(wkt);
            valid &= equalsExpectedWkt(i, object, geometry);
            final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
            GeometryFactory otherGeometryFactory;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
                otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
            } else {
                otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
            }
            final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
            final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
            valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
            i++;
        }
    }
    if (!valid) {
        Assert.fail("Has Errors");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record)

Example 18 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class CreateIndex method main.

public static void main(final String[] args) {
    SymbolLibrary.findSymbol("maki/police");
    final Resource makiFile = new UrlResource("https://www.mapbox.com/maki/www/maki.json");
    final List<MapEx> symbolList = Json.toMapList(makiFile);
    final SymbolLibrary symbolLibrary = new SymbolLibrary("maki", "Maki");
    for (final MapEx symbolMap : symbolList) {
        final String name = "maki/" + symbolMap.getString("icon");
        final String title = symbolMap.getString("name");
        symbolLibrary.addSymbolSvg(name, title);
    }
    final File symbolLibraryFile = new File("src/main/resources/META-INF/com.revolsys.swing.map.symbol.SymbolLibrary.json");
    MapObjectFactory.write(symbolLibraryFile, symbolLibrary);
    final SymbolLibrary symbolLibrary2 = MapObjectFactory.toObject(symbolLibraryFile);
}
Also used : UrlResource(com.revolsys.spring.resource.UrlResource) MapEx(com.revolsys.collection.map.MapEx) Resource(com.revolsys.spring.resource.Resource) UrlResource(com.revolsys.spring.resource.UrlResource) SymbolLibrary(com.revolsys.swing.map.symbol.SymbolLibrary) File(java.io.File)

Example 19 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class Gdal method loadSettings.

public static long loadSettings(final Dataset dataset, final Resource resource) {
    final Resource settingsFile = resource.newResourceAddExtension("rgobject");
    if (settingsFile.exists()) {
        try {
            final Map<String, Object> settings = Json.toMap(settingsFile);
            final String boundingBoxWkt = (String) settings.get("boundingBox");
            if (Property.hasValue(boundingBoxWkt)) {
                final BoundingBox boundingBox = BoundingBox.newBoundingBox(boundingBoxWkt);
                if (!boundingBox.isEmpty()) {
                    setSpatialReference(dataset, boundingBox.getGeometryFactory());
                    final double x = boundingBox.getMinX();
                    final double width = boundingBox.getWidth();
                    final int imageWidth = dataset.getRasterXSize();
                    final double y = boundingBox.getMaxY();
                    final double height = boundingBox.getHeight();
                    final int imageHeight = dataset.getRasterYSize();
                    final double[] transform = new double[] { x, width / imageWidth, 0, y, 0, -height / imageHeight };
                    dataset.SetGeoTransform(transform);
                }
            }
            return settingsFile.getLastModified();
        } catch (final Throwable e) {
            Logs.error(Gdal.class, "Unable to load:" + settingsFile, e);
            return -1;
        }
    } else {
        return -1;
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 20 with Resource

use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.

the class GeometryWriter method newGeometryWriter.

@SuppressWarnings("unchecked")
static <GW extends GeometryWriter> GW newGeometryWriter(final Object target, final MapEx properties) {
    final Resource resource = Resource.getResource(target);
    final GeometryWriterFactory writerFactory = IoFactory.factory(GeometryWriterFactory.class, resource);
    return (GW) writerFactory.newGeometryWriter(resource, properties);
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3