]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / technical / ProjectSettingsServiceImpl.java
index 35b0665518eb483d994f2151469d702cdc2f98b5..3d0a6e0b245f4448715d4be5b0b91f5ddfbc66e5 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.service.technical;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -37,434 +38,520 @@ import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.ValidationCycle.Actor;
 import org.splat.dal.dao.som.Database;
 import org.splat.manox.XDOM;
-
+import org.splat.service.SimulationContextService;
 
 public class ProjectSettingsServiceImpl implements ProjectSettingsService {
 
-//  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<ProjectSettingsService.Step>                          steps;        // Ordered list of (transient) study steps
-       private  Vector<ProjectSettingsValidationCycle>               concycles;    // Configuration document validation cycles
-
-//  Temporary attributes initialized from the configuration file for populating the database with object types
-    private  LinkedHashMap<String,String>          mapuse;       // Document type names and uses mapping
-    private  Vector<String>                        context;      // Simulation Context type names
-    private  Vector<String>                        kname;        // Knowledge Element type names
-    private  Vector<NamedNodeMap>                  flows;        // Document flows
-    private  Vector<NamedNodeMap>                  sclass;       // Study classifications
-
-//  Other resources
-       private         static ProjectSettingsServiceImpl  my     = null;       // Singleton instance
+       // 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<ProjectSettingsService.Step> steps; // Ordered list of (transient) study steps
+       private Vector<ProjectSettingsValidationCycle> concycles; // Configuration document validation cycles
+
+       // Temporary attributes initialized from the configuration file for populating the database with object types
+       private LinkedHashMap<String, String> mapuse; // Document type names and uses mapping
+       private Vector<String> context; // Simulation Context type names
+       private Vector<String> kname; // Knowledge Element type names
+       private Vector<NamedNodeMap> flows; // Document flows
+       private Vector<NamedNodeMap> sclass; // Study classifications
+
+       // Other resources
+       private static ProjectSettingsServiceImpl my = null; // Singleton instance
        private Database _database;
-    protected final static Logger           logger = Logger.getLogger(ProjectSettingsServiceImpl.class);
+       /**
+        * Injected simulation context service.
+        */
+       private SimulationContextService _simulationContextService;
+       protected final static Logger logger = Logger
+                       .getLogger(ProjectSettingsServiceImpl.class);
+
+       public enum FileNaming {
+               title, encoded, asis
+       }
 
-    public enum FileNaming { title, encoded, asis }
        public static class ProjectSettingsValidationCycle {
-//  -----------------------------------
-      private String  name;
-      private Actor[] actor;
-
-      private ProjectSettingsValidationCycle () {
-       this.name  = "built-in";
-       this.actor = new Actor[] { null, null, null };
-      }
-      private ProjectSettingsValidationCycle (String name, Actor[] actor) {
-        this.name  = name;
-        this.actor = actor;
-      }
-      public String getName () {
-        return name;
-      }
-      public Actor[] getActorTypes () {
-        return actor;
-      }
-    }
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-       protected ProjectSettingsServiceImpl () {
-//  ----------------------------
-         reprop = new Properties();
-      steps  = new Vector<ProjectSettingsService.Step>();
-      my = this;
-       }       
-    
-//  ==============================================================================================================================
-//  Public functions
-//  ==============================================================================================================================
-
-       public void configure (String filename) throws IOException, SQLException {
-//  ---------------------------------------
-      if (!steps.isEmpty()) return;       // Project already configured
-
-      Database base   = getDatabase().getMe();
-         File     config = new File(filename);
-         if  (config.exists()) {
-        loadCustomization(config);
-         } else {
-        logger.fatal("Could not find the database configuration file \"" + config.getAbsolutePath() + "\"");
-        throw new FileNotFoundException();
-         }
-         base.configure(reprop);
-      if (!base.isInitialized()) {
-        base.initialize();
-        initialize();   // Populates the database with all necessary stuff
-      }
+               // -----------------------------------
+               private String name;
+               private Actor[] actor;
+
+               private ProjectSettingsValidationCycle() {
+                       this.name = "built-in";
+                       this.actor = new Actor[] { null, null, null };
+               }
+
+               private ProjectSettingsValidationCycle(String name, Actor[] actor) {
+                       this.name = name;
+                       this.actor = actor;
+               }
+
+               public String getName() {
+                       return name;
+               }
+
+               public Actor[] getActorTypes() {
+                       return actor;
+               }
        }
 
-    public List<ProjectSettingsService.Step> getAllSteps () {
-//  ---------------------------------------
-      return steps;
-    }
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
+       protected ProjectSettingsServiceImpl() {
+               // ----------------------------
+               reprop = new Properties();
+               steps = new Vector<ProjectSettingsService.Step>();
+               my = this;
+       }
+
+       // ==============================================================================================================================
+       // Public functions
+       // ==============================================================================================================================
+
+       public void configure(String filename) throws IOException, SQLException {
+               // ---------------------------------------
+               if (!steps.isEmpty())
+                       return; // Project already configured
+
+               Database base = getDatabase().getMe();
+               File config = new File(filename);
+               if (config.exists()) {
+                       loadCustomization(config);
+               } else {
+                       logger.fatal("Could not find the database configuration file \""
+                                       + config.getAbsolutePath() + "\"");
+                       throw new FileNotFoundException();
+               }
+               base.configure(reprop);
+               if (!base.isInitialized()) {
+                       base.initialize();
+                       initialize(); // Populates the database with all necessary stuff
+               }
+       }
+
+       public List<ProjectSettingsService.Step> getAllSteps() {
+               // ---------------------------------------
+               return steps;
+       }
+
+       /**
+        * Return the validation cycles of result documents defined in the workflow, ordered by study activities and ending by the default
+        * validation cycle, if defined.
+        * 
+        * @return the validation cycles of the workflow
+        */
+       public static List<ProjectSettingsValidationCycle> getAllValidationCycles() {
+               // -------------------------------------------------------------
+               return my.concycles;
+       }
+
+       public FileNaming getFileNamingScheme() {
+               // -----------------------------------------------
+               return naming;
+       }
+
+       public static ProjectSettingsValidationCycle getNewValidationCycle() {
+               // ------------------------------------------------------
+               return new ProjectSettingsValidationCycle();
+       }
+
+       public String getReferencePattern() {
+               return 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)
+                               return step;
+               }
+               return null;
+       }
+
+       public List<ProjectSettingsService.Step> getStepsOf(
+                       Class<? extends ProjectElement> level) {
+               // ---------------------------------------------------------------------------
+               Vector<ProjectSettingsService.Step> result = new Vector<ProjectSettingsService.Step>();
+
+               for (int i = 0; i < steps.size(); i++) {
+                       ProjectSettingsService.Step step = steps.get(i);
+                       if (step.appliesTo(level))
+                               result.add(step);
+               }
+               return result;
+       }
+
+       // ==============================================================================================================================
+       // Protected member function
+       // ==============================================================================================================================
+
+       public void initialize() {
+               // ----------------------------
+               createDocumentTypes();
+               createSimulationContextTypes();
+               createKnowledgeElementTypes();
+       }
+
+       // ==============================================================================================================================
+       // Private member function
+       // ==============================================================================================================================
+
+       private void loadCustomization(File config) {
+               // --------------------------------------------
+               try {
+                       DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
+                                       .newInstance();
+                       DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
+
+                       org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
+                       HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
+                                       .getDocumentElement());
+
+                       // Repository tag initializing the reprop attribute
+                       Node child = children.get("database");
+                       HashMap<String, Node> datag = XDOM.getNamedChildNodes(child);
+
+                       String disk = datag.get("repository").getAttributes().getNamedItem(
+                                       "disk").getNodeValue();
+                       if (!disk.endsWith("/"))
+                               disk = disk + "/";
+                       logger.info("Database root set to " + disk);
+                       reprop.setProperty("repository", disk);
+
+                       // Formats tag initializing the reference pattern and date attributes
+                       child = children.get("formats");
+                       datag = XDOM.getNamedChildNodes(child);
+
+                       NamedNodeMap natr = datag.get("references").getAttributes();
+                       pattern = natr.getNamedItem("study").getNodeValue();
+
+                       natr = datag.get("files").getAttributes();
+                       naming = FileNaming.valueOf(natr.getNamedItem("name")
+                                       .getNodeValue());
+
+                       natr = datag.get("versions").getAttributes();
+                       versioning = natr.getNamedItem("pattern").getNodeValue();
+
+                       // Activities tag initializing the steps and rex attributes
+                       child = children.get("activities");
+                       NodeList nlist = child.getChildNodes();
+                       Vector<NamedNodeMap> flist = new Vector<NamedNodeMap>();
+                       Vector<String> resultype = new Vector<String>();
+                       Vector<NamedNodeMap> clist = new Vector<NamedNodeMap>();
+
+                       int snum = 1; // Base number of steps
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (child.getNodeName().equals("scenario")) {
+                                       NodeList slist = child.getChildNodes();
+                                       for (int j = 0; j < slist.getLength(); j++) {
+                                               child = slist.item(j);
+                                               if (!child.getNodeName().equals("step"))
+                                                       continue;
+                                               HashMap<String, Node> tags = XDOM
+                                                               .getNamedChildNodes(child);
+
+                                               natr = tags.get("storage").getAttributes();
+                                               ProjectSettingsService.Step step = new ProjectSettingsService.Step(
+                                                               snum, Scenario.class, natr.getNamedItem("path")
+                                                                               .getNodeValue());
+
+                                               // Keeping flow and classification information for eventual later use
+                                               natr = tags.get("flow").getAttributes();
+                                               flist.add(natr);
+                                               child = natr.getNamedItem("result");
+                                               if (child != null)
+                                                       resultype.add(child.getNodeValue());
+
+                                               child = tags.get("classification");
+                                               if (child != null)
+                                                       clist.add(child.getAttributes());
+                                               else
+                                                       clist.add(null);
+
+                                               if (natr.getNamedItem("contents").getNodeValue()
+                                                               .equals("knowledge")) {
+                                                       // TODO In a given scenario, only one step must contain knowledges
+                                                       step.contents.add(KnowledgeElement.class);
+                                               } else {
+                                                       step.contents.add(Document.class);
+                                               }
+                                               steps.add(step);
+                                               snum += 1;
+                                       }
+                               } else {
+                                       if (!child.getNodeName().equals("step"))
+                                               continue;
+                                       HashMap<String, Node> tags = XDOM.getNamedChildNodes(child);
+
+                                       natr = tags.get("storage").getAttributes(); // Mandatory information
+                                       ProjectSettingsService.Step step = new ProjectSettingsService.Step(
+                                                       snum, Study.class, natr.getNamedItem("path")
+                                                                       .getNodeValue());
+
+                                       // Keeping flow and classification information for eventual later use
+                                       natr = tags.get("flow").getAttributes();
+                                       flist.add(natr);
+                                       child = natr.getNamedItem("result");
+                                       if (child != null)
+                                               resultype.add(child.getNodeValue());
+
+                                       child = tags.get("classification"); // Optional information
+                                       if (child != null)
+                                               clist.add(child.getAttributes());
+                                       else
+                                               clist.add(null);
+
+                                       if (natr.getNamedItem("contents").getNodeValue().equals(
+                                                       "knowledge")) {
+                                               // TODO Error: knowledges must be attached to scenarios
+                                       } else {
+                                               step.contents.add(Document.class);
+                                       }
+                                       steps.add(step);
+                                       snum += 1;
+                               }
+                       }
+                       // Validations tag
+                       child = children.get("validations");
+                       concycles = new Vector<ProjectSettingsValidationCycle>();
+                       datag = XDOM.getNamedChildNodes(child);
+
+                       String[] step = { "review", "approval", "acceptance" };
+                       resultype.add("default");
+                       for (Iterator<String> i = resultype.iterator(); i.hasNext();) {
+                               Actor[] actor = { null, null, null };
+                               String name = i.next();
+                               child = datag.get(name);
+                               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)
+                                               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().getMe().isInitialized())
+                               return; // No need to load object type definitions as they are already stored
+
+                       // Documents tag
+                       child = children.get("documents");
+                       nlist = child.getChildNodes();
+
+                       flows = flist; // Kept for later use in document type definition
+                       sclass = clist; // Kept for later use in simulation context type definition
+                       mapuse = new LinkedHashMap<String, String>();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               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)
+                                       uses = child.getNodeValue();
+                               mapuse.put(type, uses); // Must be added to the map even if no (null) uses
+                       }
+                       // Simulation Contexts tag
+                       child = children.get("contexts");
+                       nlist = child.getChildNodes();
+
+                       context = new Vector<String>();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("article"))
+                                       continue;
+
+                               context.add(child.getAttributes().getNamedItem("type")
+                                               .getNodeValue());
+                       }
+                       // Knowledge Elements tag
+                       child = children.get("knowledges");
+                       nlist = child.getChildNodes();
+
+                       kname = new Vector<String>();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("article"))
+                                       continue;
+
+                               kname.add(child.getAttributes().getNamedItem("type")
+                                               .getNodeValue());
+                       }
+               } catch (Exception error) {
+                       logger.info("Error in customization", error);
+               }
+       }
+
+       private void createDocumentTypes() {
+               // -----------------------------------
+               DocumentType.Properties tprop = new DocumentType.Properties();
+               HashMap<String, Vector<ProjectSettingsService.Step>> mapsteps = new HashMap<String, Vector<ProjectSettingsService.Step>>();
+               HashMap<String, ProjectSettingsService.Step> mapresult = new HashMap<String, ProjectSettingsService.Step>();
+               HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+
+               Vector<ProjectSettingsService.Step> slist = null; // List of Steps to which each document type is valid
+               int snum = 0; // Step number
+               String type = null;
+               String uses = null;
+               for (Iterator<NamedNodeMap> i = flows.iterator(); i.hasNext(); snum++) {
+                       NamedNodeMap flow = i.next();
+                       ProjectSettingsService.Step step = steps.get(snum);
+                       String[] contents = flow.getNamedItem("contents").getNodeValue()
+                                       .split(",");
+                       for (int j = 0; j < contents.length; j++) {
+                               type = contents[j];
+                               if (!mapuse.containsKey(type)) {
+                                       logger.warn("Undefined \"" + type + "\" document type.");
+                                       continue;
+                               }
+                               slist = mapsteps.get(type);
+                               if (slist == null)
+                                       slist = new Vector<ProjectSettingsService.Step>();
+                               slist.add(step);
+                               mapsteps.put(type, slist);
+                       }
+                       Node result = flow.getNamedItem("result");
+                       if (result != null)
+                               mapresult.put(result.getNodeValue(), step);
+               }
+               try {
+                       DocumentType tdoc = null;
+                       Set<String> tset = mapuse.keySet();
+                       ProjectSettingsService.Step step;
+                       for (Iterator<String> i = tset.iterator(); i.hasNext();) {
+                               type = i.next();
+                               slist = mapsteps.get(type);
+                               uses = mapuse.get(type);
+                               step = mapresult.get(type);
+
+                               tprop.clear();
+                               tprop.setName(type).setStep(
+                                               slist.toArray(new ProjectSettingsService.Step[slist
+                                                               .size()]));
+                               if (uses != null) {
+                                       tdoc = maptype.get(uses);
+                                       if (tdoc == null)
+                                               logger
+                                                               .warn("Undefined \"" + uses
+                                                                               + "\" document type.");
+                                       else
+                                               tprop.setUses(tdoc);
+                               }
+                               if (step != null)
+                                       tprop.setResult(step);
+
+                               tprop.disableCheck();
+                               tdoc = Document.createType(tprop); // Creation of Document Types
+                               tdoc.approve();
+                               maptype.put(type, tdoc);
+                       }
+               } catch (Exception error) {
+                       logger.warn("Error creating document types, reason:", error); // Should not happen
+               }
+       }
+
+       private void createKnowledgeElementTypes() {
+               // -------------------------------------------
+               try {
+                       KnowledgeElementType ktype = KnowledgeElement.createType("usecase"); // Internal reserved knowledge element type
+                       ktype.reserve();
+                       for (Iterator<String> i = kname.iterator(); i.hasNext();) {
+                               String type = i.next();
+
+                               ktype = KnowledgeElement.createType(type); // Knowledge Elements Types defined in the configuration
+                               ktype.approve();
+                       }
+               } catch (Exception error) {
+                       logger.warn("Error creating knowledge types, reason:", error); // Should not happen
+               }
+       }
+
+       private void createSimulationContextTypes() {
+               // --------------------------------------------
+               HashMap<String, ProjectSettingsService.Step> mapstep = new HashMap<String, ProjectSettingsService.Step>();
+               int snum = 0;
+               for (Iterator<NamedNodeMap> i = sclass.iterator(); i.hasNext(); snum++) {
+                       NamedNodeMap clatr = i.next();
+                       if (clatr == null)
+                               continue;
+
+                       String[] clist = clatr.getNamedItem("context").getNodeValue()
+                                       .split(",");
+                       for (int j = 0; j < clist.length; j++) {
+                               mapstep.put(clist[j], steps.get(snum));
+                       }
+               }
+               try {
+                       SimulationContextType tctex = null;
+                       for (Iterator<String> i = context.iterator(); i.hasNext();) {
+                               String type = i.next();
+                               if (!mapstep.containsKey(type)) {
+                                       logger
+                                                       .warn("Could not find \""
+                                                                       + type
+                                                                       + "\" classification. Simulation Context type ignored.");
+                                       continue;
+                               }
+                               tctex = getSimulationContextService().createType(type,
+                                               mapstep.get(type)); // Creation of Simulation Context Types
+                               tctex.approve();
+                       }
+               } catch (Exception error) {
+                       logger.warn("Error creating context types, reason:", error); // Should not happen
+               }
+       }
 
