Search in sources :

Example 21 with Resource

use of org.apache.cayenne.resource.Resource in project cayenne by apache.

the class ImportDataMapAction method importDataMap.

protected void importDataMap() {
    File dataMapFile = selectDataMap(Application.getFrame());
    if (dataMapFile == null) {
        return;
    }
    DataMap newMap;
    try {
        URL url = dataMapFile.toURI().toURL();
        DataMapLoader loader = application.getInjector().getInstance(DataMapLoader.class);
        newMap = loader.load(new URLResource(url));
        ConfigurationNode root = getProjectController().getProject().getRootNode();
        newMap.setName(NameBuilder.builder(newMap, root).baseName(newMap.getName()).name());
        Resource baseResource = ((DataChannelDescriptor) root).getConfigurationSource();
        if (baseResource != null) {
            Resource dataMapResource = baseResource.getRelativeResource(nameMapper.configurationLocation(newMap));
            newMap.setConfigurationSource(dataMapResource);
        }
        getProjectController().addDataMap(this, newMap);
    } catch (Exception ex) {
        logObj.info("Error importing DataMap.", ex);
        JOptionPane.showMessageDialog(Application.getFrame(), "Error reading DataMap: " + ex.getMessage(), "Can't Open DataMap", JOptionPane.OK_OPTION);
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) File(java.io.File) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

Resource (org.apache.cayenne.resource.Resource)21 URLResource (org.apache.cayenne.resource.URLResource)13 URL (java.net.URL)11 Test (org.junit.Test)11 Injector (org.apache.cayenne.di.Injector)8 DataMap (org.apache.cayenne.map.DataMap)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)6 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)6 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)5 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)5 File (java.io.File)4 ConfigurationNameMapper (org.apache.cayenne.configuration.ConfigurationNameMapper)4 DefaultConfigurationNameMapper (org.apache.cayenne.configuration.DefaultConfigurationNameMapper)4 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)4 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)4 DIBootstrap (org.apache.cayenne.di.DIBootstrap)4 Module (org.apache.cayenne.di.Module)4 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)4 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)4 Assert (org.junit.Assert)4