Source Code Cross Referenced for ModelAssistantImpl.java in  » UML » MetaBoss » com » metaboss » sdlctools » models » modelassistant » metabossmodel » modelintegrity » 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.modelintegrity 
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.modelintegrity;
016:
017:        import java.io.File;
018:        import java.util.ArrayList;
019:        import java.util.Collection;
020:        import java.util.Collections;
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.impl.metabossmodel.ModelElementResolverImpl;
035:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
036:        import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
037:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
038:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
039:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryClass;
040:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryModelPackage;
041:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
042:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
043:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.NamespaceClass;
044:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
045:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryClass;
046:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryModelPackage;
047:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
048:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
049:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscription;
050:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionClass;
051:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperationClass;
052:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
053:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.SystemClass;
054:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationType;
055:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
056:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
057:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
058:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinality;
059:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
060:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleClass;
061:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
062:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotype;
063:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
064:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
065:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
066:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotype;
067:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
068:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Report;
069:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
070:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElementClass;
071:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
072:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorCardinality;
073:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorCardinalityEnum;
074:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
075:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.SystemUsageModelPackage;
076:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.UsageSpecificationClass;
077:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
078:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
079:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineModelPackage;
080:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateType;
081:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
082:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.NameConversionTypeEnum;
083:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnology;
084:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnologyClass;
085:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.StorageTechnology;
086:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibrary;
087:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryClass;
088:        import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryModelPackage;
089:        import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DiagramModelElement;
090:        import com.metaboss.sdlctools.models.modelassistant.metabossmodel.SingleModelAssistantImplBase;
091:
092:        /** Implementation of the assistant to MetaBoss models.
093:         * Looks after some basic model integrity rules such as:
094:         * <UL>
095:         * <LI>Automatically generate the Name of every ModelElement, which has been created without one</LI>
096:         * <LI>Create new DesignLibrary for Enterprise, which has been created without one</LI>
097:         * <LI>Create new TechnologyLibrary for Enterprise, which has been created without one</LI>
098:         * <LI>Create new DataDictionary for DesignLibrary, which has been created without one</LI>
099:         * <LI>Create missing AssociationRoles for Association (must always be two)</LI>
100:         * <LI>Ensure that AssociationRole has a PluralName, AggregationType and Cardinality setup.</LI>
101:         * <LI>Ensure that Attribute has a stereotype if it was created without it.</LI>
102:         * <LI>Ensure that Entity has a PluralName and Streotype if it was created without them.</LI>
103:         * <LI>Ensure that Report has an output level if it was created without it.</LI>
104:         * <LI>Ensure that Selector has Cardinality if it was created without it.</LI>
105:         * <LI>Ensure that corresponding diagram elements are deleted when ModelElement is deleted</LI>
106:         * </UL> */
107:        public class ModelAssistantImpl extends SingleModelAssistantImplBase {
108:            /** String constant which is used to identify this assistant as an owner of certain model elements */
109:            public static final String ASSISTANT_IDENTIFIER = ModelAssistantImpl.class
110:                    .getPackage().getName();
111:
112:            // Variables below are cached for whole session with the model regardless of the kind of model it is
113:            ModelRepository mModelRepository = null;
114:            MetaBossModelPackage mRootPackage = null;
115:            ModelElementClass mModelElementClass = null;
116:            DesignLibraryModelPackage mDesignLibraryModel = null;
117:            DesignLibraryClass mDesignLibraryClass = null;
118:            TechnologyLibraryModelPackage mTechnologyLibraryModel = null;
119:            TechnologyLibraryClass mTechnologyLibraryClass = null;
120:            RelationalStorageTechnologyClass mRelationalStorageTechnologyClass = null;
121:            DataDictionaryModelPackage mDataDictionaryModel = null;
122:            DataDictionaryClass mDataDictionaryClass = null;
123:            NamespaceClass mNamespaceClass = null;
124:            EnterpriseModelPackage mEnterpriseModel = null;
125:            SystemClass mSystemClass = null;
126:            EventSubscriptionClass mEventSubscriptionClass = null;
127:            EventSubscriptionOperationClass mEventSubscriptionOperationClass = null;
128:            SystemImplementationModelPackage mSystemImplementationModel = null;
129:            AssociationRoleClass mAssociationRoleClass = null;
130:            ReportOutputElementClass mReportOuputElementClass = null;
131:            SystemUsageModelPackage mSystemUsageModelPackage = null;
132:            UsageSpecificationClass mUsageSpecificationClass = null;
133:
134:            TargetSystemUsageSpecificationHelper mTargetSystemUsageSpecificationHelper = null;
135:            TargetEventSubscriptionOperationHelper mTargetEventSubscriptionOperationHelper = null;
136:
137:            public ModelAssistantImpl() {
138:                // Create source and target helpers
139:                mTargetSystemUsageSpecificationHelper = new TargetSystemUsageSpecificationHelper(
140:                        this );
141:                mTargetEventSubscriptionOperationHelper = new TargetEventSubscriptionOperationHelper(
142:                        this );
143:            }
144:
145:            // As per interface 
146:            public void assignToModel(String pModelName)
147:                    throws ModelRepositoryException {
148:                try {
149:                    Context lContext = new InitialContext();
150:                    mModelRepository = (ModelRepository) lContext
151:                            .lookup(ModelRepository.COMPONENT_URL);
152:                    mRootPackage = (MetaBossModelPackage) mModelRepository
153:                            .getModelExtent(pModelName);
154:                    mModelElementClass = mRootPackage.getModelElement();
155:                    mDesignLibraryModel = mRootPackage.getDesignLibraryModel();
156:                    mDesignLibraryClass = mDesignLibraryModel
157:                            .getDesignLibrary();
158:                    mTechnologyLibraryModel = mRootPackage
159:                            .getTechnologyLibraryModel();
160:                    mTechnologyLibraryClass = mTechnologyLibraryModel
161:                            .getTechnologyLibrary();
162:                    mRelationalStorageTechnologyClass = mTechnologyLibraryModel
163:                            .getRelationalStorageTechnology();
164:                    ;
165:                    mDataDictionaryModel = mRootPackage
166:                            .getDataDictionaryModel();
167:                    mDataDictionaryClass = mDataDictionaryModel
168:                            .getDataDictionary();
169:                    mNamespaceClass = mDataDictionaryModel.getNamespace();
170:                    mEnterpriseModel = mRootPackage.getEnterpriseModel();
171:                    mSystemClass = mEnterpriseModel.getSystem();
172:                    mEventSubscriptionClass = mEnterpriseModel
173:                            .getEventSubscription();
174:                    mEventSubscriptionOperationClass = mEnterpriseModel
175:                            .getEventSubscriptionOperation();
176:                    mSystemImplementationModel = mEnterpriseModel
177:                            .getSystemImplementationModel();
178:                    mAssociationRoleClass = mSystemImplementationModel
179:                            .getAssociationRole();
180:                    mReportOuputElementClass = mSystemImplementationModel
181:                            .getReportOutputElement();
182:                    mSystemUsageModelPackage = mEnterpriseModel
183:                            .getSystemUsageModel();
184:                    mUsageSpecificationClass = mSystemUsageModelPackage
185:                            .getUsageSpecification();
186:                } catch (NamingException e) {
187:                    throw new ModelRepositoryInternalException(
188:                            "Unable to looklup repository", e);
189:                }
190:            }
191:
192:            // As per interface 
193:            public void dismissFromModel(String pModelName) {
194:                mModelRepository = null;
195:                mRootPackage = null;
196:                mModelElementClass = null;
197:                mDesignLibraryModel = null;
198:                mDesignLibraryClass = null;
199:                mTechnologyLibraryModel = null;
200:                mTechnologyLibraryClass = null;
201:                mRelationalStorageTechnologyClass = null;
202:                mDataDictionaryModel = null;
203:                mDataDictionaryClass = null;
204:                mNamespaceClass = null;
205:                mEnterpriseModel = null;
206:                mSystemClass = null;
207:                mEventSubscriptionClass = null;
208:                mEventSubscriptionOperationClass = null;
209:                mSystemImplementationModel = null;
210:                mAssociationRoleClass = null;
211:                mReportOuputElementClass = null;
212:                mSystemUsageModelPackage = null;
213:                mUsageSpecificationClass = null;
214:            }
215:
216:            // As per interface 
217:            public Collection verifyConstraints(String pModelName) {
218:                List lViolations = new ArrayList();
219:                // Iterate through objects which we can check
220:                for (Iterator lIter = mRelationalStorageTechnologyClass
221:                        .refAllOfType().iterator(); lIter.hasNext();)
222:                    verifyIntegrity(lViolations,
223:                            (RelationalStorageTechnology) lIter.next());
224:                for (Iterator lIter = mSystemClass.refAllOfType().iterator(); lIter
225:                        .hasNext();)
226:                    mTargetSystemUsageSpecificationHelper
227:                            .verifyConstraints(
228:                                    lViolations,
229:                                    (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lIter
230:                                            .next());
231:                for (Iterator lIter = mEventSubscriptionClass.refAllOfType()
232:                        .iterator(); lIter.hasNext();)
233:                    mTargetEventSubscriptionOperationHelper.verifyConstraints(
234:                            lViolations, (EventSubscription) lIter.next());
235:                // Return what we have
236:                return Collections.unmodifiableCollection(lViolations);
237:            }
238:
239:            // As per interface 
240:            public void rectifyModel(String pModelName) {
241:                // Iterate through objects which we can check
242:                for (Iterator lIter = mRelationalStorageTechnologyClass
243:                        .refAllOfType().iterator(); lIter.hasNext();)
244:                    ensureIntegrity((RelationalStorageTechnology) lIter.next());
245:                for (Iterator lIter = mSystemClass.refAllOfType().iterator(); lIter
246:                        .hasNext();)
247:                    mTargetSystemUsageSpecificationHelper
248:                            .rectifyModel((com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lIter
249:                                    .next());
250:                for (Iterator lIter = mEventSubscriptionClass.refAllOfType()
251:                        .iterator(); lIter.hasNext();)
252:                    mTargetEventSubscriptionOperationHelper
253:                            .rectifyModel((EventSubscription) lIter.next());
254:            }
255:
256:            // As per interface 
257:            public void onModelElementBeingDeleted(String pModelName,
258:                    RefObject pModelElementToBeDeleted)
259:                    throws ModelRepositoryException {
260:                // See if this element is of the type we are interested in
261:                // Find out kind of package first and than the kind of element
262:                // This way the search will be faster
263:                RefPackage lImmeditePackage = pModelElementToBeDeleted
264:                        .refImmediatePackage();
265:                // Every object is a ModelElement, so call this method for everyone of them
266:                onDeletingModelElement((ModelElement) pModelElementToBeDeleted);
267:
268:                // Call superclass which will dispatch to the generic listeners
269:                super .onModelElementBeingDeleted(pModelName,
270:                        pModelElementToBeDeleted);
271:            }
272:
273:            // As per interface 
274:            public void onModelElementJustCreated(String pModelName,
275:                    RefObject pModelElementJustCreated)
276:                    throws ModelRepositoryException {
277:                // Every object is a ModelElement, so call this method for everyone of them
278:                onJustCreatedModelElement((ModelElement) pModelElementJustCreated);
279:                // Now see if this element is of the type we are interested in
280:                // Find out kind of package first and than the kind of element
281:                // This way the search will be faster
282:                RefPackage lImmeditePackage = pModelElementJustCreated
283:                        .refImmediatePackage();
284:                if (lImmeditePackage instanceof  EnterpriseModelPackage) {
285:                    if (pModelElementJustCreated instanceof  Enterprise)
286:                        onJustCreatedEnterprise((Enterprise) pModelElementJustCreated);
287:                    else if (pModelElementJustCreated instanceof  com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
288:                        onJustCreatedSystem((com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pModelElementJustCreated);
289:                    else if (pModelElementJustCreated instanceof  com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation)
290:                        onJustCreatedOperation((com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation) pModelElementJustCreated);
291:                    //			else	
292:                    //			if (pModelElementJustCreated instanceof OperationInputField)
293:                    //				onJustCreatedOperationInputField((OperationInputField)pModelElementJustCreated);
294:                    //			else
295:                    //			if (pModelElementJustCreated instanceof OperationOutputField)
296:                    //				onJustCreatedOperationOutputField((OperationOutputField)pModelElementJustCreated);
297:                } else if (lImmeditePackage instanceof  TechnologyLibraryModelPackage) {
298:                    if (pModelElementJustCreated instanceof  RelationalStorageTechnology)
299:                        onJustCreatedRelationalStorageTechnology((RelationalStorageTechnology) pModelElementJustCreated);
300:                } else if (lImmeditePackage instanceof  SystemImplementationModelPackage) {
301:                    if (pModelElementJustCreated instanceof  Association)
302:                        onJustCreatedAssociation((Association) pModelElementJustCreated);
303:                    else if (pModelElementJustCreated instanceof  AssociationRole)
304:                        onJustCreatedAssociationRole((AssociationRole) pModelElementJustCreated);
305:                    else if (pModelElementJustCreated instanceof  Attribute)
306:                        onJustCreatedAttribute((Attribute) pModelElementJustCreated);
307:                    else if (pModelElementJustCreated instanceof  Entity)
308:                        onJustCreatedEntity((Entity) pModelElementJustCreated);
309:                    else if (pModelElementJustCreated instanceof  Report)
310:                        onJustCreatedReport((Report) pModelElementJustCreated);
311:                    else if (pModelElementJustCreated instanceof  Selector)
312:                        onJustCreatedSelector((Selector) pModelElementJustCreated);
313:                } else if (lImmeditePackage instanceof  StateMachineModelPackage) {
314:                    if (pModelElementJustCreated instanceof  State)
315:                        onJustCreatedState((State) pModelElementJustCreated);
316:                    else if (pModelElementJustCreated instanceof  StateMachine)
317:                        onJustCreatedStateMachine((StateMachine) pModelElementJustCreated);
318:                }
319:                // Call superclass which will dispatch to the generic listeners
320:                super .onModelElementJustCreated(pModelName,
321:                        pModelElementJustCreated);
322:            }
323:
324:            private void onJustCreatedEnterprise(Enterprise pEnterprise)
325:                    throws ModelRepositoryException {
326:                // Automatically create DesignLibrary if there is none yet
327:                DesignLibrary lDesignLibrary = pEnterprise.getDesignLibrary();
328:                if (lDesignLibrary == null) {
329:                    lDesignLibrary = mDesignLibraryClass.createDesignLibrary();
330:                    lDesignLibrary.setName("Default");
331:                    lDesignLibrary
332:                            .setDescription("Enterprise wide library of reuseable model elements");
333:                    pEnterprise.setDesignLibrary(lDesignLibrary);
334:                    // Find and create 'core' datadictionary in the design library
335:                    String lDesignLibraryModelName = System
336:                            .getProperty("MetaBoss.Home")
337:                            + File.separator
338:                            + "designlib"
339:                            + File.separator
340:                            + "Model.xml";
341:                    if (!mModelRepository
342:                            .containsModel(lDesignLibraryModelName))
343:                        // Must throw exception. Can not really try to open model here because we may hit deadlock wuth threads
344:                        throw new ModelRepositoryException(
345:                                "Design library from "
346:                                        + lDesignLibraryModelName
347:                                        + " is not loaded. Unable to autocomplete creation of the Enterprise DataDictionary");
348:                    MetaBossModelPackage lDesignLibraryPackage = (MetaBossModelPackage) mModelRepository
349:                            .getModelExtent(lDesignLibraryModelName);
350:                    DataDictionary lOriginalCoreDataDictionary = (DataDictionary) lDesignLibraryPackage
351:                            .getModelElement().getByRef(
352:                                    "DesignLibrary/dataDictionaries[core]");
353:                    // Now find the name of the model we are creating data dictionary in
354:                    String lWorkingModelName = mModelRepository
355:                            .getOwnerModelName(pEnterprise);
356:                    DataDictionary lCopiedCoreDataDictionary = (DataDictionary) mModelRepository
357:                            .copyModelElement(lOriginalCoreDataDictionary,
358:                                    lWorkingModelName, true,
359:                                    ModelElementResolverImpl.getInstance());
360:                    lCopiedCoreDataDictionary.setDesignLibrary(lDesignLibrary);
361:                }
362:                // Automatically create TechnologyLibrary if there is none yet
363:                TechnologyLibrary lTechnologyLibrary = pEnterprise
364:                        .getTechnologyLibrary();
365:                if (lTechnologyLibrary == null) {
366:                    lTechnologyLibrary = mTechnologyLibraryClass
367:                            .createTechnologyLibrary();
368:                    lTechnologyLibrary.setName("Default");
369:                    lTechnologyLibrary
370:                            .setDescription("Enterprise wide library of reuseable technology definitions.");
371:                    pEnterprise.setTechnologyLibrary(lTechnologyLibrary);
372:
373:                    // Find the MetaBoss TechnologyLibrary and copy stuff from it 
374:                    String lTechnologyLibraryModelName = System
375:                            .getProperty("MetaBoss.Home")
376:                            + File.separator
377:                            + "technologylib"
378:                            + File.separator
379:                            + "Model.xml";
380:                    if (!mModelRepository
381:                            .containsModel(lTechnologyLibraryModelName))
382:                        // Must throw exception. Can not really try to open model here because we may hit deadlock wuth threads
383:                        throw new ModelRepositoryException(
384:                                "Technology library from "
385:                                        + lTechnologyLibraryModelName
386:                                        + " is not loaded. Unable to autocomplete creation of the Enterprise Technology Library");
387:                    MetaBossModelPackage lTechnologyLibraryPackage = (MetaBossModelPackage) mModelRepository
388:                            .getModelExtent(lTechnologyLibraryModelName);
389:                    TechnologyLibrary lSourceTechnologyLibrary = (TechnologyLibrary) lTechnologyLibraryPackage
390:                            .getModelElement().getByRef("TechnologyLibrary");
391:                    String lWorkingModelName = mModelRepository
392:                            .getOwnerModelName(lTechnologyLibrary);
393:                    // Now copy all storage technologies
394:                    for (Iterator lLibraryTechnologiesIterator = lSourceTechnologyLibrary
395:                            .getStorageTechnologies().iterator(); lLibraryTechnologiesIterator
396:                            .hasNext();) {
397:                        StorageTechnology lLibraryStorageTechnology = (StorageTechnology) lLibraryTechnologiesIterator
398:                                .next();
399:                        StorageTechnology lEnterpriseStorageTechnology = (StorageTechnology) mModelRepository
400:                                .copyModelElement(lLibraryStorageTechnology,
401:                                        lWorkingModelName, true,
402:                                        ModelElementResolverImpl.getInstance());
403:                        lTechnologyLibrary.getStorageTechnologies().add(
404:                                lEnterpriseStorageTechnology);
405:                    }
406:                }
407:            }
408:
409:            private void onJustCreatedRelationalStorageTechnology(
410:                    RelationalStorageTechnology pRelationalStorageTechnology) {
411:                ensureIntegrity(pRelationalStorageTechnology);
412:            }
413:
414:            private void onJustCreatedAssociation(Association pAssociation) {
415:                // Ensure that there are always two AssociationRoles
416:                List lRoles = pAssociation.getRoles();
417:                // Cardinality constraint is checked elsewhere, just skip it
418:                if (lRoles.size() < 2) {
419:                    AssociationRole lFirstAssociationRole = mAssociationRoleClass
420:                            .createAssociationRole();
421:                    lRoles.add(lFirstAssociationRole);
422:                    if (lRoles.size() < 2) {
423:                        AssociationRole lSecondAssociationRole = mAssociationRoleClass
424:                                .createAssociationRole();
425:                        lRoles.add(lSecondAssociationRole);
426:                    }
427:                }
428:            }
429:
430:            private void onJustCreatedAttribute(Attribute pAttribute) {
431:                // Set default stereotype if none setup by now
432:                AttributeStereotype lAttributeStereotype = pAttribute
433:                        .getStereotype();
434:                if (lAttributeStereotype == null)
435:                    pAttribute.setStereotype(AttributeStereotypeEnum.OPTIONAL);
436:            }
437:
438:            private void onJustCreatedReport(Report pReport) {
439:                // Add top level output element if there is none as of yet
440:                ReportOutputElement lTopLevelOutputElement = pReport
441:                        .getTopLevelOutputElement();
442:                if (lTopLevelOutputElement == null) {
443:                    lTopLevelOutputElement = mReportOuputElementClass
444:                            .createReportOutputElement();
445:                    pReport.setTopLevelOutputElement(lTopLevelOutputElement);
446:                }
447:            }
448:
449:            private void onJustCreatedSystem(
450:                    com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem) {
451:                // Create empty data dictionary if none created yet
452:                DataDictionary lDataDictionary = pSystem.getDataDictionary();
453:                if (lDataDictionary == null) {
454:                    lDataDictionary = mDataDictionaryClass
455:                            .createDataDictionary();
456:                    lDataDictionary.setName("Default");
457:                    lDataDictionary
458:                            .setDescription("This DataDictionary contains elements specific to the System it belongs to");
459:                    pSystem.setDataDictionary(lDataDictionary);
460:                }
461:                // If there is a data dictionary - ensure that it has a namespace for the
462:                // system data types
463:                Namespace lSystemNamespace = lDataDictionary
464:                        .findSubNamespace("System");
465:                if (lSystemNamespace == null) {
466:                    lSystemNamespace = mNamespaceClass.createNamespace();
467:                    lSystemNamespace.setName("System");
468:                    lSystemNamespace
469:                            .setDescription("This Namespace is reserved for implicit data types and type templates used in the system.");
470:                    lDataDictionary.getSubNamespaces().add(lSystemNamespace);
471:                }
472:            }
473:
474:            private void onJustCreatedEntity(Entity pEntity) {
475:                // Set autogenerated value to the plural name if none set up by now
476:                String lPluralName = pEntity.getPluralName();
477:                if (lPluralName == null)
478:                    pEntity.setPluralName(pEntity.getName() + "s");
479:
480:                // Set default stereotype if none setup by now
481:                EntityStereotype lStereotype = pEntity.getStereotype();
482:                if (lStereotype == null)
483:                    pEntity.setStereotype(EntityStereotypeEnum.CARD_FILE);
484:            }
485:
486:            private void onJustCreatedOperation(Operation pOperation) {
487:                // Set query flag. This ensures that the explicit value is always set for the unique flag
488:                pOperation.setQuery(pOperation.isQuery());
489:            }
490:
491:            private void onJustCreatedSelector(Selector pSelector) {
492:                // Set default stereotype if none setup by now
493:                SelectorCardinality lCardinality = pSelector.getCardinality();
494:                if (lCardinality == null)
495:                    pSelector
496:                            .setCardinality(SelectorCardinalityEnum.ZERO_TO_MANY);
497:            }
498:
499:            // Set constant name to the state machine
500:            private void onJustCreatedStateMachine(StateMachine pStateMachine)
501:                    throws ModelRepositoryException {
502:                // There is only one state machine per entity, so the simplest is just to call it that
503:                pStateMachine.setName(StylesheetImpl
504:                        .getEntityStateMachineName());
505:            }
506:
507:            // Set constant name to the state machine
508:            private void onJustCreatedState(State pState)
509:                    throws ModelRepositoryException {
510:                StateType lStateType = pState.getType();
511:                if (lStateType == null)
512:                    pState.setType(StateTypeEnum.NORMAL);
513:            }
514:
515:            private void onDeletingModelElement(ModelElement pModelElement) {
516:                // Delete associated diagram elements.
517:                // This seemingly stupid loop avoids getting into concurrent modifications
518:                // problems with iterators
519:                while (true) {
520:                    Collection lDiagramModelElements = pModelElement
521:                            .getDiagramModelElements();
522:                    if (lDiagramModelElements.isEmpty())
523:                        break; // Done
524:                    ((DiagramModelElement) lDiagramModelElements.iterator()
525:                            .next()).refDelete();
526:                }
527:            }
528:
529:            private void onChangingNameOfDomain(Domain pDomain,
530:                    String pOldName, String pNewName) {
531:                // Rename implicit data types namespace
532:                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = pDomain
533:                        .getSystem();
534:                if (lSystem != null) {
535:                    DataDictionary lDataDictionary = lSystem
536:                            .getDataDictionary();
537:                    if (lDataDictionary != null) {
538:                        Namespace lSystemNamespace = lDataDictionary
539:                                .findSubNamespace("System");
540:                        if (lSystemNamespace != null) {
541:                            Namespace lDomainNamespace = lSystemNamespace
542:                                    .findSubNamespace(pOldName);
543:                            if (lDomainNamespace != null)
544:                                lDomainNamespace.setName(pNewName);
545:                        }
546:                    }
547:                }
548:            }
549:
550:            private void onChangingNameOfEntity(Entity pEntity,
551:                    String pOldName, String pNewName) {
552:                // Rename implicit data types
553:                DataType lInstanceIdDataType = pEntity.getInstanceIdDataType();
554:                if (lInstanceIdDataType != null)
555:                    lInstanceIdDataType.setName(pNewName + "InstanceId");
556:                DataType lVersionIdDataType = pEntity.getVersionIdDataType();
557:                if (lVersionIdDataType != null)
558:                    lVersionIdDataType.setName(pNewName + "VersionId");
559:            }
560:
561:            private void onJustCreatedAssociationRole(
562:                    AssociationRole pAssociationRole) {
563:                // Set autogenerated value to the plural name if none set up by now
564:                String lPluralName = pAssociationRole.getPluralName();
565:                if (lPluralName == null)
566:                    pAssociationRole.setPluralName(pAssociationRole.getName()
567:                            + "s");
568:
569:                // Set default aggregation type if none setup by now
570:                AggregationType lAggregationType = pAssociationRole
571:                        .getAggregationType();
572:                if (lAggregationType == null)
573:                    pAssociationRole
574:                            .setAggregationType(AggregationTypeEnum.NONE);
575:
576:                // Set default cardinality if none setup by now
577:                AssociationRoleCardinality lAssociationRoleCardinality = pAssociationRole
578:                        .getCardinality();
579:                if (lAssociationRoleCardinality == null)
580:                    pAssociationRole
581:                            .setCardinality(AssociationRoleCardinalityEnum.ONE);
582:            }
583:
584:            private void onJustCreatedModelElement(ModelElement pModelElement) {
585:                // Set autogenerated value to the name if none set up by now
586:                // Value would be the name of the type concatenated with the count of
587:                // types - so it makes it globally unque name within model.
588:                if (pModelElement.getName() == null) {
589:                    String lTypeName = (String) pModelElement.refMetaObject()
590:                            .refGetValue("name");
591:                    // We need to append a counter to the name and than still guard against clashes
592:                    // since some elements might have been deleted and count of elements might be the same as
593:                    // it has ben some time ago  
594:                    Collection lAllOfClass = pModelElement.refClass()
595:                            .refAllOfClass();
596:                    String lProposedModelElementName = null;
597:                    for (int lInstanceCount = lAllOfClass.size(); lProposedModelElementName == null; lInstanceCount++) {
598:                        lProposedModelElementName = lTypeName
599:                                + Integer.toString(lInstanceCount);
600:                        // Ensure that the name is unique
601:                        for (Iterator lAllOfClassIter = lAllOfClass.iterator(); lAllOfClassIter
602:                                .hasNext();) {
603:                            ModelElement lClassInstance = (ModelElement) lAllOfClassIter
604:                                    .next();
605:                            if (!lClassInstance.equals(this )) {
606:                                String lClassInstanceName = lClassInstance
607:                                        .getName();
608:                                if (lClassInstanceName != null
609:                                        && lClassInstanceName
610:                                                .equals(lProposedModelElementName)) {
611:                                    // Name is taken
612:                                    lProposedModelElementName = null;
613:                                    break;
614:                                }
615:                            }
616:                        }
617:                    }
618:                    // Check again just in case the name has been setup by now
619:                    if (pModelElement.getName() == null)
620:                        pModelElement.setName(lProposedModelElementName);
621:                }
622:            }
623:
624:            // This helper method ensures that the RelationalStorageTechnology definition is valid
625:            // If something is out of order - it fills it with default values
626:            private void ensureIntegrity(
627:                    RelationalStorageTechnology pRelationalStorageTechnology) {
628:                {
629:                    if (pRelationalStorageTechnology
630:                            .getAssociationPrimaryKeyConstraintNameConversionType() == null)
631:                        pRelationalStorageTechnology
632:                                .setAssociationPrimaryKeyConstraintNameConversionType(NameConversionTypeEnum.NONE);
633:                }
634:                {
635:                    if (pRelationalStorageTechnology
636:                            .getAssociationPrimaryKeyConstraintNamePrefix() == null)
637:                        pRelationalStorageTechnology
638:                                .setAssociationPrimaryKeyConstraintNamePrefix("");
639:                }
640:                {
641:                    if (pRelationalStorageTechnology
642:                            .getAssociationPrimaryKeyConstraintNameSuffix() == null)
643:                        pRelationalStorageTechnology
644:                                .setAssociationPrimaryKeyConstraintNameSuffix("");
645:                }
646:                {
647:                    if (pRelationalStorageTechnology
648:                            .getAssociationRoleColumnNameConversionType() == null)
649:                        pRelationalStorageTechnology
650:                                .setAssociationRoleColumnNameConversionType(NameConversionTypeEnum.NONE);
651:                }
652:                {
653:                    if (pRelationalStorageTechnology
654:                            .getAssociationRoleColumnNamePrefix() == null)
655:                        pRelationalStorageTechnology
656:                                .setAssociationRoleColumnNamePrefix("");
657:                }
658:                {
659:                    if (pRelationalStorageTechnology
660:                            .getAssociationRoleColumnNameSuffix() == null)
661:                        pRelationalStorageTechnology
662:                                .setAssociationRoleColumnNameSuffix("");
663:                }
664:
665:                {
666:                    String lReferenceValueColumnName = pRelationalStorageTechnology
667:                            .getReferenceValueColumnName();
668:                    if (lReferenceValueColumnName == null
669:                            || lReferenceValueColumnName.trim().length() == 0)
670:                        pRelationalStorageTechnology
671:                                .setReferenceValueColumnName("valid_value");
672:                }
673:
674:                {
675:                    String lReferenceDescriptionColumnName = pRelationalStorageTechnology
676:                            .getReferenceDescriptionColumnName();
677:                    if (lReferenceDescriptionColumnName == null
678:                            || lReferenceDescriptionColumnName.trim().length() == 0)
679:                        pRelationalStorageTechnology
680:                                .setReferenceDescriptionColumnName("valid_value_description");
681:                }
682:
683:                {
684:                    String lReferenceWeightColumnName = pRelationalStorageTechnology
685:                            .getReferenceWeightColumnName();
686:                    if (lReferenceWeightColumnName == null
687:                            || lReferenceWeightColumnName.trim().length() == 0)
688:                        pRelationalStorageTechnology
689:                                .setReferenceWeightColumnName("comparable_weight");
690:                }
691:
692:                {
693:                    String lEntityInstanceIdColumnName = pRelationalStorageTechnology
694:                            .getEntityInstanceIdColumnName();
695:                    if (lEntityInstanceIdColumnName == null
696:                            || lEntityInstanceIdColumnName.trim().length() == 0)
697:                        pRelationalStorageTechnology
698:                                .setEntityInstanceIdColumnName("record_id");
699:                }
700:
701:                {
702:                    String lEntityVersionIdColumnName = pRelationalStorageTechnology
703:                            .getEntityVersionIdColumnName();
704:                    if (lEntityVersionIdColumnName != null
705:                            && lEntityVersionIdColumnName.trim().length() == 0)
706:                        pRelationalStorageTechnology
707:                                .setEntityVersionIdColumnName("version_id");
708:                }
709:
710:                {
711:                    String lEntityStateColumnName = pRelationalStorageTechnology
712:                            .getEntityStateColumnName();
713:                    if (lEntityStateColumnName != null
714:                            && lEntityStateColumnName.trim().length() == 0)
715:                        pRelationalStorageTechnology
716:                                .setEntityStateColumnName("state");
717:                }
718:            }
719:
720:            // This helper method ensures that the RelationalStorageTechnology definition is valid
721:            // If something is out of order - it fills it with default values
722:            private void verifyIntegrity(Collection pViolations,
723:                    RelationalStorageTechnology pRelationalStorageTechnology) {
724:                // Simple modeling constraints will automatically ensure that we have errors with regards to null values
725:                // So we only have to validate firther constraints
726:                {
727:                    String lReferenceValueColumnName = pRelationalStorageTechnology
728:                            .getReferenceValueColumnName();
729:                    if (lReferenceValueColumnName != null
730:                            && lReferenceValueColumnName.trim().length() == 0)
731:                        pViolations
732:                                .add(new ConstraintViolationException(
733:                                        pRelationalStorageTechnology,
734:                                        pRelationalStorageTechnology
735:                                                .refMetaObject(),
736:                                        "The Reference Value Column Name attribute is empty. It must have not empty value."));
737:                }
738:
739:                {
740:                    String lReferenceDescriptionColumnName = pRelationalStorageTechnology
741:                            .getReferenceDescriptionColumnName();
742:                    if (lReferenceDescriptionColumnName != null
743:                            && lReferenceDescriptionColumnName.trim().length() == 0)
744:                        pViolations
745:                                .add(new ConstraintViolationException(
746:                                        pRelationalStorageTechnology,
747:                                        pRelationalStorageTechnology
748:                                                .refMetaObject(),
749:                                        "The Reference Description Column Name attribute is empty. It must have not empty value."));
750:                }
751:
752:                {
753:                    String lReferenceWeightColumnName = pRelationalStorageTechnology
754:                            .getReferenceWeightColumnName();
755:                    if (lReferenceWeightColumnName != null
756:                            && lReferenceWeightColumnName.trim().length() == 0)
757:                        pViolations
758:                                .add(new ConstraintViolationException(
759:                                        pRelationalStorageTechnology,
760:                                        pRelationalStorageTechnology
761:                                                .refMetaObject(),
762:                                        "The Reference Weight Column Name attribute is empty. It must have not empty value."));
763:                }
764:
765:                {
766:                    String lEntityInstanceIdColumnName = pRelationalStorageTechnology
767:                            .getEntityInstanceIdColumnName();
768:                    if (lEntityInstanceIdColumnName != null
769:                            && lEntityInstanceIdColumnName.trim().length() == 0)
770:                        pViolations
771:                                .add(new ConstraintViolationException(
772:                                        pRelationalStorageTechnology,
773:                                        pRelationalStorageTechnology
774:                                                .refMetaObject(),
775:                                        "The Entity Instance Id Column Name attribute is empty. It must have not empty value."));
776:                }
777:
778:                {
779:                    String lEntityVersionIdColumnName = pRelationalStorageTechnology
780:                            .getEntityVersionIdColumnName();
781:                    if (lEntityVersionIdColumnName != null
782:                            && lEntityVersionIdColumnName.trim().length() == 0)
783:                        pViolations
784:                                .add(new ConstraintViolationException(
785:                                        pRelationalStorageTechnology,
786:                                        pRelationalStorageTechnology
787:                                                .refMetaObject(),
788:                                        "The Entity Version Id Column Name attribute is empty. It must have not empty value."));
789:                }
790:
791:                {
792:                    String lEntityStateColumnName = pRelationalStorageTechnology
793:                            .getEntityStateColumnName();
794:                    if (lEntityStateColumnName != null
795:                            && lEntityStateColumnName.trim().length() == 0)
796:                        pViolations
797:                                .add(new ConstraintViolationException(
798:                                        pRelationalStorageTechnology,
799:                                        pRelationalStorageTechnology
800:                                                .refMetaObject(),
801:                                        "The Entity State Column Name attribute is empty. It must have not empty value."));
802:                }
803:            }
804:        }
w_w___w__.j_a_v___a___2s__.com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.