Source Code Cross Referenced for UMLModelToMetaBossModelConvertor.java in  » UML » MetaBoss » com » metaboss » sdlctools » models » impl » metabossmodel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » MetaBoss » com.metaboss.sdlctools.models.impl.metabossmodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012:        // POSSIBILITY OF SUCH DAMAGE.
0013:        //
0014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015:        package com.metaboss.sdlctools.models.impl.metabossmodel;
0016:
0017:        import java.io.File;
0018:        import java.util.ArrayList;
0019:        import java.util.Collection;
0020:        import java.util.HashMap;
0021:        import java.util.Iterator;
0022:        import java.util.List;
0023:
0024:        import javax.jmi.reflect.ConstraintViolationException;
0025:        import javax.naming.Context;
0026:        import javax.naming.InitialContext;
0027:        import javax.naming.NamingException;
0028:
0029:        import org.apache.commons.logging.Log;
0030:        import org.apache.commons.logging.LogFactory;
0031:        import org.omg.uml.foundation.datatypes.AggregationKindEnum;
0032:        import org.omg.uml.foundation.datatypes.PseudostateKindEnum;
0033:
0034:        import com.metaboss.sdlctools.models.ModelAlreadyLoadedException;
0035:        import com.metaboss.sdlctools.models.ModelNotLoadedException;
0036:        import com.metaboss.sdlctools.models.ModelRepository;
0037:        import com.metaboss.sdlctools.models.ModelRepositoryException;
0038:        import com.metaboss.sdlctools.models.ModelRepositoryNotFoundException;
0039:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
0040:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
0041:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraintClass;
0042:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
0043:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
0044:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0045:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataTypeClass;
0046:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
0047:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
0048:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyClass;
0049:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
0050:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0051:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureClass;
0052:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0053:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureFieldClass;
0054:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
0055:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
0056:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.AbstractOperation;
0057:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
0058:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
0059:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventClass;
0060:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataField;
0061:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataFieldClass;
0062:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventMessageField;
0063:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventMessageFieldClass;
0064:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscription;
0065:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionClass;
0066:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
0067:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperationClass;
0068:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
0069:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageClass;
0070:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
0071:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageFieldClass;
0072:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageTypeEnum;
0073:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0074:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationClass;
0075:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
0076:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputFieldClass;
0077:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
0078:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputFieldClass;
0079:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
0080:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessageClass;
0081:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0082:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ServiceClass;
0083:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0084:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ServicemoduleClass;
0085:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.SystemClass;
0086:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum;
0087:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
0088:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
0089:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationClass;
0090:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0091:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
0092:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleClass;
0093:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0094:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeClass;
0095:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
0096:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0097:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.DomainClass;
0098:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0099:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityClass;
0100:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
0101:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
0102:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorCardinalityEnum;
0103:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorClass;
0104:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputField;
0105:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputFieldClass;
0106:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
0107:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateClass;
0108:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
0109:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineClass;
0110:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
0111:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
0112:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.TransitionClass;
0113:
0114:        /** This is a utility class which converts UML models with special MetaBoss profile to the MetaBoss models */
0115:        public final class UMLModelToMetaBossModelConvertor {
0116:            private static final Log sLogger = LogFactory
0117:                    .getLog(UMLModelToMetaBossModelConvertor.class);
0118:
0119:            // This clas is used to pass down the context of the conversion
0120:            private static class ConversionContext {
0121:                public ModelRepository mModelRepository = null;
0122:                public String mSourceModelName = null;
0123:                public String mTargetModelName = null;
0124:                public MetaBossModelPackage mMetaBossModelExtent = null;
0125:                public org.omg.uml.UmlPackage mUMLModelExtent = null;
0126:                public UMLStylesheet.UMLMetaBossProfile mMetaBossProfile = null;
0127:                // The cache for objects where there is one-to-one mapping between metaboss element and uml element
0128:                // Used to improve performance of the conversion 
0129:                public HashMap mModelElementsMap = new HashMap(); // Uml element is the key and associated ModelElement is the value
0130:
0131:                public TypeTemplate getTypetemplate(
0132:                        org.omg.uml.foundation.core.UmlClass pUmlTypeTemplate)
0133:                        throws ModelRepositoryException {
0134:                    TypeTemplate lTypeTemplate = null;
0135:                    if ((lTypeTemplate = (TypeTemplate) mModelElementsMap
0136:                            .get(pUmlTypeTemplate)) == null)
0137:                        mModelElementsMap.put(pUmlTypeTemplate,
0138:                                lTypeTemplate = getMetaBossTypeTemplate(this ,
0139:                                        pUmlTypeTemplate));
0140:                    return lTypeTemplate;
0141:                }
0142:
0143:                public DataType getDataType(
0144:                        org.omg.uml.foundation.core.DataType pUmlDataType)
0145:                        throws ModelRepositoryException {
0146:                    DataType lDataType = null;
0147:                    if ((lDataType = (DataType) mModelElementsMap
0148:                            .get(pUmlDataType)) == null)
0149:                        mModelElementsMap.put(pUmlDataType,
0150:                                lDataType = getMetaBossDataType(this ,
0151:                                        pUmlDataType));
0152:                    return lDataType;
0153:                }
0154:
0155:                public EventSubscription getEventSubscription(
0156:                        org.omg.uml.foundation.core.Classifier pUmlEventSubscription)
0157:                        throws ModelRepositoryException {
0158:                    EventSubscription lEventSubscription = null;
0159:                    if ((lEventSubscription = (EventSubscription) mModelElementsMap
0160:                            .get(pUmlEventSubscription)) == null)
0161:                        mModelElementsMap
0162:                                .put(
0163:                                        pUmlEventSubscription,
0164:                                        lEventSubscription = getMetaBossEventSubscription(
0165:                                                this , pUmlEventSubscription));
0166:                    return lEventSubscription;
0167:                }
0168:            }
0169:
0170:            public static void doConversion(String pSourceUMLModelName,
0171:                    String pTargetMetaBossModelName)
0172:                    throws ModelRepositoryException {
0173:                try {
0174:                    sLogger
0175:                            .info("UMLModel to MetaBoss model conversion utility");
0176:                    ConversionContext lConversionContext = new ConversionContext();
0177:                    Context lContext = new InitialContext();
0178:                    lConversionContext.mModelRepository = (ModelRepository) lContext
0179:                            .lookup(ModelRepository.COMPONENT_URL);
0180:
0181:                    // Ensure that the design and technology libraties are loaded
0182:                    String lDesignLibraryModelName = System
0183:                            .getProperty("MetaBoss.Home")
0184:                            + File.separator
0185:                            + "designlib"
0186:                            + File.separator
0187:                            + "Model.xml";
0188:                    if (!lConversionContext.mModelRepository
0189:                            .containsModel(lDesignLibraryModelName))
0190:                        lConversionContext.mModelRepository.openModel(
0191:                                lDesignLibraryModelName, new File(
0192:                                        lDesignLibraryModelName),
0193:                                ModelRepository.METAMODEL_NAME_METABOSS);
0194:                    String lTechnologyLibraryModelName = System
0195:                            .getProperty("MetaBoss.Home")
0196:                            + File.separator
0197:                            + "technologylib"
0198:                            + File.separator
0199:                            + "Model.xml";
0200:                    if (!lConversionContext.mModelRepository
0201:                            .containsModel(lTechnologyLibraryModelName))
0202:                        lConversionContext.mModelRepository.openModel(
0203:                                lTechnologyLibraryModelName, new File(
0204:                                        lTechnologyLibraryModelName),
0205:                                ModelRepository.METAMODEL_NAME_METABOSS);
0206:
0207:                    // Obtain source model package
0208:                    if (!lConversionContext.mModelRepository
0209:                            .containsModel(pSourceUMLModelName))
0210:                        throw new ModelNotLoadedException(pSourceUMLModelName);
0211:                    lConversionContext.mSourceModelName = pSourceUMLModelName;
0212:                    lConversionContext.mUMLModelExtent = (org.omg.uml.UmlPackage) lConversionContext.mModelRepository
0213:                            .getModelExtent(pSourceUMLModelName);
0214:                    // Load standard MetaBoss profile
0215:                    lConversionContext.mMetaBossProfile = UMLStylesheet
0216:                            .loadMetaBossProfile(
0217:                                    lConversionContext.mModelRepository,
0218:                                    lConversionContext.mUMLModelExtent);
0219:                    // Create target model package
0220:                    if (lConversionContext.mModelRepository
0221:                            .containsModel(pTargetMetaBossModelName))
0222:                        throw new ModelAlreadyLoadedException(
0223:                                pTargetMetaBossModelName);
0224:                    try {
0225:                        lConversionContext.mModelRepository.createModel(
0226:                                pTargetMetaBossModelName, null,
0227:                                ModelRepository.METAMODEL_NAME_METABOSS, null);
0228:                        lConversionContext.mTargetModelName = pTargetMetaBossModelName;
0229:                        lConversionContext.mMetaBossModelExtent = (MetaBossModelPackage) lConversionContext.mModelRepository
0230:                                .getModelExtent(pTargetMetaBossModelName);
0231:                        lConversionContext.mModelRepository.beginTransaction();
0232:                        // See if it is an enterprise model
0233:                        List lEnterprises = lConversionContext.mModelRepository
0234:                                .searchByXPath(pSourceUMLModelName,
0235:                                        UMLStylesheet.getAllEnterprisesXPath());
0236:                        if (!lEnterprises.isEmpty()) {
0237:                            if (lEnterprises.size() != 1)
0238:                                throw new ConstraintViolationException(
0239:                                        null,
0240:                                        null,
0241:                                        "There can only be at most one package with 'enterprise' stereotype in the model.");
0242:                            org.omg.uml.modelmanagement.UmlPackage lEnterpriseUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lEnterprises
0243:                                    .get(0);
0244:                            convertEnterprise(lConversionContext,
0245:                                    lEnterpriseUmlPackage);
0246:                        }
0247:                        // Commit transaction - this will fully create the model in memory
0248:                        lConversionContext.mModelRepository.commitTransaction();
0249:                        sLogger.info("Conversion completed");
0250:                    } finally {
0251:                        if (lConversionContext.mModelRepository
0252:                                .isInTransaction())
0253:                            lConversionContext.mModelRepository
0254:                                    .rollbackTransaction();
0255:                    }
0256:                } catch (NamingException e) {
0257:                    throw new ModelRepositoryNotFoundException(e);
0258:                }
0259:            }
0260:
0261:            private static void convertEnterprise(
0262:                    ConversionContext pConversionContext,
0263:                    org.omg.uml.modelmanagement.UmlPackage pEnterpriseUmlPackage)
0264:                    throws ModelRepositoryException {
0265:                sLogger.info("Converting '" + pEnterpriseUmlPackage.getName()
0266:                        + "' Enterprise model");
0267:                Enterprise lEnterprise = pConversionContext.mMetaBossModelExtent
0268:                        .getEnterpriseModel().getEnterprise()
0269:                        .createEnterprise();
0270:                lEnterprise.setName(pEnterpriseUmlPackage.getName());
0271:                UMLUtils.copyComment(pEnterpriseUmlPackage, lEnterprise);
0272:                // Convert design library
0273:                sLogger.info("Converting DesignLibrary");
0274:                convertDesignLibrary(pConversionContext, lEnterprise);
0275:
0276:                // Convert system interfaces
0277:                sLogger.info("Converting Systems");
0278:                convertSystems(pConversionContext, lEnterprise);
0279:                sLogger.info("Converting System DataDictionaries");
0280:                convertSystemDataDictionaries(pConversionContext, lEnterprise);
0281:                sLogger.info("Converting Servicemodules");
0282:                convertServicemodules(pConversionContext, lEnterprise);
0283:                sLogger.info("Converting Messages");
0284:                convertMessages(pConversionContext, lEnterprise);
0285:                convertMessageFields(pConversionContext, lEnterprise);
0286:                sLogger.info("Converting Structures");
0287:                convertStructures(pConversionContext, lEnterprise);
0288:                convertStructureFields(pConversionContext, lEnterprise);
0289:                sLogger.info("Converting Services");
0290:                convertServices(pConversionContext, lEnterprise);
0291:                convertOperations(pConversionContext, lEnterprise);
0292:                sLogger.info("Converting Event Subscriptions");
0293:                convertEventSubscriptions(pConversionContext, lEnterprise);
0294:                // Convert system implementations
0295:                sLogger.info("Converting Domains");
0296:                convertDomains(pConversionContext, lEnterprise);
0297:                convertEntities(pConversionContext, lEnterprise);
0298:                convertEntityGeneralizations(pConversionContext, lEnterprise);
0299:                convertEntityAssociations(pConversionContext, lEnterprise);
0300:                convertEntityAttributes(pConversionContext, lEnterprise);
0301:                convertEntitySelectors(pConversionContext, lEnterprise);
0302:                convertEntityStateMachines(pConversionContext, lEnterprise);
0303:                convertEntityPrimaryKeys(pConversionContext, lEnterprise);
0304:                sLogger.info("Done converting '"
0305:                        + pEnterpriseUmlPackage.getName()
0306:                        + "' Enterprise model");
0307:            }
0308:
0309:            private static void convertSystems(
0310:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0311:                    throws ModelRepositoryException {
0312:                // Add all systems
0313:                SystemClass lSystemClass = pConversionContext.mMetaBossModelExtent
0314:                        .getEnterpriseModel().getSystem();
0315:                List lSystems = pConversionContext.mModelRepository
0316:                        .searchByXPath(pConversionContext.mSourceModelName,
0317:                                UMLStylesheet.getAllSystemsXPath(pEnterprise));
0318:                for (Iterator lSystemsIterator = lSystems.iterator(); lSystemsIterator
0319:                        .hasNext();) {
0320:                    org.omg.uml.modelmanagement.UmlPackage lSystemUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lSystemsIterator
0321:                            .next();
0322:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lSystemClass
0323:                            .createSystem();
0324:                    lSystem.setName(lSystemUmlPackage.getName());
0325:                    lSystem.setEnterprise(pEnterprise);
0326:                    UMLUtils.copyComment(lSystemUmlPackage, lSystem);
0327:                }
0328:            }
0329:
0330:            private static void convertServices(
0331:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0332:                    throws ModelRepositoryException {
0333:                // Add all services
0334:                ServiceClass lServiceClass = pConversionContext.mMetaBossModelExtent
0335:                        .getEnterpriseModel().getService();
0336:                List lServices = pConversionContext.mModelRepository
0337:                        .searchByXPath(pConversionContext.mSourceModelName,
0338:                                UMLStylesheet.getAllServicesXPath(pEnterprise));
0339:                for (Iterator lServicesIterator = lServices.iterator(); lServicesIterator
0340:                        .hasNext();) {
0341:                    org.omg.uml.foundation.core.UmlClass lServiceUmlElement = (org.omg.uml.foundation.core.UmlClass) lServicesIterator
0342:                            .next();
0343:                    Service lService = lServiceClass.createService();
0344:                    lService.setName(lServiceUmlElement.getName());
0345:                    lService.setServicemodule(getMetaBossServicemodule(
0346:                            pConversionContext, lServiceUmlElement));
0347:                    UMLUtils.copyComment(lServiceUmlElement, lService);
0348:                }
0349:            }
0350:
0351:            private static void convertEventSubscriptions(
0352:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0353:                    throws ModelRepositoryException {
0354:                // Add all event subscriptions
0355:                EventSubscriptionClass lEventSubscriptionClass = pConversionContext.mMetaBossModelExtent
0356:                        .getEnterpriseModel().getEventSubscription();
0357:                List lEventSubscriptions = pConversionContext.mModelRepository
0358:                        .searchByXPath(
0359:                                pConversionContext.mSourceModelName,
0360:                                UMLStylesheet
0361:                                        .getAllEventSubscriptionsXPath(pEnterprise));
0362:                for (Iterator lEventSubscriptionsIterator = lEventSubscriptions
0363:                        .iterator(); lEventSubscriptionsIterator.hasNext();) {
0364:                    org.omg.uml.foundation.core.UmlClass lEventSubscriptionUmlElement = (org.omg.uml.foundation.core.UmlClass) lEventSubscriptionsIterator
0365:                            .next();
0366:                    EventSubscription lEventSubscription = lEventSubscriptionClass
0367:                            .createEventSubscription();
0368:                    lEventSubscription.setName(lEventSubscriptionUmlElement
0369:                            .getName());
0370:                    lEventSubscription
0371:                            .setServicemodule(getMetaBossServicemodule(
0372:                                    pConversionContext,
0373:                                    lEventSubscriptionUmlElement));
0374:                    UMLUtils.copyComment(lEventSubscriptionUmlElement,
0375:                            lEventSubscription);
0376:                    // Cache the element
0377:                    pConversionContext.mModelElementsMap.put(
0378:                            lEventSubscriptionUmlElement, lEventSubscription);
0379:                }
0380:                // Convert internal susbscription bits and pieces
0381:                convertEventSubscriptionOperations(pConversionContext,
0382:                        pEnterprise);
0383:                convertEventSubscriptionEvents(pConversionContext, pEnterprise);
0384:
0385:                // Now work on the synchronisation events
0386:                for (Iterator lEventSubscriptionsIterator = lEventSubscriptions
0387:                        .iterator(); lEventSubscriptionsIterator.hasNext();) {
0388:                    org.omg.uml.foundation.core.UmlClass lEventSubscriptionUmlElement = (org.omg.uml.foundation.core.UmlClass) lEventSubscriptionsIterator
0389:                            .next();
0390:                    String lSynchronisationEventName = UMLUtils
0391:                            .getSingleOptionalTagValue(
0392:                                    lEventSubscriptionUmlElement,
0393:                                    UMLStylesheet.EventSubscriptionClassStereotypeTagName_SynchronisationEventName);
0394:                    if (lSynchronisationEventName != null) {
0395:                        EventSubscription lEventSubscription = pConversionContext
0396:                                .getEventSubscription(lEventSubscriptionUmlElement);
0397:                        lEventSubscription
0398:                                .setSynchronisationEvent(lEventSubscription
0399:                                        .getEvent(lSynchronisationEventName));
0400:                    }
0401:                }
0402:            }
0403:
0404:            private static void convertEventSubscriptionOperations(
0405:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0406:                    throws ModelRepositoryException {
0407:                // Add all Operations
0408:                EventSubscriptionOperationClass lEventSubscriptionOperationClass = pConversionContext.mMetaBossModelExtent
0409:                        .getEnterpriseModel().getEventSubscriptionOperation();
0410:                List lSubscriptionOperations = pConversionContext.mModelRepository
0411:                        .searchByXPath(
0412:                                pConversionContext.mSourceModelName,
0413:                                UMLStylesheet
0414:                                        .getAllEventSubscriptionOperationsXPath(pEnterprise));
0415:                for (Iterator lOperationsIterator = lSubscriptionOperations
0416:                        .iterator(); lOperationsIterator.hasNext();) {
0417:                    org.omg.uml.foundation.core.Operation lOperationUmlElement = (org.omg.uml.foundation.core.Operation) lOperationsIterator
0418:                            .next();
0419:                    org.omg.uml.foundation.core.Classifier lUmlOwnerEventSubscription = lOperationUmlElement
0420:                            .getOwner();
0421:                    EventSubscription lOwnerEventSubscription = pConversionContext
0422:                            .getEventSubscription(lUmlOwnerEventSubscription);
0423:                    EventSubscriptionOperation lOperation = lEventSubscriptionOperationClass
0424:                            .createEventSubscriptionOperation();
0425:                    lOperation.setName(lOperationUmlElement.getName());
0426:                    lOperation.setSubscription(lOwnerEventSubscription);
0427:                    UMLUtils.copyComment(lOperationUmlElement, lOperation);
0428:                    // Copy contents using the generic routine
0429:                    convertOperationContents(pConversionContext,
0430:                            lOwnerEventSubscription.getName(),
0431:                            lOperationUmlElement, lOperation);
0432:                }
0433:            }
0434:
0435:            private static void convertEventSubscriptionEvents(
0436:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0437:                    throws ModelRepositoryException {
0438:                EventDataFieldClass lEventDataFieldClass = pConversionContext.mMetaBossModelExtent
0439:                        .getEnterpriseModel().getEventDataField();
0440:                EventMessageFieldClass lEventMessageFieldClass = pConversionContext.mMetaBossModelExtent
0441:                        .getEnterpriseModel().getEventMessageField();
0442:                // Add all Events
0443:                EventClass lEventClass = pConversionContext.mMetaBossModelExtent
0444:                        .getEnterpriseModel().getEvent();
0445:                List lEvents = pConversionContext.mModelRepository
0446:                        .searchByXPath(pConversionContext.mSourceModelName,
0447:                                UMLStylesheet.getAllEventsXPath(pEnterprise));
0448:                for (Iterator lEventsIterator = lEvents.iterator(); lEventsIterator
0449:                        .hasNext();) {
0450:                    org.omg.uml.foundation.core.Operation lEventUmlElement = (org.omg.uml.foundation.core.Operation) lEventsIterator
0451:                            .next();
0452:                    org.omg.uml.foundation.core.Classifier lUmlOwnerEventSubscription = lEventUmlElement
0453:                            .getOwner();
0454:                    EventSubscription lOwnerEventSubscription = pConversionContext
0455:                            .getEventSubscription(lUmlOwnerEventSubscription);
0456:                    Event lEvent = lEventClass.createEvent();
0457:                    lEvent.setName(lEventUmlElement.getName());
0458:                    lEvent.setSubscription(lOwnerEventSubscription);
0459:                    UMLUtils.copyComment(lEventUmlElement, lEvent);
0460:                    // Convert parameters
0461:                    for (Iterator lEventParametersIterator = lEventUmlElement
0462:                            .getParameter().iterator(); lEventParametersIterator
0463:                            .hasNext();) {
0464:                        org.omg.uml.foundation.core.Parameter lParameter = (org.omg.uml.foundation.core.Parameter) lEventParametersIterator
0465:                                .next();
0466:                        // We do not copy derived operation parameters to the metaboss model
0467:                        String lDerivedTagValue = UMLUtils
0468:                                .getSingleOptionalTagValue(
0469:                                        lParameter,
0470:                                        UMLStylesheet.GenericParameterStereotypeTagName_Derived);
0471:                        boolean lDerived = Boolean.valueOf(lDerivedTagValue)
0472:                                .booleanValue();
0473:                        if (lDerived)
0474:                            continue; // We do not copy derived operation parameters to the metaboss model
0475:
0476:                        // First see which kind of parameter is it
0477:                        org.omg.uml.foundation.datatypes.ParameterDirectionKind lKind = lParameter
0478:                                .getKind();
0479:                        org.omg.uml.foundation.core.Classifier lParameterUmlType = lParameter
0480:                                .getType();
0481:                        String lIsArrayTagValue = UMLUtils
0482:                                .getSingleOptionalTagValue(
0483:                                        lParameter,
0484:                                        UMLStylesheet.GenericParameterStereotypeTagName_IsArray);
0485:                        if (lKind == null)
0486:                            throw new ConstraintViolationException(
0487:                                    lParameter,
0488:                                    null,
0489:                                    "The Event parameter must specify kind (In or Return). Parameter '"
0490:                                            + lParameter.getName()
0491:                                            + "' from the '"
0492:                                            + lEventUmlElement.getName()
0493:                                            + "' operation does not specify kind.");
0494:                        if (lKind
0495:                                .equals(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN)) {
0496:                            // Check the type of the return - if it is the message - than this is the message
0497:                            if (lParameterUmlType != null) {
0498:                                if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true
0499:                                        && lParameterUmlType
0500:                                                .getStereotype()
0501:                                                .contains(
0502:                                                        pConversionContext.mMetaBossProfile.mServicemoduleMessageStereotype)) {
0503:                                    // This is the message 
0504:                                    EventMessageField lEventMessageField = lEventMessageFieldClass
0505:                                            .createEventMessageField();
0506:                                    lEventMessageField.setName(lParameter
0507:                                            .getName());
0508:                                    lEventMessageField.setEvent(lEvent);
0509:                                    UMLUtils.copyComment(lParameter,
0510:                                            lEventMessageField);
0511:                                    Message lMessageFieldType = getMetaBossMessage(
0512:                                            pConversionContext,
0513:                                            (org.omg.uml.foundation.core.UmlClass) lParameterUmlType);
0514:                                    lEventMessageField
0515:                                            .setMessageType(lMessageFieldType);
0516:                                    lEventMessageField.setArray(Boolean
0517:                                            .valueOf(lIsArrayTagValue)
0518:                                            .booleanValue());
0519:                                } else {
0520:                                    // This is the data field
0521:                                    EventDataField lEventDataField = lEventDataFieldClass
0522:                                            .createEventDataField();
0523:                                    lEventDataField.setName(lParameter
0524:                                            .getName());
0525:                                    lEventDataField.setEvent(lEvent);
0526:                                    UMLUtils.copyComment(lParameter,
0527:                                            lEventDataField);
0528:                                    if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.DataType) == true) {
0529:                                        DataType lStructureFieldType = pConversionContext
0530:                                                .getDataType((org.omg.uml.foundation.core.DataType) lParameterUmlType);
0531:                                        lEventDataField
0532:                                                .setDataType(lStructureFieldType);
0533:                                    } else if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true) {
0534:                                        Structure lStructureFieldType = getMetaBossStructure(
0535:                                                pConversionContext,
0536:                                                (org.omg.uml.foundation.core.UmlClass) lParameterUmlType);
0537:                                        lEventDataField
0538:                                                .setStructureType(lStructureFieldType);
0539:                                    }
0540:                                    lEventDataField.setArray(Boolean.valueOf(
0541:                                            lIsArrayTagValue).booleanValue());
0542:                                }
0543:                            } else
0544:                                throw new ConstraintViolationException(
0545:                                        lParameterUmlType,
0546:                                        null,
0547:                                        "Type of the Event parameter can only be a UML Data Type or UML Class representing either Structure or Message. Type of the '"
0548:                                                + lParameter.getName()
0549:                                                + "' field in the '"
0550:                                                + lEvent.getName()
0551:                                                + "' Operation is not valid.");
0552:                        } else
0553:                            throw new ConstraintViolationException(
0554:                                    lParameter,
0555:                                    null,
0556:                                    "The Event parameter can only be of 'In' kind. Parameter '"
0557:                                            + lParameter.getName()
0558:                                            + "' from the '"
0559:                                            + lEventUmlElement.getName()
0560:                                            + "' event definition specifies unsupported parameter kind '"
0561:                                            + lKind.toString() + "'.");
0562:                    }
0563:                }
0564:            }
0565:
0566:            private static void convertOperationContents(
0567:                    ConversionContext pConversionContext, String pParentName,
0568:                    org.omg.uml.foundation.core.Operation pUmlOperation,
0569:                    AbstractOperation pOperation)
0570:                    throws ModelRepositoryException {
0571:                OperationInputFieldClass lOperationInputFieldClass = pConversionContext.mMetaBossModelExtent
0572:                        .getEnterpriseModel().getOperationInputField();
0573:                OperationOutputFieldClass lOperationOutputFieldClass = pConversionContext.mMetaBossModelExtent
0574:                        .getEnterpriseModel().getOperationOutputField();
0575:                OperationOutputMessageClass lOperationOutputMessageClass = pConversionContext.mMetaBossModelExtent
0576:                        .getEnterpriseModel().getOperationOutputMessage();
0577:                for (Iterator lOperationParametersIterator = pUmlOperation
0578:                        .getParameter().iterator(); lOperationParametersIterator
0579:                        .hasNext();) {
0580:                    org.omg.uml.foundation.core.Parameter lParameter = (org.omg.uml.foundation.core.Parameter) lOperationParametersIterator
0581:                            .next();
0582:                    // We do not copy derived operation parameters to the metaboss model
0583:                    String lDerivedTagValue = UMLUtils
0584:                            .getSingleOptionalTagValue(
0585:                                    lParameter,
0586:                                    UMLStylesheet.GenericParameterStereotypeTagName_Derived);
0587:                    boolean lDerived = Boolean.valueOf(lDerivedTagValue)
0588:                            .booleanValue();
0589:                    if (lDerived)
0590:                        continue; // We do not copy derived operation parameters to the metaboss model
0591:
0592:                    // First see which kind of parameter is it
0593:                    org.omg.uml.foundation.datatypes.ParameterDirectionKind lKind = lParameter
0594:                            .getKind();
0595:                    org.omg.uml.foundation.core.Classifier lParameterUmlType = lParameter
0596:                            .getType();
0597:                    String lIsArrayTagValue = UMLUtils
0598:                            .getSingleOptionalTagValue(
0599:                                    lParameter,
0600:                                    UMLStylesheet.GenericParameterStereotypeTagName_IsArray);
0601:                    if (lKind == null)
0602:                        throw new ConstraintViolationException(lParameter,
0603:                                null,
0604:                                "The Operation parameter must specify kind (In or Return). Parameter '"
0605:                                        + lParameter.getName() + "' from the '"
0606:                                        + pUmlOperation.getName()
0607:                                        + "' operation does not specify kind.");
0608:                    if (lKind
0609:                            .equals(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN)) {
0610:                        // This is the operation input field
0611:                        OperationInputField lOperationInputField = lOperationInputFieldClass
0612:                                .createOperationInputField();
0613:                        lOperationInputField.setName(lParameter.getName());
0614:                        lOperationInputField.setOperation(pOperation);
0615:                        UMLUtils.copyComment(lParameter, lOperationInputField);
0616:                        if (lParameterUmlType != null) {
0617:                            if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.DataType) == true) {
0618:                                DataType lStructureFieldType = pConversionContext
0619:                                        .getDataType((org.omg.uml.foundation.core.DataType) lParameterUmlType);
0620:                                lOperationInputField
0621:                                        .setDataType(lStructureFieldType);
0622:                            } else if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true) {
0623:                                Structure lStructureFieldType = getMetaBossStructure(
0624:                                        pConversionContext,
0625:                                        (org.omg.uml.foundation.core.UmlClass) lParameterUmlType);
0626:                                lOperationInputField
0627:                                        .setStructureType(lStructureFieldType);
0628:                            } else
0629:                                throw new ConstraintViolationException(
0630:                                        lParameterUmlType,
0631:                                        null,
0632:                                        "Type of the Operation Input field can only be a UML Data Type or UML Class representing Structure. Type of the '"
0633:                                                + lParameter.getName()
0634:                                                + "' field in the '"
0635:                                                + pOperation.getName()
0636:                                                + "' Operation is not valid.");
0637:                        }
0638:                        lOperationInputField.setArray(Boolean.valueOf(
0639:                                lIsArrayTagValue).booleanValue());
0640:                    } else if (lKind
0641:                            .equals(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_RETURN)) {
0642:                        // Check the type of the return - if it is the message - than this is the message
0643:                        if (lParameterUmlType != null) {
0644:                            if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true
0645:                                    && lParameterUmlType
0646:                                            .getStereotype()
0647:                                            .contains(
0648:                                                    pConversionContext.mMetaBossProfile.mServicemoduleMessageStereotype)) {
0649:                                // This is the output message 
0650:                                OperationOutputMessage lOperationOutputMessage = lOperationOutputMessageClass
0651:                                        .createOperationOutputMessage();
0652:                                lOperationOutputMessage.setName(lParameter
0653:                                        .getName());
0654:                                lOperationOutputMessage
0655:                                        .setOperation(pOperation);
0656:                                UMLUtils.copyComment(lParameter,
0657:                                        lOperationOutputMessage);
0658:                                Message lMessageFieldType = getMetaBossMessage(
0659:                                        pConversionContext,
0660:                                        (org.omg.uml.foundation.core.UmlClass) lParameterUmlType);
0661:                                lOperationOutputMessage
0662:                                        .setMessageType(lMessageFieldType);
0663:                                lOperationOutputMessage.setArray(Boolean
0664:                                        .valueOf(lIsArrayTagValue)
0665:                                        .booleanValue());
0666:                            } else {
0667:                                // This is the output field
0668:                                OperationOutputField lOperationOutputField = lOperationOutputFieldClass
0669:                                        .createOperationOutputField();
0670:                                lOperationOutputField.setName(lParameter
0671:                                        .getName());
0672:                                lOperationOutputField.setOperation(pOperation);
0673:                                UMLUtils.copyComment(lParameter,
0674:                                        lOperationOutputField);
0675:                                if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.DataType) == true) {
0676:                                    DataType lStructureFieldType = pConversionContext
0677:                                            .getDataType((org.omg.uml.foundation.core.DataType) lParameterUmlType);
0678:                                    lOperationOutputField
0679:                                            .setDataType(lStructureFieldType);
0680:                                } else if ((lParameterUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true) {
0681:                                    Structure lStructureFieldType = getMetaBossStructure(
0682:                                            pConversionContext,
0683:                                            (org.omg.uml.foundation.core.UmlClass) lParameterUmlType);
0684:                                    lOperationOutputField
0685:                                            .setStructureType(lStructureFieldType);
0686:                                }
0687:                                lOperationOutputField.setArray(Boolean.valueOf(
0688:                                        lIsArrayTagValue).booleanValue());
0689:                            }
0690:                        } else
0691:                            throw new ConstraintViolationException(
0692:                                    lParameterUmlType,
0693:                                    null,
0694:                                    "Type of the Operation Output field can only be a UML Data Type or UML Class representing either Structure or Message. Type of the '"
0695:                                            + lParameter.getName()
0696:                                            + "' field in the '"
0697:                                            + pOperation.getName()
0698:                                            + "' Operation is not valid.");
0699:                    } else
0700:                        throw new ConstraintViolationException(
0701:                                lParameter,
0702:                                null,
0703:                                "The Operation parameter must specify parameter kind (In or Return). Parameter '"
0704:                                        + lParameter.getName()
0705:                                        + "' from the '"
0706:                                        + pUmlOperation.getName()
0707:                                        + "' operation specifies unsupported parameter kind '"
0708:                                        + lKind.toString() + "'.");
0709:                }
0710:                // Convert constraints if necessary
0711:                Collection lSourceUMLConstraints = pUmlOperation
0712:                        .getConstraint();
0713:                if (!lSourceUMLConstraints.isEmpty()) {
0714:                    // Build context string
0715:                    String lParentContextName = pParentName.substring(0, 1)
0716:                            .toUpperCase()
0717:                            + pParentName.substring(1);
0718:                    String lOperationName = pOperation.getName();
0719:                    String lOperationContextName = lOperationName.substring(0,
0720:                            1).toLowerCase()
0721:                            + lOperationName.substring(1);
0722:                    StringBuffer lParametersStringBuffer = new StringBuffer();
0723:                    for (Iterator lInputFieldsIterator = pOperation
0724:                            .getInputFields().iterator(); lInputFieldsIterator
0725:                            .hasNext();) {
0726:                        OperationInputField lInputField = (OperationInputField) lInputFieldsIterator
0727:                                .next();
0728:                        String lParameterName = lInputField.getName();
0729:                        String lParameterContextName = lParameterName
0730:                                .substring(0, 1).toLowerCase()
0731:                                + lParameterName.substring(1);
0732:                        lParametersStringBuffer.append(lParameterContextName);
0733:                        if (lInputFieldsIterator.hasNext())
0734:                            lParametersStringBuffer.append(", ");
0735:                    }
0736:                    String lConstraintStringStart = "context " + pParentName
0737:                            + ":" + lOperationName + "("
0738:                            + lParametersStringBuffer.toString() + ") pre : ";
0739:                    convertConstraints(pConversionContext,
0740:                            lSourceUMLConstraints, pOperation
0741:                                    .getInputConstraints(),
0742:                            lConstraintStringStart);
0743:                }
0744:            }
0745:
0746:            private static void convertOperations(
0747:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0748:                    throws ModelRepositoryException {
0749:                // Add all Operations
0750:                OperationClass lOperationClass = pConversionContext.mMetaBossModelExtent
0751:                        .getEnterpriseModel().getOperation();
0752:                // Used to cache the current structure
0753:                org.omg.uml.foundation.core.Classifier lCurrentUmlOwnerService = null;
0754:                Service lCurrentOwnerService = null;
0755:                List lOperations = pConversionContext.mModelRepository
0756:                        .searchByXPath(pConversionContext.mSourceModelName,
0757:                                UMLStylesheet
0758:                                        .getAllOperationsXPath(pEnterprise));
0759:                for (Iterator lOperationsIterator = lOperations.iterator(); lOperationsIterator
0760:                        .hasNext();) {
0761:                    org.omg.uml.foundation.core.Operation lOperationUmlElement = (org.omg.uml.foundation.core.Operation) lOperationsIterator
0762:                            .next();
0763:                    org.omg.uml.foundation.core.Classifier lUmlOwnerService = lOperationUmlElement
0764:                            .getOwner();
0765:                    if (lCurrentUmlOwnerService == null
0766:                            || lCurrentUmlOwnerService.equals(lUmlOwnerService) == false) {
0767:                        lCurrentUmlOwnerService = lUmlOwnerService;
0768:                        lCurrentOwnerService = getMetaBossService(
0769:                                pConversionContext, lCurrentUmlOwnerService);
0770:                    }
0771:                    Operation lOperation = lOperationClass.createOperation();
0772:                    lOperation.setName(lOperationUmlElement.getName());
0773:                    lOperation.setQuery(lOperationUmlElement.isQuery());
0774:                    lOperation.setService(lCurrentOwnerService);
0775:                    String lTransactionPolicyTagValue = UMLUtils
0776:                            .getSingleOptionalTagValue(
0777:                                    lOperationUmlElement,
0778:                                    UMLStylesheet.ServiceOperationStereotypeTagName_TransactionPolicy);
0779:                    lOperation
0780:                            .setTransactionPolicy(lTransactionPolicyTagValue != null ? TransactionPolicyEnum
0781:                                    .forName(lTransactionPolicyTagValue)
0782:                                    : TransactionPolicyEnum.SUPPORTED);
0783:                    UMLUtils.copyComment(lOperationUmlElement, lOperation);
0784:                    // Copy contents using the generic routine
0785:                    convertOperationContents(pConversionContext,
0786:                            lCurrentOwnerService.getName(),
0787:                            lOperationUmlElement, lOperation);
0788:                }
0789:            }
0790:
0791:            private static void convertServicemodules(
0792:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0793:                    throws ModelRepositoryException {
0794:                // Add all servicemodules
0795:                ServicemoduleClass lServicemoduleClass = pConversionContext.mMetaBossModelExtent
0796:                        .getEnterpriseModel().getServicemodule();
0797:                List lServicemodules = pConversionContext.mModelRepository
0798:                        .searchByXPath(pConversionContext.mSourceModelName,
0799:                                UMLStylesheet
0800:                                        .getAllServicemodulesXPath(pEnterprise));
0801:                for (Iterator lServicemodulesIterator = lServicemodules
0802:                        .iterator(); lServicemodulesIterator.hasNext();) {
0803:                    org.omg.uml.modelmanagement.UmlPackage lServicemoduleUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lServicemodulesIterator
0804:                            .next();
0805:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule lServicemodule = lServicemoduleClass
0806:                            .createServicemodule();
0807:                    lServicemodule.setName(lServicemoduleUmlPackage.getName());
0808:                    lServicemodule.setSystem(getMetaBossSystem(
0809:                            pConversionContext, lServicemoduleUmlPackage));
0810:                    UMLUtils.copyComment(lServicemoduleUmlPackage,
0811:                            lServicemodule);
0812:                }
0813:            }
0814:
0815:            private static void convertDomains(
0816:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0817:                    throws ModelRepositoryException {
0818:                // Add all servicemodules
0819:                DomainClass lDomainClass = pConversionContext.mMetaBossModelExtent
0820:                        .getEnterpriseModel().getSystemImplementationModel()
0821:                        .getDomain();
0822:                List lDomains = pConversionContext.mModelRepository
0823:                        .searchByXPath(pConversionContext.mSourceModelName,
0824:                                UMLStylesheet.getAllDomainsXPath(pEnterprise));
0825:                for (Iterator lDomainsIterator = lDomains.iterator(); lDomainsIterator
0826:                        .hasNext();) {
0827:                    org.omg.uml.modelmanagement.UmlPackage lDomainUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lDomainsIterator
0828:                            .next();
0829:                    Domain lDomain = lDomainClass.createDomain();
0830:                    lDomain.setName(lDomainUmlPackage.getName());
0831:                    lDomain.setSystem(getMetaBossSystem(pConversionContext,
0832:                            lDomainUmlPackage));
0833:                    UMLUtils.copyComment(lDomainUmlPackage, lDomain);
0834:                }
0835:            }
0836:
0837:            // Helper converts entities from UML model to the MetaBoss model
0838:            private static void convertEntities(
0839:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0840:                    throws ModelRepositoryException {
0841:                // Add all services
0842:                EntityClass lEntityClass = pConversionContext.mMetaBossModelExtent
0843:                        .getEnterpriseModel().getSystemImplementationModel()
0844:                        .getEntity();
0845:                List lEntities = pConversionContext.mModelRepository
0846:                        .searchByXPath(pConversionContext.mSourceModelName,
0847:                                UMLStylesheet.getAllEntitiesXPath(pEnterprise));
0848:                // At the first go setup the entities themselves
0849:                for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
0850:                        .hasNext();) {
0851:                    org.omg.uml.foundation.core.UmlClass lEntityUmlElement = (org.omg.uml.foundation.core.UmlClass) lEntitiesIterator
0852:                            .next();
0853:                    Entity lEntity = lEntityClass.createEntity();
0854:                    lEntity.setName(lEntityUmlElement.getName());
0855:                    lEntity.setDomain(getMetaBossDomain(pConversionContext,
0856:                            lEntityUmlElement));
0857:                    lEntity.setAbstract(lEntityUmlElement.isAbstract());
0858:                    lEntity.setFinal(lEntityUmlElement.isLeaf());
0859:                    UMLUtils.copyComment(lEntityUmlElement, lEntity);
0860:                    String lTypeTagValue = UMLUtils.getSingleOptionalTagValue(
0861:                            lEntityUmlElement,
0862:                            UMLStylesheet.EntityClassStereotypeTagName_Type);
0863:                    lEntity
0864:                            .setStereotype(lTypeTagValue != null ? EntityStereotypeEnum
0865:                                    .forName(lTypeTagValue)
0866:                                    : EntityStereotypeEnum.CARD_FILE);
0867:                    String lPluralNameTagValue = UMLUtils
0868:                            .getSingleOptionalTagValue(
0869:                                    lEntityUmlElement,
0870:                                    UMLStylesheet.EntityClassStereotypeTagName_PluralName);
0871:                    lEntity
0872:                            .setPluralName(lPluralNameTagValue != null ? lPluralNameTagValue
0873:                                    : (lEntityUmlElement.getName() + "s"));
0874:                    // Convert constraints if necessary
0875:                    Collection lSourceUMLConstraints = lEntityUmlElement
0876:                            .getConstraint();
0877:                    if (!lSourceUMLConstraints.isEmpty()) {
0878:                        String lEntityName = lEntity.getName();
0879:                        String lContextName = lEntityName.substring(0, 1)
0880:                                .toUpperCase()
0881:                                + lEntityName.substring(1);
0882:                        String lConstraintStringStart = "context "
0883:                                + lContextName + " inv : ";
0884:                        convertConstraints(pConversionContext,
0885:                                lSourceUMLConstraints,
0886:                                lEntity.getConstraints(),
0887:                                lConstraintStringStart);
0888:                    }
0889:                }
0890:            }
0891:
0892:            // Helper converts constraints from UML model to the MetaBoss model
0893:            private static void convertConstraints(
0894:                    ConversionContext pConversionContext,
0895:                    Collection pSourceUMLConstraints,
0896:                    Collection pTargetMetaBossConstraints,
0897:                    String pConstraintStringStart)
0898:                    throws ModelRepositoryException {
0899:                ModelElementConstraintClass lModelElementConstraintClass = pConversionContext.mMetaBossModelExtent
0900:                        .getModelElementConstraint();
0901:                int lConstraintStringStartLength = pConstraintStringStart
0902:                        .length();
0903:                for (Iterator lSourceConstraintsIterator = pSourceUMLConstraints
0904:                        .iterator(); lSourceConstraintsIterator.hasNext();) {
0905:                    org.omg.uml.foundation.core.Constraint lUMLConstraint = (org.omg.uml.foundation.core.Constraint) lSourceConstraintsIterator
0906:                            .next();
0907:                    if (lUMLConstraint
0908:                            .getStereotype()
0909:                            .contains(
0910:                                    pConversionContext.mMetaBossProfile.mConstraintStereotype)) {
0911:                        org.omg.uml.foundation.datatypes.BooleanExpression lConstraintExpression = lUMLConstraint
0912:                                .getBody();
0913:                        if (lConstraintExpression.getLanguage().equals("OCL")
0914:                                && lConstraintExpression.getBody().startsWith(
0915:                                        pConstraintStringStart)) {
0916:                            ModelElementConstraint lMetaBossConstraint = lModelElementConstraintClass
0917:                                    .createModelElementConstraint();
0918:                            lMetaBossConstraint.setName(lUMLConstraint
0919:                                    .getName());
0920:                            UMLUtils.copyComment(lUMLConstraint,
0921:                                    lMetaBossConstraint);
0922:                            lMetaBossConstraint
0923:                                    .setOclExpression(lConstraintExpression
0924:                                            .getBody()
0925:                                            .substring(
0926:                                                    lConstraintStringStartLength));
0927:                            String lDefaultErrorTextTagValue = UMLUtils
0928:                                    .getSingleOptionalTagValue(
0929:                                            lUMLConstraint,
0930:                                            UMLStylesheet.ConstraintStereotypeTagName_DefaultErrorText);
0931:                            if (lDefaultErrorTextTagValue != null)
0932:                                lMetaBossConstraint
0933:                                        .setDefaultErrorText(lDefaultErrorTextTagValue);
0934:                            pTargetMetaBossConstraints.add(lMetaBossConstraint);
0935:                        }
0936:                    }
0937:                }
0938:            }
0939:
0940:            private static void convertEntityAttributes(
0941:                    ConversionContext pConversionContext, Enterprise pEnterprise)
0942:                    throws ModelRepositoryException {
0943:                // Will create and setup all attributes
0944:                AttributeClass lAttributeClass = pConversionContext.mMetaBossModelExtent
0945:                        .getEnterpriseModel().getSystemImplementationModel()
0946:                        .getAttribute();
0947:                // Used to cache the current structure
0948:                org.omg.uml.foundation.core.Classifier lCurrentUmlOwnerEntity = null;
0949:                Entity lCurrentOwnerEntity = null;
0950:                List lAttributes = pConversionContext.mModelRepository
0951:                        .searchByXPath(pConversionContext.mSourceModelName,
0952:                                UMLStylesheet
0953:                                        .getAllAttributesXPath(pEnterprise));
0954:                for (Iterator lAttributesIterator = lAttributes.iterator(); lAttributesIterator
0955:                        .hasNext();) {
0956:                    org.omg.uml.foundation.core.Attribute lAttributeUmlClass = (org.omg.uml.foundation.core.Attribute) lAttributesIterator
0957:                            .next();
0958:
0959:                    String lDerivedTagValue = UMLUtils
0960:                            .getSingleOptionalTagValue(
0961:                                    lAttributeUmlClass,
0962:                                    UMLStylesheet.EntityAttributeStereotypeTagName_Derived);
0963:                    boolean lDerived = Boolean.valueOf(lDerivedTagValue)
0964:                            .booleanValue();
0965:                    if (lDerived)
0966:                        continue; // We do not copy derived attributes to metaboss model
0967:                    org.omg.uml.foundation.core.Classifier lUmlOwnerEntity = lAttributeUmlClass
0968:                            .getOwner();
0969:                    if (lCurrentUmlOwnerEntity == null
0970:                            || lCurrentUmlOwnerEntity.equals(lUmlOwnerEntity) == false) {
0971:                        lCurrentUmlOwnerEntity = lUmlOwnerEntity;
0972:                        lCurrentOwnerEntity = getMetaBossEntity(
0973:                                pConversionContext, lCurrentUmlOwnerEntity);
0974:                    }
0975:                    Attribute lAttribute = lAttributeClass.createAttribute();
0976:                    lAttribute.setName(lAttributeUmlClass.getName());
0977:                    lAttribute.setEntity(lCurrentOwnerEntity);
0978:                    String lAttributeTypeTagValue = UMLUtils
0979:                            .getSingleOptionalTagValue(
0980:                                    lAttributeUmlClass,
0981:                                    UMLStylesheet.EntityAttributeStereotypeTagName_Type);
0982:                    lAttribute
0983:                            .setStereotype(lAttributeTypeTagValue != null ? AttributeStereotypeEnum
0984:                                    .forName(lAttributeTypeTagValue)
0985:                                    : AttributeStereotypeEnum.OPTIONAL);
0986:                    String lIsUsedForOrderingTagValue = UMLUtils
0987:                            .getSingleOptionalTagValue(
0988:                                    lAttributeUmlClass,
0989:                                    UMLStylesheet.EntityAttributeStereotypeTagName_IsUsedForOrdering);
0990:                    lAttribute.setUsedForOrdering(Boolean.valueOf(
0991:                            lIsUsedForOrderingTagValue).booleanValue());
0992:
0993:                    UMLUtils.copyComment(lAttributeUmlClass, lAttribute);
0994:                    org.omg.uml.foundation.core.Classifier lAttributeUmlType = lAttributeUmlClass
0995:                            .getType();
0996:                    if (lAttributeUmlType != null) {
0997:                        if ((lAttributeUmlType instanceof  org.omg.uml.foundation.core.DataType) == true) {
0998:                            DataType lStructureFieldType = pConversionContext
0999:                                    .getDataType((org.omg.uml.foundation.core.DataType) lAttributeUmlType);
1000:                            lAttribute.setDataType(lStructureFieldType);
1001:                        } else
1002:                            throw new ConstraintViolationException(
1003:                                    lAttributeUmlClass, null,
1004:                                    "Type of the Entity attribute can only be a UML Data Type. Type of the '"
1005:                                            + lAttributeUmlClass.getName()
1006:                                            + "' attribute in the '"
1007:                                            + lCurrentOwnerEntity.getName()
1008:                                            + "' Entity is not valid.");
1009:                    }
1010:                }
1011:            }
1012:
1013:            // Helper method. Iterates over all entities and converts Primary Key element tags to the MetaBoss model
1014:            // Note that it has to be called after entities, generalisations, attributes and associations are converted already
1015:            private static void convertEntityPrimaryKeys(
1016:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1017:                    throws ModelRepositoryException {
1018:                List lEntities = pConversionContext.mModelRepository
1019:                        .searchByXPath(pConversionContext.mSourceModelName,
1020:                                UMLStylesheet.getAllEntitiesXPath(pEnterprise));
1021:                // At the first go setup the entities themselves
1022:                for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
1023:                        .hasNext();) {
1024:                    org.omg.uml.foundation.core.UmlClass lEntityUmlElement = (org.omg.uml.foundation.core.UmlClass) lEntitiesIterator
1025:                            .next();
1026:                    String[] lPrimaryKeyElementTagValues = UMLUtils
1027:                            .getMultipleOptionalTagValue(
1028:                                    lEntityUmlElement,
1029:                                    UMLStylesheet.EntityClassStereotypeTagName_PrimaryKeyElement);
1030:                    if (lPrimaryKeyElementTagValues != null
1031:                            && lPrimaryKeyElementTagValues.length > 0) {
1032:                        Entity lMetaBossEntity = getMetaBossEntity(
1033:                                pConversionContext, lEntityUmlElement);
1034:                        Collection lPrimaryKeyElements = lMetaBossEntity
1035:                                .getPrimaryKeyElements();
1036:                        for (int i = 0; i < lPrimaryKeyElementTagValues.length; i++) {
1037:                            String lPrimaryKeyElementName = lPrimaryKeyElementTagValues[i];
1038:                            Attribute lPossibleAttribute = lMetaBossEntity
1039:                                    .findCombinedAttribute(lPrimaryKeyElementName);
1040:                            if (lPossibleAttribute != null) {
1041:                                lPrimaryKeyElements.add(lPossibleAttribute);
1042:                                continue;
1043:                            }
1044:                            AssociationRole lPossibleReference = lMetaBossEntity
1045:                                    .findCombinedReference(lPrimaryKeyElementName);
1046:                            if (lPossibleReference != null) {
1047:                                lPrimaryKeyElements.add(lPossibleReference);
1048:                                continue;
1049:                            }
1050:                            throw new ConstraintViolationException(
1051:                                    lEntityUmlElement, null,
1052:                                    "Unrecognised PrimaryKey element name '"
1053:                                            + lPrimaryKeyElementName
1054:                                            + "'. EntityRef: "
1055:                                            + lMetaBossEntity.getRef());
1056:                        }
1057:                    }
1058:                }
1059:            }
1060:
1061:            // Converts the entity state machines from the uml to metaboss model
1062:            private static void convertEntityStateMachines(
1063:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1064:                    throws ModelRepositoryException {
1065:                // Will create and setup all selectors
1066:                StateClass lStateClass = pConversionContext.mMetaBossModelExtent
1067:                        .getStateMachineModel().getState();
1068:                StateMachineClass lStateMachineClass = pConversionContext.mMetaBossModelExtent
1069:                        .getStateMachineModel().getStateMachine();
1070:                TransitionClass lTransitionClass = pConversionContext.mMetaBossModelExtent
1071:                        .getStateMachineModel().getTransition();
1072:                List lStateMachines = pConversionContext.mModelRepository
1073:                        .searchByXPath(
1074:                                pConversionContext.mSourceModelName,
1075:                                UMLStylesheet
1076:                                        .getAllEntityStateMachinesXPath(pEnterprise));
1077:                for (Iterator lStateMachinesIterator = lStateMachines
1078:                        .iterator(); lStateMachinesIterator.hasNext();) {
1079:                    org.omg.uml.behavioralelements.statemachines.StateMachine lUMLStateMachine = (org.omg.uml.behavioralelements.statemachines.StateMachine) lStateMachinesIterator
1080:                            .next();
1081:                    org.omg.uml.foundation.core.Classifier lUmlOwnerEntity = (org.omg.uml.foundation.core.Classifier) lUMLStateMachine
1082:                            .getContext();
1083:                    Entity lMetaBossOwnerEntity = getMetaBossEntity(
1084:                            pConversionContext, lUmlOwnerEntity);
1085:                    String lStateMachineName = lUMLStateMachine.getName();
1086:                    if (lStateMachineName == null
1087:                            || lStateMachineName.length() == 0)
1088:                        lStateMachineName = lMetaBossOwnerEntity.getName()
1089:                                + "StateMachine";
1090:                    StateMachine lMetaBossStateMachine = lStateMachineClass
1091:                            .createStateMachine();
1092:                    lMetaBossStateMachine.setName(lStateMachineName);
1093:                    UMLUtils.copyComment(lUMLStateMachine,
1094:                            lMetaBossStateMachine);
1095:                    lMetaBossOwnerEntity.setStateMachine(lMetaBossStateMachine);
1096:                    // Convert states
1097:                    org.omg.uml.behavioralelements.statemachines.State lTopState = lUMLStateMachine
1098:                            .getTop();
1099:                    if (lTopState instanceof  org.omg.uml.behavioralelements.statemachines.CompositeState) {
1100:                        org.omg.uml.behavioralelements.statemachines.CompositeState lCompositeTopState = (org.omg.uml.behavioralelements.statemachines.CompositeState) lTopState;
1101:                        for (Iterator lStatesIterator = lCompositeTopState
1102:                                .getSubvertex().iterator(); lStatesIterator
1103:                                .hasNext();) {
1104:                            org.omg.uml.behavioralelements.statemachines.StateVertex lStateVertex = (org.omg.uml.behavioralelements.statemachines.StateVertex) lStatesIterator
1105:                                    .next();
1106:                            if (lStateVertex instanceof  org.omg.uml.behavioralelements.statemachines.Pseudostate) {
1107:                                org.omg.uml.behavioralelements.statemachines.Pseudostate lPseudoState = (org.omg.uml.behavioralelements.statemachines.Pseudostate) lStateVertex;
1108:                                if (lPseudoState.getKind().equals(
1109:                                        PseudostateKindEnum.PK_INITIAL)) {
1110:                                    State lTargetState = lStateClass
1111:                                            .createState();
1112:                                    lTargetState
1113:                                            .setName(lPseudoState.getName());
1114:                                    lTargetState.setType(StateTypeEnum.INITIAL);
1115:                                    UMLUtils.copyComment(lPseudoState,
1116:                                            lTargetState);
1117:                                    lTargetState
1118:                                            .setStateMachine(lMetaBossStateMachine);
1119:                                } else
1120:                                    throw new ConstraintViolationException(
1121:                                            lStateVertex, null,
1122:                                            "Unsupported kind of the the Pseudostate StateVertex. State is not valid.");
1123:                            } else if (lStateVertex instanceof  org.omg.uml.behavioralelements.statemachines.FinalState) {
1124:                                org.omg.uml.behavioralelements.statemachines.FinalState lFinalState = (org.omg.uml.behavioralelements.statemachines.FinalState) lStateVertex;
1125:                                State lTargetState = lStateClass.createState();
1126:                                lTargetState.setName(lFinalState.getName());
1127:                                lTargetState.setType(StateTypeEnum.FINAL);
1128:                                UMLUtils.copyComment(lFinalState, lTargetState);
1129:                                lTargetState
1130:                                        .setStateMachine(lMetaBossStateMachine);
1131:                            } else if (lStateVertex instanceof  org.omg.uml.behavioralelements.statemachines.SimpleState) {
1132:                                org.omg.uml.behavioralelements.statemachines.SimpleState lSimpleState = (org.omg.uml.behavioralelements.statemachines.SimpleState) lStateVertex;
1133:                                State lTargetState = lStateClass.createState();
1134:                                lTargetState.setName(lSimpleState.getName());
1135:                                lTargetState.setType(StateTypeEnum.NORMAL);
1136:                                UMLUtils
1137:                                        .copyComment(lSimpleState, lTargetState);
1138:                                lTargetState
1139:                                        .setStateMachine(lMetaBossStateMachine);
1140:                            } else
1141:                                throw new ConstraintViolationException(
1142:                                        lStateVertex, null,
1143:                                        "Unsupported type of the StateVertex. State is not valid.");
1144:                        }
1145:                    } else
1146:                        throw new ConstraintViolationException(lTopState, null,
1147:                                "Unsupported type of the StateMachine top. StateMachine is not valid.");
1148:                    // Work on transitions
1149:                    for (Iterator lTransitionsIterator = lUMLStateMachine
1150:                            .getTransitions().iterator(); lTransitionsIterator
1151:                            .hasNext();) {
1152:                        org.omg.uml.behavioralelements.statemachines.Transition lUmlTransition = (org.omg.uml.behavioralelements.statemachines.Transition) lTransitionsIterator
1153:                                .next();
1154:                        Transition lMetaBossTransition = lTransitionClass
1155:                                .createTransition();
1156:                        lMetaBossTransition.setName(lUmlTransition.getName());
1157:                        UMLUtils.copyComment(lUmlTransition,
1158:                                lMetaBossTransition);
1159:                        lMetaBossTransition
1160:                                .setStateMachine(lMetaBossStateMachine);
1161:                        lMetaBossTransition
1162:                                .setStartState(getMetaBossState(
1163:                                        pConversionContext, lUmlTransition
1164:                                                .getSource()));
1165:                        lMetaBossTransition
1166:                                .setEndState(getMetaBossState(
1167:                                        pConversionContext, lUmlTransition
1168:                                                .getTarget()));
1169:                    }
1170:                }
1171:            }
1172:
1173:            private static void convertEntitySelectors(
1174:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1175:                    throws ModelRepositoryException {
1176:                // Will create and setup all selectors
1177:                SelectorClass lSelectorClass = pConversionContext.mMetaBossModelExtent
1178:                        .getEnterpriseModel().getSystemImplementationModel()
1179:                        .getSelector();
1180:                SelectorInputFieldClass lSelectorInputFieldClass = pConversionContext.mMetaBossModelExtent
1181:                        .getEnterpriseModel().getSystemImplementationModel()
1182:                        .getSelectorInputField();
1183:                // Used to cache the current structure
1184:                org.omg.uml.foundation.core.Classifier lCurrentUmlOwnerEntity = null;
1185:                Entity lCurrentOwnerEntity = null;
1186:                List lSelectors = pConversionContext.mModelRepository
1187:                        .searchByXPath(
1188:                                pConversionContext.mSourceModelName,
1189:                                UMLStylesheet
1190:                                        .getAllEntitySelectorsXPath(pEnterprise));
1191:                for (Iterator lSelectorsIterator = lSelectors.iterator(); lSelectorsIterator
1192:                        .hasNext();) {
1193:                    org.omg.uml.foundation.core.Operation lSelectorUmlClass = (org.omg.uml.foundation.core.Operation) lSelectorsIterator
1194:                            .next();
1195:                    org.omg.uml.foundation.core.Classifier lUmlOwnerEntity = lSelectorUmlClass
1196:                            .getOwner();
1197:                    if (lCurrentUmlOwnerEntity == null
1198:                            || lCurrentUmlOwnerEntity.equals(lUmlOwnerEntity) == false) {
1199:                        lCurrentUmlOwnerEntity = lUmlOwnerEntity;
1200:                        lCurrentOwnerEntity = getMetaBossEntity(
1201:                                pConversionContext, lCurrentUmlOwnerEntity);
1202:                    }
1203:                    // We will skip conversion of the implicit selectors - they should be
1204:                    // generated automatically as required
1205:                    String lIsImplicitTagValue = UMLUtils
1206:                            .getSingleOptionalTagValue(
1207:                                    lSelectorUmlClass,
1208:                                    UMLStylesheet.EntitySelectorStereotypeTagName_Derived);
1209:                    boolean lIsImplicit = Boolean.valueOf(lIsImplicitTagValue)
1210:                            .booleanValue();
1211:                    if (lIsImplicit)
1212:                        continue; // Skip this selector because it is implicit
1213:                    Selector lSelector = lSelectorClass.createSelector();
1214:                    lSelector.setName(lSelectorUmlClass.getName());
1215:                    lSelector.setEntity(lCurrentOwnerEntity);
1216:                    String lCardinalityTagValue = UMLUtils
1217:                            .getSingleOptionalTagValue(
1218:                                    lSelectorUmlClass,
1219:                                    UMLStylesheet.EntitySelectorStereotypeTagName_Cardinality);
1220:                    lSelector
1221:                            .setCardinality(lCardinalityTagValue != null ? SelectorCardinalityEnum
1222:                                    .forName(lCardinalityTagValue)
1223:                                    : SelectorCardinalityEnum.ZERO_TO_MANY);
1224:                    String lDefaultSQLQueryTagValue = UMLUtils
1225:                            .getSingleOptionalTagValue(
1226:                                    lSelectorUmlClass,
1227:                                    UMLStylesheet.EntitySelectorStereotypeTagName_DefaultSQLQuery);
1228:                    lSelector
1229:                            .setTextOfSqlSelect(lDefaultSQLQueryTagValue != null ? lDefaultSQLQueryTagValue
1230:                                    : "");
1231:                    lSelector.setImplicit(lIsImplicit);
1232:                    UMLUtils.copyComment(lSelectorUmlClass, lSelector);
1233:                    // Deal with input parameters
1234:                    for (Iterator lSelectorParametersIterator = lSelectorUmlClass
1235:                            .getParameter().iterator(); lSelectorParametersIterator
1236:                            .hasNext();) {
1237:                        org.omg.uml.foundation.core.Parameter lParameter = (org.omg.uml.foundation.core.Parameter) lSelectorParametersIterator
1238:                                .next();
1239:                        // First see which kind of parameter is it
1240:                        org.omg.uml.foundation.datatypes.ParameterDirectionKind lKind = lParameter
1241:                                .getKind();
1242:                        org.omg.uml.foundation.core.Classifier lParameterUmlType = lParameter
1243:                                .getType();
1244:                        String lIsArrayTagValue = UMLUtils
1245:                                .getSingleOptionalTagValue(
1246:                                        lParameter,
1247:                                        UMLStylesheet.GenericParameterStereotypeTagName_IsArray);
1248:                        if (lKind == null
1249:                                || lKind
1250:                                        .equals(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN) == false)
1251:                            throw new ConstraintViolationException(
1252:                                    lParameter,
1253:                                    null,
1254:                                    "The Selector can only have input parameters defined. Parameter '"
1255:                                            + lParameter.getName()
1256:                                            + "' from the '"
1257:                                            + lSelectorUmlClass.getName()
1258:                                            + "' Selector does not specify the right parameter kind.");
1259:                        SelectorInputField lSelectorInputField = lSelectorInputFieldClass
1260:                                .createSelectorInputField();
1261:                        lSelectorInputField.setName(lParameter.getName());
1262:                        lSelectorInputField.setArray(Boolean.valueOf(
1263:                                lIsArrayTagValue).booleanValue());
1264:                        lSelectorInputField.setSelector(lSelector);
1265:                        UMLUtils.copyComment(lParameter, lSelectorInputField);
1266:                        if (lParameterUmlType == null
1267:                                || (lParameterUmlType instanceof  org.omg.uml.foundation.core.DataType) == false)
1268:                            throw new ConstraintViolationException(
1269:                                    lParameterUmlType, null,
1270:                                    "Type of the Selector Input field can only be a UML Data Type. Type of the '"
1271:                                            + lParameter.getName()
1272:                                            + "' field in the '"
1273:                                            + lSelectorUmlClass.getName()
1274:                                            + "' Selector is not valid.");
1275:                        DataType lStructureFieldType = pConversionContext
1276:                                .getDataType((org.omg.uml.foundation.core.DataType) lParameterUmlType);
1277:                        lSelectorInputField.setDataType(lStructureFieldType);
1278:                    }
1279:                }
1280:            }
1281:
1282:            private static void convertEntityGeneralizations(
1283:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1284:                    throws ModelRepositoryException {
1285:                // Will find and setup all generalisations
1286:                List lGeneralizations = pConversionContext.mModelRepository
1287:                        .searchByXPath(
1288:                                pConversionContext.mSourceModelName,
1289:                                UMLStylesheet
1290:                                        .getAllEntityGeneralizationsXPath(pEnterprise));
1291:                for (Iterator lGeneralizationsIterator = lGeneralizations
1292:                        .iterator(); lGeneralizationsIterator.hasNext();) {
1293:                    org.omg.uml.foundation.core.Generalization lGeneralization = (org.omg.uml.foundation.core.Generalization) lGeneralizationsIterator
1294:                            .next();
1295:                    org.omg.uml.foundation.core.UmlClass lSubEntityUmlClass = (org.omg.uml.foundation.core.UmlClass) lGeneralization
1296:                            .getChild();
1297:                    Entity lSubEntity = getMetaBossEntity(pConversionContext,
1298:                            lSubEntityUmlClass);
1299:                    org.omg.uml.foundation.core.UmlClass lSuperEntityUmlClass = (org.omg.uml.foundation.core.UmlClass) lGeneralization
1300:                            .getParent();
1301:                    Entity lSuperEntity = getMetaBossEntity(pConversionContext,
1302:                            lSuperEntityUmlClass);
1303:                    lSubEntity.setSupertype(lSuperEntity);
1304:                }
1305:            }
1306:
1307:            private static void convertEntityAssociations(
1308:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1309:                    throws ModelRepositoryException {
1310:                // Will find and setup all associations
1311:                AssociationClass lAssociationClass = pConversionContext.mMetaBossModelExtent
1312:                        .getEnterpriseModel().getSystemImplementationModel()
1313:                        .getAssociation();
1314:
1315:                List lAssociations = pConversionContext.mModelRepository
1316:                        .searchByXPath(
1317:                                pConversionContext.mSourceModelName,
1318:                                UMLStylesheet
1319:                                        .getAllEntityAssociationsXPath(pEnterprise));
1320:                for (Iterator lAssociationsIterator = lAssociations.iterator(); lAssociationsIterator
1321:                        .hasNext();) {
1322:                    org.omg.uml.foundation.core.UmlAssociation lUmlAssociation = (org.omg.uml.foundation.core.UmlAssociation) lAssociationsIterator
1323:                            .next();
1324:                    List lUmlAssociationEnds = lUmlAssociation.getConnection();
1325:                    if (lUmlAssociationEnds.size() != 2)
1326:                        throw new ConstraintViolationException(
1327:                                lUmlAssociation,
1328:                                null,
1329:                                "UML Association must contain exactly two Association End points. Association '"
1330:                                        + lUmlAssociation.getName()
1331:                                        + "' contains "
1332:                                        + lUmlAssociationEnds.size()
1333:                                        + " endpoints.");
1334:                    org.omg.uml.foundation.core.AssociationEnd lUmlAssociationEnd1 = (org.omg.uml.foundation.core.AssociationEnd) lUmlAssociationEnds
1335:                            .get(0);
1336:                    org.omg.uml.foundation.core.AssociationEnd lUmlAssociationEnd2 = (org.omg.uml.foundation.core.AssociationEnd) lUmlAssociationEnds
1337:                            .get(1);
1338:
1339:                    org.omg.uml.foundation.core.UmlClass lEnd1EntityUmlClass = (org.omg.uml.foundation.core.UmlClass) lUmlAssociationEnd1
1340:                            .getParticipant();
1341:                    Entity lEnd1Entity = getMetaBossEntity(pConversionContext,
1342:                            lEnd1EntityUmlClass);
1343:
1344:                    org.omg.uml.foundation.core.UmlClass lEnd2EntityUmlClass = (org.omg.uml.foundation.core.UmlClass) lUmlAssociationEnd2
1345:                            .getParticipant();
1346:                    Entity lEnd2Entity = getMetaBossEntity(pConversionContext,
1347:                            lEnd2EntityUmlClass);
1348:
1349:                    Domain lAssociationDomain = lEnd1Entity.getDomain();
1350:                    if (!lAssociationDomain.equals(lEnd2Entity.getDomain()))
1351:                        throw new ConstraintViolationException(
1352:                                lUmlAssociation,
1353:                                null,
1354:                                "UML Association which represents an association betwen Entities must refer to exactly two Entities from the same Domain. Association '"
1355:                                        + lUmlAssociation.getName()
1356:                                        + "' refers to Entities from different Domains.");
1357:
1358:                    Association lAssociation = lAssociationClass
1359:                            .createAssociation();
1360:                    lAssociation.setName(lUmlAssociation.getName());
1361:                    lAssociation.setDomain(lAssociationDomain);
1362:                    UMLUtils.copyComment(lUmlAssociation, lAssociation);
1363:
1364:                    // Work on converting ends		
1365:                    convertAssociationRole(pConversionContext, lAssociation,
1366:                            lEnd1Entity, lUmlAssociationEnd1);
1367:                    convertAssociationRole(pConversionContext, lAssociation,
1368:                            lEnd2Entity, lUmlAssociationEnd2);
1369:                }
1370:            }
1371:
1372:            //Helper. Converts single Uml AssociationEnd to the MetaBoss model
1373:            private static void convertAssociationRole(
1374:                    ConversionContext pConversionContext,
1375:                    Association pOwnerAssociation,
1376:                    Entity pParticipatingEntity,
1377:                    org.omg.uml.foundation.core.AssociationEnd pSourceAssociationEnd)
1378:                    throws ModelRepositoryException {
1379:                // Will setup required association role
1380:                AssociationRoleClass lAssociationRoleClass = pConversionContext.mMetaBossModelExtent
1381:                        .getEnterpriseModel().getSystemImplementationModel()
1382:                        .getAssociationRole();
1383:                AssociationRole lAssociationRole = lAssociationRoleClass
1384:                        .createAssociationRole();
1385:                lAssociationRole.setName(pSourceAssociationEnd.getName());
1386:                lAssociationRole.setAssociation(pOwnerAssociation);
1387:                lAssociationRole.setEntity(pParticipatingEntity);
1388:                String lPluralNameTagValue = UMLUtils
1389:                        .getSingleOptionalTagValue(
1390:                                pSourceAssociationEnd,
1391:                                UMLStylesheet.AssociationRoleStereotypeTagName_PluralName);
1392:                lAssociationRole
1393:                        .setPluralName(lPluralNameTagValue != null ? lPluralNameTagValue
1394:                                : (pSourceAssociationEnd.getName() + "s"));
1395:                UMLUtils.copyComment(pSourceAssociationEnd, lAssociationRole);
1396:                org.omg.uml.foundation.datatypes.AggregationKind lUmlAggregationKind = pSourceAssociationEnd
1397:                        .getAggregation();
1398:                if (lUmlAggregationKind
1399:                        .equals(AggregationKindEnum.AK_COMPOSITE))
1400:                    lAssociationRole
1401:                            .setAggregationType(AggregationTypeEnum.COMPOSITION);
1402:                else if (lUmlAggregationKind
1403:                        .equals(AggregationKindEnum.AK_AGGREGATE))
1404:                    lAssociationRole
1405:                            .setAggregationType(AggregationTypeEnum.AGGREGATION);
1406:                else
1407:                    lAssociationRole
1408:                            .setAggregationType(AggregationTypeEnum.NONE);
1409:                org.omg.uml.foundation.datatypes.Multiplicity lMultiplicity = pSourceAssociationEnd
1410:                        .getMultiplicity();
1411:                Collection lMultilicityRanges = lMultiplicity.getRange();
1412:                if (lMultilicityRanges.isEmpty())
1413:                    throw new ConstraintViolationException(
1414:                            pSourceAssociationEnd,
1415:                            null,
1416:                            "UML Association End must define exactly one multiplicity range. Association End '"
1417:                                    + pSourceAssociationEnd.getName()
1418:                                    + "' from the '"
1419:                                    + pOwnerAssociation.getName()
1420:                                    + "' Association does not define any.");
1421:                if (lMultilicityRanges.size() > 1)
1422:                    throw new ConstraintViolationException(
1423:                            pSourceAssociationEnd,
1424:                            null,
1425:                            "UML Association End must define a simple \"From...To\" multiplicity range. Association End '"
1426:                                    + pSourceAssociationEnd.getName()
1427:                                    + "' from the '"
1428:                                    + pOwnerAssociation.getName()
1429:                                    + "' Association defines a complex multiplicity range which is not supported.");
1430:                org.omg.uml.foundation.datatypes.MultiplicityRange lMultiplicityRange = (org.omg.uml.foundation.datatypes.MultiplicityRange) lMultilicityRanges
1431:                        .iterator().next();
1432:                if (lMultiplicityRange.getLower() == 0
1433:                        && lMultiplicityRange.getUpper() != 1)
1434:                    lAssociationRole
1435:                            .setCardinality(AssociationRoleCardinalityEnum.ZERO_TO_MANY);
1436:                else if (lMultiplicityRange.getLower() == 0
1437:                        && lMultiplicityRange.getUpper() == 1)
1438:                    lAssociationRole
1439:                            .setCardinality(AssociationRoleCardinalityEnum.ZERO_OR_ONE);
1440:                else if (lMultiplicityRange.getLower() == 1
1441:                        && lMultiplicityRange.getUpper() != 1)
1442:                    lAssociationRole
1443:                            .setCardinality(AssociationRoleCardinalityEnum.ONE_TO_MANY);
1444:                else if (lMultiplicityRange.getLower() == 1
1445:                        && lMultiplicityRange.getUpper() == 1)
1446:                    lAssociationRole
1447:                            .setCardinality(AssociationRoleCardinalityEnum.ONE);
1448:                else
1449:                    throw new ConstraintViolationException(
1450:                            pSourceAssociationEnd,
1451:                            null,
1452:                            "UML Association End contains unsupported multiplicity range definition. Association End '"
1453:                                    + pSourceAssociationEnd.getName()
1454:                                    + "' from the '"
1455:                                    + pOwnerAssociation.getName()
1456:                                    + "' Association defines multiplicity range with lower limit "
1457:                                    + lMultiplicityRange.getLower()
1458:                                    + " and upper limit "
1459:                                    + lMultiplicityRange.getUpper());
1460:
1461:            }
1462:
1463:            private static void convertMessages(
1464:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1465:                    throws ModelRepositoryException {
1466:                // Add all messages
1467:                MessageClass lMessageClass = pConversionContext.mMetaBossModelExtent
1468:                        .getEnterpriseModel().getMessage();
1469:                List lMessages = pConversionContext.mModelRepository
1470:                        .searchByXPath(pConversionContext.mSourceModelName,
1471:                                UMLStylesheet.getAllMessagesXPath(pEnterprise));
1472:                for (Iterator lMessagesIterator = lMessages.iterator(); lMessagesIterator
1473:                        .hasNext();) {
1474:                    org.omg.uml.foundation.core.UmlClass lMessageUmlClass = (org.omg.uml.foundation.core.UmlClass) lMessagesIterator
1475:                            .next();
1476:                    // We do not copy derived messages to the metaboss model
1477:                    String lDerivedTagValue = UMLUtils
1478:                            .getSingleOptionalTagValue(
1479:                                    lMessageUmlClass,
1480:                                    UMLStylesheet.MessageClassStereotypeTagName_Derived);
1481:                    boolean lDerived = Boolean.valueOf(lDerivedTagValue)
1482:                            .booleanValue();
1483:                    if (lDerived)
1484:                        continue; // We do not copy derived messages to the metaboss model
1485:                    Message lMessage = lMessageClass.createMessage();
1486:                    lMessage.setName(lMessageUmlClass.getName());
1487:                    Servicemodule lServicemodule = findMetaBossServicemodule(
1488:                            pConversionContext, lMessageUmlClass);
1489:                    AbstractNamespace lNamespace = findMetaBossNamespace(
1490:                            pConversionContext, lMessageUmlClass.getNamespace());
1491:                    if (lServicemodule != null)
1492:                        lMessage.setServicemodule(lServicemodule);
1493:                    else if (lNamespace != null)
1494:                        lMessage.setNamespace(lNamespace);
1495:                    String lDefaultText = UMLUtils
1496:                            .getSingleOptionalTagValue(
1497:                                    lMessageUmlClass,
1498:                                    UMLStylesheet.MessageClassStereotypeTagName_DefaultText);
1499:                    if (lDefaultText != null)
1500:                        lMessage.setDefaultText(lDefaultText);
1501:                    String lMessageTypeTagValue = UMLUtils
1502:                            .getSingleOptionalTagValue(
1503:                                    lMessageUmlClass,
1504:                                    UMLStylesheet.MessageClassStereotypeTagName_Type);
1505:                    lMessage
1506:                            .setType(lMessageTypeTagValue != null ? MessageTypeEnum
1507:                                    .forName(lMessageTypeTagValue)
1508:                                    : MessageTypeEnum.INFORMATION);
1509:                    UMLUtils.copyComment(lMessageUmlClass, lMessage);
1510:                }
1511:            }
1512:
1513:            private static void convertMessageFields(
1514:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1515:                    throws ModelRepositoryException {
1516:                // Add all message fields
1517:                MessageFieldClass lMessageFieldClass = pConversionContext.mMetaBossModelExtent
1518:                        .getEnterpriseModel().getMessageField();
1519:                List lMessageFields = pConversionContext.mModelRepository
1520:                        .searchByXPath(pConversionContext.mSourceModelName,
1521:                                UMLStylesheet
1522:                                        .getAllMessageFieldsXPath(pEnterprise));
1523:                org.omg.uml.foundation.core.Classifier lCurrentUmlOwnerMessage = null;
1524:                Message lCurrentOwnerMessage = null;
1525:                for (Iterator lMessageFieldsIterator = lMessageFields
1526:                        .iterator(); lMessageFieldsIterator.hasNext();) {
1527:                    org.omg.uml.foundation.core.Attribute lMessageFieldUmlClass = (org.omg.uml.foundation.core.Attribute) lMessageFieldsIterator
1528:                            .next();
1529:                    org.omg.uml.foundation.core.Classifier lUmlOwnerMessage = lMessageFieldUmlClass
1530:                            .getOwner();
1531:                    // We do not copy derived messages (and their fields) to the metaboss model
1532:                    String lDerivedTagValue = UMLUtils
1533:                            .getSingleOptionalTagValue(
1534:                                    lUmlOwnerMessage,
1535:                                    UMLStylesheet.MessageClassStereotypeTagName_Derived);
1536:                    boolean lDerived = Boolean.valueOf(lDerivedTagValue)
1537:                            .booleanValue();
1538:                    if (lDerived)
1539:                        continue; // We do not copy derived messages (and their fields) to the metaboss model
1540:                    if (lCurrentUmlOwnerMessage == null
1541:                            || lCurrentUmlOwnerMessage.equals(lUmlOwnerMessage) == false) {
1542:                        lCurrentUmlOwnerMessage = lUmlOwnerMessage;
1543:                        lCurrentOwnerMessage = getMetaBossMessage(
1544:                                pConversionContext, lCurrentUmlOwnerMessage);
1545:                    }
1546:                    MessageField lMessageField = lMessageFieldClass
1547:                            .createMessageField();
1548:                    lMessageField.setName(lMessageFieldUmlClass.getName());
1549:                    lMessageField.setMessage(lCurrentOwnerMessage);
1550:                    UMLUtils.copyComment(lMessageFieldUmlClass, lMessageField);
1551:                    org.omg.uml.foundation.core.Classifier lMessageUmlType = lMessageFieldUmlClass
1552:                            .getType();
1553:                    if (lMessageUmlType != null) {
1554:                        if ((lMessageUmlType instanceof  org.omg.uml.foundation.core.DataType) == false)
1555:                            throw new ConstraintViolationException(
1556:                                    lMessageFieldUmlClass,
1557:                                    null,
1558:                                    "Type of the Message attribute can only be a primitive UML Data Type (ie. can not be a UML Class). Type of the '"
1559:                                            + lMessageFieldUmlClass.getName()
1560:                                            + "' attribute in the '"
1561:                                            + lCurrentOwnerMessage.getName()
1562:                                            + "' message is not primitive.");
1563:                        DataType lMessageFieldType = pConversionContext
1564:                                .getDataType((org.omg.uml.foundation.core.DataType) lMessageUmlType);
1565:                        lMessageField.setDataType(lMessageFieldType);
1566:                    }
1567:                }
1568:            }
1569:
1570:            private static void convertStructures(
1571:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1572:                    throws ModelRepositoryException {
1573:                // Add all messages
1574:                StructureClass lStructureClass = pConversionContext.mMetaBossModelExtent
1575:                        .getDataDictionaryModel().getStructure();
1576:                List lStructures = pConversionContext.mModelRepository
1577:                        .searchByXPath(pConversionContext.mSourceModelName,
1578:                                UMLStylesheet
1579:                                        .getAllStructuresXPath(pEnterprise));
1580:                for (Iterator lStructuresIterator = lStructures.iterator(); lStructuresIterator
1581:                        .hasNext();) {
1582:                    org.omg.uml.foundation.core.UmlClass lStructureUmlClass = (org.omg.uml.foundation.core.UmlClass) lStructuresIterator
1583:                            .next();
1584:                    Structure lStructure = lStructureClass.createStructure();
1585:                    lStructure.setName(lStructureUmlClass.getName());
1586:                    Servicemodule lServicemodule = findMetaBossServicemodule(
1587:                            pConversionContext, lStructureUmlClass);
1588:                    AbstractNamespace lNamespace = findMetaBossNamespace(
1589:                            pConversionContext, lStructureUmlClass
1590:                                    .getNamespace());
1591:                    if (lServicemodule != null)
1592:                        lStructure.setServicemodule(lServicemodule);
1593:                    else if (lNamespace != null)
1594:                        lStructure.setNamespace(lNamespace);
1595:                    UMLUtils.copyComment(lStructureUmlClass, lStructure);
1596:
1597:                    // Convert constraints if necessary
1598:                    Collection lSourceUMLConstraints = lStructureUmlClass
1599:                            .getConstraint();
1600:                    if (!lSourceUMLConstraints.isEmpty()) {
1601:                        String lStructureName = lStructure.getName();
1602:                        String lContextName = lStructureName.substring(0, 1)
1603:                                .toUpperCase()
1604:                                + lStructureName.substring(1);
1605:                        String lConstraintStringStart = "context "
1606:                                + lContextName + " inv : ";
1607:                        convertConstraints(pConversionContext,
1608:                                lSourceUMLConstraints, lStructure
1609:                                        .getConstraints(),
1610:                                lConstraintStringStart);
1611:                    }
1612:
1613:                }
1614:            }
1615:
1616:            private static void convertStructureFields(
1617:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1618:                    throws ModelRepositoryException {
1619:                // Add all Structure fields
1620:                StructureFieldClass lStructureFieldClass = pConversionContext.mMetaBossModelExtent
1621:                        .getDataDictionaryModel().getStructureField();
1622:                // Used to cache the current structure
1623:                org.omg.uml.foundation.core.Classifier lCurrentUmlOwnerStructure = null;
1624:                Structure lCurrentOwnerStructure = null;
1625:                List lStructureFields = pConversionContext.mModelRepository
1626:                        .searchByXPath(
1627:                                pConversionContext.mSourceModelName,
1628:                                UMLStylesheet
1629:                                        .getAllStructureFieldsXPath(pEnterprise));
1630:                for (Iterator lStructureFieldsIterator = lStructureFields
1631:                        .iterator(); lStructureFieldsIterator.hasNext();) {
1632:                    org.omg.uml.foundation.core.Attribute lStructureFieldUmlClass = (org.omg.uml.foundation.core.Attribute) lStructureFieldsIterator
1633:                            .next();
1634:                    org.omg.uml.foundation.core.Classifier lUmlOwnerStructure = lStructureFieldUmlClass
1635:                            .getOwner();
1636:                    if (lCurrentUmlOwnerStructure == null
1637:                            || lCurrentUmlOwnerStructure
1638:                                    .equals(lUmlOwnerStructure) == false) {
1639:                        lCurrentUmlOwnerStructure = lUmlOwnerStructure;
1640:                        lCurrentOwnerStructure = getMetaBossStructure(
1641:                                pConversionContext, lCurrentUmlOwnerStructure);
1642:                    }
1643:                    StructureField lStructureField = lStructureFieldClass
1644:                            .createStructureField();
1645:                    lStructureField.setName(lStructureFieldUmlClass.getName());
1646:                    lStructureField.setOwnerStructure(lCurrentOwnerStructure);
1647:                    UMLUtils.copyComment(lStructureFieldUmlClass,
1648:                            lStructureField);
1649:                    org.omg.uml.foundation.core.Classifier lStructureUmlType = lStructureFieldUmlClass
1650:                            .getType();
1651:                    if (lStructureUmlType != null) {
1652:                        if ((lStructureUmlType instanceof  org.omg.uml.foundation.core.DataType) == true) {
1653:                            DataType lStructureFieldType = pConversionContext
1654:                                    .getDataType((org.omg.uml.foundation.core.DataType) lStructureUmlType);
1655:                            lStructureField.setDataType(lStructureFieldType);
1656:                        } else if ((lStructureUmlType instanceof  org.omg.uml.foundation.core.UmlClass) == true) {
1657:                            Structure lStructureFieldType = getMetaBossStructure(
1658:                                    pConversionContext,
1659:                                    (org.omg.uml.foundation.core.UmlClass) lStructureUmlType);
1660:                            lStructureField
1661:                                    .setStructureType(lStructureFieldType);
1662:                        } else
1663:                            throw new ConstraintViolationException(
1664:                                    lStructureFieldUmlClass,
1665:                                    null,
1666:                                    "Type of the Structure field can only be a primitive UML Data Type or Structure. Type of the '"
1667:                                            + lStructureFieldUmlClass.getName()
1668:                                            + "' field in the '"
1669:                                            + lCurrentOwnerStructure.getName()
1670:                                            + "' Structure is not valid.");
1671:                    }
1672:                    org.omg.uml.foundation.datatypes.Multiplicity lMultiplicity = lStructureFieldUmlClass
1673:                            .getMultiplicity();
1674:                    Collection lMultilicityRanges = lMultiplicity.getRange();
1675:                    if (lMultilicityRanges.isEmpty())
1676:                        throw new ConstraintViolationException(
1677:                                lStructureFieldUmlClass, null,
1678:                                "UML Attribute must define exactly one multiplicity range. Attribute '"
1679:                                        + lStructureFieldUmlClass.getName()
1680:                                        + "' from the '"
1681:                                        + lUmlOwnerStructure.getName()
1682:                                        + "' Structure does not define any.");
1683:                    if (lMultilicityRanges.size() > 1)
1684:                        throw new ConstraintViolationException(
1685:                                lStructureFieldUmlClass,
1686:                                null,
1687:                                "UML Attribute must define a simple \"From...To\" multiplicity range. Attribute '"
1688:                                        + lStructureFieldUmlClass.getName()
1689:                                        + "' from the '"
1690:                                        + lUmlOwnerStructure.getName()
1691:                                        + "' Structure defines a complex multiplicity range which is not supported.");
1692:                    org.omg.uml.foundation.datatypes.MultiplicityRange lMultiplicityRange = (org.omg.uml.foundation.datatypes.MultiplicityRange) lMultilicityRanges
1693:                            .iterator().next();
1694:                    if (lMultiplicityRange.getLower() == 0
1695:                            && lMultiplicityRange.getUpper() != 1)
1696:                        lStructureField.setArray(true);
1697:                    else if (lMultiplicityRange.getLower() == 0
1698:                            && lMultiplicityRange.getUpper() == 1)
1699:                        lStructureField.setArray(false);
1700:                    else
1701:                        throw new ConstraintViolationException(
1702:                                lStructureFieldUmlClass,
1703:                                null,
1704:                                "UML Attribute contains unsupported multiplicity range definition. Only simple '0..1' and '0..*' are suported. Attribute '"
1705:                                        + lStructureFieldUmlClass.getName()
1706:                                        + "' from the '"
1707:                                        + lUmlOwnerStructure.getName()
1708:                                        + "' Structure defines multiplicity range with lower limit "
1709:                                        + lMultiplicityRange.getLower()
1710:                                        + " and upper limit "
1711:                                        + lMultiplicityRange.getUpper());
1712:                }
1713:            }
1714:
1715:            private static void convertSystemDataDictionaries(
1716:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1717:                    throws ModelRepositoryException {
1718:                List lDataDictionaries = pConversionContext.mModelRepository
1719:                        .searchByXPath(
1720:                                pConversionContext.mSourceModelName,
1721:                                UMLStylesheet
1722:                                        .getAllSystemDataDictionariesXPath(pEnterprise));
1723:                // At the first go create namespaces and typetemplates
1724:                for (Iterator lDataDictionariesIterator = lDataDictionaries
1725:                        .iterator(); lDataDictionariesIterator.hasNext();) {
1726:                    org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lDataDictionariesIterator
1727:                            .next();
1728:                    DataDictionary lDataDictionary = pConversionContext.mMetaBossModelExtent
1729:                            .getDataDictionaryModel().getDataDictionary()
1730:                            .createDataDictionary();
1731:                    lDataDictionary.setName("Default");
1732:                    lDataDictionary.setSystem(getMetaBossSystem(
1733:                            pConversionContext, lDataDictionaryUmlPackage));
1734:                    UMLUtils.copyComment(lDataDictionaryUmlPackage,
1735:                            lDataDictionary);
1736:                    // Now work on namespaces, typetemplates and data types
1737:                    convertNamespaces(pConversionContext,
1738:                            lDataDictionaryUmlPackage, lDataDictionary);
1739:                    convertTypetemplates(pConversionContext,
1740:                            lDataDictionaryUmlPackage, lDataDictionary);
1741:                }
1742:                // At the second go create data types
1743:                for (Iterator lDataDictionariesIterator = lDataDictionaries
1744:                        .iterator(); lDataDictionariesIterator.hasNext();) {
1745:                    org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lDataDictionariesIterator
1746:                            .next();
1747:                    convertDataTypes(pConversionContext,
1748:                            lDataDictionaryUmlPackage, getMetaBossSystem(
1749:                                    pConversionContext,
1750:                                    lDataDictionaryUmlPackage)
1751:                                    .getDataDictionary());
1752:                }
1753:            }
1754:
1755:            private static void convertDesignLibrary(
1756:                    ConversionContext pConversionContext, Enterprise pEnterprise)
1757:                    throws ModelRepositoryException {
1758:                org.omg.uml.modelmanagement.UmlPackage lDesignLibraryUmlPackage = UMLUtils
1759:                        .findUmlPackage(
1760:                                pConversionContext.mSourceModelName,
1761:                                pEnterprise,
1762:                                UMLStylesheet
1763:                                        .getAllDesignLibrariesXPath(pEnterprise));
1764:                if (lDesignLibraryUmlPackage != null) {
1765:                    DesignLibrary lDesignLibrary = pConversionContext.mMetaBossModelExtent
1766:                            .getDesignLibraryModel().getDesignLibrary()
1767:                            .createDesignLibrary();
1768:                    lDesignLibrary.setName("Default");
1769:                    lDesignLibrary.setEnterprise(pEnterprise);
1770:                    UMLUtils.copyComment(lDesignLibraryUmlPackage,
1771:                            lDesignLibrary);
1772:                    // Now work on data dictionary
1773:                    List lDataDictionaries = pConversionContext.mModelRepository
1774:                            .searchByXPath(
1775:                                    pConversionContext.mSourceModelName,
1776:                                    UMLStylesheet
1777:                                            .getAllDataDictionariesXPath(lDesignLibrary));
1778:                    if (!lDataDictionaries.isEmpty()) {
1779:                        org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lDataDictionaries
1780:                                .get(0);
1781:                        DataDictionary lDataDictionary = pConversionContext.mMetaBossModelExtent
1782:                                .getDataDictionaryModel().getDataDictionary()
1783:                                .createDataDictionary();
1784:                        lDataDictionary.setName(lDataDictionaryUmlPackage
1785:                                .getName());
1786:                        lDataDictionary.setDesignLibrary(lDesignLibrary);
1787:                        UMLUtils.copyComment(lDataDictionaryUmlPackage,
1788:                                lDataDictionary);
1789:                        // Now work on namespaces, typetemplates and data types
1790:                        convertNamespaces(pConversionContext,
1791:                                lDataDictionaryUmlPackage, lDataDictionary);
1792:                        convertTypetemplates(pConversionContext,
1793:                                lDataDictionaryUmlPackage, lDataDictionary);
1794:                        convertDataTypes(pConversionContext,
1795:                                lDataDictionaryUmlPackage, lDataDictionary);
1796:                    }
1797:                }
1798:            }
1799:
1800:            private static void convertNamespaces(
1801:                    ConversionContext pConversionContext,
1802:                    org.omg.uml.modelmanagement.UmlPackage pNamespaceUmlPackage,
1803:                    AbstractNamespace pNamespace)
1804:                    throws ModelRepositoryException {
1805:                List lSubNamespaces = pConversionContext.mModelRepository
1806:                        .searchByXPath(pNamespaceUmlPackage, "./Package");
1807:                for (Iterator lSubNamespacesIterator = lSubNamespaces
1808:                        .iterator(); lSubNamespacesIterator.hasNext();) {
1809:                    org.omg.uml.modelmanagement.UmlPackage lSubNamespaceUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lSubNamespacesIterator
1810:                            .next();
1811:                    Namespace lNamespace = pConversionContext.mMetaBossModelExtent
1812:                            .getDataDictionaryModel().getNamespace()
1813:                            .createNamespace();
1814:                    lNamespace.setName(lSubNamespaceUmlPackage.getName());
1815:                    lNamespace.setNamespace(pNamespace);
1816:                    UMLUtils.copyComment(lSubNamespaceUmlPackage, lNamespace);
1817:                    convertNamespaces(pConversionContext,
1818:                            lSubNamespaceUmlPackage, lNamespace);
1819:                }
1820:            }
1821:
1822:            private static void convertTypetemplates(
1823:                    ConversionContext pConversionContext,
1824:                    org.omg.uml.modelmanagement.UmlPackage pDataDictionaryUmlPackage,
1825:                    DataDictionary pDataDictionary)
1826:                    throws ModelRepositoryException {
1827:                List lTypetemplates = pConversionContext.mModelRepository
1828:                        .searchByXPath(
1829:                                pConversionContext.mSourceModelName,
1830:                                UMLStylesheet
1831:                                        .getAllTypetemplatesXPath(pDataDictionary));
1832:                for (Iterator lTypetemplatesIterator = lTypetemplates
1833:                        .iterator(); lTypetemplatesIterator.hasNext();) {
1834:                    org.omg.uml.foundation.core.UmlClass lUmlTypetemplate = (org.omg.uml.foundation.core.UmlClass) lTypetemplatesIterator
1835:                            .next();
1836:                    // Find matching MetaBoss model Namespace
1837:                    AbstractNamespace lTypetemplateNamespace = getMetaBossNamespace(
1838:                            pConversionContext, lUmlTypetemplate.getNamespace());
1839:                    TypeTemplate lTypeTemplate = pConversionContext.mMetaBossModelExtent
1840:                            .getDataDictionaryModel().getTypeTemplate()
1841:                            .createTypeTemplate();
1842:                    lTypeTemplate.setName(lUmlTypetemplate.getName());
1843:                    UMLUtils.copyComment(lUmlTypetemplate, lTypeTemplate);
1844:                    lTypeTemplate.setNamespace(lTypetemplateNamespace);
1845:                    // Cache the element
1846:                    pConversionContext.mModelElementsMap.put(lUmlTypetemplate,
1847:                            lTypeTemplate);
1848:                    // Now convert typetemplate parameters
1849:                    convertTypetemplateParameters(pConversionContext,
1850:                            lUmlTypetemplate, lTypeTemplate);
1851:                }
1852:            }
1853:
1854:            // Helper. Converts parameter definitions from the Uml Typetemplate the MetaBoss Property Descriptor
1855:            private static void convertTypetemplateParameters(
1856:                    ConversionContext pConversionContext,
1857:                    org.omg.uml.foundation.core.UmlClass pSourceTypetemplate,
1858:                    TypeTemplate pTargetTypeTemplate)
1859:                    throws ModelRepositoryException {
1860:                com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptorClass lPropertyDescriptorClass = pConversionContext.mMetaBossModelExtent
1861:                        .getDataDictionaryModel().getPropertyDescriptor();
1862:                // Convert all parameters in the loop
1863:                List lTemplateParameters = pSourceTypetemplate
1864:                        .getTemplateParameter();
1865:                for (Iterator lTemplateParametersIterator = lTemplateParameters
1866:                        .iterator(); lTemplateParametersIterator.hasNext();) {
1867:                    org.omg.uml.foundation.core.TemplateParameter lUmlTemplateParameter = (org.omg.uml.foundation.core.TemplateParameter) lTemplateParametersIterator
1868:                            .next();
1869:                    org.omg.uml.foundation.core.Parameter lUmlParameter = (org.omg.uml.foundation.core.Parameter) lUmlTemplateParameter
1870:                            .getParameter();
1871:                    PropertyDescriptor lPropertyDescriptor = lPropertyDescriptorClass
1872:                            .createPropertyDescriptor();
1873:                    lPropertyDescriptor
1874:                            .setParentTypetemplate(pTargetTypeTemplate);
1875:                    lPropertyDescriptor.setName(lUmlParameter.getName());
1876:                    String lIsArrayTagValue = UMLUtils
1877:                            .getSingleOptionalTagValue(
1878:                                    lUmlParameter,
1879:                                    UMLStylesheet.GenericParameterStereotypeTagName_IsArray);
1880:                    lPropertyDescriptor.setArray(Boolean.valueOf(
1881:                            lIsArrayTagValue).booleanValue());
1882:                    UMLUtils.copyComment(lUmlParameter, lPropertyDescriptor);
1883:                    // Call recursive method to add child property decriptors if it is necessary
1884:                    if (!lUmlParameter.getTemplateParameter().isEmpty()) {
1885:                        lPropertyDescriptor.setContainer(true);
1886:                        // Need to convers sub parameters
1887:                        convertTypetemplateParameters(pConversionContext,
1888:                                lUmlParameter, lPropertyDescriptor);
1889:                    } else
1890:                        lPropertyDescriptor.setContainer(false);
1891:                }
1892:            }
1893:
1894:            // Helper. Converts parameter definitions from the Uml Parameter to the MetaBoss Property Descriptor
1895:            private static void convertTypetemplateParameters(
1896:                    ConversionContext pConversionContext,
1897:                    org.omg.uml.foundation.core.Parameter pSourceParameter,
1898:                    PropertyDescriptor pTargetPropertyDescriptor)
1899:                    throws ModelRepositoryException {
1900:                com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptorClass lPropertyDescriptorClass = pConversionContext.mMetaBossModelExtent
1901:                        .getDataDictionaryModel().getPropertyDescriptor();
1902:                // Convert all parameters in the loop
1903:                List lTemplateParameters = pSourceParameter
1904:                        .getTemplateParameter();
1905:                for (Iterator lTemplateParametersIterator = lTemplateParameters
1906:                        .iterator(); lTemplateParametersIterator.hasNext();) {
1907:                    org.omg.uml.foundation.core.TemplateParameter lUmlTemplateParameter = (org.omg.uml.foundation.core.TemplateParameter) lTemplateParametersIterator
1908:                            .next();
1909:                    org.omg.uml.foundation.core.Parameter lUmlParameter = (org.omg.uml.foundation.core.Parameter) lUmlTemplateParameter
1910:                            .getParameter();
1911:                    PropertyDescriptor lPropertyDescriptor = lPropertyDescriptorClass
1912:                            .createPropertyDescriptor();
1913:                    lPropertyDescriptor
1914:                            .setParentDescriptor(pTargetPropertyDescriptor);
1915:                    lPropertyDescriptor.setName(lUmlParameter.getName());
1916:                    String lIsArrayTagValue = UMLUtils
1917:                            .getSingleOptionalTagValue(
1918:                                    lUmlParameter,
1919:                                    UMLStylesheet.GenericParameterStereotypeTagName_IsArray);
1920:                    lPropertyDescriptor.setArray(Boolean.valueOf(
1921:                            lIsArrayTagValue).booleanValue());
1922:                    UMLUtils.copyComment(lUmlParameter, lPropertyDescriptor);
1923:                    // Call recursive method to add child property decriptors if it is necessary
1924:                    if (!lUmlParameter.getTemplateParameter().isEmpty()) {
1925:                        lPropertyDescriptor.setContainer(true);
1926:                        // Need to convers sub parameters
1927:                        convertTypetemplateParameters(pConversionContext,
1928:                                lUmlParameter, lPropertyDescriptor);
1929:                    } else
1930:                        lPropertyDescriptor.setContainer(false);
1931:                }
1932:            }
1933:
1934:            private static void convertDataTypes(
1935:                    ConversionContext pConversionContext,
1936:                    org.omg.uml.modelmanagement.UmlPackage pDataDictionaryUmlPackage,
1937:                    DataDictionary pDataDictionary)
1938:                    throws ModelRepositoryException {
1939:                DataTypeClass lDataTypeClass = pConversionContext.mMetaBossModelExtent
1940:                        .getDataDictionaryModel().getDataType();
1941:                List lDataTypes = pConversionContext.mModelRepository
1942:                        .searchByXPath(pConversionContext.mSourceModelName,
1943:                                UMLStylesheet
1944:                                        .getAllDataTypesXPath(pDataDictionary));
1945:                for (Iterator lDataTypesIterator = lDataTypes.iterator(); lDataTypesIterator
1946:                        .hasNext();) {
1947:                    org.omg.uml.foundation.core.DataType lUmlDataType = (org.omg.uml.foundation.core.DataType) lDataTypesIterator
1948:                            .next();
1949:                    // Find matching MetaBoss model Namespace
1950:                    AbstractNamespace lDataTypeNamespace = getMetaBossNamespace(
1951:                            pConversionContext, lUmlDataType.getNamespace());
1952:                    DataType lDataType = lDataTypeClass.createDataType();
1953:                    lDataType.setName(lUmlDataType.getName());
1954:                    lDataType.setNamespace(lDataTypeNamespace);
1955:                    UMLUtils.copyComment(lUmlDataType, lDataType);
1956:                    // Now convert typetemplate binding if necessary
1957:                    org.omg.uml.foundation.core.Binding lUmlBinding = UMLUtils
1958:                            .findUmlBinding(lUmlDataType, UMLStylesheet
1959:                                    .getClientBindingXPath());
1960:                    if (lUmlBinding != null) {
1961:                        // Found the binding - there must be one and only supplier - and it should be the template 
1962:                        Collection lSuppliers = lUmlBinding.getSupplier();
1963:                        if (lSuppliers.isEmpty())
1964:                            throw new ConstraintViolationException(
1965:                                    null,
1966:                                    null,
1967:                                    "There can only be exactly one Type Template bound to the template based DataType. DataType '"
1968:                                            + lUmlDataType.getName()
1969:                                            + "' has none.");
1970:                        if (lSuppliers.size() > 1)
1971:                            throw new ConstraintViolationException(
1972:                                    null,
1973:                                    null,
1974:                                    "There can only be exactly one Type Template bound to the template based DataType. DataType '"
1975:                                            + lUmlDataType.getName()
1976:                                            + "' has "
1977:                                            + lSuppliers.size() + ".");
1978:                        org.omg.uml.foundation.core.UmlClass lUmlTypetemplate = (org.omg.uml.foundation.core.UmlClass) lSuppliers
1979:                                .iterator().next();
1980:                        lDataType.setTypetemplate(pConversionContext
1981:                                .getTypetemplate(lUmlTypetemplate));
1982:                        // Copy template parameters
1983:                        List lTypetemplateBindings = pConversionContext.mModelRepository
1984:                                .searchByXPath(
1985:                                        pConversionContext.mSourceModelName,
1986:                                        UMLStylesheet
1987:                                                .getAllDataTypeTemplateBindingsXPath(lDataType));
1988:                        for (Iterator lTypetemplateBindingsIterator = lTypetemplateBindings
1989:                                .iterator(); lTypetemplateBindingsIterator
1990:                                .hasNext();) {
1991:                            org.omg.uml.foundation.core.Binding lBinding = (org.omg.uml.foundation.core.Binding) lTypetemplateBindingsIterator
1992:                                    .next();
1993:                            for (Iterator lArgumentsIter = lBinding
1994:                                    .getArgument().iterator(); lArgumentsIter
1995:                                    .hasNext();) {
1996:                                org.omg.uml.foundation.core.TemplateArgument lArgument = (org.omg.uml.foundation.core.TemplateArgument) lArgumentsIter
1997:                                        .next();
1998:                                org.omg.uml.foundation.core.ModelElement lModelElement = lArgument
1999:                                        .getModelElement();
2000:                                String lParameterName = lModelElement.getName();
2001:                                String lParameterValue = UMLUtils
2002:                                        .getSingleOptionalTagValue(
2003:                                                lModelElement,
2004:                                                UMLStylesheet.GenericArgumentStereotypeTagName_Value);
2005:                                Property lProperty = addTypetemplateProperty(
2006:                                        pConversionContext, lDataType,
2007:                                        lParameterName, lParameterValue);
2008:                                UMLUtils.copyComment(lModelElement, lProperty);
2009:                            }
2010:                        }
2011:                    }
2012:                    // Cache the element
2013:                    pConversionContext.mModelElementsMap.put(lUmlDataType,
2014:                            lDataType);
2015:                }
2016:            }
2017:
2018:            // Adds one typetemplate patrameter to the given data type	
2019:            private static Property addTypetemplateProperty(
2020:                    ConversionContext pConversionContext, DataType pDataType,
2021:                    String pParameterName, String pParameterValue) {
2022:                PropertyClass lPropertyClass = pConversionContext.mMetaBossModelExtent
2023:                        .getDataDictionaryModel().getProperty();
2024:                TypeTemplate lTypeTemplate = pDataType.getTypetemplate();
2025:                if (lTypeTemplate == null)
2026:                    throw new ConstraintViolationException(
2027:                            pDataType,
2028:                            null,
2029:                            "Only DataType which is bound to the TypeTemplate can have template parameters.");
2030:                if (pParameterName.length() == 0)
2031:                    throw new ConstraintViolationException(null, null,
2032:                            "Template parameter name can not be an empty string.");
2033:                Property lLastProperty = null;
2034:                String[] lParameterNameParts = pParameterName.split("\\.");
2035:                for (int i = 0; i < lParameterNameParts.length; i++) {
2036:                    String lPropertyKey = lParameterNameParts[i];
2037:                    Integer lPropertyArrayIndex = null;
2038:                    String lPropertyName = null;
2039:                    if (lPropertyKey.endsWith("]")) {
2040:                        String[] lTemp = lPropertyKey.split("\\[");
2041:                        if (lTemp.length != 2 || lTemp[0].length() == 0
2042:                                || lTemp[1].length() < 2)
2043:                            throw new ConstraintViolationException(null, null,
2044:                                    "Malformed template parameter name '"
2045:                                            + pParameterName + "'");
2046:                        lPropertyName = lTemp[0];
2047:                        lPropertyArrayIndex = new Integer(lTemp[1].substring(0,
2048:                                lTemp[1].length() - 1));
2049:                    } else
2050:                        lPropertyName = lPropertyKey;
2051:                    // May need to get the property from the datatype or may be from the property	 
2052:                    Property lProperty = (lLastProperty == null) ? pDataType
2053:                            .findTypetemplatePropertyByKey(lPropertyKey)
2054:                            : lLastProperty.findPropertyByKey(lPropertyKey);
2055:                    if (lProperty == null) {
2056:                        // Need to create the property
2057:                        lProperty = lPropertyClass.createProperty();
2058:                        lProperty.setName(lPropertyName);
2059:                        if (lLastProperty == null) {
2060:                            lProperty.setDataType(pDataType);
2061:                            lProperty.setDescriptor(lTypeTemplate
2062:                                    .getPropertyDescriptor(lPropertyName));
2063:                        } else {
2064:                            lProperty.setParentProperty(lLastProperty);
2065:                            lProperty.setDescriptor(lLastProperty
2066:                                    .getDescriptor().getPropertyDescriptor(
2067:                                            lPropertyName));
2068:                        }
2069:                    }
2070:                    lLastProperty = lProperty;
2071:                }
2072:                // The lLastProperty now contains the newly created or found property
2073:                if (pParameterValue != null)
2074:                    lLastProperty.setValue(pParameterValue);
2075:                return lLastProperty;
2076:            }
2077:
2078:            // Gets namespace in MetaBoss model corresponding to the given UML namespace
2079:            // Throws exception if Namespace is not found
2080:            private static AbstractNamespace getMetaBossNamespace(
2081:                    ConversionContext pConversionContext,
2082:                    org.omg.uml.foundation.core.Namespace pUmlNamespace)
2083:                    throws ModelRepositoryException {
2084:                List lOwnerDataDictionaries = pConversionContext.mModelRepository
2085:                        .searchByXPath(pUmlNamespace, UMLStylesheet
2086:                                .getOwnerDataDictionaryXPath());
2087:                if (lOwnerDataDictionaries.isEmpty())
2088:                    throw new ConstraintViolationException(
2089:                            null,
2090:                            null,
2091:                            "ModelElement "
2092:                                    + pUmlNamespace.toString()
2093:                                    + " must be contained inside the DataDictionary package.");
2094:                if (lOwnerDataDictionaries.size() != 1)
2095:                    throw new ConstraintViolationException(
2096:                            pUmlNamespace,
2097:                            null,
2098:                            "Model Element can not be owned by more than one DataDictionary and DataDictionary packages can not be nested (ie. one DataDictionary can not contain the other one).");
2099:                org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDataDictionaries
2100:                        .get(0);
2101:                DataDictionary lDataDictionary = getMetaBossDataDictionary(
2102:                        pConversionContext, lDataDictionaryUmlPackage);
2103:
2104:                // Build the path (ie. collect level names) to the namespace from the data dictionary package 
2105:                List lNamespaceElements = new ArrayList();
2106:                if (!lDataDictionaryUmlPackage.equals(pUmlNamespace)) {
2107:                    lNamespaceElements.add(0, pUmlNamespace.getName());
2108:                    for (org.omg.uml.foundation.core.Namespace lUmlNamespace = pUmlNamespace
2109:                            .getNamespace(); lDataDictionaryUmlPackage
2110:                            .equals(lUmlNamespace) == false; lUmlNamespace = lUmlNamespace
2111:                            .getNamespace())
2112:                        lNamespaceElements.add(0, lUmlNamespace.getName());
2113:                }
2114:                // Build ref expression and get the namespace
2115:                StringBuffer lNamespaceRef = new StringBuffer(lDataDictionary
2116:                        .getRef());
2117:                for (Iterator lNamespaceElementsIterator = lNamespaceElements
2118:                        .iterator(); lNamespaceElementsIterator.hasNext();) {
2119:                    lNamespaceRef.append("/subNamespaces[");
2120:                    lNamespaceRef.append((String) lNamespaceElementsIterator
2121:                            .next());
2122:                    lNamespaceRef.append("]");
2123:                }
2124:                return (AbstractNamespace) pConversionContext.mMetaBossModelExtent
2125:                        .getModelElement().getByRef(lNamespaceRef.toString());
2126:            }
2127:
2128:            // Gets namespace in MetaBoss model corresponding to the given UML namespace
2129:            // Throws exception if Namespace is not found
2130:            private static AbstractNamespace findMetaBossNamespace(
2131:                    ConversionContext pConversionContext,
2132:                    org.omg.uml.foundation.core.Namespace pUmlNamespace)
2133:                    throws ModelRepositoryException {
2134:                List lOwnerDataDictionaries = pConversionContext.mModelRepository
2135:                        .searchByXPath(pUmlNamespace, UMLStylesheet
2136:                                .getOwnerDataDictionaryXPath());
2137:                if (lOwnerDataDictionaries.isEmpty())
2138:                    return null;
2139:                if (lOwnerDataDictionaries.size() != 1)
2140:                    throw new ConstraintViolationException(
2141:                            pUmlNamespace,
2142:                            null,
2143:                            "Model Element can not be owned by more than one DataDictionary and DataDictionary packages can not be nested (ie. one DataDictionary can not contain the other one).");
2144:                org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDataDictionaries
2145:                        .get(0);
2146:                DataDictionary lDataDictionary = getMetaBossDataDictionary(
2147:                        pConversionContext, lDataDictionaryUmlPackage);
2148:
2149:                // Build the path (ie. collect level names) to the namespace from the data dictionary package 
2150:                List lNamespaceElements = new ArrayList();
2151:                if (!lDataDictionaryUmlPackage.equals(pUmlNamespace)) {
2152:                    lNamespaceElements.add(0, pUmlNamespace.getName());
2153:                    for (org.omg.uml.foundation.core.Namespace lUmlNamespace = pUmlNamespace
2154:                            .getNamespace(); lDataDictionaryUmlPackage
2155:                            .equals(lUmlNamespace) == false; lUmlNamespace = lUmlNamespace
2156:                            .getNamespace())
2157:                        lNamespaceElements.add(0, lUmlNamespace.getName());
2158:                }
2159:                // Build ref expression and get the namespace
2160:                StringBuffer lNamespaceRef = new StringBuffer(lDataDictionary
2161:                        .getRef());
2162:                for (Iterator lNamespaceElementsIterator = lNamespaceElements
2163:                        .iterator(); lNamespaceElementsIterator.hasNext();) {
2164:                    lNamespaceRef.append("/subNamespaces[");
2165:                    lNamespaceRef.append((String) lNamespaceElementsIterator
2166:                            .next());
2167:                    lNamespaceRef.append("]");
2168:                }
2169:                return (AbstractNamespace) pConversionContext.mMetaBossModelExtent
2170:                        .getModelElement().findByRef(lNamespaceRef.toString());
2171:            }
2172:
2173:            // Gets System in MetaBoss model corresponding to the system where given UMLModel element resides
2174:            // Throws exception if desired object is not found
2175:            private static com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System getMetaBossSystem(
2176:                    ConversionContext pConversionContext,
2177:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2178:                    throws ModelRepositoryException {
2179:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lOwnerSystem = findMetaBossSystem(
2180:                        pConversionContext, pUMLModelElement);
2181:                if (lOwnerSystem == null)
2182:                    throw new ConstraintViolationException(
2183:                            null,
2184:                            null,
2185:                            "ModelElement "
2186:                                    + pUMLModelElement.toString()
2187:                                    + " must be contained inside the System package.");
2188:                return lOwnerSystem;
2189:            }
2190:
2191:            // Finds System in MetaBoss model corresponding to the system where given UMLModel element resides
2192:            // Returns null if desired object is not found
2193:            private static com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System findMetaBossSystem(
2194:                    ConversionContext pConversionContext,
2195:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2196:                    throws ModelRepositoryException {
2197:                List lOwnerSystems = pConversionContext.mModelRepository
2198:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2199:                                .getOwnerSystemXPath());
2200:                if (lOwnerSystems.isEmpty())
2201:                    return null;
2202:                if (lOwnerSystems.size() != 1)
2203:                    throw new ConstraintViolationException(
2204:                            null,
2205:                            null,
2206:                            "Model Element can not be owned by more than one System and System packages can not be nested (ie. one System can not contain another one).");
2207:                org.omg.uml.modelmanagement.UmlPackage lSystemUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerSystems
2208:                        .get(0);
2209:                // Build ref expression and get the system
2210:                StringBuffer lSystemRef = new StringBuffer(
2211:                        "Enterprise/systems[");
2212:                lSystemRef.append(lSystemUmlPackage.getName());
2213:                lSystemRef.append("]");
2214:                return (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pConversionContext.mMetaBossModelExtent
2215:                        .getModelElement().getByRef(lSystemRef.toString());
2216:            }
2217:
2218:            // Finds Domain in MetaBoss model corresponding to the domain where given UMLModel element resides
2219:            // Returns null if desired object is not found
2220:            private static com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain findMetaBossDomain(
2221:                    ConversionContext pConversionContext,
2222:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2223:                    throws ModelRepositoryException {
2224:                List lOwnerDomains = pConversionContext.mModelRepository
2225:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2226:                                .getOwnerDomainXPath());
2227:                if (lOwnerDomains.isEmpty())
2228:                    return null;
2229:                if (lOwnerDomains.size() != 1)
2230:                    throw new ConstraintViolationException(
2231:                            null,
2232:                            null,
2233:                            "Model Element can not be owned by more than one Domain and Domain packages can not be nested (ie. one Domain can not contain another one).");
2234:                org.omg.uml.modelmanagement.UmlPackage lDomainUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDomains
2235:                        .get(0);
2236:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lOwnerSystem = getMetaBossSystem(
2237:                        pConversionContext, pUMLModelElement);
2238:                return lOwnerSystem.findDomain(lDomainUmlPackage.getName());
2239:            }
2240:
2241:            // Gets Enterprise in MetaBoss model corresponding to the enterprise where given UMLModel element resides
2242:            // Throws exception if desired object is not found
2243:            private static Enterprise getMetaBossEnterprise(
2244:                    ConversionContext pConversionContext,
2245:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2246:                    throws ModelRepositoryException {
2247:                Enterprise lOwnerEnterprise = findMetaBossEnterprise(
2248:                        pConversionContext, pUMLModelElement);
2249:                if (lOwnerEnterprise == null)
2250:                    throw new ConstraintViolationException(
2251:                            null,
2252:                            null,
2253:                            "ModelElement "
2254:                                    + pUMLModelElement.toString()
2255:                                    + " must be contained inside the Enterprise package.");
2256:                return lOwnerEnterprise;
2257:            }
2258:
2259:            // Finds Enterprise in MetaBoss model corresponding to the enterprise where given UMLModel element resides
2260:            // Returns null if desired object is not found
2261:            private static Enterprise findMetaBossEnterprise(
2262:                    ConversionContext pConversionContext,
2263:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2264:                    throws ModelRepositoryException {
2265:                List lOwnerEnterprises = pConversionContext.mModelRepository
2266:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2267:                                .getOwnerEnterpriseXPath());
2268:                if (lOwnerEnterprises.isEmpty())
2269:                    return null;
2270:                if (lOwnerEnterprises.size() != 1)
2271:                    throw new ConstraintViolationException(
2272:                            null,
2273:                            null,
2274:                            "Model Element can not be owned by more than one Enterprise and Enterprise packages can not be nested (ie. one Enterprise can not contain another one).");
2275:                return (Enterprise) pConversionContext.mMetaBossModelExtent
2276:                        .getModelElement().getByRef("Enterprise");
2277:            }
2278:
2279:            // Gets DesignLibrary in MetaBoss model corresponding to the enterprise where given UMLModel element resides
2280:            // Throws exception if desired object is not found
2281:            private static DesignLibrary getMetaBossDesignLibrary(
2282:                    ConversionContext pConversionContext,
2283:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2284:                    throws ModelRepositoryException {
2285:                DesignLibrary lOwnerDesignLibrary = findMetaBossDesignLibrary(
2286:                        pConversionContext, pUMLModelElement);
2287:                if (lOwnerDesignLibrary == null)
2288:                    throw new ConstraintViolationException(
2289:                            null,
2290:                            null,
2291:                            "ModelElement "
2292:                                    + pUMLModelElement.toString()
2293:                                    + " must be contained inside the DesignLibrary package.");
2294:                return lOwnerDesignLibrary;
2295:            }
2296:
2297:            // Finds DesignLibrary in MetaBoss model corresponding to the enterprise where given UMLModel element resides
2298:            // Returns null if desired object is not found
2299:            private static DesignLibrary findMetaBossDesignLibrary(
2300:                    ConversionContext pConversionContext,
2301:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2302:                    throws ModelRepositoryException {
2303:                List lOwnerDesignLibraries = pConversionContext.mModelRepository
2304:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2305:                                .getOwnerDesignLibraryXPath());
2306:                if (lOwnerDesignLibraries.isEmpty())
2307:                    return null;
2308:                if (lOwnerDesignLibraries.size() != 1)
2309:                    throw new ConstraintViolationException(
2310:                            null,
2311:                            null,
2312:                            "Model Element can not be owned by more than one DesignLibrary and DesignLibrary packages can not be nested (ie. one DesignLibrary can not contain another one).");
2313:                org.omg.uml.modelmanagement.UmlPackage lDesignLibraryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDesignLibraries
2314:                        .get(0);
2315:                StringBuffer lDesignLibraryRef = new StringBuffer();
2316:                Enterprise lOwnerEnterprise = findMetaBossEnterprise(
2317:                        pConversionContext, pUMLModelElement);
2318:                if (lOwnerEnterprise != null)
2319:                    lDesignLibraryRef.append(lOwnerEnterprise.getRef()
2320:                            + "/designLibrary");
2321:                else
2322:                    lDesignLibraryRef.append("DesignLibrary");
2323:                // ote that we use get here (get will throw exception) because we do want get to complain if something,
2324:                // what we have found in UML is missing from the MetaBoss model. 
2325:                return (DesignLibrary) pConversionContext.mMetaBossModelExtent
2326:                        .getModelElement().getByRef(
2327:                                lDesignLibraryRef.toString());
2328:            }
2329:
2330:            // Gets Servicemodule in MetaBoss model corresponding to the servicemodule where given UMLModel element resides
2331:            // throws exception if servicemodule is not found
2332:            private static Servicemodule getMetaBossServicemodule(
2333:                    ConversionContext pConversionContext,
2334:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2335:                    throws ModelRepositoryException {
2336:                List lOwnerServicemodules = pConversionContext.mModelRepository
2337:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2338:                                .getOwnerServicemoduleXPath());
2339:                if (lOwnerServicemodules.isEmpty())
2340:                    throw new ConstraintViolationException(
2341:                            null,
2342:                            null,
2343:                            "ModelElement "
2344:                                    + pUMLModelElement.toString()
2345:                                    + " must be contained inside the Servicemodule package.");
2346:                if (lOwnerServicemodules.size() != 1)
2347:                    throw new ConstraintViolationException(
2348:                            pUMLModelElement,
2349:                            null,
2350:                            "Model Element can not be owned by more than one Servicemodule and Servicemodule packages can not be nested (ie. one Servicemodule can not contain the other one).");
2351:                return convertToMetaBossServicemodule(
2352:                        pConversionContext,
2353:                        (org.omg.uml.modelmanagement.UmlPackage) lOwnerServicemodules
2354:                                .get(0));
2355:            }
2356:
2357:            // Finds Servicemodule in MetaBoss model corresponding to the servicemodule where given UMLModel element resides
2358:            // throws exception if servicemodule is not found
2359:            private static Servicemodule findMetaBossServicemodule(
2360:                    ConversionContext pConversionContext,
2361:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2362:                    throws ModelRepositoryException {
2363:                List lOwnerServicemodules = pConversionContext.mModelRepository
2364:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2365:                                .getOwnerServicemoduleXPath());
2366:                if (lOwnerServicemodules.isEmpty())
2367:                    return null;
2368:                if (lOwnerServicemodules.size() != 1)
2369:                    throw new ConstraintViolationException(
2370:                            pUMLModelElement,
2371:                            null,
2372:                            "Model Element can not be owned by more than one Servicemodule and Servicemodule packages can not be nested (ie. one Servicemodule can not contain the other one).");
2373:                return convertToMetaBossServicemodule(
2374:                        pConversionContext,
2375:                        (org.omg.uml.modelmanagement.UmlPackage) lOwnerServicemodules
2376:                                .get(0));
2377:            }
2378:
2379:            // Helper. converts UmlPackage to the MetaBoss servicemodule
2380:            private static Servicemodule convertToMetaBossServicemodule(
2381:                    ConversionContext pConversionContext,
2382:                    org.omg.uml.modelmanagement.UmlPackage pUMLServicemodulePackage)
2383:                    throws ModelRepositoryException {
2384:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lOwnerSystem = getMetaBossSystem(
2385:                        pConversionContext, pUMLServicemodulePackage);
2386:                // Build ref expression and get the system
2387:                StringBuffer lServicemoduleRef = new StringBuffer(
2388:                        "Enterprise/systems[");
2389:                lServicemoduleRef.append(lOwnerSystem.getName());
2390:                lServicemoduleRef.append("]/servicemodules[");
2391:                lServicemoduleRef.append(pUMLServicemodulePackage.getName());
2392:                lServicemoduleRef.append("]");
2393:                return (Servicemodule) pConversionContext.mMetaBossModelExtent
2394:                        .getModelElement().getByRef(
2395:                                lServicemoduleRef.toString());
2396:            }
2397:
2398:            // Finds Domain in MetaBoss model corresponding to the Domain where given UMLModel element resides
2399:            private static Domain getMetaBossDomain(
2400:                    ConversionContext pConversionContext,
2401:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2402:                    throws ModelRepositoryException {
2403:                List lOwnerDomains = pConversionContext.mModelRepository
2404:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2405:                                .getOwnerDomainXPath());
2406:                if (lOwnerDomains.isEmpty())
2407:                    throw new ConstraintViolationException(
2408:                            null,
2409:                            null,
2410:                            "ModelElement "
2411:                                    + pUMLModelElement.toString()
2412:                                    + " must be contained inside the Servicemodule package.");
2413:                if (lOwnerDomains.size() != 1)
2414:                    throw new ConstraintViolationException(
2415:                            pUMLModelElement,
2416:                            null,
2417:                            "Model Element can not be owned by more than one Servicemodule and Servicemodule packages can not be nested (ie. one Servicemodule can not contain the other one).");
2418:                org.omg.uml.modelmanagement.UmlPackage lDomainUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDomains
2419:                        .get(0);
2420:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lOwnerSystem = getMetaBossSystem(
2421:                        pConversionContext, pUMLModelElement);
2422:                // Build ref expression and get the system
2423:                StringBuffer lDomainRef = new StringBuffer(
2424:                        "Enterprise/systems[");
2425:                lDomainRef.append(lOwnerSystem.getName());
2426:                lDomainRef.append("]/domains[");
2427:                lDomainRef.append(lDomainUmlPackage.getName());
2428:                lDomainRef.append("]");
2429:                return (Domain) pConversionContext.mMetaBossModelExtent
2430:                        .getModelElement().getByRef(lDomainRef.toString());
2431:            }
2432:
2433:            // Gets Message in MetaBoss model corresponding to the given  UML Class representing the message
2434:            // Throws exception if desired object is not found
2435:            private static Message getMetaBossMessage(
2436:                    ConversionContext pConversionContext,
2437:                    org.omg.uml.foundation.core.Classifier pUMLMessage)
2438:                    throws ModelRepositoryException {
2439:                // Try Servicemodule or Namespace
2440:                Servicemodule lMetaBossServicemodule = findMetaBossServicemodule(
2441:                        pConversionContext, pUMLMessage);
2442:                if (lMetaBossServicemodule != null)
2443:                    return lMetaBossServicemodule.getMessage(pUMLMessage
2444:                            .getName());
2445:                return getMetaBossNamespace(pConversionContext,
2446:                        pUMLMessage.getNamespace()).getMessage(
2447:                        pUMLMessage.getName());
2448:            }
2449:
2450:            // Gets Structure in MetaBoss model corresponding to the given UML Class representing the structure
2451:            // Throws exception if desired object is not found
2452:            private static Structure getMetaBossStructure(
2453:                    ConversionContext pConversionContext,
2454:                    org.omg.uml.foundation.core.Classifier pUMLStructure)
2455:                    throws ModelRepositoryException {
2456:                // Try Servicemodule or Namespace
2457:                Servicemodule lMetaBossServicemodule = findMetaBossServicemodule(
2458:                        pConversionContext, pUMLStructure);
2459:                if (lMetaBossServicemodule != null)
2460:                    return lMetaBossServicemodule.getStructure(pUMLStructure
2461:                            .getName());
2462:                return getMetaBossNamespace(pConversionContext,
2463:                        pUMLStructure.getNamespace()).getStructure(
2464:                        pUMLStructure.getName());
2465:            }
2466:
2467:            // Gets Entity in MetaBoss model corresponding to the given UML Class representing the entity
2468:            // Throws exception if desired object is not found
2469:            private static Entity getMetaBossEntity(
2470:                    ConversionContext pConversionContext,
2471:                    org.omg.uml.foundation.core.Classifier pUMLEntity)
2472:                    throws ModelRepositoryException {
2473:                Domain lMetaBossDomain = getMetaBossDomain(pConversionContext,
2474:                        pUMLEntity);
2475:                return lMetaBossDomain.getEntity(pUMLEntity.getName());
2476:            }
2477:
2478:            // Finds Entity in MetaBoss model corresponding to the given UML Class representing the entity
2479:            // Returns null if desired object is not found
2480:            private static Entity findMetaBossEntity(
2481:                    ConversionContext pConversionContext,
2482:                    org.omg.uml.foundation.core.Classifier pUMLEntity)
2483:                    throws ModelRepositoryException {
2484:                Domain lMetaBossDomain = findMetaBossDomain(pConversionContext,
2485:                        pUMLEntity);
2486:                if (lMetaBossDomain != null)
2487:                    return lMetaBossDomain.findEntity(pUMLEntity.getName());
2488:                return null;
2489:            }
2490:
2491:            // Gets Entity in MetaBoss model corresponding to the given UML Class representing the entity
2492:            // Throws exception if desired object is not found
2493:            private static StateMachine getMetaBossStateMachine(
2494:                    ConversionContext pConversionContext,
2495:                    org.omg.uml.behavioralelements.statemachines.StateMachine pUMLStateMachine)
2496:                    throws ModelRepositoryException {
2497:                org.omg.uml.foundation.core.ModelElement lContext = pUMLStateMachine
2498:                        .getContext();
2499:                // Check if this is state machine belongs to an entity
2500:                if (lContext instanceof  org.omg.uml.foundation.core.Classifier) {
2501:                    Entity lPossibleOwnerEntity = findMetaBossEntity(
2502:                            pConversionContext,
2503:                            (org.omg.uml.foundation.core.Classifier) lContext);
2504:                    if (lPossibleOwnerEntity != null)
2505:                        return lPossibleOwnerEntity.getStateMachine();
2506:                }
2507:                throw new ConstraintViolationException(null, null,
2508:                        "StateMachine '" + pUMLStateMachine
2509:                                + "' is not found in the MetaBoss model.");
2510:            }
2511:
2512:            // Gets State in the MetaBoss model corresponding to the given UML State representing the state of the state machine
2513:            // Throws exception if desired object is not found
2514:            private static State getMetaBossState(
2515:                    ConversionContext pConversionContext,
2516:                    org.omg.uml.behavioralelements.statemachines.StateVertex pUMLState)
2517:                    throws ModelRepositoryException {
2518:                StateMachine lStateMachine = getMetaBossStateMachine(
2519:                        pConversionContext, pUMLState.getContainer()
2520:                                .getStateMachine());
2521:                return lStateMachine.getState(pUMLState.getName());
2522:            }
2523:
2524:            // Gets Service in MetaBoss model corresponding to the given UML Class representing the service
2525:            // Throws exception if desired object is not found
2526:            private static Service getMetaBossService(
2527:                    ConversionContext pConversionContext,
2528:                    org.omg.uml.foundation.core.Classifier pUMLService)
2529:                    throws ModelRepositoryException {
2530:                Servicemodule lMetaBossServicemodule = getMetaBossServicemodule(
2531:                        pConversionContext, pUMLService);
2532:                return lMetaBossServicemodule.getService(pUMLService.getName());
2533:            }
2534:
2535:            // Gets EventSubscription in MetaBoss model corresponding to the given UML Class representing the service
2536:            // Throws exception if desired object is not found
2537:            private static EventSubscription getMetaBossEventSubscription(
2538:                    ConversionContext pConversionContext,
2539:                    org.omg.uml.foundation.core.Classifier pUMLEventSubscription)
2540:                    throws ModelRepositoryException {
2541:                Servicemodule lMetaBossServicemodule = getMetaBossServicemodule(
2542:                        pConversionContext, pUMLEventSubscription);
2543:                return lMetaBossServicemodule
2544:                        .getEventSubscription(pUMLEventSubscription.getName());
2545:            }
2546:
2547:            // Gets DataDictionary in MetaBoss model which owns the given UML object
2548:            private static DataDictionary getMetaBossDataDictionary(
2549:                    ConversionContext pConversionContext,
2550:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2551:                    throws ModelRepositoryException {
2552:                DataDictionary lOwnerDataDictionary = findMetaBossDataDictionary(
2553:                        pConversionContext, pUMLModelElement);
2554:                if (lOwnerDataDictionary == null)
2555:                    throw new ConstraintViolationException(
2556:                            null,
2557:                            null,
2558:                            "ModelElement "
2559:                                    + pUMLModelElement.toString()
2560:                                    + " must be contained inside the DataDictionary package.");
2561:                return lOwnerDataDictionary;
2562:            }
2563:
2564:            // Find DataDictionary in MetaBoss model which owns the given UML object
2565:            // Returns null if desired object is not found
2566:            private static DataDictionary findMetaBossDataDictionary(
2567:                    ConversionContext pConversionContext,
2568:                    org.omg.uml.foundation.core.ModelElement pUMLModelElement)
2569:                    throws ModelRepositoryException {
2570:                // Check if this is data type belongs to enterprise
2571:                List lOwnerDataDictionaries = pConversionContext.mModelRepository
2572:                        .searchByXPath(pUMLModelElement, UMLStylesheet
2573:                                .getOwnerDataDictionaryXPath());
2574:                if (lOwnerDataDictionaries.isEmpty())
2575:                    return null;
2576:                else if (lOwnerDataDictionaries.size() == 1) {
2577:                    org.omg.uml.modelmanagement.UmlPackage lDataDictionaryUmlPackage = (org.omg.uml.modelmanagement.UmlPackage) lOwnerDataDictionaries
2578:                            .get(0);
2579:                    // Try to find an owner system 
2580:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lOwnerSystem = findMetaBossSystem(
2581:                            pConversionContext, lDataDictionaryUmlPackage);
2582:                    if (lOwnerSystem != null)
2583:                        return lOwnerSystem.getDataDictionary();
2584:                    // This DataDictionary is not owned by system - it must be owned by design library
2585:                    // Get it by its name 
2586:                    DesignLibrary lOwnerDesignLibrary = getMetaBossDesignLibrary(
2587:                            pConversionContext, lDataDictionaryUmlPackage);
2588:                    return lOwnerDesignLibrary
2589:                            .getDataDictionary(lDataDictionaryUmlPackage
2590:                                    .getName());
2591:                } else
2592:                    throw new ConstraintViolationException(
2593:                            pUMLModelElement,
2594:                            null,
2595:                            "Model Element can not be owned by more than one DataDictionary and DataDictionary packages can not be nested (ie. one DataDictionary can not contain the other one).");
2596:            }
2597:
2598:            // Gets DataType in MetaBoss model which corresponds to the given UML object
2599:            private static DataType getMetaBossDataType(
2600:                    ConversionContext pConversionContext,
2601:                    org.omg.uml.foundation.core.DataType pUMLDataType)
2602:                    throws ModelRepositoryException {
2603:                DataType lDataType = findMetaBossDataType(pConversionContext,
2604:                        pUMLDataType);
2605:                if (lDataType == null)
2606:                    throw new ConstraintViolationException(null, null,
2607:                            "DataType '" + pUMLDataType
2608:                                    + "' is not found in the MetaBoss model.");
2609:                return lDataType;
2610:            }
2611:
2612:            // Finds DataType in MetaBoss model corresponding to the given UML DataType
2613:            private static DataType findMetaBossDataType(
2614:                    ConversionContext pConversionContext,
2615:                    org.omg.uml.foundation.core.DataType pUMLDataType)
2616:                    throws ModelRepositoryException {
2617:                // Find matching MetaBoss model Namespace
2618:                AbstractNamespace lDataTypeNamespace = getMetaBossNamespace(
2619:                        pConversionContext, pUMLDataType.getNamespace());
2620:                return lDataTypeNamespace.findDataType(pUMLDataType.getName());
2621:            }
2622:
2623:            // Gets TypeTemplate in MetaBoss model which corresponds to the given UML object
2624:            private static TypeTemplate getMetaBossTypeTemplate(
2625:                    ConversionContext pConversionContext,
2626:                    org.omg.uml.foundation.core.UmlClass pUMLTypeTemplate)
2627:                    throws ModelRepositoryException {
2628:                TypeTemplate lTypeTemplate = findMetaBossTypeTemplate(
2629:                        pConversionContext, pUMLTypeTemplate);
2630:                if (lTypeTemplate == null)
2631:                    throw new ConstraintViolationException(null, null,
2632:                            "TypeTemplate '" + pUMLTypeTemplate
2633:                                    + "' is not found in the MetaBoss model.");
2634:                return lTypeTemplate;
2635:            }
2636:
2637:            // Finds TypeTemplate in MetaBoss model corresponding to the given UML TypeTemplate
2638:            private static TypeTemplate findMetaBossTypeTemplate(
2639:                    ConversionContext pConversionContext,
2640:                    org.omg.uml.foundation.core.UmlClass pUMLTypeTemplate)
2641:                    throws ModelRepositoryException {
2642:                // Find matching MetaBoss model Namespace
2643:                AbstractNamespace lTypeTemplateNamespace = getMetaBossNamespace(
2644:                        pConversionContext, pUMLTypeTemplate.getNamespace());
2645:                return lTypeTemplateNamespace.findTypeTemplate(pUMLTypeTemplate
2646:                        .getName());
2647:            }
2648:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.