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 {
/**
* 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.
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;
}
/**
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);
}
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 {
/**
* 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;
// 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();
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);
}
}
// 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