X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Workspace%2FSiman-Common%2Fsrc%2Forg%2Fsplat%2Fservice%2Ftechnical%2FProjectSettingsServiceImpl.java;fp=Workspace%2FSiman-Common%2Fsrc%2Forg%2Fsplat%2Fservice%2Ftechnical%2FProjectSettingsServiceImpl.java;h=f079a5afd2c5a16ebbccebaf452e1163e50dc286;hb=c46cc52d33ba94d0b6776ff8c1e1f744b0ed2cab;hp=88a779e22122e348703cf7650dd2e55a16fa29d8;hpb=7251198e4f5cf1bedbaa320e2b5cefbb03400b3e;p=tools%2Fsiman.git diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java index 88a779e..f079a5a 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -37,6 +37,9 @@ import org.splat.manox.XDOM; import org.splat.service.DocumentTypeService; import org.splat.service.KnowledgeElementTypeService; import org.splat.service.SimulationContextTypeService; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; import org.springframework.transaction.annotation.Transactional; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -46,7 +49,8 @@ import org.w3c.dom.NodeList; /** * SIMAN workflow configuration data service. */ -public class ProjectSettingsServiceImpl implements ProjectSettingsService { +public class ProjectSettingsServiceImpl implements ProjectSettingsService, + ResourceLoaderAware { /** * The logger for the service. @@ -59,6 +63,20 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { */ private final static String TYPE_ATTR = "type"; + /** + * Steps configuration storage. + */ + private StepsConfigService _stepsConfigService; + /** + * Resource loader injected by Spring. + */ + private ResourceLoader _resourceLoader; + + /** + * Configuration resource injected by Spring. + */ + private Resource _config; + // Non persistent configuration information /** * Repository settings. @@ -76,10 +94,6 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * Pattern of the presentation of version numbers. */ private transient String _versioning; - /** - * Ordered list of (transient) study steps. - */ - private transient final List _steps = new ArrayList(); /** * Configuration document validation cycles. */ @@ -217,7 +231,24 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { // ============================================================================================================================== /** - * Load workflow configuration from the given file.
Create necessary default staff in the database if it is not initialized yet. + * Load workflow configuration from the file defined by config property.
+ * Create necessary default staff in the database if it is not initialized yet. + * + * @throws IOException + * if there is a file reading or index creation problem + * @throws SQLException + * if there is a database population problem + */ + @Transactional + public void configure() throws IOException, SQLException { + if (getConfig() != null) { + configure("file:" + getConfig().getFile().getAbsolutePath()); + } + } + + /** + * Load workflow configuration from the given file.
+ * Create necessary default staff in the database if it is not initialized yet. * * @param filename * the workflow configuration file @@ -229,12 +260,17 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { @Transactional public void configure(final String filename) throws IOException, SQLException { - if (!_steps.isEmpty()) { + if (!getStepsConfigService().getSteps().isEmpty()) { return; // Project already configured } Database base = getDatabase().getCheckedDB(); - File config = new File(filename); + if (LOG.isInfoEnabled()) { + LOG.info("Loading configuration from: " + + getResource(filename).getFile().getAbsolutePath()); + LOG.info("Root: " + getResource("/").getURI()); + } + File config = getResource(filename).getFile(); if (config.exists()) { loadCustomization(config); } else { @@ -255,7 +291,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * @return the list of steps from project settings */ public List getAllSteps() { - return _steps; + return getStepsConfigService().getSteps(); } /** @@ -305,8 +341,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { */ public ProjectSettingsService.Step getStep(final int number) { ProjectSettingsService.Step res = null; - for (int i = 0; i < _steps.size(); i++) { - ProjectSettingsService.Step step = _steps.get(i); + for (int i = 0; i < getStepsConfigService().getSteps().size(); i++) { + ProjectSettingsService.Step step = getStepsConfigService() + .getSteps().get(i); if (step.getNumber() == number) { res = step; break; @@ -315,26 +352,6 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { return res; } - /** - * Get steps of the given project element (study or scenario). - * - * @param level - * the project element (study or scenario) - * @return the list of steps - */ - public List getStepsOf( - final Class level) { - List result = new ArrayList(); - - for (int i = 0; i < _steps.size(); i++) { - ProjectSettingsService.Step step = _steps.get(i); - if (step.appliesTo(level)) { - result.add(step); - } - } - return result; - } - /** * Check if a file of the given format should be imported during check-out of a document of the given type. * @@ -679,7 +696,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { step.setModule(module.getAttribute("name")); } - _steps.add(step); + getStepsConfigService().getSteps().add(step); res += 1; } return res; @@ -764,7 +781,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { String uses = null; for (Iterator i = _flows.iterator(); i.hasNext(); snum++) { NamedNodeMap flow = i.next(); - ProjectSettingsService.Step step = _steps.get(snum); + ProjectSettingsService.Step step = getStepsConfigService() + .getSteps().get(snum); String[] contents = flow.getNamedItem("contents").getNodeValue() .split(","); for (int j = 0; j < contents.length; j++) { @@ -804,7 +822,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { // Parse uses attribute String[] usesArr = uses.split(","); List usesTypesList = new ArrayList(); - for (String usesType: usesArr) { + for (String usesType : usesArr) { tdoc = maptype.get(usesType.trim()); if (tdoc == null) { LOG.warn("Undefined \"" + usesType.trim() @@ -815,7 +833,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } } - tprop.setUses(usesTypesList.toArray(new DocumentType[]{})); + tprop.setUses(usesTypesList + .toArray(new DocumentType[] {})); } if (step != null) { tprop.setResult(step); @@ -876,7 +895,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { String[] clist = clatr.getNamedItem("context").getNodeValue() .split(","); for (int j = 0; j < clist.length; j++) { - mapstep.put(clist[j], _steps.get(snum)); + mapstep.put(clist[j], getStepsConfigService().getSteps() + .get(snum)); } } } @@ -978,4 +998,64 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { final DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } + + /** + * {@inheritDoc} + * + * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader) + */ + @Override + public void setResourceLoader(final ResourceLoader resourceLoader) { + this._resourceLoader = resourceLoader; + } + + /** + * Get resource by means of Spring resource loader. + * + * @param location + * the resource location + * @return the resource + */ + public Resource getResource(final String location) { + return _resourceLoader.getResource(location); + } + + /** + * Get the config. + * + * @return the config + */ + public Resource getConfig() { + return _config; + } + + /** + * Set the config. + * + * @param config + * the config to set + */ + public void setConfig(final Resource config) { + _config = config; + } + + /** + * Get the stepsConfigService. + * + * @return the stepsConfigService + */ + public StepsConfigService getStepsConfigService() { + return _stepsConfigService; + } + + /** + * Set the stepsConfigService. + * + * @param stepsConfigService + * the stepsConfigService to set + */ + public void setStepsConfigService( + final StepsConfigService stepsConfigService) { + _stepsConfigService = stepsConfigService; + } } \ No newline at end of file