]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Salome HOME
The checkin from SALOME operation is updated (ScenarioService.checkin()). Versioning...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / technical / ProjectSettingsServiceImpl.java
index c9498f5135faf538d6b0270257892a4a192cda01..6830946e56aed99223542cea343f079c3310e779 100644 (file)
@@ -87,8 +87,18 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * Document type mappings to file formats which should be imported into SALOME during check-out.
         */
        private transient final Map<String, List<String>> _mapimport = new HashMap<String, List<String>>();
+       /**
+        * Default document types structured by step.formats.
+        */
+       private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
 
        // Temporary attributes initialized from the configuration file for populating the database with object types
+       /**
+        * Step.format keys structured by Default document types names. This map is used for loading config before document types are created in
+        * the database. When document types are created then _defdoctype is filled.
+        */
+       private transient final Map<String, List<String>> _defdoctypeKeys = new HashMap<String, List<String>>();
+
        /**
         * Document type names and uses mapping.
         */
@@ -128,11 +138,6 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        private DocumentTypeService _documentTypeService;
 
-       /**
-        * Default document types structured by step.formats.
-        */
-       private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
-
        /**
         * File naming strategy enumeration.
         */
@@ -354,6 +359,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
        public DocumentType getDefaultDocumentType(final Step step,
                        final String format) {
                String[] table = format.split("\\x2E");
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Trying to get default type: " + step.getNumber() + "."
+                                       + table[table.length - 1]);
+               }
                return _defdoctype
                                .get(step.getNumber() + "." + table[table.length - 1]); // May be null
        }
@@ -543,33 +552,53 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        private void loadDefaultDocTypes(final Map<String, Node> children) {
                _defdoctype.clear();
+               _defdoctypeKeys.clear();
                Node child = children.get("default-doctypes");
-               NodeList nlist = child.getChildNodes();
+               if (child != null) {
+                       NodeList nlist = child.getChildNodes();
 
-               List<DocumentType> listype = getDocumentTypeService().selectAllTypes();
-               Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
-               for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
-                       DocumentType type = i.next();
-                       maptype.put(type.getName(), type);
-               }
-               for (int i = 0; i < nlist.getLength(); i++) {
-                       child = nlist.item(i);
-                       if (!child.getNodeName().equals("step")) {
-                               continue;
+                       List<DocumentType> listype = getDocumentTypeService()
+                                       .selectAllTypes();
+                       Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+                       for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
+                               DocumentType type = i.next();
+                               maptype.put(type.getName(), type);
                        }
-
-                       String nstep = child.getAttributes().getNamedItem("number")
-                                       .getNodeValue();
-                       NodeList map = child.getChildNodes();
-                       for (int j = 0; j < map.getLength(); j++) {
-                               child = map.item(j);
-                               if (!child.getNodeName().equals("mapping")) {
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("step")) {
                                        continue;
                                }
-                               NamedNodeMap natr = child.getAttributes();
-                               String dext = natr.getNamedItem("extension").getNodeValue();
-                               String type = natr.getNamedItem(TYPE_ATTR).getNodeValue();
-                               _defdoctype.put(nstep + "." + dext, maptype.get(type));
+
+                               String nstep = child.getAttributes().getNamedItem("number")
+                                               .getNodeValue();
+                               NodeList map = child.getChildNodes();
+                               for (int j = 0; j < map.getLength(); j++) {
+                                       child = map.item(j);
+                                       if (!child.getNodeName().equals("mapping")) {
+                                               continue;
+                                       }
+                                       NamedNodeMap natr = child.getAttributes();
+                                       String dext = natr.getNamedItem("extension").getNodeValue();
+                                       String type = natr.getNamedItem(TYPE_ATTR).getNodeValue();
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Map default type: " + nstep + "." + dext
+                                                               + ": (type name = " + type + ")"
+                                                               + maptype.get(type));
+                                       }
+                                       _defdoctype.put(nstep + "." + dext, maptype.get(type));
+                                       // Remember the key if type is not created yet
+                                       if (maptype.get(type) == null) {
+                                               List<String> keys;
+                                               if (_defdoctypeKeys.containsKey(type)) {
+                                                       keys = _defdoctypeKeys.get(type);
+                                               } else {
+                                                       keys = new ArrayList<String>();
+                                                       _defdoctypeKeys.put(type, keys);
+                                               }
+                                               keys.add(nstep + "." + dext);
+                                       }
+                               }
                        }
                }
        }
@@ -777,6 +806,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
                                        getDocumentTypeService().approve(tdoc);
                                        maptype.put(type, tdoc);
+                                       // Remember default type if it is
+                                       if (_defdoctypeKeys.containsKey(type)) {
+                                               for (String key : _defdoctypeKeys.get(type)) {
+                                                       if (LOG.isDebugEnabled()) {
+                                                               LOG.debug("Put mapping for default type: "
+                                                                               + key + ": " + tdoc);
+                                                       }
+                                                       _defdoctype.put(key, tdoc);
+                                               }
+                                       }
                                }
                        }
                } catch (Exception error) {