From: rkv Date: Wed, 14 Nov 2012 06:52:46 +0000 (+0000) Subject: Code cleaning and PMD rules respecting. X-Git-Tag: Root_Delivery1_2012_12_06~75 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8a7f56933595142be7ffb18d08be845e115ca328;p=tools%2Fsiman.git Code cleaning and PMD rules respecting. --- diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java index b3c32c7..524c556 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java @@ -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; + } } /** 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 14e6e66..d8da972 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -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 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 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(); - datag = XDOM.getNamedChildNodes(child); - - String[] step = { "review", "approval", "acceptance" }; - resultype.add("default"); - for (Iterator 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(); + 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 ownerClass, final int snum, + final List flist, final List clist, + final List resultype) { + int res = snum; + if ("step".equals(node.getNodeName())) { + HashMap 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(); - 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(); - 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(); - 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 loadValidationCycles( + final Map children, final List resultype) { + Node child = children.get("validations"); + List cycles = new ArrayList(); + Map datag = XDOM.getNamedChildNodes(child); + NamedNodeMap natr; + + String[] step = { "review", "approval", "acceptance" }; + resultype.add("default"); + for (Iterator 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 loadArticles(final Map children, + final String listName) { + Node child = children.get(listName); + NodeList nlist = child.getChildNodes(); + + List articles = new ArrayList(); + 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); } diff --git a/Workspace/Siman/src/org/splat/simer/Converter.java b/Workspace/Siman/src/org/splat/simer/Converter.java index c687485..37657d3 100644 --- a/Workspace/Siman/src/org/splat/simer/Converter.java +++ b/Workspace/Siman/src/org/splat/simer/Converter.java @@ -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 diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 47f1a00..432d45a 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -363,11 +363,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { protected void remove(final Publication doctag) { for (Iterator 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(); diff --git a/Workspace/Siman/src/org/splat/simer/StudyMenu.java b/Workspace/Siman/src/org/splat/simer/StudyMenu.java index be1930d..3117d1c 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyMenu.java +++ b/Workspace/Siman/src/org/splat/simer/StudyMenu.java @@ -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 i = steps.iterator(); i.hasNext();) { Step step = i.next(); int number = step.getNumber();