SaveUnit createSaveUnit(ConfigurationNode node, Resource baseResource) { SaveUnit unit = new SaveUnit(); unit.node = node; unit.sourceConfiguration = node.acceptVisitor(resourceGetter); String targetLocation = nameMapper.configurationLocation(node); Resource targetResource = baseResource.getRelativeResource(targetLocation); if (unit.sourceConfiguration == null) { unit.sourceConfiguration = targetResource; } // attempt to convert targetResource to a File... if that fails, // FileProjectSaver is not appropriate for handling a given project.. URL targetUrl = targetResource.getURL(); try { unit.targetFile = Util.toFile(targetUrl); } catch (IllegalArgumentException e) { throw new CayenneRuntimeException("Can't save configuration to the following location: '%s'. " + "Is this a valid file location?. (%s)", e, targetUrl, e.getMessage()); } return unit; }
descriptor.setName(nameMapper.configurationNodeName(DataChannelDescriptor.class, configurationResource));
protected void importDataMap() { File dataMapFile = selectDataMap(Application.getFrame()); if (dataMapFile == null) { return; } DataMap newMap; try { URL url = dataMapFile.toURI().toURL(); try (InputStream in = url.openStream();) { InputSource inSrc = new InputSource(in); inSrc.setSystemId(dataMapFile.getAbsolutePath()); newMap = new MapLoader().loadDataMap(inSrc); } 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); } }
Resource baseResource = descriptor.getConfigurationSource(); String dataMapLocation = nameMapper.configurationLocation(DataMap.class, dataMapName);
@Override public void save(Project project) { DataMap dataMap = (DataMap) project.getRootNode(); if (projectController.getCurrentDataMap() != null) { projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.REMOVE)); projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.ADD)); } else { DataChannelDescriptor currentDomain = (DataChannelDescriptor) projectController.getProject().getRootNode(); Resource baseResource = currentDomain.getConfigurationSource(); // a new DataMap, so need to set configuration source for it if (baseResource != null) { Resource dataMapResource = baseResource.getRelativeResource(nameMapper.configurationLocation(dataMap)); dataMap.setConfigurationSource(dataMapResource); } projectController.addDataMap(Application.getFrame(), dataMap); } }