Changeset 8009


Ignore:
Timestamp:
07/12/11 16:53:16 (8 years ago)
Author:
mnagni
Message:
 
Location:
mauRepo/xmi2sqlalchemy/trunk/src/main
Files:
1 added
5 deleted
17 edited
2 moved

Legend:

Unmodified
Added
Removed
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/UMLElementsArchive.java

    r8004 r8009  
    4545import java.util.concurrent.Future; 
    4646 
    47 import ndg.services.newmoon.velocity.python.support.ClassModel; 
     47import ndg.services.newmoon.collect.ClassModel; 
    4848import ndg.services.newmoon.xmiModel.EAStub; 
    4949import ndg.services.newmoon.xmiModel.UMLAssociation; 
     
    6262import ndg.services.newmoon.xmiModel.UML_ID; 
    6363import ndg.services.newmoon.xmiModel.adapter.UMLTaggedValueAdapter; 
    64 import ndg.services.newmoon.xmiModel.dummy.CoreImplementation; 
    6564import ndg.services.newmoon.xmiModel.v11.Dictionary; 
    6665 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/AttributeModel.java

    r8004 r8009  
    3030 *  
    3131 */ 
    32 package ndg.services.newmoon.velocity.python.support; 
     32package ndg.services.newmoon.collect; 
    3333 
    3434import ndg.services.newmoon.collect.CollectClassesClosure.CollectionType; 
     35 
    3536 
    3637/** 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/ClassModel.java

    r8005 r8009  
    3030 *  
    3131 */ 
    32 package ndg.services.newmoon.velocity.python.support; 
     32package ndg.services.newmoon.collect; 
    3333 
    3434import java.util.ArrayList; 
     
    3737import java.util.Set; 
    3838 
     39import ndg.services.newmoon.velocity.python.support.ExportModel; 
     40import ndg.services.newmoon.velocity.python.support.ImportCollector; 
     41import ndg.services.newmoon.velocity.python.support.SimpleKeyValue; 
    3942import ndg.services.newmoon.xmiModel.UMLClass; 
    4043 
     
    4750                Enumeration, CodeList, Union, DataType, Boolean, None, Metaclass; 
    4851        } 
    49          
    50         private final ImportCollector importCollector = new ImportCollector(); 
    5152        private final UMLClass associatedClass; 
    5253        private STEREOTYPE stereotype = STEREOTYPE.None; 
     
    5455        private final Set<ClassModel> parents = new HashSet<ClassModel>(); 
    5556        private final Set<AttributeModel> attributeModel = new HashSet<AttributeModel>(); 
    56         private final boolean skipIt; 
    5757         
    5858        /** 
     
    6262                super(); 
    6363                this.associatedClass = associatedClass; 
    64                 this.skipIt = false; 
    6564        } 
    6665         
     
    106105 
    107106        /** 
    108          * @return the ic 
    109          * @deprecated 
    110          */ 
    111         public ImportCollector getImportCollector() { 
    112                 return importCollector; 
    113         } 
    114  
    115         /** 
    116107         * @return the parents 
    117108         */ 
     
    126117                return attributeModel; 
    127118        } 
    128  
    129         /** 
    130          * @return the skipIt 
    131          */ 
    132         public boolean isSkipIt() { 
    133                 return skipIt; 
    134         }        
    135  
     119         
    136120        /* (non-Javadoc) 
    137121         * @see java.lang.Object#hashCode() 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/CollectClassModel.java

    r7998 r8009  
    3636import java.util.Set; 
    3737 
    38 import ndg.services.newmoon.velocity.python.support.ClassModel; 
    3938import ndg.services.newmoon.xmiModel.UMLClass; 
    4039 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/CollectClasses.java

    r7998 r8009  
    3434 
    3535import ndg.services.newmoon.NewmoonException; 
    36 import ndg.services.newmoon.velocity.python.support.ClassModel; 
    3736import ndg.services.newmoon.xmiModel.UMLClass; 
    3837 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/collect/CollectClassesClosure.java

    r8006 r8009  
    4141import ndg.services.newmoon.NewmoonException; 
    4242import ndg.services.newmoon.UMLElementsArchive; 
    43 import ndg.services.newmoon.velocity.python.GenerateClasses.EmbeddedType; 
    44 import ndg.services.newmoon.velocity.python.support.AttributeModel; 
    45 import ndg.services.newmoon.velocity.python.support.ClassModel; 
    46 import ndg.services.newmoon.velocity.python.support.ClassModel.STEREOTYPE; 
     43import ndg.services.newmoon.collect.ClassModel.STEREOTYPE; 
    4744import ndg.services.newmoon.velocity.python.support.SimpleKeyValue; 
    4845import ndg.services.newmoon.xmiModel.UMLAssociationEnd; 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateClassesClosure.java

    r8006 r8009  
    4040 
    4141import ndg.services.newmoon.NewmoonException; 
    42 import ndg.services.newmoon.velocity.python.support.ASCodeList; 
    43 import ndg.services.newmoon.velocity.python.support.ASEnumeration; 
    44 import ndg.services.newmoon.velocity.python.support.ASText; 
    45 import ndg.services.newmoon.velocity.python.support.ASUnion; 
    46 import ndg.services.newmoon.velocity.python.support.ClassModel; 
    47 import ndg.services.newmoon.velocity.python.support.ClassModel.STEREOTYPE; 
    48 import ndg.services.newmoon.xmiModel.UMLClass; 
     42import ndg.services.newmoon.collect.ClassModel; 
    4943 
    5044import org.apache.commons.collections.Closure; 
    51 import org.apache.commons.collections.CollectionUtils; 
    5245import org.apache.velocity.context.Context; 
    5346 
     
    7366 
    7467        private enum CONTEXT { 
    75                 classModel, imports, stereotype 
     68                classModel, imports, stereotype, attributes 
    7669        }; 
    7770         
     
    10497         
    10598        private void writeAll(ClassModel cm) throws IOException { 
    106                         if (skipIt(cm)) 
    107                                 return;                  
    108                         generateImports(cm);                     
    109                         vcontext.put(CONTEXT.stereotype.name(), getStereotypeDummy(cm.getStereotype())); 
    110                         vcontext.put(CONTEXT.classModel.name(), cm);     
     99                        PythonClassModel pcm = new PythonClassModel(cm); 
     100                        if (pcm.skipIt()) 
     101                                return;  
     102                        vcontext.put(CONTEXT.imports.name(), pcm.generateImports());                     
     103                        vcontext.put(CONTEXT.stereotype.name(), pcm.getStereotypeImplementation()); 
     104                        vcontext.put(CONTEXT.classModel.name(), pcm);    
     105                        vcontext.put(CONTEXT.attributes.name(), pcm.getAttributes()); 
    111106                        File fl = new File(getHelper().generatePythonPackage(cm.getAssociatedClass().getUmlPackage()), cm.getAssociatedClass().getName().toLowerCase() + ".py"); 
    112107                        Writer sqlTablesWriter = new FileWriter(fl, true); 
     
    114109                        sqlTablesWriter.close();                         
    115110        } 
    116  
    117         private void generateImports(ClassModel cm) { 
    118                 PythonImportClosure closure = new PythonImportClosure(); 
    119                 List toImport = new ArrayList(); 
    120                 CollectionUtils.addAll(toImport, cm.getParents().iterator()); 
    121                 CollectionUtils.addIgnoreNull(toImport, getStereotypeDummy(cm.getStereotype())); 
    122  
    123                 if (cm.isUnion()) { 
    124                         CollectionUtils.addAll(toImport, cm.getAttributeModel().iterator()); 
    125                         //not the best solution but ok for now 
    126                         //toImport.add(new ASText());                    
    127                 } 
    128                  
    129                 CollectionUtils.forAllDo(toImport, closure); 
    130                  
    131                 //loop over cm elements  -- TO BE DONE!!! 
    132                 vcontext.put(CONTEXT.imports.name(), closure.getImportMap()); 
    133         } 
    134          
    135         private boolean skipIt(ClassModel cm) { 
    136                 return cm.getAssociatedClass().getClass().equals(ASEnumeration.class)  
    137                                 || cm.getAssociatedClass().getClass().equals(ASCodeList.class) 
    138                                 || cm.getAssociatedClass().getClass().equals(ASUnion.class); 
    139         } 
    140          
    141         private UMLClass getStereotypeDummy(STEREOTYPE stereotype) { 
    142                 if (stereotype == null) 
    143                         return null; 
    144                  
    145                 switch (stereotype) { 
    146                 case Enumeration: 
    147                         return new ASEnumeration(); 
    148                 case CodeList: 
    149                         return new ASCodeList(); 
    150                 case Union: 
    151                         return new ASUnion();                    
    152                 default: 
    153                         break; 
    154                 } 
    155                 return null; 
    156         } 
    157          
    158111} 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateFromClassModel.java

    r7998 r8009  
    3333 
    3434import ndg.services.newmoon.NewmoonException; 
    35 import ndg.services.newmoon.velocity.python.support.ClassModel; 
     35import ndg.services.newmoon.collect.ClassModel; 
    3636 
    3737import org.apache.commons.collections.Closure; 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateModuleHelper.java

    r8004 r8009  
    3939import ndg.services.newmoon.UMLElementsArchive; 
    4040import ndg.services.newmoon.UMLElementsArchive.PropertyMap; 
    41 import ndg.services.newmoon.velocity.python.support.ClassModel.STEREOTYPE; 
     41import ndg.services.newmoon.collect.ClassModel.STEREOTYPE; 
    4242import ndg.services.newmoon.xmiModel.UMLClass; 
    4343import ndg.services.newmoon.xmiModel.UMLClassDataType; 
     
    105105        } 
    106106         
    107         /* 
    108         public static boolean skipElement(UMLModel pakkage){ 
    109                 return pakkage.toString().contains("19103"); 
    110         } 
    111         */ 
    112          
    113107        public static boolean skipElement(UMLClassDataType clazz){ 
    114108                return getXMIClassToSQLMap().containsKey(clazz.getName())  
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/GenerateTables_.java

    r8006 r8009  
    4242 
    4343import ndg.services.newmoon.UMLElementsArchive; 
     44import ndg.services.newmoon.collect.AttributeModel; 
    4445import ndg.services.newmoon.collect.CollectClassModel; 
    4546import ndg.services.newmoon.velocity.python.support.AssociationTable; 
    46 import ndg.services.newmoon.velocity.python.support.AttributeModel; 
    4747import ndg.services.newmoon.velocity.python.support.ForeignKey; 
    4848import ndg.services.newmoon.velocity.python.support.ImportCollector; 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/InnerGenerateTablesClosure.java

    r8006 r8009  
    4444import ndg.services.newmoon.UMLElementsArchive; 
    4545import ndg.services.newmoon.UMLElementsArchive.PropertyMap; 
     46import ndg.services.newmoon.collect.AttributeModel; 
     47import ndg.services.newmoon.collect.ClassModel; 
     48import ndg.services.newmoon.collect.ClassModel.STEREOTYPE; 
    4649import ndg.services.newmoon.velocity.python.support.AssociationTable; 
    47 import ndg.services.newmoon.velocity.python.support.AttributeModel; 
    48 import ndg.services.newmoon.velocity.python.support.ClassModel; 
    49 import ndg.services.newmoon.velocity.python.support.ClassModel.STEREOTYPE; 
    5050import ndg.services.newmoon.velocity.python.support.ForeignKey; 
    5151import ndg.services.newmoon.velocity.python.support.ImportCollector; 
     
    168168                collectInheritedParents(tm); 
    169169                updateImportToSQLTables(tm.getAssociatedClass()); 
     170                addInheritanceAsComposition(tm); 
    170171        } 
    171172 
     
    216217                } 
    217218        } 
    218  
     219         
     220        private void addInheritanceAsComposition(TableModel child) throws NewmoonException, IOException { 
     221                UMLClass umlClass = child.getAssociatedClass();          
     222                for (ClassModel cm : getClassModel(umlClass).getParents()) { 
     223                        if (cm == null || checkIfSkipProcess(cm))  
     224                                continue; 
     225 
     226                        TableModel parent = processUMLclass(cm); 
     227                        Relationship rl = new Relationship(child, parent, parent.getAssociatedClass().getName(), 
     228                                        false); 
     229                         
     230                        ForeignKey fk = new ForeignKey(child, parent.getAssociatedClass().getName()); 
     231                        parent.getFk().add(fk); 
     232                        rl.setRelationType(RELATION_TYPE.ONE_TO_ONE); 
     233                        child.getRelationship().add(rl); 
     234                } 
     235        }        
     236         
    219237        private boolean checkIfSkipProcess(ClassModel classModel) { 
    220238                return (classModel.isCodeList()  
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/PythonImportClosure.java

    r8004 r8009  
    3535import java.util.Set; 
    3636 
    37 import ndg.services.newmoon.velocity.python.support.AttributeModel; 
    38 import ndg.services.newmoon.velocity.python.support.ClassModel; 
     37import ndg.services.newmoon.collect.AttributeModel; 
     38import ndg.services.newmoon.collect.ClassModel; 
    3939import ndg.services.newmoon.velocity.python.support.ImportCollector; 
    4040import ndg.services.newmoon.velocity.python.support.TableModel; 
     
    5454                @Override 
    5555                public void execute(Object input) { 
     56                        if (input == null) 
     57                                return;  
    5658                        UMLClassDataType umlType = null; 
    5759                        if (input instanceof UMLClassDataType) { 
     
    6062                                umlType = ((TableModel)input).getAssociatedClass(); 
    6163                        } else if (input instanceof AttributeModel) { 
    62                                 umlType = ((AttributeModel)input).getAssociatedType().getAssociatedClass(); 
     64                                AttributeModel am = ((AttributeModel)input); 
     65                                if (am.getAssociatedType() == null) 
     66                                        return; 
     67                                umlType = am.getAssociatedType().getAssociatedClass(); 
    6368                        } else if (input instanceof ClassModel) { 
    6469                                umlType = ((ClassModel)input).getAssociatedClass(); 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/UnionElement.java

    r7998 r8009  
    3232package ndg.services.newmoon.velocity.python; 
    3333 
    34 import ndg.services.newmoon.velocity.python.GenerateClasses.EmbeddedType; 
     34import ndg.services.newmoon.collect.CollectClassesClosure.CollectionType; 
    3535 
    3636 
     
    4747         * @param collectionType 
    4848         */ 
    49         public UnionElement(String type, EmbeddedType collectionType) { 
     49        public UnionElement(String type, CollectionType collectionType) { 
    5050                super(); 
    5151                this.type = type; 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ExportModel.java

    r7998 r8009  
    3434import java.util.Set; 
    3535 
     36import ndg.services.newmoon.collect.AttributeModel; 
    3637import ndg.services.newmoon.xmiModel.UMLClass; 
    3738 
     
    4344        public UMLClass getAssociatedClass(); 
    4445        public Set<AttributeModel> getAttributeModel(); 
    45         public boolean isSkipIt(); 
    4646} 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/ImportCollector.java

    r8004 r8009  
    7777                        return; 
    7878                 
    79                 /* 
    80                 String format = "%s, %s"; 
    81                 value = String.format(format, new Object[] { importMap.get(key), umlClass.getName() }); 
    82                 */       
    83                  
    8479                String key = getModule(umlClass); 
    8580                if (!importMap.containsKey(key)) { 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/java/ndg/services/newmoon/velocity/python/support/TableModel.java

    r7998 r8009  
    3636import java.util.Set; 
    3737 
     38import ndg.services.newmoon.collect.AttributeModel; 
    3839import ndg.services.newmoon.xmiModel.UMLClass; 
    3940 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/mapping.vm

    r8004 r8009  
    3333 
    3434#macro( generateProperties $tableModel) 
    35         #if($tableModel.relationship.size() > 0 && $tableModel.oa.size() > 0) 
    36 , properties  = {#identicalAttributes($tableModel), #relationColumns($tableModel)} 
    37         #elseif($tableModel.relationship.size() > 0) 
     35        ###if($tableModel.relationship.size() > 0 && $tableModel.oa.size() > 0) 
     36##, properties  = {#identicalAttributes($tableModel), #relationColumns($tableModel)} 
     37##      #elseif($tableModel.relationship.size() > 0) 
    3838, properties  = {#relationColumns($tableModel)} 
    3939##      #elseif($tableModel.oa.size() > 0) 
    4040##, properties  = {#identicalAttributes($tableModel)} 
    41         #end 
     41##      #end 
    4242#end 
    4343 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm

    r8008 r8009  
    111111#end 
    112112 
     113#macro (getter_ $attribute) 
     114#set ( $methodName = "$display.capitalize( $attribute.name )") 
     115${tab}def get${methodName}(self): 
     116#if($attribute.parentName) 
     117${tab}${tab}return self._${attribute.parentName}.${attribute.name} 
     118#else 
     119${tab}${tab}return self._${attribute.name} 
     120#end 
     121#end 
     122 
     123#macro (setter_ $attribute) 
     124#set ( $methodName = "$display.capitalize( $attribute.name )") 
     125${tab}def set${methodName}(self, value): 
     126#if($attribute.typeName) 
     127${tab}${tab} if (isinstance(value, ${attribute.typeName})): 
     128#end 
     129#if($attribute.parentName) 
     130${tab}${tab}${tab} self._${attribute.parentName}.set${methodName}(value) 
     131#else 
     132${tab}${tab}${tab} self._${attribute.name} = value 
     133#end 
     134#end 
     135 
     136#macro ( dogettersetter_ $attributes) 
     137#foreach($attribute in $attributes) 
     138 
     139#getter_($attribute) 
     140 
     141#setter_($attribute) 
     142#end 
     143#end 
     144 
     145#macro( attributes_ $attributes, $parents) 
     146#foreach($attribute in $attributes) 
     147#if($attribute.parent) 
     148${tab}${tab}self._${attribute.name} 
     149#end 
     150#end 
     151#if($parents) 
     152#foreach( $parent in $parents) 
     153${tab}${tab}self._${parent.associatedClass.name}         
     154#end 
     155#end 
     156#end 
     157 
    113158#importing($imports) 
    114159 
     
    138183${tab}''' 
    139184${tab}def __init__(self): 
    140 #addAggregate($classModel) 
    141 ${tab}${tab}super(${classModel.associatedClass.name}, self).__init__() 
    142185#end 
    143186#if (!($classModel.isEnumeration() || $classModel.isCodeList() || $classModel.isUnion())) 
    144 #attributes($classModel.attributeModel) 
    145 #gettersetter($classModel) 
     187#attributes_($attributes, $classModel.parents) 
     188${tab}${tab}super(${classModel.associatedClass.name}, self).__init__() 
     189#dogettersetter_($attributes) 
    146190#end 
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/sqlAlchemyTables.vm

    r8006 r8009  
    66 
    77#macro( attributeType $attribute) 
    8 #if($attribute.associatedType.associatedClass.name.equalsIgnoreCase('boolean') 
     8#if(!$attribute.associatedType.associatedClass.name.equalsIgnoreCase('boolean') 
    99&& ($attribute.associatedType.isCodeList() || $attribute.associatedType.isEnumeration())) 
    1010${attribute.associatedType.associatedClass.name}.db_type()#elseif($attribute.hasMultiplicity()) 
Note: See TracChangeset for help on using the changeset viewer.