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