Changeset 8004 for mauRepo/xmi2sqlalchemy
- Timestamp:
- 05/12/11 17:12:15 (8 years ago)
- Location:
- mauRepo/xmi2sqlalchemy/trunk/src
- Files:
-
- 1 added
- 1 deleted
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/ModelXMI11Factory.java
r7998 r8004 37 37 import ndg.services.newmoon.xmiModel.UMLAttribute; 38 38 import ndg.services.newmoon.xmiModel.UMLClass; 39 import ndg.services.newmoon.xmiModel.UMLClassDataType; 39 40 import ndg.services.newmoon.xmiModel.UMLClassifierRole; 40 41 import ndg.services.newmoon.xmiModel.UMLCollaboration; … … 100 101 */ 101 102 @Override 102 public UMLDataType createUMLDataType(Element el, String modelId, UMLModel umlModel ){103 return new UMLDataTypeImpl(el, modelId, umlModel );103 public UMLDataType createUMLDataType(Element el, String modelId, UMLModel umlModel, UMLClassDataType type){ 104 return new UMLDataTypeImpl(el, modelId, umlModel, type); 104 105 } 105 106 -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/ModelXMIFactory.java
r7998 r8004 34 34 import ndg.services.newmoon.xmiModel.UMLAttribute; 35 35 import ndg.services.newmoon.xmiModel.UMLClass; 36 import ndg.services.newmoon.xmiModel.UMLClassDataType; 36 37 import ndg.services.newmoon.xmiModel.UMLClassifierRole; 37 38 import ndg.services.newmoon.xmiModel.UMLCollaboration; … … 60 61 public abstract UMLClassifierRole createUMLClassifierRole(Element el, String modelId); 61 62 62 public abstract UMLDataType createUMLDataType(Element el, String modelId, UMLModel umlModel );63 public abstract UMLDataType createUMLDataType(Element el, String modelId, UMLModel umlModel, UMLClassDataType type); 63 64 64 65 public abstract UMLCollaboration createUMLCollaboration(Element el, String modelId); -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/NmParser.java
r7998 r8004 292 292 private UMLDataType processDataType(Node node, UMLModel umlModel) { 293 293 //Process the DataType element 294 UMLDataType umlDT = modelFactory.createUMLDataType((Element)node, getMainModelId(), umlModel); 294 /*Actually I set the 'type' parameter to null because the 295 * uml:dataType I met are defined just on their name,say Set<GF_AttributeType> 296 * as consequence I cannot realistically set the type in the better way. 297 * Probably at the ClassModel level process it would be possible to update such value 298 */ 299 UMLDataType umlDT = modelFactory.createUMLDataType((Element)node, getMainModelId(), umlModel, null); 295 300 umlModel.getUmlDataType().add(umlDT); 296 301 return umlDT; -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/UMLElementsArchive.java
r7998 r8004 862 862 863 863 public ClassModel getClassModelByUMLClass(UMLClassDataType umlClass) { 864 UMLClassDataType intClass = umlClass; 865 if (umlClass instanceof UMLDataType) 866 intClass = ((UMLDataType)umlClass).getType(); 864 867 ClassModel cm = null; 865 868 Iterator<ClassModel> iter = getClassModel().iterator(); 866 869 while (iter.hasNext()) { 867 870 cm = iter.next(); 868 if (cm.getAssociatedClass().equals( umlClass))871 if (cm.getAssociatedClass().equals(intClass)) 869 872 return cm; 870 873 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/CollectClassesClosure.java
r7998 r8004 40 40 41 41 import ndg.services.newmoon.NewmoonException; 42 import ndg.services.newmoon.NmParser; 42 43 import ndg.services.newmoon.UMLElementsArchive; 44 import ndg.services.newmoon.velocity.python.GenerateClasses.EmbeddedType; 43 45 import ndg.services.newmoon.velocity.python.support.AttributeModel; 44 46 import ndg.services.newmoon.velocity.python.support.ClassModel; … … 50 52 import ndg.services.newmoon.xmiModel.UMLClassDataType; 51 53 import ndg.services.newmoon.xmiModel.UMLDataType; 54 import ndg.services.newmoon.xmiModel.UMLModel; 52 55 import ndg.services.newmoon.xmiModel.UMLStereotype; 53 56 import ndg.services.newmoon.xmiModel.UMLValueTagged; … … 59 62 import org.apache.commons.lang.StringUtils; 60 63 import org.apache.commons.lang.math.NumberUtils; 64 import org.w3c.dom.Node; 61 65 62 66 /** … … 65 69 */ 66 70 public class CollectClassesClosure implements Closure { 67 public enum DataType {NONE, SET, SEQUENCE, DICTIONARY, TRANSFINITE_SET}71 public enum CollectionType {NONE, SET, SEQUENCE, DICTIONARY, TRANSFINITE_SET} 68 72 69 73 private final List<ClassModel> models = new ArrayList<ClassModel>(); … … 114 118 private ClassModel processUMLclass(UMLClass umlClass) throws NewmoonException, IOException { 115 119 ClassModel cm = getExternalModel(umlClass); 116 if (cm == null ) {120 if (cm == null && umlClass != null) { 117 121 cm = new ClassModel(umlClass); 118 122 models.add(cm); … … 224 228 if (input instanceof UMLAttribute) { 225 229 generateSimpleKeyValues((UMLAttribute) input); 226 ret.add(extract SimpleAttribute((UMLAttribute) input));230 ret.add(extractAttribute((UMLAttribute) input)); 227 231 } 228 232 229 233 230 234 if (input instanceof UMLAssociationEnd) 231 ret.add(extract SimpleAttribute((UMLAssociationEnd) input));235 ret.add(extractAttribute((UMLAssociationEnd) input)); 232 236 } catch (NewmoonException e) { 233 237 this.exceptions.add(e); … … 252 256 } 253 257 254 private AttributeModel extract SimpleAttribute(UMLAttribute umlAttribute) throws NewmoonException,258 private AttributeModel extractAttribute(UMLAttribute umlAttribute) throws NewmoonException, 255 259 IOException { 256 return extract SimpleAttribute(umlAttribute.getClassifier(), umlAttribute, cm,260 return extractAttribute(umlAttribute.getClassifier(), umlAttribute, cm, 257 261 hasMolteplicity(umlAttribute), UMLElementsArchive.getInstance().isVoidable(umlAttribute)); 258 262 } 259 263 260 private AttributeModel extract SimpleAttribute(UMLAssociationEnd end) throws NewmoonException, IOException {261 return extract SimpleAttribute(end.getType(), end, cm, hasMolteplicity(end), false);262 } 263 264 private AttributeModel extract SimpleAttribute(UML_ID type, UMLValueTagged valueTagged,264 private AttributeModel extractAttribute(UMLAssociationEnd end) throws NewmoonException, IOException { 265 return extractAttribute(end.getType(), end, cm, hasMolteplicity(end), false); 266 } 267 268 private AttributeModel extractAttribute(UML_ID type, UMLValueTagged valueTagged, 265 269 ClassModel attributeOwner, boolean hasMultiplicity, boolean isVoidable) throws NewmoonException, 266 270 IOException { … … 271 275 } 272 276 273 private <T extends UMLClassDataType> AttributeModel <T>processAttribute(T umlAttribute, UMLValueTagged valueTagged,277 private <T extends UMLClassDataType> AttributeModel processAttribute(T umlAttribute, UMLValueTagged valueTagged, 274 278 boolean hasMultiplicity, boolean isVoidable) throws NewmoonException, IOException { 275 279 … … 278 282 throw new NewmoonException("No type for UML_ID: " + umlAttribute); 279 283 280 ClassModel associatedClassModel = null; 281 if (umlAttribute instanceof UMLClass) { 282 associatedClassModel = processUMLclass((UMLClass) umlAttribute); 283 } 284 285 return new AttributeModel<T>(umlAttribute, associatedClassModel, 284 ClassModel attrClassModel = null; 285 //Processes the attribute type (the called method will skip it if already exists) 286 if (umlAttribute instanceof UMLClass) 287 attrClassModel = processUMLclass((UMLClass) umlAttribute); 288 289 if (umlAttribute instanceof UMLDataType) { 290 UMLClass attrClass = extractUMLClassByDataType((UMLDataType)umlAttribute); 291 //Does the Setting missed in the NmParser ingestion 292 ((UMLDataType)umlAttribute).setType(attrClass); 293 attrClassModel = processUMLclass(attrClass); 294 } 295 296 return new AttributeModel(attrClassModel, 286 297 valueTagged.getName(), 287 298 extractIntegerValue(valueTagged, Dictionary.LOWER_BOUND), 288 299 extractIntegerValue(valueTagged, Dictionary.UPPER_BOUND), 289 300 extractIntegerValue(valueTagged, Dictionary.LENGTH), 290 isVoidable); 301 isVoidable, 302 extractCollectionType(umlAttribute.getName())); 291 303 } 292 304 … … 302 314 } 303 315 304 private UMLClass extractUMLClassByDataType(UMLDataTypeumlDataType) {316 private <T extends UMLClassDataType> UMLClass extractUMLClassByDataType(T umlDataType) { 305 317 /* For now I assume that any DataType name is of the format 306 318 * 'xxx<UMLClass_name>' … … 308 320 int beginIndex = umlDataType.getName().indexOf("<") + 1; 309 321 int endIndex = umlDataType.getName().indexOf(">"); 310 String umlClassName = umlDataType.getName().substring(beginIndex, endIndex); 322 String umlClassName = umlDataType.getName(); 323 if (beginIndex > 0 && endIndex > 0) 324 umlClassName = umlDataType.getName().substring(beginIndex, endIndex); 311 325 return UMLElementsArchive.getInstance().getUMLClassByName(umlClassName); 312 326 } … … 381 395 } 382 396 } 397 398 /** 399 * @see EmbeddedType#EmbeddedType() 400 **/ 401 private CollectionType extractCollectionType(String definition) { 402 if (definition.matches("Sequence(<|<).*(>|>)")) 403 return CollectionType.SEQUENCE; 404 if (definition.matches("Set(<|<).*(>|>)")) 405 return CollectionType.SET ; 406 if (definition.matches("Dictionary(<|<).*(>|>)")) 407 return CollectionType.DICTIONARY ; 408 if (definition.matches("TranfiniteSet(<|<).*(>|>)")) 409 return CollectionType.DICTIONARY ; 410 if (definition.matches("(<|<)undefined(>|>)")) 411 return CollectionType.NONE; 412 else 413 return CollectionType.NONE; 414 } 383 415 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateClassesClosure.java
r7999 r8004 42 42 import ndg.services.newmoon.velocity.python.support.ASCodeList; 43 43 import ndg.services.newmoon.velocity.python.support.ASEnumeration; 44 import ndg.services.newmoon.velocity.python.support.ASText; 44 45 import ndg.services.newmoon.velocity.python.support.ASUnion; 45 46 import ndg.services.newmoon.velocity.python.support.ClassModel; … … 122 123 if (cm.isUnion()) { 123 124 CollectionUtils.addAll(toImport, cm.getAttributeModel().iterator()); 125 //not the best solution but ok for now 126 toImport.add(new ASText()); 124 127 } 125 128 -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateModuleHelper.java
r7998 r8004 49 49 50 50 import org.apache.commons.io.FileUtils; 51 import org.apache.commons.io.IOUtils; 51 52 import org.apache.commons.lang.StringUtils; 52 53 import org.slf4j.Logger; … … 140 141 141 142 public File generatePythonPackage(UMLModel model) throws IOException { 143 checkRootInit(); 144 142 145 File file = 143 146 model == null ? getBaseDir() : 144 147 new File(getBaseDir(), StringUtils.replaceChars(model.toString(), '.', File.separatorChar).toLowerCase()); 145 148 146 149 if (!file.exists()) { 147 150 FileUtils.forceMkdir(file); … … 155 158 return file; 156 159 } 160 161 private void checkRootInit() throws IOException { 162 File file = new File(getBaseDir(), "__init__.py"); 163 if (!file.exists()) 164 file.createNewFile(); 165 } 157 166 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateTables_.java
r7998 r8004 133 133 private void writeAll(InnerGenerateTablesClosure closure) throws IOException { 134 134 PythonImportClosure importClosure = new PythonImportClosure(); 135 136 checkReciprocalTables(closure );135 136 checkReciprocalTables(closure, importClosure); 137 137 138 138 List<TableModel> tbs = sortTableModels(closure); 139 139 //-- THINK BEFORE CHANGE THE ORDER!! --// 140 applyTemplate(tbs, CONTEXT.tableModel, sqlTablesStrBuffer, tableTemplateFile); 141 CollectionUtils.forAllDo(tbs, importClosure); 142 143 applyTemplate(closure.getNotSortable(), CONTEXT.tableModel, sqlTablesStrBuffer, tableTemplateFile); 144 CollectionUtils.forAllDo(closure.getNotSortable(), importClosure); 145 146 applyTemplate(closure.getAssociationTable(), CONTEXT.associationTable, sqlTablesStrBuffer, associationTemplateFile); 147 CollectionUtils.forAllDo(closure.getAssociationTable(), importClosure); 148 140 applyTemplate(tbs, CONTEXT.tableModel, sqlTablesStrBuffer, tableTemplateFile); 141 applyTemplate(closure.getNotSortable(), CONTEXT.tableModel, sqlTablesStrBuffer, tableTemplateFile); 142 applyTemplate(closure.getAssociationTable(), CONTEXT.associationTable, sqlTablesStrBuffer, associationTemplateFile); 149 143 vcontext.put(CONTEXT.imports.name(), importClosure.getImportMap()); 150 144 … … 202 196 } 203 197 204 private void checkReciprocalTables(InnerGenerateTablesClosure closure) { 205 Iterator<TableModel> iterator = closure.getTableModels().iterator(); 198 private void checkReciprocalTables(InnerGenerateTablesClosure closure, PythonImportClosure importClosure) { 199 //Imports the classes necessaries for the table declaration 200 CollectionUtils.forAllDo(closure.getTableModels(), importClosure); 201 202 Iterator<TableModel> iterator = closure.getTableModels().iterator(); 206 203 while (iterator.hasNext()) { 207 204 TableModel tb = iterator.next(); 208 209 205 /* 210 206 * Checks if one attribute or one of attribuite's children … … 219 215 * and eventually set up a many-to-many relationship 220 216 */ 221 checkTableAttributeOverriding(tb); 222 } 223 } 224 225 private void checkTableAttributeOverriding(TableModel tb){ 217 checkTableAttributeOverriding(tb, importClosure); 218 } 219 } 220 221 private void checkTableAttributeOverriding(TableModel tb, PythonImportClosure importClosure){ 222 //Imports the classes necessaries for the table definition 223 CollectionUtils.forAllDo(tb.getAttributeModel(), importClosure); 224 226 225 Set<TableModel> ovm = new HashSet<TableModel>(); 227 226 for (AttributeModel am : tb.getAttributeModel()) { -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/InnerGenerateTablesClosure.java
r7999 r8004 55 55 import ndg.services.newmoon.xmiModel.UMLClass; 56 56 import ndg.services.newmoon.xmiModel.UMLClassDataType; 57 import ndg.services.newmoon.xmiModel.UMLDataType; 57 58 58 59 import org.apache.commons.collections.Closure; … … 142 143 143 144 private ClassModel getClassModel(UMLClassDataType umlClass) { 144 return UMLElementsArchive.getInstance().getClassModelByUMLClass( 145 umlClass); 145 return UMLElementsArchive.getInstance().getClassModelByUMLClass(umlClass); 146 146 } 147 147 148 148 private TableModel processUMLclass(ClassModel classModel) 149 149 throws NewmoonException, IOException { 150 151 if (checkIfSkipProcess(classModel)) 152 return null; 153 150 154 if (tableModelExists(classModel)) 151 155 return getTableModel(classModel); … … 168 172 IOException { 169 173 AttributeModel am = null; 170 Iterator<AttributeModel> iter = getClassModel( 171 parent.getAssociatedClass()).getAttributeModel().iterator();174 Iterator<AttributeModel> iter = getClassModel(parent.getAssociatedClass()) 175 .getAttributeModel().iterator(); 172 176 while (iter.hasNext()) { 173 177 am = iter.next(); 174 175 ClassModel cm = getClassModel(am.getAssociatedType()); 176 177 if (cm == null || isToSkip(cm)) { 178 ClassModel cm = am.getAssociatedType(); 179 180 if (cm == null || checkIfSkipProcess(cm)) { 178 181 parent.getAttributeModel().add(am); 179 182 continue; … … 181 184 182 185 TableModel child = processUMLclass(cm); 186 if (child == null) 187 continue; 188 183 189 /* 184 190 * Voidable should be manage with a "status" more than with a NULL … … 210 216 } 211 217 212 private boolean isToSkip(ClassModel classModel) { 213 return (classModel.isCodeList() || classModel.isEnumeration() || isMapped(classModel 214 .getAssociatedClass())); 215 } 216 218 private boolean checkIfSkipProcess(ClassModel classModel) { 219 return (classModel.isCodeList() 220 || classModel.isEnumeration() 221 || checkIfIsPrimitiveAttribute(classModel)); 222 } 223 224 private boolean checkIfIsPrimitiveAttribute(ClassModel classModel) { 225 return GenerateModuleHelper.getXMIClassToSQLMap().containsKey(classModel.getAssociatedClass().getName()); 226 } 227 217 228 private boolean tableModelExists(ClassModel classModel) { 218 229 return tableModels.contains(new TableModel(classModel … … 675 686 return helper; 676 687 } 677 678 /**679 * Verifies if the associated UMLClass is mapped by the680 * {@link PropertyMap#XMI_TO_SQL_MAP} file.681 *682 * @return <code>true</code> if is mapped, <code>false</code> otherwise683 **/684 public boolean isMapped(UMLClassDataType associatedClass) {685 String typeName = StringUtils.defaultIfEmpty(GenerateModuleHelper686 .getXMIClassToSQLMap().getProperty(associatedClass.getName()),687 "");688 return typeName.equals(associatedClass.getName());689 }690 688 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/PythonImportClosure.java
r7998 r8004 39 39 import ndg.services.newmoon.velocity.python.support.ImportCollector; 40 40 import ndg.services.newmoon.velocity.python.support.TableModel; 41 import ndg.services.newmoon.xmiModel.UMLClass;42 41 import ndg.services.newmoon.xmiModel.UMLClassDataType; 43 import ndg.services.newmoon.xmiModel.UMLDataType;44 42 45 43 import org.apache.commons.collections.Closure; … … 57 55 public void execute(Object input) { 58 56 UMLClassDataType umlType = null; 59 if (input instanceof UMLClassDataType) 57 if (input instanceof UMLClassDataType) { 60 58 umlType = (UMLClassDataType)input; 61 62 if (input instanceof TableModel) 63 umlType = ((TableModel)input).getAssociatedClass(); 64 if (input instanceof AttributeModel) 65 umlType = ((AttributeModel)input).getAssociatedType(); 66 if (input instanceof ClassModel) 59 } else if (input instanceof TableModel) { 60 umlType = ((TableModel)input).getAssociatedClass(); 61 } else if (input instanceof AttributeModel) { 62 umlType = ((AttributeModel)input).getAssociatedType().getAssociatedClass(); 63 } else if (input instanceof ClassModel) { 67 64 umlType = ((ClassModel)input).getAssociatedClass(); 65 } 68 66 importCollector.updateImports(umlType); 69 67 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ASCodeList.java
r7974 r8004 44 44 45 45 /** 46 * @param id47 * @param root48 * @param leaf49 * @param abstrakt50 * @param umlPackage51 46 */ 52 47 public ASCodeList() { -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ASEnumeration.java
r7974 r8004 44 44 45 45 /** 46 * @param id47 * @param root48 * @param leaf49 * @param abstrakt50 * @param umlPackage51 46 */ 52 47 public ASEnumeration() { -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ASUnion.java
r7998 r8004 44 44 45 45 /** 46 * @param id47 * @param root48 * @param leaf49 * @param abstrakt50 * @param umlPackage51 46 */ 52 47 public ASUnion() { -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/AttributeModel.java
r7998 r8004 32 32 package ndg.services.newmoon.velocity.python.support; 33 33 34 import ndg.services.newmoon.UMLElementsArchive.PropertyMap; 35 import ndg.services.newmoon.xmiModel.UMLClassDataType; 36 import ndg.services.newmoon.xmiModel.UML_ID; 34 import ndg.services.newmoon.collect.CollectClassesClosure.CollectionType; 37 35 38 36 /** … … 45 43 * 46 44 */ 47 public class AttributeModel<T extends UMLClassDataType> { 48 private final T associatedType; 49 private final ClassModel associatedClassModel; 45 public class AttributeModel { 46 private final ClassModel associatedType; 50 47 private final String name; 51 48 private final Integer lowerBound; … … 53 50 private final int lenght; 54 51 private final boolean voidable; 52 private final CollectionType collectionType; 55 53 56 54 /** … … 61 59 * @param lenght 62 60 */ 63 public AttributeModel( T associatedType, ClassModel associatedClassModel,61 public AttributeModel(ClassModel associatedType, 64 62 String name, int lowerBound, Integer upperBound, 65 Integer lenght, boolean voidable) { 66 this.associatedType = associatedType; 67 this.associatedClassModel = associatedClassModel; 63 Integer lenght, boolean voidable, CollectionType collectionType) { 64 this.associatedType = associatedType; 68 65 this.name = name; 69 66 this.lowerBound = lowerBound; 70 67 this.upperBound = upperBound; 71 68 this.lenght = lenght; 72 this.voidable = voidable; 69 this.voidable = voidable; 70 this.collectionType = collectionType; 73 71 } 74 72 75 /**76 * @return the associatedClassModel77 * @deprecated probably in future will be merged in the associatedDataType78 */79 public ClassModel getAssociatedClassModel() {80 return associatedClassModel;81 }82 83 73 /** 84 74 * Returns the associated type. 85 75 * @return the associatedType 86 76 */ 87 public T getAssociatedType() {77 public ClassModel getAssociatedType() { 88 78 return associatedType; 89 79 } 90 80 91 /**92 * Returns the associated UMLClass. If the UMLClass is mapped in the93 * {@link PropertyMap#XMI_TO_SQL_MAP} file then the appropriate UMLClass94 * is returned.95 * @return the associatedClass96 */97 /*98 public UMLClass getAssociatedClass() {99 if (associatedClass == null || associatedClass.getName() == null)100 return null;101 102 String typeName = StringUtils.defaultIfEmpty(103 GenerateModuleHelper.getXMIClassToSQLMap().getProperty(associatedClass.getName()), associatedClass.getName());104 105 if (typeName.equals(associatedClass.getName()))106 return associatedClass;107 108 return new UMLClassAdapter(new UML_IDAdapder(null, null, typeName), false, false, false, null);109 }110 */111 112 81 public boolean hasMultiplicity() { 113 return upperBound > 1; 82 return upperBound > 1 83 || collectionType.equals(CollectionType.SET) 84 || collectionType.equals(CollectionType.SEQUENCE); 114 85 } 115 86 … … 139 110 return upperBound; 140 111 } 141 112 113 /** 114 * @return the collection 115 */ 116 public CollectionType getCollectionType() { 117 return collectionType; 118 } 119 142 120 /** 143 121 * @return the lenght -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ImportCollector.java
r7998 r8004 41 41 import ndg.services.newmoon.xmiModel.UMLClass; 42 42 import ndg.services.newmoon.xmiModel.UMLClassDataType; 43 import ndg.services.newmoon.xmiModel.UML_ID;44 43 45 44 import org.apache.commons.collections.CollectionUtils; -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/xmiModel/UMLDataType.java
r7998 r8004 39 39 public interface UMLDataType extends UMLClassDataType { 40 40 UMLModel getUmlModel(); 41 UMLClassDataType getType(); 42 void setType(UMLClassDataType type); 41 43 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/xmiModel/adapter/UMLDataTypeAdapter.java
r7998 r8004 32 32 package ndg.services.newmoon.xmiModel.adapter; 33 33 34 import ndg.services.newmoon.xmiModel.UMLClassDataType; 34 35 import ndg.services.newmoon.xmiModel.UMLDataType; 35 36 import ndg.services.newmoon.xmiModel.UMLModel; … … 42 43 public class UMLDataTypeAdapter extends UMLClassDataTypeAdapter implements UMLDataType { 43 44 45 private UMLClassDataType type; 46 44 47 /** 45 48 * @param id … … 48 51 * @param abstrakt 49 52 */ 50 public UMLDataTypeAdapter(UML_ID id, boolean root, boolean leaf, boolean abstrakt, UMLModel umlModel ) {53 public UMLDataTypeAdapter(UML_ID id, boolean root, boolean leaf, boolean abstrakt, UMLModel umlModel, UMLClassDataType type) { 51 54 super(id, root, leaf, abstrakt, umlModel); 55 this.type = type; 56 } 57 58 /* (non-Javadoc) 59 * @see ndg.services.newmoon.xmiModel.UMLDataType#getType() 60 */ 61 @Override 62 public UMLClassDataType getType() { 63 return type; 52 64 } 53 65 … … 77 89 return super.equals(obj); 78 90 } 91 92 /* (non-Javadoc) 93 * @see ndg.services.newmoon.xmiModel.UMLDataType#setType(ndg.services.newmoon.xmiModel.UMLClassDataType) 94 */ 95 @Override 96 public void setType(UMLClassDataType type) { 97 this.type = type; 98 } 79 99 } -
mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/xmiModel/v11/UMLDataTypeImpl.java
r7998 r8004 32 32 package ndg.services.newmoon.xmiModel.v11; 33 33 34 import ndg.services.newmoon.xmiModel.UMLClassDataType; 34 35 import ndg.services.newmoon.xmiModel.UMLModel; 35 36 import ndg.services.newmoon.xmiModel.adapter.UMLDataTypeAdapter; … … 50 51 * @param abstrakt 51 52 */ 52 public UMLDataTypeImpl(Element el, String modelId, UMLModel umlModel ) {53 public UMLDataTypeImpl(Element el, String modelId, UMLModel umlModel, UMLClassDataType type) { 53 54 super(new UML_IDAdapder(el.getAttribute(Dictionary.XMI_ID), modelId, el.getAttribute(Dictionary.NAME)), 54 55 Boolean.getBoolean(el.getAttribute(Dictionary.ROOT)), 55 56 Boolean.getBoolean(el.getAttribute(Dictionary.LEAF)), 56 57 Boolean.getBoolean(el.getAttribute(Dictionary.ABSTRACT)), 57 umlModel); 58 umlModel, 59 type); 58 60 } 59 61 -
mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm
r7998 r8004 1 #macro( substituteType $typeName) 2 #if($typeName.equals('CharacterString')) 3 ASText#elseif($typeName.equals('Character')) 4 ASText#elseif($typeName.equals('Integer')) 5 Integer#elseif($typeName.equals('Boolean')) 6 BOOLEAN#elseif($typeName.equals('Real')) 7 NUMERIC#elseif($typeName.equals('Vector')) 8 ARRAY#elseif($typeName.equals('Number')) 9 NUMERIC#else 10 ${typeName} 11 #end 12 #end 1 13 2 14 #macro( tableName $tableModel) -
mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity.properties
r7998 r8004 2 2 nmVelocity.resource.loader.description = Velocity Classpath Resource Loader 3 3 nmVelocity.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 4 nmVelocity.resource.loader.path = . 5 4 6 velocimacro.library = global_library.vm 5 7 runtime.references.strict = false -
mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/mapping.vm
r7998 r8004 1 1 ## mapping.vm 2 2 3 3 4 #macro( beforeInsertListener $tableModel) -
mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm
r7998 r8004 40 40 #macro (unionDictionary $attributeModel) 41 41 #foreach($item in $attributeModel) 42 '${item.name}': ${item.associatedClass.name}#if($foreach.hasNext),#end42 '${item.name}':#substituteType(${item.associatedType.associatedClass.name})#if($foreach.hasNext),#end 43 43 #end 44 44 #end -
mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/sqlAlchemyTables.vm
r7998 r8004 5 5 ########################################################################## 6 6 7 8 7 #macro( attributeType $attribute) 9 #set ($fkName = ${attribute.associatedClassModel.associatedType}) 10 #if(($attribute.associatedClassModel.isCodeList() || $attribute.associatedClassModel.isEnumeration())) 11 ${attribute.associatedType.name}.db_type()#elseif($attribute.hasMultiplicity()) 12 ARRAY(${attribute.associatedType.name})#else 13 ${attribute.associatedType.name}(#if($attribute.lenght > 0)${attribute.lenght}#end)#end 8 #if(($attribute.associatedType.isCodeList() || $attribute.associatedType.isEnumeration())) 9 ${attribute.associatedType.associatedClass.name}.db_type()#elseif($attribute.hasMultiplicity()) 10 ARRAY(#substituteType(${attribute.associatedType.associatedClass.name}))#else 11 #substituteType(${attribute.associatedType.associatedClass.name})(#if($attribute.lenght > 0)${attribute.lenght}#end)#end 14 12 #end 15 13 16 14 #macro( column $attribute) 17 Column('_${attribute.name}', #attributeType($attribute) #checkNullable($attribute)), 18 #end 19 20 #macro( inheritanceColumn $tableModel) 21 #foreach( $parent in $tableModel.inherited) 22 #set ($pn = ${parent.associatedClass.name.toLowerCase()}) 23 #set ($tn = ${tableModel.associatedClass.name.toLowerCase()}) 24 ${tab}Column('${tn}_${pn}_id', Integer),#end 25 #if($tableModel.inherited && $tableModel.inherited.size() > 0) 26 #foreach( $parent in $tableModel.inherited) 27 #set ($pn = ${parent.associatedClass.name.toLowerCase()}) 28 #set ($tn = ${tableModel.associatedClass.name.toLowerCase()}) 29 ForeignKeyConstraint(['${tn}_${pn}_id'], 30 ['${pn}.${pn}_id']),#end 31 #end 15 Column('_${attribute.name}', #attributeType(${attribute}) #checkNullable($attribute)), 32 16 #end 33 17 … … 71 55 #end 72 56 Column('t_type', String(30), nullable=False, default='${associatedCN}'), 73 ##inheritanceColumn($tableModel)74 57 ${tab}extend_existing=False,) 75 58 #end -
mauRepo/xmi2sqlalchemy/trunk/src/test/java/ngn/services/newmoon/DOMParser.java
r7998 r8004 5 5 import java.io.File; 6 6 import java.io.InputStream; 7 import java. util.ArrayList;7 import java.net.URL; 8 8 import java.util.HashMap; 9 import java.util.List;10 9 import java.util.Map; 11 10 import java.util.Scanner; … … 15 14 import ndg.services.newmoon.NmParser; 16 15 import ndg.services.newmoon.UMLElementsArchive; 17 import ndg.services.newmoon.NewmoonManager.NM_PARAM;18 16 import ndg.services.newmoon.collect.CollectClasses; 19 17 import ndg.services.newmoon.velocity.python.GenerateClassesClosure; 20 18 import ndg.services.newmoon.velocity.python.GenerateFromClassModel; 21 19 import ndg.services.newmoon.velocity.python.GenerateModuleHelper; 22 import ndg.services.newmoon.velocity.python.GenerateTables;23 20 import ndg.services.newmoon.velocity.python.GenerateTables_; 24 import ndg.services.newmoon.velocity.python.support.ClassModel;25 21 import ndg.services.newmoon.xmiModel.UMLClass; 26 22 import ndg.services.newmoon.xmiModel.UMLModel; 27 23 28 import org.apache.commons.collections.CollectionUtils; 24 import org.apache.commons.io.FileUtils; 25 import org.apache.commons.io.IOUtils; 29 26 import org.junit.Assert; 30 27 import org.junit.Test; … … 32 29 public class DOMParser { 33 30 31 //EXECUTION_DIR is where the incoming file/ZIP is copied 32 //XMI_DOC is the name of the main XMI file 34 33 public enum NM_PARAM { 35 34 XMI_DOC("xmi-path"), REPORT_NAME("reportname"), WORKING_DIRECTORY("working-directory"), DEPENDENCY_REGISTER_PATH( … … 65 64 @Test 66 65 public final void testParseXmlFile() { 67 InputStream inputXML = NmParser.class.getClassLoader().getResourceAsStream("CEDA_Model/CEDA_ModelXMI.xml"); 68 InputStream inputAddClass = NmParser.class.getClassLoader().getResourceAsStream("CEDA_Model/AdditionalClasses.txt"); 66 //InputStream inputXML = NmParser.class.getClassLoader().getResourceAsStream("CEDA_Model/CEDA_ModelXMI.xml"); 67 //InputStream inputAddClass = NmParser.class.getClassLoader().getResourceAsStream("CEDA_Model/AdditionalClasses.txt"); 68 //File baseDir = new File(GenerateModuleHelper.class.getClassLoader().getResource(".").getPath()); 69 69 70 File baseDir = new File(GenerateModuleHelper.class.getClassLoader().getResource(".").getPath()); 70 Map<NewmoonManager.NM_PARAM, String> params = new HashMap<NewmoonManager.NM_PARAM, String>(); 71 params.put(NewmoonManager.NM_PARAM.EXECUTION_DIR, GenerateModuleHelper.class.getClassLoader().getResource(".").getPath()); 72 params.put(NewmoonManager.NM_PARAM.XMI_DOC, "CEDA_Model/CEDA_ModelXMI.xml"); 73 params.put(NewmoonManager.NM_PARAM.OUTPUT_DIR, "encode"); 71 74 75 execute(params); 76 } 77 78 private void execute(Map<NewmoonManager.NM_PARAM, String> params) { 72 79 try { 80 File baseDir = new File(params.get(NewmoonManager.NM_PARAM.EXECUTION_DIR)); 81 82 InputStream inputXML = FileUtils.openInputStream(new File(baseDir, params.get(NewmoonManager.NM_PARAM.XMI_DOC))); 83 InputStream inputAddClass = FileUtils.openInputStream(new File(baseDir, "CEDA_Model/AdditionalClasses.txt")); 84 73 85 NmParser xmiParser = new NmParser(inputXML, null); 74 Future<UMLModel> myModel = UMLElementsArchive.getInstance().startNewParser(xmiParser); 75 76 UMLElementsArchive.getInstance().waitParserToComplete(); 86 Future<UMLModel> myModel = UMLElementsArchive.getInstance().startNewParser(xmiParser); 87 UMLElementsArchive.getInstance().waitParserToComplete(); 77 88 78 89 /* I try to generate just what I need */ 79 90 UMLModel umlModel = myModel.get(); 80 91 81 List<UMLClass> umlClasses = new ArrayList<UMLClass>();82 umlClasses.addAll(UMLElementsArchive.getInstance().getUMLElementByType(UMLClass.class));83 92 84 CollectClasses cc = new CollectClasses(umlClasses); 93 File outDir = new File(baseDir, params.get(NewmoonManager.NM_PARAM.OUTPUT_DIR)); 94 outDir.mkdir(); 95 96 //Generates the ClassModels 97 CollectClasses cc = new CollectClasses(UMLElementsArchive.getInstance().getUMLElementByType(UMLClass.class)); 85 98 UMLElementsArchive.getInstance().getClassModel().addAll(cc.execute()); 86 99 87 GenerateFromClassModel gen = new GenerateFromClassModel(new GenerateClassesClosure(baseDir)); 100 //Generates the python classes 101 GenerateFromClassModel gen = new GenerateFromClassModel(new GenerateClassesClosure(outDir)); 88 102 gen.execute(UMLElementsArchive.getInstance().getClassModel()); 89 90 GenerateTables_ gen2 = new GenerateTables_(baseDir); 103 104 //Generates the sqlalchemy tables 105 GenerateTables_ gen2 = new GenerateTables_(outDir); 91 106 gen2.execute(umlModel); 92 93 //GenerateClasses gp = new GenerateClasses(cms);94 //gp.execute();95 96 /*97 GenerateModule module = new GenerateModule(umlModel);98 UMLElementsArchive.getInstance().startNewParser(module);99 UMLElementsArchive.getInstance().waitParserToComplete();100 */101 102 103 104 // Is better to generate the table on a separate process in order to minimize the generated tables105 /*106 umlClasses.clear();107 umlClasses.addAll(UMLElementsArchive.getInstance().getUMLClassesByUMLModel(umlModel));108 if (inputAddClass != null) {109 Scanner sc = new Scanner(inputAddClass);110 if (sc.hasNext()) {111 CollectionUtils.addIgnoreNull(umlClasses,112 UMLElementsArchive.getInstance().getUMLClassByName(sc.next()));113 }114 }115 */116 117 //GenerateTables tables = new GenerateTables(umlClasses);118 //tables.execute();119 120 107 } catch (Exception e) { 121 108 e.printStackTrace(); … … 127 114 Assert.assertTrue(Boolean.TRUE); // TODO 128 115 } 129 130 private class XMI2SQL {131 Map<NewmoonManager.NM_PARAM, String> params = new HashMap<NewmoonManager.NM_PARAM, String>();132 // ---- mandatory parameters ----//133 // hidden134 //params.put(NM_PARAM.WORKING_DIRECTORY, );135 }136 116 }
Note: See TracChangeset
for help on using the changeset viewer.