-/**
- * Return the validation cycles of result documents defined in the workflow, ordered by study activities
- * and ending by the default validation cycle, if defined.
- * 
- * @return the validation cycles of the workflow
- */
-    public static List<ProjectSettingsValidationCycle> getAllValidationCycles () {
-//  -------------------------------------------------------------
-      return my.concycles;
-    }
-
-    public FileNaming getFileNamingScheme () {
-//  -----------------------------------------------
-      return naming;
-    }
-
-    public static ProjectSettingsValidationCycle getNewValidationCycle () {
-//  ------------------------------------------------------
-      return  new ProjectSettingsValidationCycle();
-    }
-
-    public String getReferencePattern () {
-      return 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)  return step;
-      }
-      return null;
-    }
-
-       public List<ProjectSettingsService.Step> getStepsOf (Class<? extends ProjectElement> level) {
-//  ---------------------------------------------------------------------------
-      Vector<ProjectSettingsService.Step> result = new Vector<ProjectSettingsService.Step>();
-      
-      for (int i=0; i<steps.size(); i++) {
-       ProjectSettingsService.Step step = steps.get(i);
-        if  (step.appliesTo(level)) result.add(step);         
-      }
-      return result;
-    }
-
-//  ==============================================================================================================================
-//  Protected member function
-//  ==============================================================================================================================
-
-    public void initialize () {
-//  ----------------------------
-      createDocumentTypes();
-      createSimulationContextTypes();
-      createKnowledgeElementTypes();
-    }
-
-//  ==============================================================================================================================
-//  Private member function
-//  ==============================================================================================================================
-    
-    private void loadCustomization (File config) {
-//  --------------------------------------------
-      try {
-        DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
-        DocumentBuilder        dBuilder = dfactory.newDocumentBuilder();
-        
-        org.w3c.dom.Document   conf     = dBuilder.parse(config.getPath());
-        HashMap<String, Node>  children = XDOM.getNamedChildNodes(conf.getDocumentElement());
-
-//      Repository tag initializing the reprop attribute
-        Node                   child = children.get("database");
-        HashMap<String, Node>  datag = XDOM.getNamedChildNodes(child);
-
-        String disk = datag.get("repository").getAttributes().getNamedItem("disk").getNodeValue();
-        if (!disk.endsWith("/")) disk = disk + "/";
-        logger.info("Database root set to " + disk);
-        reprop.setProperty("repository", disk);
-
-//      Formats tag initializing the reference pattern and date attributes
-        child = children.get("formats");
-        datag = XDOM.getNamedChildNodes(child);
-
-        NamedNodeMap natr = datag.get("references").getAttributes();
-        pattern    = natr.getNamedItem("study").getNodeValue();
-        
-        natr       = datag.get("files").getAttributes();
-        naming     = FileNaming.valueOf(natr.getNamedItem("name").getNodeValue());
-        
-        natr       = datag.get("versions").getAttributes();
-        versioning = natr.getNamedItem("pattern").getNodeValue();
-
-//      Activities tag initializing the steps and rex attributes
-                               child     = children.get("activities");
-        NodeList               nlist     = child.getChildNodes();
-        Vector<NamedNodeMap>   flist     = new Vector<NamedNodeMap>();
-        Vector<String>         resultype = new Vector<String>();
-        Vector<NamedNodeMap>   clist     = new Vector<NamedNodeMap>();
-
-        int snum = 1;                                        // Base number of steps
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (child.getNodeName().equals("scenario")) {
-               NodeList slist = child.getChildNodes();
-            for (int j=0; j<slist.getLength(); j++) {
-              child = slist.item(j);
-              if (!child.getNodeName().equals("step")) continue;
-              HashMap<String, Node>  tags = XDOM.getNamedChildNodes(child);
-
-              natr = tags.get("storage").getAttributes();
-              ProjectSettingsService.Step step = new ProjectSettingsService.Step(snum, Scenario.class, natr.getNamedItem("path").getNodeValue());
-
-//            Keeping flow and classification information for eventual later use
-              natr = tags.get("flow").getAttributes();
-              flist.add(natr);              
-              child = natr.getNamedItem("result");
-              if (child != null) resultype.add(child.getNodeValue());
-
-              child = tags.get("classification");
-              if (child != null) clist.add( child.getAttributes() );
-              else               clist.add( null );
-
-              if (natr.getNamedItem("contents").getNodeValue().equals("knowledge")) {
-//TODO            In a given scenario, only one step must contain knowledges
-                 step.contents.add(KnowledgeElement.class);
-              } else {
-               step.contents.add(Document.class);
-              }
-              steps.add(step);
-              snum += 1;
-            }
-          } else {
-            if (!child.getNodeName().equals("step")) continue;
-            HashMap<String, Node>  tags = XDOM.getNamedChildNodes(child);
-
-            natr = tags.get("storage").getAttributes();      // Mandatory information
-            ProjectSettingsService.Step step = new ProjectSettingsService.Step(snum, Study.class, natr.getNamedItem("path").getNodeValue());
-
-//          Keeping flow and classification information for eventual later use
-            natr = tags.get("flow").getAttributes();
-            flist.add(natr);              
-            child = natr.getNamedItem("result");
-            if (child != null) resultype.add(child.getNodeValue());
-
-            child = tags.get("classification");              // Optional information
-            if (child != null) clist.add( child.getAttributes() );
-            else               clist.add( null );
-
-            if (natr.getNamedItem("contents").getNodeValue().equals("knowledge")) {
-//TODO        Error: knowledges must be attached to scenarios
-            } else {
-              step.contents.add(Document.class);
-            }
-            steps.add(step);
-            snum += 1;
-          }
-        }
-//      Validations tag
-        child     = children.get("validations");
-        concycles = new Vector<ProjectSettingsValidationCycle>();
-        datag     = XDOM.getNamedChildNodes(child);
-
-        String[]  step   = { "review", "approval", "acceptance" };
-        resultype.add("default");
-        for (Iterator<String> i=resultype.iterator(); i.hasNext(); ) {
-          Actor[] actor = {  null,     null,       null        };
-          String  name  = i.next();
-          child = datag.get(name);
-          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) 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().getMe().isInitialized()) return;         // No need to load object type definitions as they are already stored
-
-//      Documents tag
-        child  = children.get("documents");
-           nlist  = child.getChildNodes();
-
-           flows  = flist;             // Kept for later use in document type definition
-           sclass = clist;             // Kept for later use in simulation context type definition
-        mapuse = new LinkedHashMap<String,String>();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          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) uses = child.getNodeValue();
-          mapuse.put(type, uses);   // Must be added to the map even if no (null) uses
-        }
-//      Simulation Contexts tag
-        child  = children.get("contexts");
-           nlist  = child.getChildNodes();
-
-           context  = new Vector<String>();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (!child.getNodeName().equals("article")) continue;
-          
-          context.add(child.getAttributes().getNamedItem("type").getNodeValue());
-        }
-//      Knowledge Elements tag
-        child  = children.get("knowledges");
-           nlist  = child.getChildNodes();
-
-           kname  = new Vector<String>();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (!child.getNodeName().equals("article")) continue;
-          
-          kname.add(child.getAttributes().getNamedItem("type").getNodeValue());
-        }
-      }
-      catch (Exception error) {
-               logger.info("Error in customization", error);
-      }
-    }
-
-    private void createDocumentTypes () {
-//  -----------------------------------
-      DocumentType.Properties       tprop     = new DocumentType.Properties();
-      HashMap<String,Vector<ProjectSettingsService.Step>>  mapsteps  = new HashMap<String,Vector<ProjectSettingsService.Step>>();
-      HashMap<String,ProjectSettingsService.Step>          mapresult = new HashMap<String,ProjectSettingsService.Step>();
-      HashMap<String,DocumentType>  maptype   = new HashMap<String,DocumentType>();
-        
-      Vector<ProjectSettingsService.Step> slist = null;     // List of Steps to which each document type is valid
-      int          snum  = 0;        // Step number
-      String       type  = null;
-      String       uses  = null;
-      for (Iterator<NamedNodeMap> i=flows.iterator(); i.hasNext(); snum++) {
-           NamedNodeMap    flow     = i.next();
-           ProjectSettingsService.Step            step     = steps.get(snum);
-        String[]        contents = flow.getNamedItem("contents").getNodeValue().split(",");
-        for (int j=0; j<contents.length; j++) {
-             type = contents[j];
-                 if (!mapuse.containsKey(type)) {
-            logger.warn("Undefined \"" + type + "\" document type.");
-            continue;
-          }                  slist = mapsteps.get(type);
-          if (slist == null) slist = new Vector<ProjectSettingsService.Step>();
-          slist.add(step);
-          mapsteps.put(type, slist);
-        }
-        Node result = flow.getNamedItem("result");
-        if  (result != null)  mapresult.put(result.getNodeValue(), step);
-      }
-      try {
-        DocumentType tdoc = null;
-        Set<String>  tset = mapuse.keySet();
-        ProjectSettingsService.Step         step;
-        for (Iterator<String> i=tset.iterator(); i.hasNext(); ) {
-          type  = i.next();
-          slist = mapsteps.get(type);
-          uses  = mapuse.get(type);
-          step  = mapresult.get(type);
-
-          tprop.clear();
-          tprop.setName(type).setStep(slist.toArray(new ProjectSettingsService.Step[slist.size()]));
-          if (uses != null) {
-               tdoc = maptype.get(uses);
-               if (tdoc == null) logger.warn("Undefined \"" + uses + "\" document type.");
-               else              tprop.setUses(tdoc);
-          }
-          if (step != null)   tprop.setResult(step);
-
-          tprop.disableCheck();
-          tdoc = Document.createType(tprop);                                  // Creation of Document Types
-          tdoc.approve();
-          maptype.put(type, tdoc);
-        }
-      } catch (Exception error) {
-        logger.warn("Error creating document types, reason:", error);         // Should not happen
-      }
-    }
-
-    private void createKnowledgeElementTypes () {
-//  -------------------------------------------
-      try {
-        KnowledgeElementType ktype = KnowledgeElement.createType("usecase");  // Internal reserved knowledge element type
-        ktype.reserve();
-        for (Iterator<String> i=kname.iterator(); i.hasNext(); ) {
-          String  type = i.next();
-
-          ktype = KnowledgeElement.createType(type);                          // Knowledge Elements Types defined in the configuration
-          ktype.approve();
-        }
-      } catch (Exception error) {
-        logger.warn("Error creating knowledge types, reason:", error);        // Should not happen
-      }
-    }
-
-    private void createSimulationContextTypes () {
-//  --------------------------------------------
-      HashMap<String,ProjectSettingsService.Step>  mapstep = new HashMap<String,ProjectSettingsService.Step>();
-      int snum = 0;
-      for (Iterator<NamedNodeMap> i=sclass.iterator(); i.hasNext(); snum++) {
-        NamedNodeMap clatr = i.next();
-        if (clatr == null) continue;
-
-        String[]        clist = clatr.getNamedItem("context").getNodeValue().split(",");
-        for (int j=0; j<clist.length; j++) {
-          mapstep.put(clist[j], steps.get(snum));
-        }
-      }
-      try {
-       SimulationContextType tctex = null;
-        for (Iterator<String> i=context.iterator(); i.hasNext(); ) {
-          String type = i.next();
-             if (!mapstep.containsKey(type)) {
-            logger.warn("Could not find \"" + type + "\" classification. Simulation Context type ignored.");
-            continue;
-             }
-             tctex = SimulationContext.createType(type, mapstep.get(type));   // Creation of Simulation Context Types
-             tctex.approve();
-        }
-      } catch (Exception error) {
-        logger.warn("Error creating context types, reason:", error);       // Should not happen
-      }
-    }
        /**
         * Get the database.
+        * 
         * @return the database
         */
        public Database getDatabase() {
                return _database;
        }
+
        /**
         * Set the database.
-        * @param database the database to set
+        * 
+        * @param database
+        *            the database to set
         */
        public void setDatabase(Database database) {
                _database = database;
        }
+
+       /**
+        * Get the simulationContextService.
+        * 
+        * @return the simulationContextService
+        */
+       public SimulationContextService getSimulationContextService() {
+               return _simulationContextService;
+       }
+
+       /**
+        * Set the simulationContextService.
+        * 
+        * @param simulationContextService
+        *            the simulationContextService to set
+        */
+       public void setSimulationContextService(
+                       SimulationContextService simulationContextService) {
+               _simulationContextService = simulationContextService;
+       }
 }
\ No newline at end of file