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=b537b10f8db4e2c7de6b525265afbde1a2e0bf11;hb=9fda852a4a9e79db45d8d462b4d4fddefa5a89a5;hp=14eda4605e519557e7aa64024a7ede672034d8a9;hpb=99f082643ad18cdac91d4493d0d29c9723692546;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 14eda46..b537b10 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -22,10 +22,6 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.log4j.Logger; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; @@ -40,7 +36,13 @@ import org.splat.manox.XDOM; import org.splat.service.DocumentTypeService; import org.splat.service.KnowledgeElementTypeService; import org.splat.service.SimulationContextTypeService; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +/** + * SIMAN configuration data service. + */ public class ProjectSettingsServiceImpl implements ProjectSettingsService { /** @@ -50,22 +52,57 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { .getLogger(ProjectSettingsServiceImpl.class); // Non persistent configuration information - private Properties reprop; // Repository settings - private String pattern; // Pattern of study references - private FileNaming naming; // Scheme of file names stored into the repository - private String versioning; // Pattern of the presentation of version numbers - private Vector steps; // Ordered list of (transient) study steps - private Vector concycles; // Configuration document validation cycles + /** + * Repository settings. + */ + private final Properties reprop = new Properties(); + /** + * Pattern of study references. + */ + private String pattern; + /** + * Scheme of file names stored into the repository. + */ + private FileNaming naming; + /** + * Pattern of the presentation of version numbers. + */ + private String versioning; + /** + * Ordered list of (transient) study steps. + */ + private final Vector steps = new Vector(); + /** + * Configuration document validation cycles. + */ + private Vector concycles; // Temporary attributes initialized from the configuration file for populating the database with object types - private LinkedHashMap mapuse; // Document type names and uses mapping - private Vector context; // Simulation Context type names - private Vector kname; // Knowledge Element type names - private Vector flows; // Document flows - private Vector sclass; // Study classifications + /** + * Document type names and uses mapping. + */ + private LinkedHashMap mapuse; + /** + * Simulation Context type names. + */ + private Vector context; + /** + * Knowledge Element type names. + */ + private Vector kname; + /** + * Document flows. + */ + private Vector flows; + /** + * Study classifications. + */ + private Vector sclass; // Other resources - private static ProjectSettingsServiceImpl my = null; // Singleton instance + /** + * Database service to check its version, etc. + */ private Database _database; /** * Injected simulation context type service. @@ -84,48 +121,80 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { title, encoded, asis } + /** + * Validation cycle defined in the XML configuration. + */ public static class ProjectSettingsValidationCycle { - // ----------------------------------- - private String name; - private Actor[] actor; - + /** + * Cycle (document) type name. + */ + private final String name; + /** + * Array of cycle actors positions in the organization. TODO: Must be replaced by Roles. + */ + private final Actor[] actor; + + /** + * Default constructor. + */ private ProjectSettingsValidationCycle() { this.name = "built-in"; this.actor = new Actor[] { null, null, null }; } - private ProjectSettingsValidationCycle(String name, Actor[] actor) { + /** + * Create a validation cycle definition for the given document type name and actors positions. + * + * @param name + * the document type name + * @param actor + * the array of actors positions + */ + private ProjectSettingsValidationCycle(final String name, + final Actor[] actor) { this.name = name; this.actor = actor; } + /** + * The processed document type name. + * + * @return the document type name + */ public String getName() { return name; } + /** + * Get an array of cycle actors positions. + * + * @return the array of actors positions + * @see org.splat.dal.bo.som.ValidationCycle.Actor + */ public Actor[] getActorTypes() { return actor; } } - // ============================================================================================================================== - // Construction - // ============================================================================================================================== - protected ProjectSettingsServiceImpl() { - // ---------------------------- - reprop = new Properties(); - steps = new Vector(); - my = this; - } - // ============================================================================================================================== // Public functions // ============================================================================================================================== - public void configure(String filename) throws IOException, SQLException { - // --------------------------------------- - if (!steps.isEmpty()) + /** + * 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 + * @throws IOException + * if there is a file reading or index creation problem + * @throws SQLException + * if there is a database population problem + */ + public void configure(final String filename) throws IOException, + SQLException { + if (!steps.isEmpty()) { return; // Project already configured + } Database base = getDatabase().getCheckedDB(); File config = new File(filename); @@ -143,8 +212,12 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } + /** + * Get ordered list of (transient) study steps. + * + * @return the list of steps from project settings + */ public List getAllSteps() { - // --------------------------------------- return steps; } @@ -154,59 +227,79 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * * @return the validation cycles of the workflow */ - public static List getAllValidationCycles() { - // ------------------------------------------------------------- - return my.concycles; + public List getAllValidationCycles() { + return concycles; } + /** + * Get file naming scheme setting. + * + * @return file naming scheme + * @see org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming + */ public FileNaming getFileNamingScheme() { - // ----------------------------------------------- return naming; } - public static ProjectSettingsValidationCycle getNewValidationCycle() { - // ------------------------------------------------------ - return new ProjectSettingsValidationCycle(); - } - + /** + * Get a pattern of study references. + * + * @return the reference pattern + */ public String getReferencePattern() { return pattern; } + /** + * Get a pattern of the presentation of version numbers. + * + * @return the version numbers presentation pattern + */ public String getRevisionPattern() { - // ------------------------------------------ return versioning; } - public static ProjectSettingsService.Step getStep(int number) { - // --------------------------------------- - for (int i = 0; i < my.steps.size(); i++) { - ProjectSettingsService.Step step = my.steps.get(i); - if (step.number == number) + /** + * Get a study step by its sequential number. + * + * @param number + * the step number + * @return the step + */ + public ProjectSettingsService.Step getStep(final int number) { + for (int i = 0; i < steps.size(); i++) { + ProjectSettingsService.Step step = steps.get(i); + if (step.number == number) { return step; + } } return null; } + /** + * 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( - Class level) { - // --------------------------------------------------------------------------- + final Class level) { Vector result = new Vector(); for (int i = 0; i < steps.size(); i++) { ProjectSettingsService.Step step = steps.get(i); - if (step.appliesTo(level)) + if (step.appliesTo(level)) { result.add(step); + } } return result; } - // ============================================================================================================================== - // Protected member function - // ============================================================================================================================== - - public void initialize() { - // ---------------------------- + /** + * Initialize the database: create all necessary default staff defined in the configuration file. + */ + protected void initialize() { createDocumentTypes(); createSimulationContextTypes(); createKnowledgeElementTypes(); @@ -216,8 +309,13 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { // Private member function // ============================================================================================================================== - private void loadCustomization(File config) { - // -------------------------------------------- + /** + * Read the configuration file and fill transient project settings fields. + * + * @param config + * the configuration XML file + */ + private void loadCustomization(final File config) { try { DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory .newInstance(); @@ -233,8 +331,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { String disk = datag.get("repository").getAttributes().getNamedItem( "disk").getNodeValue(); - if (!disk.endsWith("/")) + if (!disk.endsWith("/")) { disk = disk + "/"; + } logger.info("Database root set to " + disk); reprop.setProperty("repository", disk); @@ -266,8 +365,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { NodeList slist = child.getChildNodes(); for (int j = 0; j < slist.getLength(); j++) { child = slist.item(j); - if (!child.getNodeName().equals("step")) + if (!child.getNodeName().equals("step")) { continue; + } HashMap tags = XDOM .getNamedChildNodes(child); @@ -280,14 +380,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { natr = tags.get("flow").getAttributes(); flist.add(natr); child = natr.getNamedItem("result"); - if (child != null) + if (child != null) { resultype.add(child.getNodeValue()); + } child = tags.get("classification"); - if (child != null) + if (child != null) { clist.add(child.getAttributes()); - else + } else { clist.add(null); + } if (natr.getNamedItem("contents").getNodeValue() .equals("knowledge")) { @@ -300,8 +402,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { snum += 1; } } else { - if (!child.getNodeName().equals("step")) + if (!child.getNodeName().equals("step")) { continue; + } HashMap tags = XDOM.getNamedChildNodes(child); natr = tags.get("storage").getAttributes(); // Mandatory information @@ -313,14 +416,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { natr = tags.get("flow").getAttributes(); flist.add(natr); child = natr.getNamedItem("result"); - if (child != null) + if (child != null) { resultype.add(child.getNodeValue()); + } child = tags.get("classification"); // Optional information - if (child != null) + if (child != null) { clist.add(child.getAttributes()); - else + } else { clist.add(null); + } if (natr.getNamedItem("contents").getNodeValue().equals( "knowledge")) { @@ -343,21 +448,24 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { Actor[] actor = { null, null, null }; String name = i.next(); child = datag.get(name); - if (child == null) + if (child == null) { continue; // Document type not subject of any validation + } natr = child.getAttributes(); for (int j = 0; j < step.length; j++) { child = natr.getNamedItem(step[j]); - if (child == null) + if (child == null) { continue; // Validation step not required + } actor[j] = Actor.valueOf(child.getNodeValue()); } concycles.add(new ProjectSettingsValidationCycle(name, actor)); } concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle - if (getDatabase().getCheckedDB().isInitialized()) + if (getDatabase().getCheckedDB().isInitialized()) { return; // No need to load object type definitions as they are already stored + } // Documents tag child = children.get("documents"); @@ -368,15 +476,17 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { mapuse = new LinkedHashMap(); for (int i = 0; i < nlist.getLength(); i++) { child = nlist.item(i); - if (!child.getNodeName().equals("article")) + if (!child.getNodeName().equals("article")) { continue; + } natr = child.getAttributes(); String type = natr.getNamedItem("type").getNodeValue(); String uses = null; child = natr.getNamedItem("uses"); - if (child != null) + if (child != null) { uses = child.getNodeValue(); + } mapuse.put(type, uses); // Must be added to the map even if no (null) uses } // Simulation Contexts tag @@ -386,8 +496,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { context = new Vector(); for (int i = 0; i < nlist.getLength(); i++) { child = nlist.item(i); - if (!child.getNodeName().equals("article")) + if (!child.getNodeName().equals("article")) { continue; + } context.add(child.getAttributes().getNamedItem("type") .getNodeValue()); @@ -399,8 +510,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { kname = new Vector(); for (int i = 0; i < nlist.getLength(); i++) { child = nlist.item(i); - if (!child.getNodeName().equals("article")) + if (!child.getNodeName().equals("article")) { continue; + } kname.add(child.getAttributes().getNamedItem("type") .getNodeValue()); @@ -410,8 +522,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } + /** + * Create in the database document types defined in the custom configuration. + */ private void createDocumentTypes() { - // ----------------------------------- DocumentType.Properties tprop = new DocumentType.Properties(); HashMap> mapsteps = new HashMap>(); HashMap mapresult = new HashMap(); @@ -433,14 +547,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { continue; } slist = mapsteps.get(type); - if (slist == null) + if (slist == null) { slist = new Vector(); + } slist.add(step); mapsteps.put(type, slist); } Node result = flow.getNamedItem("result"); - if (result != null) + if (result != null) { mapresult.put(result.getNodeValue(), step); + } } try { DocumentType tdoc = null; @@ -458,15 +574,17 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { .size()])); if (uses != null) { tdoc = maptype.get(uses); - if (tdoc == null) + if (tdoc == null) { logger .warn("Undefined \"" + uses + "\" document type."); - else + } else { tprop.setUses(tdoc); + } } - if (step != null) + if (step != null) { tprop.setResult(step); + } tprop.disableCheck(); tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types @@ -478,8 +596,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } + /** + * Create in the database knowledge types defined in the custom configuration. + */ private void createKnowledgeElementTypes() { - // ------------------------------------------- try { KnowledgeElementType ktype = getKnowledgeElementTypeService() .createType("usecase"); // Internal reserved knowledge element type @@ -495,14 +615,17 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } + /** + * Create in the database simulation contexts types defined in the custom configuration. + */ private void createSimulationContextTypes() { - // -------------------------------------------- HashMap mapstep = new HashMap(); int snum = 0; for (Iterator i = sclass.iterator(); i.hasNext(); snum++) { NamedNodeMap clatr = i.next(); - if (clatr == null) + if (clatr == null) { continue; + } String[] clist = clatr.getNamedItem("context").getNodeValue() .split(","); @@ -545,7 +668,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * @param database * the database to set */ - public void setDatabase(Database database) { + public void setDatabase(final Database database) { _database = database; } @@ -565,7 +688,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * the simulationContextTypeService to set */ public void setSimulationContextTypeService( - SimulationContextTypeService simulationContextTypeService) { + final SimulationContextTypeService simulationContextTypeService) { _simulationContextTypeService = simulationContextTypeService; } @@ -585,12 +708,13 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * the knowledgeElementTypeService to set */ public void setKnowledgeElementTypeService( - KnowledgeElementTypeService knowledgeElementTypeService) { + final KnowledgeElementTypeService knowledgeElementTypeService) { _knowledgeElementTypeService = knowledgeElementTypeService; } /** * Get the documentTypeService. + * * @return the documentTypeService */ public DocumentTypeService getDocumentTypeService() { @@ -599,9 +723,12 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { /** * Set the documentTypeService. - * @param documentTypeService the documentTypeService to set + * + * @param documentTypeService + * the documentTypeService to set */ - public void setDocumentTypeService(DocumentTypeService documentTypeService) { + public void setDocumentTypeService( + final DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } } \ No newline at end of file