]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Code cleaning and PMD rules respecting.
authorrkv <rkv@opencascade.com>
Wed, 14 Nov 2012 06:52:46 +0000 (06:52 +0000)
committerrkv <rkv@opencascade.com>
Wed, 14 Nov 2012 06:52:46 +0000 (06:52 +0000)
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Workspace/Siman/src/org/splat/simer/Converter.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/org/splat/simer/StudyMenu.java

index b3c32c73ff2f9dc0d6013dcc026a90ae1519d892..524c556b6d4c9723e814a53737851a929bca4bce 100644 (file)
@@ -45,6 +45,10 @@ public interface ProjectSettingsService {
                 * Data path for this step.
                 */
                private String _path;
+               /**
+                * Executable module for this step.
+                */
+               private String _module;
 
                /**
                 * Create a transient study step definition.
@@ -138,6 +142,22 @@ public interface ProjectSettingsService {
                public String getPath() {
                        return _path;
                }
+
+               /**
+                * Get the module.
+                * @return the module
+                */
+               public String getModule() {
+                       return _module;
+               }
+
+               /**
+                * Set the module.
+                * @param module the module to set
+                */
+               public void setModule(final String module) {
+                       _module = module;
+               }
        }
 
        /**
index 14e6e66d58e7a01d791636fe656a70450573b36e..d8da9723f442678c5e58fa4279b058051b7ef128 100644 (file)
@@ -37,12 +37,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.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 /**
- * SIMAN configuration data service.
+ * SIMAN workflow configuration data service.
  */
 public class ProjectSettingsServiceImpl implements ProjectSettingsService {
 
@@ -129,11 +130,11 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                /**
                 * Cycle (document) type name.
                 */
-               private final String _name;
+               private transient final String _name;
                /**
                 * Array of cycle actors positions in the organization. TODO: Must be replaced by Roles.
                 */
-               private final Actor[] _actor;
+               private transient final Actor[] _actor;
 
                /**
                 * Default constructor.
@@ -364,166 +365,181 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        int snum = 1; // Base number of steps
                        for (int i = 0; i < nlist.getLength(); i++) {
                                child = nlist.item(i);
-                               if (child.getNodeName().equals("scenario")) {
+                               if ("scenario".equals(child.getNodeName())) {
                                        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(null);
-                                               } else {
-                                                       clist.add(child.getAttributes());
-                                               }
-
-                                               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;
+                                               snum = loadStep(slist.item(j), Scenario.class, snum,
+                                                               flist, clist, resultype);
                                        }
                                } 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(null);
-                                       } else {
-                                               clist.add(child.getAttributes());
-                                       }
-
-                                       if (natr.getNamedItem("contents").getNodeValue().equals(
-                                                       "knowledge")) {
-                                               // TODO Error: knowledges must be attached to scenarios
-                                               LOG.error("Error: knowledges must be attached to scenarios.");
-                                       } else {
-                                               step._contents.add(Document.class);
-                                       }
-                                       _steps.add(step);
-                                       snum += 1;
+                                       snum = loadStep(child, Study.class, snum, flist, clist,
+                                                       resultype);
                                }
                        }
                        // Validations tag
-                       child = children.get("validations");
-                       _concycles = new ArrayList<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
+                       _concycles = loadValidationCycles(children, resultype);
+
+                       if (!getDatabase().getCheckedDB().isInitialized()) {
+                               // Load object type definitions
+                               // 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 ("article".equals(child.getNodeName())) {
+                                               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
                                        }
-                                       actor[j] = Actor.valueOf(child.getNodeValue());
                                }
-                               _concycles.add(new ProjectSettingsValidationCycle(name, actor));
+                               // Simulation Contexts tag
+                               _context = loadArticles(children, "contexts");
+                               // Knowledge Elements tag
+                               _kname = loadArticles(children, "knowledges");
                        }
-                       _concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
+               } catch (Exception error) {
+                       LOG.info("Error in customization", error);
+               }
+       }
 
-                       if (getDatabase().getCheckedDB().isInitialized()) {
-                               return; // No need to load object type definitions as they are already stored
+       /**
+        * Load a step from the given XML node. Return the next step's number.
+        * 
+        * @param node
+        *            XML node to parse
+        * @param ownerClass
+        *            the class of a step's owner project element - study or scenario
+        * @param snum
+        *            step's number
+        * @param flist
+        *            list of flows
+        * @param clist
+        *            list of classifications
+        * @param resultype
+        *            list of flow results
+        * @return the next step's number
+        */
+       private int loadStep(final Node node,
+                       final Class<? extends ProjectElement> ownerClass, final int snum,
+                       final List<NamedNodeMap> flist, final List<NamedNodeMap> clist,
+                       final List<String> resultype) {
+               int res = snum;
+               if ("step".equals(node.getNodeName())) {
+                       HashMap<String, Node> tags = XDOM.getNamedChildNodes(node);
+
+                       NamedNodeMap natr = tags.get("storage").getAttributes();
+                       ProjectSettingsService.Step step = new ProjectSettingsService.Step(
+                                       snum, ownerClass, natr.getNamedItem("path")
+                                                       .getNodeValue());
+
+                       // Keeping flow and classification information for eventual later use
+                       natr = tags.get("flow").getAttributes();
+                       flist.add(natr);
+                       Node child = natr.getNamedItem("result");
+                       if (child != null) {
+                               resultype.add(child.getNodeValue());
                        }
 
-                       // 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
+                       child = tags.get("classification");
+                       if (child == null) {
+                               clist.add(null);
+                       } else {
+                               clist.add(child.getAttributes());
                        }
-                       // Simulation Contexts tag
-                       child = children.get("contexts");
-                       nlist = child.getChildNodes();
 
-                       _context = new ArrayList<String>();
-                       for (int i = 0; i < nlist.getLength(); i++) {
-                               child = nlist.item(i);
-                               if (!child.getNodeName().equals("article")) {
-                                       continue;
+                       if (natr.getNamedItem("contents").getNodeValue()
+                                       .equals("knowledge")) {
+                               if (Study.class.equals(ownerClass)) {
+                                       LOG.error("Error: knowledges must be attached to scenarios.");
+                               } else {
+                                       // TODO In a given scenario, only one step must contain knowledges
+                                       step._contents.add(KnowledgeElement.class);
                                }
-
-                               _context.add(child.getAttributes().getNamedItem("type")
-                                               .getNodeValue());
+                       } else {
+                               step._contents.add(Document.class);
+                       }
+                       
+                       Element module = (Element)tags.get("module");
+                       if (module != null) {
+                               step.setModule(module.getAttribute("name"));
                        }
-                       // Knowledge Elements tag
-                       child = children.get("knowledges");
-                       nlist = child.getChildNodes();
 
-                       _kname = new ArrayList<String>();
-                       for (int i = 0; i < nlist.getLength(); i++) {
-                               child = nlist.item(i);
-                               if (!child.getNodeName().equals("article")) {
-                                       continue;
+                       _steps.add(step);
+                       res += 1;
+               }
+               return res;
+       }
+
+       /**
+        * Get custom validation cycles.
+        * 
+        * @param children
+        *            XML nodes
+        * @param resultype
+        *            list of result types
+        * @return return list of validation cycles
+        */
+       private List<ProjectSettingsValidationCycle> loadValidationCycles(
+                       final Map<String, Node> children, final List<String> resultype) {
+               Node child = children.get("validations");
+               List<ProjectSettingsValidationCycle> cycles = new ArrayList<ProjectSettingsValidationCycle>();
+               Map<String, Node> datag = XDOM.getNamedChildNodes(child);
+               NamedNodeMap natr;
+
+               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) {
+                               // Document type is the subject of a validation
+                               natr = child.getAttributes();
+                               for (int j = 0; j < step.length; j++) {
+                                       child = natr.getNamedItem(step[j]);
+                                       if (child != null) {
+                                               actor[j] = Actor.valueOf(child.getNodeValue()); // Validation step is required
+                                       }
                                }
+                               cycles.add(new ProjectSettingsValidationCycle(name, actor));
+                       }
+               }
+               cycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
+               return cycles;
+       }
 
-                               _kname.add(child.getAttributes().getNamedItem("type")
+       /**
+        * Read list of articles types.
+        * 
+        * @param children
+        *            XML nodes containing articles
+        * @param listName
+        *            the name of the list of articles
+        * @return list of articles types
+        */
+       private List<String> loadArticles(final Map<String, Node> children,
+                       final String listName) {
+               Node child = children.get(listName);
+               NodeList nlist = child.getChildNodes();
+
+               List<String> articles = new ArrayList<String>();
+               for (int i = 0; i < nlist.getLength(); i++) {
+                       child = nlist.item(i);
+                       if (child.getNodeName().equals("article")) {
+                               articles.add(child.getAttributes().getNamedItem("type")
                                                .getNodeValue());
                        }
-               } catch (Exception error) {
-                       LOG.info("Error in customization", error);
                }
+               return articles;
        }
 
        /**
@@ -579,9 +595,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                if (uses != null) {
                                        tdoc = maptype.get(uses);
                                        if (tdoc == null) {
-                                               LOG
-                                                               .warn("Undefined \"" + uses
-                                                                               + "\" document type.");
+                                               LOG.warn("Undefined \"" + uses + "\" document type.");
                                        } else {
                                                tprop.setUses(tdoc);
                                        }
index c687485ced9ac73cf5ef4f7bc0b2e55ce0cff82f..37657d37f1cf96e5c7199b3d8e4b9eb04e09da08 100644 (file)
@@ -12,10 +12,10 @@ import javax.jms.Session;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
-import org.splat.kernel.MismatchException;
+import org.apache.log4j.Logger;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.Publication;
-import org.apache.log4j.Logger;
+import org.splat.kernel.MismatchException;
 
 
 public class Converter implements MessageListener {
@@ -23,19 +23,19 @@ public class Converter implements MessageListener {
        /**
         * Converter logger.
         */
-    final static Logger logger = Logger.getLogger(Converter.class);
+    final static private Logger LOG = Logger.getLogger(Converter.class);
 
-    private String  type;     // Type of document to be converted (e.g. geometry, model)
-    private String  from;     // Source format (e.g. py, sldprt)
-    private String  to;       // Target format (e.g. brep)
-    private String  exec;     // Command line launching the actual converter
+    private final String  type;     // Type of document to be converted (e.g. geometry, model)
+    private final String  from;     // Source format (e.g. py, sldprt)
+    private final String  to;       // Target format (e.g. brep)
+    private final String  exec;     // Command line launching the actual converter
     private String  fname;    // Absolute path of the source file to be converted
 
 //  ==============================================================================================================================
 //  Constructor
 //  ==============================================================================================================================
 
-    protected Converter (String type, String from, String to, String exec) {
+    protected Converter (final String type, final String from, final String to, final String exec) {
 //  ----------------------------------------------------------------------
       this.type  = type;
       this.from  = from;
@@ -49,12 +49,16 @@ public class Converter implements MessageListener {
 //  Public member functions
 //  ==============================================================================================================================
 
-    public void converts (Publication source) throws MismatchException {
+    public void converts (final Publication source) throws MismatchException {
 //  -----------------------------------------
       Document  sdoc = source.value();
 
-      if (!sdoc.getType().getName().equals(type)) throw new MismatchException();
-      if (!sdoc.getFormat().equals(from))         throw new MismatchException();
+      if (!sdoc.getType().getName().equals(type)) {
+               throw new MismatchException();
+       }
+      if (!sdoc.getFormat().equals(from)) {
+               throw new MismatchException();
+       }
       try {
 //      Initialization of the asynchronous communication with the actual converter
         ApplicationSettings settings = ApplicationSettings.getMe();
@@ -73,20 +77,22 @@ public class Converter implements MessageListener {
         String command    = ApplicationSettings.getApplicationPluginPath() + "converter.jar";
         String option     = "-Dresource.dir=\"" + ApplicationSettings.getApplicationResourcePath() + "\"";
         File   executable = new File(command);
-        if   (!executable.exists())   throw new NoSuchMethodException();
+        if   (!executable.exists()) {
+                       throw new NoSuchMethodException();
+               }
 
         File   sfile = sdoc.getSourceFile().asFile();
         String args;
 
         fname = sfile.getAbsolutePath();
         args  = "\"" + exec + "\" \"" + fname + "\"";
-        if (logger.isInfoEnabled()) {
-          logger.info("Launching the conversion of " + sfile.getName() + " to " + to.toUpperCase() + " format using " + command);
+        if (LOG.isInfoEnabled()) {
+          LOG.info("Launching the conversion of " + sfile.getName() + " to " + to.toUpperCase() + " format using " + command);
         }
         Runtime.getRuntime().exec("\"C:/Program Files/Java/jre6/bin/java.exe\" -jar " + option + " \"" + command + "\" " + args);
       }
       catch (Exception error) {
-       logger.error("Reason: ", error);
+       LOG.error("Reason: ", error);
       }
     }
 
@@ -94,9 +100,8 @@ public class Converter implements MessageListener {
 //  Messages
 //  ==============================================================================================================================
 
-    public void onMessage (Message msg) {
-//  -----------------------------------
+    public void onMessage (final Message msg) {
       String  result = msg.toString();
-      logger.info("Notification of availability of " + result);
+      LOG.info("Notification of availability of " + result);
        }
 }
\ No newline at end of file
index 47f1a00900a425218927e537c48a2e4f7cb37646..432d45a894f4f6e508bf106f9ab749064e1abba6 100644 (file)
@@ -363,11 +363,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        protected void remove(final Publication doctag) {
                for (Iterator<DocumentFacade> i = _contents.iterator(); i.hasNext();) {
                        DocumentFacade facade = i.next();
-                       if (!facade.isFacadeOf(doctag)) {
-                               continue;
+                       if (facade.isFacadeOf(doctag)) {
+                               i.remove();
+                               break;
                        }
-                       i.remove();
-                       break;
                }
                if (_contents.size() == 0) {
                        this.getMenu().refreshSelectedItem();
index be1930da28f744f4ff9dc20238542010390184d9..3117d1c072cf7dc19775f3e382ea86f2429d06f4 100644 (file)
@@ -90,7 +90,8 @@ public class StudyMenu extends SlidMenu {
         */
        public StudyMenu init(final Study context) {
                _study = context;
-               super.init();
+               _scopen = null;
+               init();
                return this;
        }
 
@@ -135,11 +136,10 @@ public class StudyMenu extends SlidMenu {
                        Step[] step = getProjectElementService().getSteps(_scopen);
                        int selected = Integer.valueOf(parse[1]);
                        for (int i = 0; i < step.length; i++) {
-                               if (step[i].getNumber() != selected) {
-                                       continue;
+                               if (step[i].getNumber() == selected) {
+                                       _stopen = step[i];
+                                       break;
                                }
-                               _stopen = step[i];
-                               break;
                        }
                }
                super.selects(name);
@@ -225,19 +225,17 @@ public class StudyMenu extends SlidMenu {
                }
                newstep = getProjectElementService().getSteps(_study);
                for (int i = newstep.length - 1; i > -1; i--) {
-                       if (newstep[i].getNumber() >= base) {
-                               continue;
+                       if (newstep[i].getNumber() < base) {
+                               steps.add(0, newstep[i]);
                        }
-                       steps.add(0, newstep[i]);
                }
                for (int i = askid + 1; i < scenes.length; i++) {
                        steps.add(getProjectElementService().getFirstStep(scenes[i]));
                }
                for (int i = 0; i < newstep.length; i++) {
-                       if (newstep[i].getNumber() <= last) {
-                               continue;
+                       if (newstep[i].getNumber() > last) {
+                               steps.add(newstep[i]);
                        }
-                       steps.add(newstep[i]);
                }
                return steps;
        }
@@ -282,18 +280,17 @@ public class StudyMenu extends SlidMenu {
                newstep = getProjectElementService().getSteps(_study);
                _stopen = newstep[0]; // Default selected step
                for (int i = newstep.length - 1; i > -1; i--) {
-                       if (newstep[i].getNumber() >= base) {
-                               continue;
+                       if (newstep[i].getNumber() < base) {
+                               steps.add(0, newstep[i]);
                        }
-                       steps.add(0, newstep[i]);
                }
                for (int i = 0; i < newstep.length; i++) {
-                       if (newstep[i].getNumber() <= last) {
-                               continue;
+                       if (newstep[i].getNumber() > last) {
+                               steps.add(newstep[i]);
                        }
-                       steps.add(newstep[i]);
                }
                // Creation of the menu
+               this.clear();
                for (Iterator<Step> i = steps.iterator(); i.hasNext();) {
                        Step step = i.next();
                        int number = step.getNumber();