Source Code Cross Referenced for ModelAssistantImpl.java in  » UML » MetaBoss » com » metaboss » sdlctools » models » modelassistant » metabossmodel » implicittypes » 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.modelassistant.metabossmodel.implicittypes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.sdlctools.models.modelassistant.metabossmodel.implicittypes;
016:
017:        import java.util.ArrayList;
018:        import java.util.Collection;
019:        import java.util.Collections;
020:        import java.util.Comparator;
021:        import java.util.Iterator;
022:        import java.util.List;
023:
024:        import javax.jmi.reflect.ConstraintViolationException;
025:        import javax.jmi.reflect.RefObject;
026:        import javax.jmi.reflect.RefPackage;
027:        import javax.naming.Context;
028:        import javax.naming.InitialContext;
029:        import javax.naming.NamingException;
030:
031:        import com.metaboss.sdlctools.models.ModelRepository;
032:        import com.metaboss.sdlctools.models.ModelRepositoryException;
033:        import com.metaboss.sdlctools.models.ModelRepositoryInternalException;
034:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
035:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
036:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
037:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryClass;
038:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryModelPackage;
039:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
040:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataTypeClass;
041:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
042:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.NamespaceClass;
043:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
044:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyClass;
045:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
046:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
047:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
048:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
049:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
050:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
051:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotype;
052:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
053:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
054:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
055:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
056:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineModelPackage;
057:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateType;
058:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
059:        import com.metaboss.sdlctools.models.modelassistant.metabossmodel.SingleModelAssistantImplBase;
060:
061:        /** Implementation of the assistant to MetaBoss models.
062:         * Looks after some implicit data types in the systems.
063:         * This implementation is always only serving one model. This is guaranteed
064:         * by special factory implementation */
065:        public class ModelAssistantImpl extends SingleModelAssistantImplBase {
066:            // Utility comparator, which is used to sort properties in order of deletion
067:            // The problem is that when parent property is deleted - the child property is deleted too, so
068:            // when we iterate through unused properties and issue refDelete() - we may hit already deleted property. 
069:            // This comparator sorts the properties in the reverse string sort order of the keys,
070:            // which ensures that properties are sorted in the right order for deletion (child properties before parent ones)
071:            private static Comparator sPropertiesToDeleteComparator = new Comparator() {
072:                public int compare(Object o1, Object o2) {
073:                    return ((Property) o2).getKey().compareTo(
074:                            ((Property) o1).getKey());
075:                }
076:            };
077:
078:            // Variables below are cached for whole session with the model regardless of the kind of model it is
079:            ModelRepository mModelRepository = null;
080:            MetaBossModelPackage mRootPackage = null;
081:            ModelElementClass mModelElementClass = null;
082:            DataDictionaryModelPackage mDataDictionaryModel = null;
083:            DataDictionaryClass mDataDictionaryClass = null;
084:            DataTypeClass mDataTypeClass = null;
085:            PropertyClass mPropertyClass = null;
086:            NamespaceClass mNamespaceClass = null;
087:
088:            // As per interface 
089:            public void assignToModel(String pModelName)
090:                    throws ModelRepositoryException {
091:                super .assignToModel(pModelName);
092:                try {
093:                    Context lContext = new InitialContext();
094:                    mModelRepository = (ModelRepository) lContext
095:                            .lookup(ModelRepository.COMPONENT_URL);
096:                    mRootPackage = (MetaBossModelPackage) mModelRepository
097:                            .getModelExtent(pModelName);
098:                    mModelElementClass = mRootPackage.getModelElement();
099:                    mDataDictionaryModel = mRootPackage
100:                            .getDataDictionaryModel();
101:                    mDataDictionaryClass = mDataDictionaryModel
102:                            .getDataDictionary();
103:                    mDataTypeClass = mDataDictionaryModel.getDataType();
104:                    mPropertyClass = mDataDictionaryModel.getProperty();
105:                    mNamespaceClass = mDataDictionaryModel.getNamespace();
106:                } catch (NamingException e) {
107:                    throw new ModelRepositoryInternalException(
108:                            "Unable to looklup repository", e);
109:                }
110:            }
111:
112:            // As per interface 
113:            public void dismissFromModel(String pModelName) {
114:                mRootPackage = null;
115:                mModelRepository = null;
116:                mModelElementClass = null;
117:                mDataDictionaryModel = null;
118:                mDataDictionaryClass = null;
119:                mDataTypeClass = null;
120:                mPropertyClass = null;
121:                mNamespaceClass = null;
122:                super .dismissFromModel(pModelName);
123:            }
124:
125:            // As per interface 
126:            public Collection verifyConstraints(String pModelName) {
127:                List lViolations = new ArrayList();
128:                // Ensure that every domain has a subnamespace in the system data dictionary's system namespace
129:                for (Iterator lDataDictionariesIterator = mDataDictionaryClass
130:                        .refAllOfType().iterator(); lDataDictionariesIterator
131:                        .hasNext();) {
132:                    DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
133:                            .next();
134:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDataDictionary
135:                            .getSystem();
136:                    if (lSystem != null) {
137:                        Enterprise lEnterprise = lSystem.getEnterprise();
138:                        if (lEnterprise == null)
139:                            continue; // System is not connected to enterprise
140:                        DesignLibrary lDesignLibrary = lEnterprise
141:                                .getDesignLibrary();
142:                        if (lDesignLibrary == null)
143:                            continue; // Enterpise does not have a desifn library
144:                        DataDictionary lCoreDataDictionary = lDesignLibrary
145:                                .findDataDictionary("core");
146:                        if (lCoreDataDictionary == null)
147:                            continue; // Design library does not have a data dictionary
148:
149:                        Namespace lSystemNamespace = lDataDictionary
150:                                .findSubNamespace("System");
151:                        if (lSystemNamespace != null) {
152:                            // Ensure that each domain has a corresponding namespace.
153:                            for (Iterator lDomainsIterator = lSystem
154:                                    .getDomains().iterator(); lDomainsIterator
155:                                    .hasNext();) {
156:                                Domain lDomain = (Domain) lDomainsIterator
157:                                        .next();
158:                                HelperContext lHelperContext = new HelperContext(
159:                                        lDomain);
160:                                Namespace lDomainNamespace = lHelperContext
161:                                        .getDomainNamespace();
162:                                if (lDomainNamespace != null) {
163:                                    // This domain has a namespace. Iterate through all entities and validate them
164:                                    // As abyproduct collect data types which do not have corresponding entities
165:                                    List lUnprocessedDataTypes = new ArrayList();
166:                                    lUnprocessedDataTypes
167:                                            .addAll(lDomainNamespace
168:                                                    .getDataTypes());
169:                                    // Iterate through entities and check all of them for errors
170:                                    for (Iterator lEntitiesIterator = lDomain
171:                                            .getEntities().iterator(); lEntitiesIterator
172:                                            .hasNext();) {
173:                                        Entity lEntity = (Entity) lEntitiesIterator
174:                                                .next();
175:                                        EntityHelper.verifyEntityIntegrity(
176:                                                lViolations, this , lEntity,
177:                                                lUnprocessedDataTypes,
178:                                                lHelperContext);
179:                                    }
180:                                    // Complain about unowned data types which are left in this namespace
181:                                    if (!lUnprocessedDataTypes.isEmpty()) {
182:                                        for (Iterator lUnprocessedDataTypesIterator = lUnprocessedDataTypes
183:                                                .iterator(); lUnprocessedDataTypesIterator
184:                                                .hasNext();) {
185:                                            DataType lUnprocessedDataType = (DataType) lUnprocessedDataTypesIterator
186:                                                    .next();
187:                                            lViolations
188:                                                    .add(new ConstraintViolationException(
189:                                                            lUnprocessedDataType,
190:                                                            lUnprocessedDataType
191:                                                                    .refMetaObject(),
192:                                                            "System namespace for Domain is reserved for Datatypes associated with elements of the Domain and serving well defined  purpose. Datatype '"
193:                                                                    + lUnprocessedDataType
194:                                                                            .getName()
195:                                                                    + "' appears to have no reason to be in the namespace."));
196:                                        }
197:                                    }
198:                                } else
199:                                    lViolations
200:                                            .add(new ConstraintViolationException(
201:                                                    lDomain,
202:                                                    lDomain.refMetaObject(),
203:                                                    "Domain must have a dedicated namespace for implicit types in the System data dictionary."));
204:                            }
205:                            // Ensure that each namespace has a corresponding domain.
206:                            for (Iterator lNamespacesIterator = lSystemNamespace
207:                                    .getSubNamespaces().iterator(); lNamespacesIterator
208:                                    .hasNext();) {
209:                                Namespace lDomainNamespace = (Namespace) lNamespacesIterator
210:                                        .next();
211:                                Domain lDomain = lSystem
212:                                        .findDomain(lDomainNamespace.getName());
213:                                if (lDomain == null)
214:                                    lViolations
215:                                            .add(new ConstraintViolationException(
216:                                                    lDomainNamespace,
217:                                                    lDomainNamespace
218:                                                            .refMetaObject(),
219:                                                    "System namespace inside System DataDictionary must only have a sub namespaces corresponding to domains."));
220:                            }
221:                        } else
222:                            lViolations
223:                                    .add(new ConstraintViolationException(
224:                                            lDataDictionary, lDataDictionary
225:                                                    .refMetaObject(),
226:                                            "System DataDictionary must have a System namespace used for implicit types."));
227:                    }
228:                }
229:                // Return what we have
230:                return Collections.unmodifiableCollection(lViolations);
231:            }
232:
233:            // As per interface 
234:            public void rectifyModel(String pModelName)
235:                    throws ModelRepositoryException {
236:                // Ensure that every domain has a subnamespace in the system data dictionary's system namespace
237:                for (Iterator lDataDictionariesIterator = mDataDictionaryClass
238:                        .refAllOfType().iterator(); lDataDictionariesIterator
239:                        .hasNext();) {
240:                    DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
241:                            .next();
242:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDataDictionary
243:                            .getSystem();
244:                    if (lSystem != null) {
245:                        Enterprise lEnterprise = lSystem.getEnterprise();
246:                        if (lEnterprise == null)
247:                            continue; // System is not connected to enterprise
248:                        DesignLibrary lDesignLibrary = lEnterprise
249:                                .getDesignLibrary();
250:                        if (lDesignLibrary == null)
251:                            continue; // Enterrpise does not have a desifn library
252:                        DataDictionary lCoreDataDictionary = lDesignLibrary
253:                                .findDataDictionary("core");
254:                        if (lCoreDataDictionary == null)
255:                            continue; // No core data dictionary
256:
257:                        // Work on System names pace if necesary
258:                        Namespace lSystemNamespace = lDataDictionary
259:                                .findSubNamespace("System");
260:                        if (lSystemNamespace == null) {
261:                            lSystemNamespace = mNamespaceClass
262:                                    .createNamespace();
263:                            lSystemNamespace.setName("System");
264:                            lDataDictionary.getSubNamespaces().add(
265:                                    lSystemNamespace);
266:                            logInfo("Created implicit data types namespace for the "
267:                                    + lSystem.getRef() + " System");
268:                        }
269:                        // Refresh some attributes in any case. This caters for the cases when they are different
270:                        lSystemNamespace.setDescription(StylesheetImpl
271:                                .getSystemNamespaceDescription());
272:                        // Take alist of unprocessed namespaces
273:                        List lUnprocessedNamespaces = new ArrayList();
274:                        lUnprocessedNamespaces.addAll(lSystemNamespace
275:                                .getSubNamespaces());
276:
277:                        // Iterate through domains and ensure that each domain has a corresponding namespace.
278:                        for (Iterator lDomainsIterator = lSystem.getDomains()
279:                                .iterator(); lDomainsIterator.hasNext();) {
280:                            Domain lDomain = (Domain) lDomainsIterator.next();
281:                            Namespace lDomainNamespace = lSystemNamespace
282:                                    .findSubNamespace(lDomain.getName());
283:                            if (lDomainNamespace == null) {
284:                                lDomainNamespace = mNamespaceClass
285:                                        .createNamespace();
286:                                lDomainNamespace.setName(lDomain.getName());
287:                                lSystemNamespace.getSubNamespaces().add(
288:                                        lDomainNamespace);
289:                                logInfo("Created implicit data types namespace for the "
290:                                        + lDomain.getRef() + " Domain");
291:                            } else {
292:                                lUnprocessedNamespaces.remove(lDomainNamespace);
293:                            }
294:                            // Refresh some attributes in any case. This caters for the cases when they are different
295:                            lDomainNamespace.setDescription(StylesheetImpl
296:                                    .getDomainNamespaceDescription(lDomain
297:                                            .getName()));
298:
299:                            // Iterate through all types and fix possible problems
300:                            // As a byproduct collect data types which do not have corresponding entities. They will be deleted at the end of this process
301:                            List lUnprocessedDataTypes = new ArrayList();
302:                            lUnprocessedDataTypes.addAll(lDomainNamespace
303:                                    .getDataTypes());
304:                            HelperContext lHelperContext = new HelperContext(
305:                                    lDomain);
306:                            for (Iterator lEntitiesIterator = lDomain
307:                                    .getEntities().iterator(); lEntitiesIterator
308:                                    .hasNext();) {
309:                                Entity lEntity = (Entity) lEntitiesIterator
310:                                        .next();
311:                                EntityHelper.ensureEntityIntegrity(this ,
312:                                        lEntity, lUnprocessedDataTypes,
313:                                        lHelperContext);
314:                            }
315:                            // Delete unowned data types which are left in this namespace
316:                            if (!lUnprocessedDataTypes.isEmpty()) {
317:                                for (Iterator lUnprocessedDataTypesIterator = lUnprocessedDataTypes
318:                                        .iterator(); lUnprocessedDataTypesIterator
319:                                        .hasNext();) {
320:                                    DataType lUnprocessedDataType = (DataType) lUnprocessedDataTypesIterator
321:                                            .next();
322:                                    lUnprocessedDataType.refDelete();
323:                                }
324:                            }
325:                        }
326:                        // Ensure that each namespace has a corresponding domain.
327:                        for (Iterator lUnprocessedNamespacesIterator = lUnprocessedNamespaces
328:                                .iterator(); lUnprocessedNamespacesIterator
329:                                .hasNext();) {
330:                            Namespace lNamespace = (Namespace) lUnprocessedNamespacesIterator
331:                                    .next();
332:                            lNamespace.refDelete();
333:                        }
334:                    }
335:                }
336:            }
337:
338:            // As per interface 
339:            public void onModelElementAttributeBeingUpdated(String pModelName,
340:                    RefObject pModelElementBeingUpdated, String pAttributeName,
341:                    Object pOldAttributeValue, Object pNewAttributeValue)
342:                    throws ModelRepositoryException {
343:                // See if this element is of the type we are interested in
344:                // Find out kind of package first and than the kind of element
345:                // This way the search will be faster
346:                RefPackage lImmeditePackage = pModelElementBeingUpdated
347:                        .refImmediatePackage();
348:                if (lImmeditePackage instanceof  SystemImplementationModelPackage) {
349:                    if (pModelElementBeingUpdated instanceof  Entity)
350:                        onChangingAttributeOfEntity(
351:                                (Entity) pModelElementBeingUpdated,
352:                                pAttributeName, pOldAttributeValue,
353:                                pNewAttributeValue);
354:                    else if (pModelElementBeingUpdated instanceof  Domain)
355:                        onChangingAttributeOfDomain(
356:                                (Domain) pModelElementBeingUpdated,
357:                                pAttributeName, pOldAttributeValue,
358:                                pNewAttributeValue);
359:                    else if (pModelElementBeingUpdated instanceof  Attribute)
360:                        onChangingAttributeOfAttribute(
361:                                (Attribute) pModelElementBeingUpdated,
362:                                pAttributeName, pOldAttributeValue,
363:                                pNewAttributeValue);
364:                } else if (lImmeditePackage instanceof  StateMachineModelPackage) {
365:                    if (pModelElementBeingUpdated instanceof  State)
366:                        onChangingAttributeOfState(
367:                                (State) pModelElementBeingUpdated,
368:                                pAttributeName, pOldAttributeValue,
369:                                pNewAttributeValue);
370:                }
371:            }
372:
373:            // As per interface		
374:            public void onModelElementReferenceBeingUpdated(String pModelName,
375:                    RefObject pModelElementBeingUpdated, String pReferenceName,
376:                    RefObject pReferencedModelElementToRemove,
377:                    RefObject pReferencedModelElementToAdd)
378:                    throws ModelRepositoryException {
379:            }
380:
381:            // As per interface 
382:            public void onModelElementBeingDeleted(String pModelName,
383:                    RefObject pModelElementToBeDeleted)
384:                    throws ModelRepositoryException {
385:                // See if this element is of the type we are interested in
386:                // Find out kind of package first and than the kind of element
387:                // This way the search will be faster
388:                RefPackage lImmeditePackage = pModelElementToBeDeleted
389:                        .refImmediatePackage();
390:                if (lImmeditePackage instanceof  SystemImplementationModelPackage) {
391:                    if (pModelElementToBeDeleted instanceof  Entity)
392:                        onDeletingEntity((Entity) pModelElementToBeDeleted);
393:                    else if (pModelElementToBeDeleted instanceof  Domain)
394:                        onDeletingDomain((Domain) pModelElementToBeDeleted);
395:                    else if (pModelElementToBeDeleted instanceof  Attribute)
396:                        onDeletingAttribute((Attribute) pModelElementToBeDeleted);
397:                } else if (lImmeditePackage instanceof  StateMachineModelPackage) {
398:                    if (pModelElementToBeDeleted instanceof  StateMachine)
399:                        onDeletingStateMachine((StateMachine) pModelElementToBeDeleted);
400:                    else if (pModelElementToBeDeleted instanceof  State)
401:                        onDeletingState((State) pModelElementToBeDeleted);
402:                    else if (pModelElementToBeDeleted instanceof  Transition)
403:                        onDeletingTransition((Transition) pModelElementToBeDeleted);
404:                }
405:            }
406:
407:            // As per interface 
408:            public void onModelElementJustCreated(String pModelName,
409:                    RefObject pModelElementJustCreated)
410:                    throws ModelRepositoryException {
411:                // Now see if this element is of the type we are interested in
412:                // Find out kind of package first and than the kind of element
413:                // This way the search will be faster
414:                RefPackage lImmeditePackage = pModelElementJustCreated
415:                        .refImmediatePackage();
416:                if (lImmeditePackage instanceof  SystemImplementationModelPackage) {
417:                    if (pModelElementJustCreated instanceof  Entity)
418:                        onJustCreatedEntity((Entity) pModelElementJustCreated);
419:                    else if (pModelElementJustCreated instanceof  Domain)
420:                        onJustCreatedDomain((Domain) pModelElementJustCreated);
421:                    else if (pModelElementJustCreated instanceof  Attribute)
422:                        onJustCreatedAttribute((Attribute) pModelElementJustCreated);
423:                } else if (lImmeditePackage instanceof  EnterpriseModelPackage) {
424:                    if (pModelElementJustCreated instanceof  com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
425:                        onJustCreatedSystem((com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pModelElementJustCreated);
426:                } else if (lImmeditePackage instanceof  StateMachineModelPackage) {
427:                    if (pModelElementJustCreated instanceof  StateMachine)
428:                        onJustCreatedStateMachine((StateMachine) pModelElementJustCreated);
429:                    else if (pModelElementJustCreated instanceof  State)
430:                        onJustCreatedState((State) pModelElementJustCreated);
431:                    else if (pModelElementJustCreated instanceof  Transition)
432:                        onJustCreatedTransition((Transition) pModelElementJustCreated);
433:                }
434:            }
435:
436:            private void onJustCreatedSystem(
437:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem) {
438:                // Create empty data dictionary if none created yet
439:                DataDictionary lDataDictionary = pSystem.getDataDictionary();
440:                if (lDataDictionary != null) {
441:                    // If there is a data dictionary - ensure that it has a namespace for the
442:                    // system data types
443:                    Namespace lSystemNamespace = lDataDictionary
444:                            .findSubNamespace("System");
445:                    if (lSystemNamespace == null) {
446:                        lSystemNamespace = mNamespaceClass.createNamespace();
447:                        lSystemNamespace.setName("System");
448:                        lSystemNamespace.setDescription(StylesheetImpl
449:                                .getSystemNamespaceDescription());
450:                        lDataDictionary.getSubNamespaces()
451:                                .add(lSystemNamespace);
452:                    }
453:                }
454:            }
455:
456:            private void onJustCreatedDomain(Domain pDomain) {
457:                // Automatically create a System namespace for the domain.
458:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = pDomain
459:                        .getSystem();
460:                if (lSystem == null)
461:                    return;
462:                DataDictionary lDataDictionary = lSystem.getDataDictionary();
463:                if (lDataDictionary == null)
464:                    return;
465:                Namespace lSystemNamespace = lDataDictionary
466:                        .findSubNamespace("System");
467:                if (lSystemNamespace == null)
468:                    return;
469:                Namespace lDomainNamespace = lSystemNamespace
470:                        .findSubNamespace(pDomain.getName());
471:                if (lDomainNamespace == null) {
472:                    lDomainNamespace = mNamespaceClass.createNamespace();
473:                    lDomainNamespace.setName(pDomain.getName());
474:                    lDomainNamespace.setDescription(StylesheetImpl
475:                            .getDomainNamespaceDescription(pDomain.getName()));
476:                    lSystemNamespace.getSubNamespaces().add(lDomainNamespace);
477:                }
478:            }
479:
480:            private void onJustCreatedEntity(Entity pEntity)
481:                    throws ModelRepositoryException {
482:                // Call helper to fully ensure entity integrity
483:                EntityHelper.ensureEntityIntegrity(this , pEntity, null,
484:                        new HelperContext(pEntity));
485:            }
486:
487:            // We may need to look after the ordering instruction and state data types
488:            private void onJustCreatedStateMachine(StateMachine pStateMachine)
489:                    throws ModelRepositoryException {
490:                Entity lEntity = pStateMachine.getEntity();
491:                if (lEntity == null)
492:                    return; // State machine is not assigned to entity
493:                HelperContext lHelperContext = new HelperContext(lEntity);
494:                // Work on the state data type
495:                // See if we need to create it	
496:                DataType lStateDataType = lEntity.getStateDataType();
497:                // Ensure that data types exist
498:                if (lStateDataType == null)
499:                    lStateDataType = EntityStateDataTypeHelper
500:                            .ensureEntityStateDataTypeExists(this , lEntity,
501:                                    null, lHelperContext);
502:            }
503:
504:            // We need to look after the state data type
505:            private void onJustCreatedState(State pState)
506:                    throws ModelRepositoryException {
507:                StateMachine lStateMachine = pState.getStateMachine();
508:                if (lStateMachine == null)
509:                    return; // State is not assigned to state machine
510:                Entity lEntity = lStateMachine.getEntity();
511:                if (lEntity == null)
512:                    return; // State machine is not assigned to entity
513:                // See if we need to create it	
514:                DataType lStateDataType = lEntity.getStateDataType();
515:                if (lStateDataType == null) {
516:                    if ((lStateDataType = EntityStateDataTypeHelper
517:                            .ensureEntityStateDataTypeExists(this , lEntity,
518:                                    null, new HelperContext(lEntity))) == null)
519:                        return; // Was unable to locate state data type
520:                }
521:                EntityStateDataTypeHelper lDataTypeHelper = new EntityStateDataTypeHelper(
522:                        this , lStateDataType);
523:                lDataTypeHelper.ensureStateExists(pState.getName(), pState
524:                        .getDescription(), pState.getType());
525:            }
526:
527:            // We need to look after the state data type
528:            private void onJustCreatedTransition(Transition pTransition)
529:                    throws ModelRepositoryException {
530:                State lStartState = pTransition.getStartState();
531:                State lEndState = pTransition.getEndState();
532:                if (lStartState == null || lEndState == null)
533:                    return; // Will be unable to create property
534:                StateMachine lStateMachine = pTransition.getStateMachine();
535:                if (lStateMachine == null)
536:                    return; // State is not assigned to state machine
537:                Entity lEntity = lStateMachine.getEntity();
538:                if (lEntity == null)
539:                    return; // State machine is not assigned to entity
540:                // See if we need to create it	
541:                DataType lStateDataType = lEntity.getStateDataType();
542:                if (lStateDataType == null) {
543:                    if ((lStateDataType = EntityStateDataTypeHelper
544:                            .ensureEntityStateDataTypeExists(this , lEntity,
545:                                    null, new HelperContext(lEntity))) == null)
546:                        return; // Was unable to locate state data type
547:                }
548:                EntityStateDataTypeHelper lDataTypeHelper = new EntityStateDataTypeHelper(
549:                        this , lStateDataType);
550:                lDataTypeHelper.ensureTransitionExists(lStartState.getName(),
551:                        lEndState.getName(), pTransition.getDescription());
552:            }
553:
554:            // Look after changes to name , description and type
555:            private void onChangingAttributeOfState(State pState,
556:                    String pAttributeName, Object pOldValue, Object pNewValue) {
557:                if (pAttributeName.equals("Name") == false
558:                        && pAttributeName.equals("Description") == false
559:                        && pAttributeName.equals("type") == false)
560:                    return; // Not interested in other attributes
561:                StateMachine lStateMachine = pState.getStateMachine();
562:                if (lStateMachine == null)
563:                    return; // State is not assigned to state machine
564:                Entity lEntity = lStateMachine.getEntity();
565:                if (lEntity == null)
566:                    return; // State machine is not assigned to entity
567:                HelperContext lHelperContext = new HelperContext(lEntity);
568:                // See if we need to create it	
569:                DataType lStateDataType = lEntity.getStateDataType();
570:                if (lStateDataType == null) {
571:                    if ((lStateDataType = EntityStateDataTypeHelper
572:                            .ensureEntityStateDataTypeExists(this , lEntity,
573:                                    null, lHelperContext)) == null)
574:                        return; // Was unable to locate state data type
575:                }
576:                EntityStateDataTypeHelper lDataTypeHelper = new EntityStateDataTypeHelper(
577:                        this , lStateDataType);
578:                if (pAttributeName.equals("Name")) {
579:                    // Name change. Delete old one and store the new one
580:                    if (pOldValue != null)
581:                        lDataTypeHelper.ensureStateAbsent((String) pOldValue);
582:                    if (pNewValue != null)
583:                        lDataTypeHelper.ensureStateExists((String) pNewValue,
584:                                pState.getDescription(), pState.getType());
585:                } else if (pAttributeName.equals("Description")) {
586:                    // Description update
587:                    lDataTypeHelper.ensureStateExists(pState.getName(),
588:                            (String) pNewValue, pState.getType());
589:                } else if (pAttributeName.equals("type")) {
590:                    // type update
591:                    lDataTypeHelper.ensureStateExists(pState.getName(), pState
592:                            .getDescription(), (StateType) pNewValue);
593:                }
594:            }
595:
596:            // We need to look after the state data type
597:            private void onDeletingState(State pState)
598:                    throws ModelRepositoryException {
599:                StateMachine lStateMachine = pState.getStateMachine();
600:                if (lStateMachine == null)
601:                    return; // State is not assigned to state machine
602:                Entity lEntity = lStateMachine.getEntity();
603:                if (lEntity == null)
604:                    return; // State machine is not assigned to entity
605:                // See if we need to create it	
606:                DataType lStateDataType = lEntity.getStateDataType();
607:                if (lStateDataType == null)
608:                    return; // No state data type
609:                EntityStateDataTypeHelper lDataTypeHelper = new EntityStateDataTypeHelper(
610:                        this , lStateDataType);
611:                lDataTypeHelper.ensureStateAbsent(pState.getName());
612:            }
613:
614:            // We need to look after the state data type
615:            private void onDeletingTransition(Transition pTransition)
616:                    throws ModelRepositoryException {
617:                State lStartState = pTransition.getStartState();
618:                State lEndState = pTransition.getEndState();
619:                if (lStartState == null || lEndState == null)
620:                    return; // Will be unable to create property
621:                StateMachine lStateMachine = pTransition.getStateMachine();
622:                if (lStateMachine == null)
623:                    return; // State is not assigned to state machine
624:                Entity lEntity = lStateMachine.getEntity();
625:                if (lEntity == null)
626:                    return; // State machine is not assigned to entity
627:                // See if we need to create it	
628:                DataType lStateDataType = lEntity.getStateDataType();
629:                if (lStateDataType == null)
630:                    return; // No state data type
631:                EntityStateDataTypeHelper lDataTypeHelper = new EntityStateDataTypeHelper(
632:                        this , lStateDataType);
633:                lDataTypeHelper.ensureTransitionAbsent(lStartState.getName(),
634:                        lEndState.getName());
635:            }
636:
637:            // We may need to look after the ordering instruction data type
638:            private void onJustCreatedAttribute(Attribute pAttribute) {
639:                if (!pAttribute.isUsedForOrdering())
640:                    return; // Attribute will not be used for ordering
641:                // Iterate through this entity and every possible supertype
642:                for (Entity lEntity = pAttribute.getEntity(); lEntity != null; lEntity = lEntity
643:                        .getSupertype()) {
644:                    HelperContext lHelperContext = new HelperContext(lEntity);
645:                    // Ensure that data type exists. Create one if necessary
646:                    DataType lOrderingInstructionDataType = lEntity
647:                            .getOrderingInstructionDataType();
648:                    if (lOrderingInstructionDataType == null)
649:                        lOrderingInstructionDataType = EntityOrderingInstructionsDataTypeHelper
650:                                .ensureEntityOrderingInstructionDataTypeExists(
651:                                        this , lEntity, null, lHelperContext);
652:                    EntityOrderingInstructionsDataTypeHelper lDataTypeHelper = new EntityOrderingInstructionsDataTypeHelper(
653:                            this , lOrderingInstructionDataType);
654:                    lDataTypeHelper
655:                            .ensureAttributeOrderingInstructionExists(pAttribute
656:                                    .getName());
657:                }
658:            }
659:
660:            private void onDeletingEntity(Entity pEntity) {
661:                // Delete dedicated data types
662:                DataType lInstanceIdDataType = pEntity.getInstanceIdDataType();
663:                if (lInstanceIdDataType != null)
664:                    lInstanceIdDataType.refDelete();
665:                DataType lVersionIdDataType = pEntity.getVersionIdDataType();
666:                if (lVersionIdDataType != null)
667:                    lVersionIdDataType.refDelete();
668:                DataType lStateDataType = pEntity.getStateDataType();
669:                if (lStateDataType != null)
670:                    lStateDataType.refDelete();
671:                DataType lOrderingInstructionDataType = pEntity
672:                        .getOrderingInstructionDataType();
673:                if (lOrderingInstructionDataType != null)
674:                    lOrderingInstructionDataType.refDelete();
675:            }
676:
677:            private void onChangingAttributeOfDomain(Domain pDomain,
678:                    String pAttributeName, Object pOldValue, Object pNewValue) {
679:                if (!pAttributeName.equals("Name"))
680:                    return; // Not interested
681:                // Rename implicit data types namespace
682:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = pDomain
683:                        .getSystem();
684:                if (lSystem != null) {
685:                    DataDictionary lDataDictionary = lSystem
686:                            .getDataDictionary();
687:                    if (lDataDictionary != null) {
688:                        Namespace lSystemNamespace = lDataDictionary
689:                                .findSubNamespace("System");
690:                        if (lSystemNamespace != null) {
691:                            Namespace lDomainNamespace = lSystemNamespace
692:                                    .findSubNamespace((String) pOldValue);
693:                            if (lDomainNamespace != null)
694:                                lDomainNamespace.setName((String) pNewValue);
695:                        }
696:                    }
697:                }
698:            }
699:
700:            private void onChangingAttributeOfEntity(Entity pEntity,
701:                    String pAttributeName, Object pOldValue, Object pNewValue) {
702:                if (pAttributeName.equals("Name")) {
703:                    // Rename implicit data types
704:                    DataType lInstanceIdDataType = pEntity
705:                            .getInstanceIdDataType();
706:                    if (lInstanceIdDataType != null)
707:                        lInstanceIdDataType
708:                                .setName(StylesheetImpl
709:                                        .getEntityInstanceIdDataTypeName((String) pNewValue));
710:                    DataType lVersionIdDataType = pEntity
711:                            .getVersionIdDataType();
712:                    if (lVersionIdDataType != null) {
713:                        lVersionIdDataType
714:                                .setName(StylesheetImpl
715:                                        .getEntityVersionIdDataTypeName((String) pNewValue));
716:                        lVersionIdDataType
717:                                .setDescription(StylesheetImpl
718:                                        .getEntityVersionIdDataTypeDescription((String) pNewValue));
719:                    }
720:                    DataType lStateDataType = pEntity.getStateDataType();
721:                    if (lStateDataType != null)
722:                        lStateDataType
723:                                .setName(StylesheetImpl
724:                                        .getEntityStateDataTypeName((String) pNewValue));
725:                    DataType lOrderingInstructionDataType = pEntity
726:                            .getOrderingInstructionDataType();
727:                    if (lOrderingInstructionDataType != null) {
728:                        lOrderingInstructionDataType
729:                                .setName(StylesheetImpl
730:                                        .getOrderingInstructionDataTypeName((String) pNewValue));
731:                        lOrderingInstructionDataType
732:                                .setDescription(StylesheetImpl
733:                                        .getOrderingInstructionDataTypeDescription((String) pNewValue));
734:                    }
735:                } else if (pAttributeName.equals("stereotype")) {
736:                    // Work on Version Id data type
737:                    if (((EntityStereotype) pNewValue)
738:                            .equals(EntityStereotypeEnum.CARD_FILE))
739:                        // Ensure that data type exists
740:                        EntityVersionIdDataTypeHelper
741:                                .ensureEntityVersionIdDataTypeExists(this ,
742:                                        pEntity, null, new HelperContext(
743:                                                pEntity));
744:                    else
745:                        EntityVersionIdDataTypeHelper
746:                                .ensureEntityVersionIdDataTypeAbsent(pEntity,
747:                                        null, new HelperContext(pEntity));
748:                }
749:            }
750:
751:            private void onChangingAttributeOfAttribute(Attribute pAttribute,
752:                    String pAttributeName, Object pOldValue, Object pNewValue) {
753:                // Only interested in name of orderable attribute and useForOrdering flag
754:                if (pAttributeName.equals("usedForOrdering") == false
755:                        && (pAttributeName.equals("Name") == false || pAttribute
756:                                .isUsedForOrdering() == false))
757:                    return; // Not interested in other attributes
758:                // Iterate through this entity and every possible supertype
759:                for (Entity lEntity = pAttribute.getEntity(); lEntity != null; lEntity = lEntity
760:                        .getSupertype()) {
761:                    HelperContext lHelperContext = new HelperContext(lEntity);
762:                    DataType lOrderingInstructionDataType = lEntity
763:                            .getOrderingInstructionDataType();
764:                    if (pAttributeName.equals("Name")) {
765:                        if (lOrderingInstructionDataType == null) {
766:                            if ((lOrderingInstructionDataType = EntityOrderingInstructionsDataTypeHelper
767:                                    .ensureEntityOrderingInstructionDataTypeExists(
768:                                            this , lEntity, null, lHelperContext)) == null)
769:                                return; // Was unable to locate data type
770:                        }
771:                        // Name change. Delete old one and store the new one
772:                        EntityOrderingInstructionsDataTypeHelper lDataTypeHelper = new EntityOrderingInstructionsDataTypeHelper(
773:                                this , lOrderingInstructionDataType);
774:                        if (pOldValue != null)
775:                            lDataTypeHelper
776:                                    .ensureAttributeOrderingInstructionAbsent((String) pOldValue);
777:                        if (pNewValue != null)
778:                            lDataTypeHelper
779:                                    .ensureAttributeOrderingInstructionExists((String) pNewValue);
780:                    } else if (pAttributeName.equals("usedForOrdering")) {
781:                        boolean lBecomingOrderable = pNewValue != null
782:                                && ((Boolean) pNewValue).booleanValue() == true;
783:                        // See if we need to create data type	
784:                        if (lOrderingInstructionDataType == null) {
785:                            if (!lBecomingOrderable)
786:                                return; // No datatype any way - the goal is achieved without even trying
787:                            // Ensure that data type exists
788:                            if ((lOrderingInstructionDataType = EntityOrderingInstructionsDataTypeHelper
789:                                    .ensureEntityOrderingInstructionDataTypeExists(
790:                                            this , lEntity, null, lHelperContext)) == null)
791:                                return; // Was unable to locate data type
792:                        }
793:                        if (lBecomingOrderable) {
794:                            // At this point if there was not data type it has been created
795:                            EntityOrderingInstructionsDataTypeHelper lDataTypeHelper = new EntityOrderingInstructionsDataTypeHelper(
796:                                    this , lOrderingInstructionDataType);
797:                            lDataTypeHelper
798:                                    .ensureAttributeOrderingInstructionExists(pAttribute
799:                                            .getName());
800:                        } else {
801:                            // Check if we should delete whole data type instread of just our properties
802:                            Collection lAttributesUsedForOrdering = lEntity
803:                                    .getCombinedAttributesUsedForOrdering();
804:                            if (lAttributesUsedForOrdering.size() == 1
805:                                    && (lAttributesUsedForOrdering.toArray()[0]
806:                                            .equals(pAttribute))) {
807:                                lOrderingInstructionDataType.refDelete();
808:                            } else {
809:                                EntityOrderingInstructionsDataTypeHelper lDataTypeHelper = new EntityOrderingInstructionsDataTypeHelper(
810:                                        this , lOrderingInstructionDataType);
811:                                lDataTypeHelper
812:                                        .ensureAttributeOrderingInstructionAbsent(pAttribute
813:                                                .getName());
814:                            }
815:                        }
816:                    }
817:                }
818:            }
819:
820:            private void onDeletingDomain(Domain pDomain) {
821:                // Delete implicit data types namespace
822:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = pDomain
823:                        .getSystem();
824:                if (lSystem != null) {
825:                    DataDictionary lDataDictionary = lSystem
826:                            .getDataDictionary();
827:                    if (lDataDictionary != null) {
828:                        Namespace lSystemNamespace = lDataDictionary
829:                                .findSubNamespace("System");
830:                        if (lSystemNamespace != null) {
831:                            Namespace lDomainNamespace = lSystemNamespace
832:                                    .findSubNamespace(pDomain.getName());
833:                            if (lDomainNamespace != null)
834:                                lDomainNamespace.refDelete();
835:                        }
836:                    }
837:                }
838:            }
839:
840:            // We may need to look after the ordering instruction data type
841:            private void onDeletingAttribute(Attribute pAttribute) {
842:                if (!pAttribute.isUsedForOrdering())
843:                    return; // Attribute was not be used for ordering, so it can not change the picture
844:                // Iterate through this entity and every possible supertype
845:                for (Entity lEntity = pAttribute.getEntity(); lEntity != null; lEntity = lEntity
846:                        .getSupertype()) {
847:                    // See if we have a data type	
848:                    DataType lOrderingInstructionDataType = lEntity
849:                            .getOrderingInstructionDataType();
850:                    if (lOrderingInstructionDataType == null)
851:                        continue; // Nothing to work with here
852:
853:                    // Delete either whole ordering instructions data type or just the property
854:                    Collection lAttributesUsedForOrdering = lEntity
855:                            .getCombinedAttributesUsedForOrdering();
856:                    if (lAttributesUsedForOrdering.size() == 1
857:                            && (lAttributesUsedForOrdering.toArray()[0]
858:                                    .equals(pAttribute))) {
859:                        lOrderingInstructionDataType.refDelete();
860:                    } else {
861:                        EntityOrderingInstructionsDataTypeHelper lDataTypeHelper = new EntityOrderingInstructionsDataTypeHelper(
862:                                this , lOrderingInstructionDataType);
863:                        lDataTypeHelper
864:                                .ensureAttributeOrderingInstructionAbsent(pAttribute
865:                                        .getName());
866:                    }
867:                }
868:            }
869:
870:            // We may need to look after the ordering instruction data type
871:            private void onDeletingStateMachine(StateMachine pStateMachine) {
872:                Entity lEntity = pStateMachine.getEntity();
873:                if (lEntity == null)
874:                    return; // StateMachine is not assigned to entity
875:                // Work on state data type
876:                DataType lStateDataType = lEntity.getStateDataType();
877:                if (lStateDataType != null)
878:                    lStateDataType.refDelete();
879:            }
880:
881:            // Helper - returns domain system namespace or null if there was some prioblem navigating
882:            // the model from the given entity
883:            private static Namespace getDomainSystemNamespace(Entity pEntity) {
884:                Domain lDomain = pEntity.getDomain();
885:                if (lDomain == null)
886:                    return null;
887:                String lDomainName = lDomain.getName();
888:                if (lDomainName == null)
889:                    return null;
890:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
891:                        .getSystem();
892:                if (lSystem == null)
893:                    return null;
894:                DataDictionary lSystemDataDictionary = lSystem
895:                        .getDataDictionary();
896:                if (lSystemDataDictionary == null)
897:                    return null;
898:                Namespace lSystemNamespace = lSystemDataDictionary
899:                        .findSubNamespace("System");
900:                if (lSystemNamespace == null)
901:                    return null;
902:                Namespace lDomainNamespace = lSystemNamespace
903:                        .findSubNamespace(lDomainName);
904:                if (lDomainNamespace == null)
905:                    return null;
906:                return lDomainNamespace;
907:            }
908:        }
w_ww.jav_a___2__s.___c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.