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


0001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012:        // POSSIBILITY OF SUCH DAMAGE.
0013:        //
0014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015:        package com.metaboss.sdlctools.models.modelassistant.metabossmodel.domainsupport;
0016:
0017:        import java.util.ArrayList;
0018:        import java.util.Collection;
0019:        import java.util.HashSet;
0020:        import java.util.Iterator;
0021:        import java.util.Set;
0022:
0023:        import javax.jmi.reflect.ConstraintViolationException;
0024:        import javax.jmi.reflect.RefObject;
0025:
0026:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0027:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0028:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0029:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0030:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0031:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
0032:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0033:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0034:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0035:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
0036:
0037:        /** This class containse helper methods dealing with the Entity details structure model element  */
0038:        class TargetEntityDetailsStructureHelper {
0039:            private ModelAssistantImpl mModelAssistantImpl;
0040:
0041:            TargetEntityDetailsStructureHelper(
0042:                    ModelAssistantImpl pModelAssistantImpl) {
0043:                mModelAssistantImpl = pModelAssistantImpl;
0044:
0045:                // Add entity Name attribute change listener
0046:                mModelAssistantImpl
0047:                        .addAttributeChangeListener(
0048:                                Entity.class,
0049:                                "Name",
0050:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0051:                                    public void onAttributeBeingUpdated(
0052:                                            RefObject pModelElementBeingUpdated,
0053:                                            String pAttributeName,
0054:                                            Object pOldValue, Object pNewValue) {
0055:                                        Entity lEntity = (Entity) pModelElementBeingUpdated;
0056:                                        Domain lDomain = lEntity.getDomain();
0057:                                        if (lDomain == null)
0058:                                            return; // Entity is not associated with domain
0059:                                        String lDomainName = lDomain.getName();
0060:                                        if (lDomainName == null)
0061:                                            return; // Domain does not have a name
0062:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0063:                                                .getSystem();
0064:                                        if (lSystem == null)
0065:                                            return; // Domain is not associated with system
0066:                                        Servicemodule lServicemodule = lSystem
0067:                                                .findServicemodule(StylesheetImpl
0068:                                                        .getDomainSupportServicemoduleName(lDomainName));
0069:                                        if (lServicemodule == null)
0070:                                            return; // There is no support servicemodule yet
0071:                                        if (pNewValue == null) {
0072:                                            // Only old value is known - ensure that the element is deleted
0073:                                            ensureAbsent(lServicemodule,
0074:                                                    (String) pOldValue);
0075:                                        } else {
0076:                                            // The element must be present - rename or create
0077:                                            if (pOldValue != null)
0078:                                                ensureRenamedPresent(
0079:                                                        lServicemodule,
0080:                                                        lEntity,
0081:                                                        (String) pOldValue,
0082:                                                        (String) pNewValue);
0083:                                            else
0084:                                                ensurePresent(lServicemodule,
0085:                                                        lEntity,
0086:                                                        (String) pNewValue);
0087:                                        }
0088:                                    }
0089:                                });
0090:                // Add entity stereotype attribute change listener
0091:                mModelAssistantImpl
0092:                        .addAttributeChangeListener(
0093:                                Entity.class,
0094:                                "stereotype",
0095:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0096:                                    public void onAttributeBeingUpdated(
0097:                                            RefObject pModelElementBeingUpdated,
0098:                                            String pAttributeName,
0099:                                            Object pOldValue, Object pNewValue) {
0100:                                        Entity lEntity = (Entity) pModelElementBeingUpdated;
0101:                                        String lEntityName = lEntity.getName();
0102:                                        if (lEntityName == null)
0103:                                            return; // Entity does not have a name
0104:                                        Domain lDomain = lEntity.getDomain();
0105:                                        if (lDomain == null)
0106:                                            return; // Entity is not associated with domain
0107:                                        String lDomainName = lDomain.getName();
0108:                                        if (lDomainName == null)
0109:                                            return; // Domain does not have a name
0110:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0111:                                                .getSystem();
0112:                                        if (lSystem == null)
0113:                                            return; // Domain is not associated with system
0114:                                        Servicemodule lServicemodule = lSystem
0115:                                                .findServicemodule(StylesheetImpl
0116:                                                        .getDomainSupportServicemoduleName(lDomainName));
0117:                                        if (lServicemodule == null)
0118:                                            return; // There is no support servicemodule yet
0119:                                        // Analyse the criteria and deal with the element accordingly 
0120:                                        if (EntityStereotypeEnum.CARD_FILE
0121:                                                .equals(pNewValue))
0122:                                            versionIdAttribute_EnsurePresent(
0123:                                                    lServicemodule, lEntity);
0124:                                        else
0125:                                            versionIdAttribute_EnsureAbsent(
0126:                                                    lServicemodule, lEntity);
0127:                                    }
0128:                                });
0129:                // Add entity stateMachine reference change listener
0130:                mModelAssistantImpl
0131:                        .addReferenceChangeListener(
0132:                                Entity.class,
0133:                                "stateMachine",
0134:                                new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0135:                                    public void onReferenceBeingUpdated(
0136:                                            RefObject pModelElementBeingUpdated,
0137:                                            String pReferenceName,
0138:                                            RefObject pReferencedModelElementToRemove,
0139:                                            RefObject pReferencedModelElementToAdd) {
0140:                                        Entity lEntity = (Entity) pModelElementBeingUpdated;
0141:                                        String lEntityName = lEntity.getName();
0142:                                        if (lEntityName == null)
0143:                                            return; // Entity does not have a name
0144:                                        Domain lDomain = lEntity.getDomain();
0145:                                        if (lDomain == null)
0146:                                            return; // Entity is not associated with domain
0147:                                        String lDomainName = lDomain.getName();
0148:                                        if (lDomainName == null)
0149:                                            return; // Domain does not have a name
0150:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0151:                                                .getSystem();
0152:                                        if (lSystem == null)
0153:                                            return; // Domain is not associated with system
0154:                                        Servicemodule lServicemodule = lSystem
0155:                                                .findServicemodule(StylesheetImpl
0156:                                                        .getDomainSupportServicemoduleName(lDomainName));
0157:                                        if (lServicemodule == null)
0158:                                            return; // There is no support servicemodule yet
0159:                                        // Analyse the criteria and deal with the element accordingly 
0160:                                        if (pReferencedModelElementToAdd != null)
0161:                                            stateAttribute_EnsurePresent(
0162:                                                    lServicemodule, lEntity); // State machine is being added
0163:                                        else if (pReferencedModelElementToRemove != null)
0164:                                            stateAttribute_EnsureAbsent(
0165:                                                    lServicemodule, lEntity); // State machine is being removed
0166:                                    }
0167:                                });
0168:
0169:                // Add attribute lifecycle listener
0170:                mModelAssistantImpl.addLifecycleListener(Attribute.class,
0171:                        new ModelAssistantImpl.ModelElementLifecycleListener() {
0172:                            public void onElementJustCreated(
0173:                                    RefObject pModelElementJustCreated) {
0174:                                Attribute lAttribute = (Attribute) pModelElementJustCreated;
0175:                                String lAttributeName = lAttribute.getName();
0176:                                if (lAttributeName == null)
0177:                                    return; // Attribute does not have a name
0178:                                Entity lEntity = lAttribute.getEntity();
0179:                                if (lEntity == null)
0180:                                    return; // Attribute is not associated with entity
0181:                                Domain lDomain = lEntity.getDomain();
0182:                                if (lDomain == null)
0183:                                    return; // Entity is not associated with domain
0184:                                String lDomainName = lDomain.getName();
0185:                                if (lDomainName == null)
0186:                                    return; // Domain does not have a name
0187:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0188:                                        .getSystem();
0189:                                if (lSystem == null)
0190:                                    return; // Domain is not associated with system
0191:                                Servicemodule lServicemodule = lSystem
0192:                                        .findServicemodule(StylesheetImpl
0193:                                                .getDomainSupportServicemoduleName(lDomainName));
0194:                                if (lServicemodule == null)
0195:                                    return; // There is no support servicemodule yet
0196:                                Set lAllEntitiesToConsider = new HashSet();
0197:                                lAllEntitiesToConsider.add(lEntity);
0198:                                lAllEntitiesToConsider.addAll(lEntity
0199:                                        .getCombinedSubtypes());
0200:                                for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0201:                                        .iterator(); lEntityElementsIterator
0202:                                        .hasNext();) {
0203:                                    Entity lEntityElement = (Entity) lEntityElementsIterator
0204:                                            .next();
0205:                                    String lEntityName = lEntityElement
0206:                                            .getName();
0207:                                    if (lEntityName == null)
0208:                                        continue; // Entity does not have a name
0209:                                    attribute_EnsurePresent(lServicemodule,
0210:                                            lEntityElement, lAttributeName,
0211:                                            lAttribute.getDescription(),
0212:                                            lAttribute.getDataType());
0213:                                }
0214:                            }
0215:
0216:                            public void onElementBeingDeleted(
0217:                                    RefObject pModelElementBeingDeleted) {
0218:                                Attribute lAttribute = (Attribute) pModelElementBeingDeleted;
0219:                                String lAttributeName = lAttribute.getName();
0220:                                if (lAttributeName == null)
0221:                                    return; // Attribute does not have a name
0222:                                Entity lEntity = lAttribute.getEntity();
0223:                                if (lEntity == null)
0224:                                    return; // Attribute is not associated with entity
0225:                                Domain lDomain = lEntity.getDomain();
0226:                                if (lDomain == null)
0227:                                    return; // Entity is not associated with domain
0228:                                String lDomainName = lDomain.getName();
0229:                                if (lDomainName == null)
0230:                                    return; // Domain does not have a name
0231:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0232:                                        .getSystem();
0233:                                if (lSystem == null)
0234:                                    return; // Domain is not associated with system
0235:                                Servicemodule lServicemodule = lSystem
0236:                                        .findServicemodule(StylesheetImpl
0237:                                                .getDomainSupportServicemoduleName(lDomainName));
0238:                                if (lServicemodule == null)
0239:                                    return; // There is no support servicemodule yet
0240:                                Set lAllEntitiesToConsider = new HashSet();
0241:                                lAllEntitiesToConsider.add(lEntity);
0242:                                lAllEntitiesToConsider.addAll(lEntity
0243:                                        .getCombinedSubtypes());
0244:                                for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0245:                                        .iterator(); lEntityElementsIterator
0246:                                        .hasNext();) {
0247:                                    Entity lEntityElement = (Entity) lEntityElementsIterator
0248:                                            .next();
0249:                                    String lEntityName = lEntityElement
0250:                                            .getName();
0251:                                    if (lEntityName == null)
0252:                                        continue; // Entity does not have a name
0253:                                    attribute_EnsureAbsent(lServicemodule,
0254:                                            lEntityElement, lAttributeName);
0255:                                }
0256:                            }
0257:                        });
0258:                // Add attribute Name attribute change listener
0259:                mModelAssistantImpl
0260:                        .addAttributeChangeListener(
0261:                                Attribute.class,
0262:                                "Name",
0263:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0264:                                    public void onAttributeBeingUpdated(
0265:                                            RefObject pModelElementBeingUpdated,
0266:                                            String pAttributeName,
0267:                                            Object pOldValue, Object pNewValue) {
0268:                                        Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0269:                                        Entity lEntity = lAttribute.getEntity();
0270:                                        if (lEntity == null)
0271:                                            return; // Attribute is not associated with entity
0272:                                        Domain lDomain = lEntity.getDomain();
0273:                                        if (lDomain == null)
0274:                                            return; // Entity is not associated with domain
0275:                                        String lDomainName = lDomain.getName();
0276:                                        if (lDomainName == null)
0277:                                            return; // Domain does not have a name
0278:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0279:                                                .getSystem();
0280:                                        if (lSystem == null)
0281:                                            return; // Domain is not associated with system
0282:                                        Servicemodule lServicemodule = lSystem
0283:                                                .findServicemodule(StylesheetImpl
0284:                                                        .getDomainSupportServicemoduleName(lDomainName));
0285:                                        if (lServicemodule == null)
0286:                                            return; // There is no support servicemodule yet
0287:                                        Set lAllEntitiesToConsider = new HashSet();
0288:                                        lAllEntitiesToConsider.add(lEntity);
0289:                                        lAllEntitiesToConsider.addAll(lEntity
0290:                                                .getCombinedSubtypes());
0291:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0292:                                                .iterator(); lEntityElementsIterator
0293:                                                .hasNext();) {
0294:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
0295:                                                    .next();
0296:                                            String lEntityName = lEntityElement
0297:                                                    .getName();
0298:                                            if (lEntityName == null)
0299:                                                continue; // Entity does not have a name
0300:                                            if (pNewValue == null) {
0301:                                                // Only old value is known - ensure that the element is deleted
0302:                                                attribute_EnsureAbsent(
0303:                                                        lServicemodule,
0304:                                                        lEntityElement,
0305:                                                        (String) pOldValue);
0306:                                            } else {
0307:                                                // The element must be present - rename or create
0308:                                                if (pOldValue != null)
0309:                                                    attribute_EnsureRenamedPresent(
0310:                                                            lServicemodule,
0311:                                                            lEntityElement,
0312:                                                            (String) pOldValue,
0313:                                                            (String) pNewValue,
0314:                                                            lAttribute
0315:                                                                    .getDescription(),
0316:                                                            lAttribute
0317:                                                                    .getDataType());
0318:                                                else
0319:                                                    attribute_EnsurePresent(
0320:                                                            lServicemodule,
0321:                                                            lEntityElement,
0322:                                                            (String) pNewValue,
0323:                                                            lAttribute
0324:                                                                    .getDescription(),
0325:                                                            lAttribute
0326:                                                                    .getDataType());
0327:                                            }
0328:                                        }
0329:                                    }
0330:                                });
0331:                // Add attribute Description attribute change listener
0332:                mModelAssistantImpl
0333:                        .addAttributeChangeListener(
0334:                                Attribute.class,
0335:                                "Description",
0336:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0337:                                    public void onAttributeBeingUpdated(
0338:                                            RefObject pModelElementBeingUpdated,
0339:                                            String pAttributeName,
0340:                                            Object pOldValue, Object pNewValue) {
0341:                                        Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0342:                                        String lAttributeName = lAttribute
0343:                                                .getName();
0344:                                        if (lAttributeName == null)
0345:                                            return; // Attribute does not have a name
0346:                                        Entity lEntity = lAttribute.getEntity();
0347:                                        if (lEntity == null)
0348:                                            return; // Attribute is not associated with entity
0349:                                        Domain lDomain = lEntity.getDomain();
0350:                                        if (lDomain == null)
0351:                                            return; // Entity is not associated with domain
0352:                                        String lDomainName = lDomain.getName();
0353:                                        if (lDomainName == null)
0354:                                            return; // Domain does not have a name
0355:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0356:                                                .getSystem();
0357:                                        if (lSystem == null)
0358:                                            return; // Domain is not associated with system
0359:                                        Servicemodule lServicemodule = lSystem
0360:                                                .findServicemodule(StylesheetImpl
0361:                                                        .getDomainSupportServicemoduleName(lDomainName));
0362:                                        if (lServicemodule == null)
0363:                                            return; // There is no support servicemodule yet
0364:                                        Set lAllEntitiesToConsider = new HashSet();
0365:                                        lAllEntitiesToConsider.add(lEntity);
0366:                                        lAllEntitiesToConsider.addAll(lEntity
0367:                                                .getCombinedSubtypes());
0368:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0369:                                                .iterator(); lEntityElementsIterator
0370:                                                .hasNext();) {
0371:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
0372:                                                    .next();
0373:                                            String lEntityName = lEntityElement
0374:                                                    .getName();
0375:                                            if (lEntityName == null)
0376:                                                continue; // Entity does not have a name
0377:                                            attribute_EnsurePresent(
0378:                                                    lServicemodule,
0379:                                                    lEntityElement,
0380:                                                    lAttributeName,
0381:                                                    (String) pNewValue,
0382:                                                    lAttribute.getDataType());
0383:                                        }
0384:                                    }
0385:                                });
0386:                // Add attribute dataType reference change listener
0387:                mModelAssistantImpl
0388:                        .addReferenceChangeListener(
0389:                                Attribute.class,
0390:                                "dataType",
0391:                                new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0392:                                    public void onReferenceBeingUpdated(
0393:                                            RefObject pModelElementBeingUpdated,
0394:                                            String pReferenceName,
0395:                                            RefObject pReferencedModelElementToRemove,
0396:                                            RefObject pReferencedModelElementToAdd) {
0397:                                        Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0398:                                        String lAttributeName = lAttribute
0399:                                                .getName();
0400:                                        if (lAttributeName == null)
0401:                                            return; // Attribute does not have a name
0402:                                        String lAttributeDescription = lAttribute
0403:                                                .getDescription();
0404:                                        Entity lEntity = lAttribute.getEntity();
0405:                                        if (lEntity == null)
0406:                                            return; // Attribute is not associated with entity 
0407:                                        String lEntityName = lEntity.getName();
0408:                                        if (lEntityName == null)
0409:                                            return; // Entity does not have a name
0410:                                        Domain lDomain = lEntity.getDomain();
0411:                                        if (lDomain == null)
0412:                                            return; // Entity is not associated with domain
0413:                                        String lDomainName = lDomain.getName();
0414:                                        if (lDomainName == null)
0415:                                            return; // Domain does not have a name
0416:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0417:                                                .getSystem();
0418:                                        if (lSystem == null)
0419:                                            return; // Domain is not associated with system
0420:                                        Servicemodule lServicemodule = lSystem
0421:                                                .findServicemodule(StylesheetImpl
0422:                                                        .getDomainSupportServicemoduleName(lDomainName));
0423:                                        if (lServicemodule == null)
0424:                                            return; // There is no support servicemodule yet
0425:                                        Collection lEntitySubtypes = lEntity
0426:                                                .getCombinedSubtypes();
0427:                                        // Analyse the criteria and deal with the element accordingly 
0428:                                        if (pReferencedModelElementToAdd != null) {
0429:                                            // We can use ensure..... for the whole attribute	
0430:                                            attribute_EnsurePresent(
0431:                                                    lServicemodule,
0432:                                                    lEntity,
0433:                                                    lAttributeName,
0434:                                                    lAttributeDescription,
0435:                                                    (DataType) pReferencedModelElementToAdd);
0436:                                            if (!lEntitySubtypes.isEmpty()) {
0437:                                                for (Iterator lSubtypesIter = lEntitySubtypes
0438:                                                        .iterator(); lSubtypesIter
0439:                                                        .hasNext();)
0440:                                                    attribute_EnsurePresent(
0441:                                                            lServicemodule,
0442:                                                            (Entity) lSubtypesIter
0443:                                                                    .next(),
0444:                                                            lAttributeName,
0445:                                                            lAttributeDescription,
0446:                                                            (DataType) pReferencedModelElementToAdd);
0447:                                            }
0448:                                        } else if (pReferencedModelElementToRemove != null) {
0449:                                            // We need to use specific datatype ensure. in order not to trigger creation of the structure field	
0450:                                            attributeDataType_EnsureAbsent(
0451:                                                    lServicemodule, lEntity,
0452:                                                    lAttributeName);
0453:                                            if (!lEntitySubtypes.isEmpty()) {
0454:                                                for (Iterator lSubtypesIter = lEntitySubtypes
0455:                                                        .iterator(); lSubtypesIter
0456:                                                        .hasNext();)
0457:                                                    attributeDataType_EnsureAbsent(
0458:                                                            lServicemodule,
0459:                                                            (Entity) lSubtypesIter
0460:                                                                    .next(),
0461:                                                            lAttributeName);
0462:                                            }
0463:                                        }
0464:                                    }
0465:                                });
0466:                // Add Attribute entity reference change listener
0467:                mModelAssistantImpl
0468:                        .addReferenceChangeListener(
0469:                                Attribute.class,
0470:                                "entity",
0471:                                new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0472:                                    public void onReferenceBeingUpdated(
0473:                                            RefObject pModelElementBeingUpdated,
0474:                                            String pReferenceName,
0475:                                            RefObject pReferencedModelElementToRemove,
0476:                                            RefObject pReferencedModelElementToAdd) {
0477:                                        Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0478:                                        DataType lAttributeType = lAttribute
0479:                                                .getDataType();
0480:                                        if (lAttributeType == null)
0481:                                            return; // Attribute does not have type
0482:                                        String lAttributeName = lAttribute
0483:                                                .getName();
0484:                                        if (lAttributeName == null)
0485:                                            return; // Attribute does not have a name
0486:                                        String lAttributeDescription = lAttribute
0487:                                                .getDescription();
0488:                                        if (pReferencedModelElementToRemove != null) {
0489:                                            // Ensure that the attribute is absent from this entity and all subentities
0490:                                            Entity lEntity = (Entity) pReferencedModelElementToRemove;
0491:                                            if (lEntity == null)
0492:                                                return; // Attribute is not associated with entity 
0493:                                            String lEntityName = lEntity
0494:                                                    .getName();
0495:                                            if (lEntityName == null)
0496:                                                return; // Entity does not have a name
0497:                                            Domain lDomain = lEntity
0498:                                                    .getDomain();
0499:                                            if (lDomain == null)
0500:                                                return; // Entity is not associated with domain
0501:                                            String lDomainName = lDomain
0502:                                                    .getName();
0503:                                            if (lDomainName == null)
0504:                                                return; // Domain does not have a name
0505:                                            com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0506:                                                    .getSystem();
0507:                                            if (lSystem == null)
0508:                                                return; // Domain is not associated with system
0509:                                            Servicemodule lServicemodule = lSystem
0510:                                                    .findServicemodule(StylesheetImpl
0511:                                                            .getDomainSupportServicemoduleName(lDomainName));
0512:                                            if (lServicemodule == null)
0513:                                                return; // There is no support servicemodule yet
0514:                                            Collection lEntitySubtypes = lEntity
0515:                                                    .getCombinedSubtypes();
0516:                                            // We need to use specific datatype ensure. in order not to trigger creation of the structure field	
0517:                                            attribute_EnsureAbsent(
0518:                                                    lServicemodule, lEntity,
0519:                                                    lAttributeName);
0520:                                            if (!lEntitySubtypes.isEmpty()) {
0521:                                                for (Iterator lSubtypesIter = lEntitySubtypes
0522:                                                        .iterator(); lSubtypesIter
0523:                                                        .hasNext();)
0524:                                                    attribute_EnsureAbsent(
0525:                                                            lServicemodule,
0526:                                                            (Entity) lSubtypesIter
0527:                                                                    .next(),
0528:                                                            lAttributeName);
0529:                                            }
0530:                                        }
0531:                                        // Ensure that the selector is absent or present for the entity this attribute is being added to
0532:                                        if (pReferencedModelElementToAdd != null) {
0533:                                            Entity lEntity = (Entity) pReferencedModelElementToAdd;
0534:                                            if (lEntity == null)
0535:                                                return; // Attribute is not associated with entity 
0536:                                            String lEntityName = lEntity
0537:                                                    .getName();
0538:                                            if (lEntityName == null)
0539:                                                return; // Entity does not have a name
0540:                                            Domain lDomain = lEntity
0541:                                                    .getDomain();
0542:                                            if (lDomain == null)
0543:                                                return; // Entity is not associated with domain
0544:                                            String lDomainName = lDomain
0545:                                                    .getName();
0546:                                            if (lDomainName == null)
0547:                                                return; // Domain does not have a name
0548:                                            com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0549:                                                    .getSystem();
0550:                                            if (lSystem == null)
0551:                                                return; // Domain is not associated with system
0552:                                            Servicemodule lServicemodule = lSystem
0553:                                                    .findServicemodule(StylesheetImpl
0554:                                                            .getDomainSupportServicemoduleName(lDomainName));
0555:                                            if (lServicemodule == null)
0556:                                                return; // There is no support servicemodule yet
0557:                                            Collection lEntitySubtypes = lEntity
0558:                                                    .getCombinedSubtypes();
0559:                                            attribute_EnsurePresent(
0560:                                                    lServicemodule,
0561:                                                    lEntity,
0562:                                                    lAttributeName,
0563:                                                    lAttributeDescription,
0564:                                                    (DataType) pReferencedModelElementToAdd);
0565:                                            if (!lEntitySubtypes.isEmpty()) {
0566:                                                for (Iterator lSubtypesIter = lEntitySubtypes
0567:                                                        .iterator(); lSubtypesIter
0568:                                                        .hasNext();)
0569:                                                    attribute_EnsurePresent(
0570:                                                            lServicemodule,
0571:                                                            (Entity) lSubtypesIter
0572:                                                                    .next(),
0573:                                                            lAttributeName,
0574:                                                            lAttributeDescription,
0575:                                                            (DataType) pReferencedModelElementToAdd);
0576:                                            }
0577:                                        }
0578:                                    }
0579:                                });
0580:
0581:                // Add reference Name attribute change listener
0582:                mModelAssistantImpl
0583:                        .addAttributeChangeListener(
0584:                                AssociationRole.class,
0585:                                "Name",
0586:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0587:                                    public void onAttributeBeingUpdated(
0588:                                            RefObject pModelElementBeingUpdated,
0589:                                            String pAttributeName,
0590:                                            Object pOldValue, Object pNewValue) {
0591:                                        AssociationRole lAssociationRole = (AssociationRole) pModelElementBeingUpdated;
0592:                                        Entity lEntity = lAssociationRole
0593:                                                .getReferencingEntity();
0594:                                        if (lEntity == null)
0595:                                            return; // Attribute is not associated with entity
0596:                                        Domain lDomain = lEntity.getDomain();
0597:                                        if (lDomain == null)
0598:                                            return; // Entity is not associated with domain
0599:                                        String lDomainName = lDomain.getName();
0600:                                        if (lDomainName == null)
0601:                                            return; // Domain does not have a name
0602:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0603:                                                .getSystem();
0604:                                        if (lSystem == null)
0605:                                            return; // Domain is not associated with system
0606:                                        Servicemodule lServicemodule = lSystem
0607:                                                .findServicemodule(StylesheetImpl
0608:                                                        .getDomainSupportServicemoduleName(lDomainName));
0609:                                        if (lServicemodule == null)
0610:                                            return; // There is no support servicemodule yet
0611:                                        Set lAllEntitiesToConsider = new HashSet();
0612:                                        lAllEntitiesToConsider.add(lEntity);
0613:                                        lAllEntitiesToConsider.addAll(lEntity
0614:                                                .getCombinedSubtypes());
0615:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0616:                                                .iterator(); lEntityElementsIterator
0617:                                                .hasNext();) {
0618:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
0619:                                                    .next();
0620:                                            if (pNewValue == null) {
0621:                                                // Only old value is known - ensure that the element is deleted
0622:                                                reference_EnsureAbsent(
0623:                                                        lServicemodule,
0624:                                                        lEntityElement,
0625:                                                        (String) pOldValue);
0626:                                            } else {
0627:                                                // New value is known - analyse the criteria and deal with the element accordingly
0628:                                                if (lAssociationRole
0629:                                                        .isSingular()) {
0630:                                                    // The element must be present - rename or create
0631:                                                    if (pOldValue != null)
0632:                                                        reference_EnsureRenamedPresent(
0633:                                                                lServicemodule,
0634:                                                                lEntityElement,
0635:                                                                (String) pOldValue,
0636:                                                                (String) pNewValue,
0637:                                                                lAssociationRole
0638:                                                                        .getDescription(),
0639:                                                                lAssociationRole
0640:                                                                        .getEntity());
0641:                                                    else
0642:                                                        reference_EnsurePresent(
0643:                                                                lServicemodule,
0644:                                                                lEntityElement,
0645:                                                                (String) pNewValue,
0646:                                                                lAssociationRole
0647:                                                                        .getDescription(),
0648:                                                                lAssociationRole
0649:                                                                        .getEntity());
0650:                                                } else {
0651:                                                    // The element must be absent - delete
0652:                                                    reference_EnsureAbsent(
0653:                                                            lServicemodule,
0654:                                                            lEntityElement,
0655:                                                            (String) pNewValue);
0656:                                                    if (pOldValue != null)
0657:                                                        reference_EnsureAbsent(
0658:                                                                lServicemodule,
0659:                                                                lEntityElement,
0660:                                                                (String) pOldValue);
0661:                                                }
0662:                                            }
0663:                                        }
0664:                                    }
0665:                                });
0666:                // Add reference Description attribute change listener
0667:                mModelAssistantImpl
0668:                        .addAttributeChangeListener(
0669:                                AssociationRole.class,
0670:                                "Description",
0671:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0672:                                    public void onAttributeBeingUpdated(
0673:                                            RefObject pModelElementBeingUpdated,
0674:                                            String pAttributeName,
0675:                                            Object pOldValue, Object pNewValue) {
0676:                                        AssociationRole lAssociationRole = (AssociationRole) pModelElementBeingUpdated;
0677:                                        String lAssociationRoleName = lAssociationRole
0678:                                                .getName();
0679:                                        if (lAssociationRoleName == null)
0680:                                            return; // Role does not have a name 
0681:                                        Entity lEntity = lAssociationRole
0682:                                                .getReferencingEntity();
0683:                                        if (lEntity == null)
0684:                                            return; // Attribute is not associated with entity
0685:                                        Domain lDomain = lEntity.getDomain();
0686:                                        if (lDomain == null)
0687:                                            return; // Entity is not associated with domain
0688:                                        String lDomainName = lDomain.getName();
0689:                                        if (lDomainName == null)
0690:                                            return; // Domain does not have a name
0691:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0692:                                                .getSystem();
0693:                                        if (lSystem == null)
0694:                                            return; // Domain is not associated with system
0695:                                        Servicemodule lServicemodule = lSystem
0696:                                                .findServicemodule(StylesheetImpl
0697:                                                        .getDomainSupportServicemoduleName(lDomainName));
0698:                                        if (lServicemodule == null)
0699:                                            return; // There is no support servicemodule yet
0700:                                        // Iterate through all entities having this reference and ensure that the change is reflected
0701:                                        Set lAllEntitiesToConsider = new HashSet();
0702:                                        lAllEntitiesToConsider.add(lEntity);
0703:                                        lAllEntitiesToConsider.addAll(lEntity
0704:                                                .getCombinedSubtypes());
0705:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0706:                                                .iterator(); lEntityElementsIterator
0707:                                                .hasNext();) {
0708:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
0709:                                                    .next();
0710:                                            if (lAssociationRole.isSingular())
0711:                                                reference_EnsurePresent(
0712:                                                        lServicemodule,
0713:                                                        lEntityElement,
0714:                                                        lAssociationRoleName,
0715:                                                        (String) pNewValue,
0716:                                                        lAssociationRole
0717:                                                                .getEntity());
0718:                                        }
0719:                                    }
0720:                                });
0721:                // Add reference cardinality attribute change listener
0722:                mModelAssistantImpl
0723:                        .addAttributeChangeListener(
0724:                                AssociationRole.class,
0725:                                "cardinality",
0726:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0727:                                    public void onAttributeBeingUpdated(
0728:                                            RefObject pModelElementBeingUpdated,
0729:                                            String pAttributeName,
0730:                                            Object pOldValue, Object pNewValue) {
0731:                                        AssociationRole lAssociationRole = (AssociationRole) pModelElementBeingUpdated;
0732:                                        String lAssociationRoleName = lAssociationRole
0733:                                                .getName();
0734:                                        if (lAssociationRoleName == null)
0735:                                            return; // Role does not have a name 
0736:                                        Entity lEntity = lAssociationRole
0737:                                                .getReferencingEntity();
0738:                                        if (lEntity == null)
0739:                                            return; // Attribute is not associated with entity
0740:                                        Domain lDomain = lEntity.getDomain();
0741:                                        if (lDomain == null)
0742:                                            return; // Entity is not associated with domain
0743:                                        String lDomainName = lDomain.getName();
0744:                                        if (lDomainName == null)
0745:                                            return; // Domain does not have a name
0746:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0747:                                                .getSystem();
0748:                                        if (lSystem == null)
0749:                                            return; // Domain is not associated with system
0750:                                        Servicemodule lServicemodule = lSystem
0751:                                                .findServicemodule(StylesheetImpl
0752:                                                        .getDomainSupportServicemoduleName(lDomainName));
0753:                                        if (lServicemodule == null)
0754:                                            return; // There is no support servicemodule yet
0755:                                        // Iterate through all entities having this reference and ensure that the change is reflected
0756:                                        Set lAllEntitiesToConsider = new HashSet();
0757:                                        lAllEntitiesToConsider.add(lEntity);
0758:                                        lAllEntitiesToConsider.addAll(lEntity
0759:                                                .getCombinedSubtypes());
0760:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0761:                                                .iterator(); lEntityElementsIterator
0762:                                                .hasNext();) {
0763:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
0764:                                                    .next();
0765:                                            if (AssociationRoleCardinalityEnum.ONE
0766:                                                    .equals(pNewValue)
0767:                                                    || AssociationRoleCardinalityEnum.ZERO_OR_ONE
0768:                                                            .equals(pNewValue))
0769:                                                reference_EnsurePresent(
0770:                                                        lServicemodule,
0771:                                                        lEntityElement,
0772:                                                        lAssociationRoleName,
0773:                                                        lAssociationRole
0774:                                                                .getDescription(),
0775:                                                        lAssociationRole
0776:                                                                .getEntity());
0777:                                            else
0778:                                                reference_EnsureAbsent(
0779:                                                        lServicemodule,
0780:                                                        lEntityElement,
0781:                                                        lAssociationRoleName);
0782:                                        }
0783:                                    }
0784:                                });
0785:            }
0786:
0787:            // This helper verifies constraints which are dealing with the details structure
0788:            void verifyConstraints(Collection pViolations,
0789:                    Servicemodule pServicemodule, Entity pEntity,
0790:                    Collection pUnclaimedStructures) {
0791:                String lDetailsStructureName = StylesheetImpl
0792:                        .getEntityDetailsStructureName(pEntity.getName());
0793:                Structure lDetailsStructure = pServicemodule
0794:                        .findStructure(lDetailsStructureName);
0795:                if (lDetailsStructure == null) {
0796:                    pViolations
0797:                            .add(new ConstraintViolationException(
0798:                                    pServicemodule,
0799:                                    pServicemodule.refMetaObject(),
0800:                                    "A Domain Support Servicemodule must have Details Structure for every Entity in the corresponding Domain. The '"
0801:                                            + lDetailsStructureName
0802:                                            + "' Structure not found."));
0803:                    return;
0804:                } else
0805:                    pUnclaimedStructures.remove(lDetailsStructure); // Claim the structure    				
0806:                // Work on the fields
0807:                if (pEntity != null) {
0808:                    // Copy aside the collection of the fields, so we can keep track of the unused ones
0809:                    Collection lUnclaimedFields = new ArrayList();
0810:                    lUnclaimedFields.addAll(lDetailsStructure.getFields());
0811:
0812:                    // Work on instance id field
0813:                    {
0814:                        String lInstanceIdFieldName = StylesheetImpl
0815:                                .getEntityInstanceIdStructureFieldName(pEntity
0816:                                        .getName(), pEntity
0817:                                        .getInstanceIdAttributeNameOverride());
0818:                        StructureField lInstanceIdStructureField = lDetailsStructure
0819:                                .findField(lInstanceIdFieldName);
0820:                        if (lInstanceIdStructureField != null) {
0821:                            // Claim the field
0822:                            lUnclaimedFields.remove(lInstanceIdStructureField);
0823:
0824:                            if (lInstanceIdStructureField.isArray())
0825:                                pViolations
0826:                                        .add(new ConstraintViolationException(
0827:                                                lInstanceIdStructureField,
0828:                                                lInstanceIdStructureField
0829:                                                        .refMetaObject(),
0830:                                                "An Instance Identifier field in the Details Structure must be singular. The '"
0831:                                                        + lInstanceIdFieldName
0832:                                                        + "' Field is an Array."));
0833:                            DataType lExpectedDataType = pEntity
0834:                                    .getInstanceIdDataType();
0835:                            DataType lActualDataType = lInstanceIdStructureField
0836:                                    .getDataType();
0837:                            if ((lExpectedDataType != null && lActualDataType == null)
0838:                                    || (lExpectedDataType == null && lActualDataType != null)
0839:                                    || (lExpectedDataType != null
0840:                                            && lActualDataType != null && lActualDataType
0841:                                            .equals(lExpectedDataType) == false))
0842:                                pViolations
0843:                                        .add(new ConstraintViolationException(
0844:                                                lInstanceIdStructureField,
0845:                                                lInstanceIdStructureField
0846:                                                        .refMetaObject(),
0847:                                                "The Instance Identifier field in the Details Structure must be of the same type as Entity Instance Identifier type."));
0848:                        } else
0849:                            pViolations
0850:                                    .add(new ConstraintViolationException(
0851:                                            lDetailsStructure,
0852:                                            lDetailsStructure.refMetaObject(),
0853:                                            "A Details Structure must contain the Entity Instance Identifier field for the asociated Entity. The '"
0854:                                                    + lInstanceIdFieldName
0855:                                                    + "' Field not found."));
0856:                    }
0857:                    // Work on version id field
0858:                    {
0859:                        String lVersionIdFieldName = StylesheetImpl
0860:                                .getEntityVersionIdStructureFieldName(pEntity
0861:                                        .getName(), pEntity
0862:                                        .getVersionIdAttributeNameOverride());
0863:                        StructureField lVersionIdStructureField = lDetailsStructure
0864:                                .findField(lVersionIdFieldName);
0865:                        if (lVersionIdStructureField != null) {
0866:                            if (pEntity.isModifiable()) {
0867:                                // Claim the field
0868:                                lUnclaimedFields
0869:                                        .remove(lVersionIdStructureField);
0870:
0871:                                if (lVersionIdStructureField.isArray())
0872:                                    pViolations
0873:                                            .add(new ConstraintViolationException(
0874:                                                    lVersionIdStructureField,
0875:                                                    lVersionIdStructureField
0876:                                                            .refMetaObject(),
0877:                                                    "A Version Identifier field in the Details Structure must be singular. The '"
0878:                                                            + lVersionIdFieldName
0879:                                                            + "' Field is an Array."));
0880:
0881:                                DataType lExpectedDataType = pEntity
0882:                                        .getVersionIdDataType();
0883:                                DataType lActualDataType = lVersionIdStructureField
0884:                                        .getDataType();
0885:                                if ((lExpectedDataType != null && lActualDataType == null)
0886:                                        || (lExpectedDataType == null && lActualDataType != null)
0887:                                        || (lExpectedDataType != null
0888:                                                && lActualDataType != null && lActualDataType
0889:                                                .equals(lExpectedDataType) == false))
0890:                                    pViolations
0891:                                            .add(new ConstraintViolationException(
0892:                                                    lVersionIdStructureField,
0893:                                                    lVersionIdStructureField
0894:                                                            .refMetaObject(),
0895:                                                    "The Version Identifier field in the Details Structure must be of the same type as Entity Version Identifier."));
0896:                            }
0897:                        } else if (pEntity.isModifiable())
0898:                            pViolations
0899:                                    .add(new ConstraintViolationException(
0900:                                            lDetailsStructure,
0901:                                            lDetailsStructure.refMetaObject(),
0902:                                            "A Details Structure must contain the Entity Version Identifier field if associated Entity is modifiable. The '"
0903:                                                    + lVersionIdFieldName
0904:                                                    + "' Field not found."));
0905:                    }
0906:                    // Work on state field
0907:                    {
0908:                        String lStateFieldName = StylesheetImpl
0909:                                .getEntityStateStructureFieldName(pEntity
0910:                                        .getName(), pEntity
0911:                                        .getStateAttributeNameOverride());
0912:                        StructureField lStateStructureField = lDetailsStructure
0913:                                .findField(lStateFieldName);
0914:                        if (lStateStructureField != null) {
0915:                            if (pEntity.getStateMachine() != null) {
0916:                                // Claim the field
0917:                                lUnclaimedFields.remove(lStateStructureField);
0918:
0919:                                if (lStateStructureField.isArray())
0920:                                    pViolations
0921:                                            .add(new ConstraintViolationException(
0922:                                                    lStateStructureField,
0923:                                                    lStateStructureField
0924:                                                            .refMetaObject(),
0925:                                                    "A State field in the Details Structure must be singular. The '"
0926:                                                            + lStateFieldName
0927:                                                            + "' Field is an Array."));
0928:                                DataType lExpectedDataType = pEntity
0929:                                        .getStateDataType();
0930:                                DataType lActualDataType = lStateStructureField
0931:                                        .getDataType();
0932:                                if ((lExpectedDataType != null && lActualDataType == null)
0933:                                        || (lExpectedDataType == null && lActualDataType != null)
0934:                                        || (lExpectedDataType != null
0935:                                                && lActualDataType != null && lActualDataType
0936:                                                .equals(lExpectedDataType) == false))
0937:                                    pViolations
0938:                                            .add(new ConstraintViolationException(
0939:                                                    lStateStructureField,
0940:                                                    lStateStructureField
0941:                                                            .refMetaObject(),
0942:                                                    "The State field in the Details Structure must be of the same type as Entity State."));
0943:                            }
0944:                        } else if (pEntity.getStateMachine() != null)
0945:                            pViolations
0946:                                    .add(new ConstraintViolationException(
0947:                                            lDetailsStructure,
0948:                                            lDetailsStructure.refMetaObject(),
0949:                                            "A Details Structure must contain the State field if associated Entity as a State Machine. The '"
0950:                                                    + lStateFieldName
0951:                                                    + "' Field not found."));
0952:                    }
0953:
0954:                    // Work on attributes
0955:                    for (Iterator lAttributesIterator = pEntity
0956:                            .getCombinedAttributes().iterator(); lAttributesIterator
0957:                            .hasNext();) {
0958:                        Attribute lAttribute = (Attribute) lAttributesIterator
0959:                                .next();
0960:                        String lAttributeFieldName = StylesheetImpl
0961:                                .getEntityAttributeStructureFieldName(lAttribute
0962:                                        .getName());
0963:                        StructureField lAttributeStructureField = lDetailsStructure
0964:                                .findField(lAttributeFieldName);
0965:                        if (lAttributeStructureField != null) {
0966:                            // Claim the field
0967:                            lUnclaimedFields.remove(lAttributeStructureField);
0968:
0969:                            if (lAttributeStructureField.isArray())
0970:                                pViolations
0971:                                        .add(new ConstraintViolationException(
0972:                                                lAttributeStructureField,
0973:                                                lAttributeStructureField
0974:                                                        .refMetaObject(),
0975:                                                "An Entity Attribute field in the Details Structure must be singular. The '"
0976:                                                        + lAttributeFieldName
0977:                                                        + "' Field is an Array."));
0978:
0979:                            DataType lExpectedDataType = lAttribute
0980:                                    .getDataType();
0981:                            DataType lActualDataType = lAttributeStructureField
0982:                                    .getDataType();
0983:                            if ((lExpectedDataType != null && lActualDataType == null)
0984:                                    || (lExpectedDataType == null && lActualDataType != null)
0985:                                    || (lExpectedDataType != null
0986:                                            && lActualDataType != null && lActualDataType
0987:                                            .equals(lExpectedDataType) == false))
0988:                                pViolations
0989:                                        .add(new ConstraintViolationException(
0990:                                                lAttributeStructureField,
0991:                                                lAttributeStructureField
0992:                                                        .refMetaObject(),
0993:                                                "The Entity Attribute field in the Details Structure must be of the same type as the corresponding Attribute in the Entity."));
0994:                        } else
0995:                            pViolations
0996:                                    .add(new ConstraintViolationException(
0997:                                            lDetailsStructure,
0998:                                            lDetailsStructure.refMetaObject(),
0999:                                            "A Details Structure must contain the Entity Attribute field for every Attribute in the asociated Entity. The '"
1000:                                                    + lAttributeFieldName
1001:                                                    + "' Field not found."));
1002:                    }
1003:
1004:                    // Work on references
1005:                    for (Iterator lReferencesIterator = pEntity
1006:                            .getCombinedReferences().iterator(); lReferencesIterator
1007:                            .hasNext();) {
1008:                        AssociationRole lReference = (AssociationRole) lReferencesIterator
1009:                                .next();
1010:                        if (lReference.isSingular()) {
1011:                            String lReferenceFieldName = StylesheetImpl
1012:                                    .getEntityReferenceStructureFieldName(lReference
1013:                                            .getName());
1014:                            StructureField lReferenceStructureField = lDetailsStructure
1015:                                    .findField(lReferenceFieldName);
1016:                            if (lReferenceStructureField != null) {
1017:                                // Claim the field
1018:                                lUnclaimedFields
1019:                                        .remove(lReferenceStructureField);
1020:
1021:                                if (lReferenceStructureField.isArray())
1022:                                    pViolations
1023:                                            .add(new ConstraintViolationException(
1024:                                                    lReferenceStructureField,
1025:                                                    lReferenceStructureField
1026:                                                            .refMetaObject(),
1027:                                                    "An Entity Reference field in the Details Structure must be singular. The '"
1028:                                                            + lReferenceFieldName
1029:                                                            + "' Field is an Array."));
1030:
1031:                                // Verify types
1032:                                Structure lExpectedStructureType = lReference
1033:                                        .getEntity() != null ? pServicemodule
1034:                                        .findStructure(StylesheetImpl
1035:                                                .getEntityKeyStructureName(lReference
1036:                                                        .getEntity().getName()))
1037:                                        : null;
1038:                                Structure lActualStructureType = lReferenceStructureField
1039:                                        .getStructureType();
1040:                                if ((lExpectedStructureType != null && lActualStructureType == null)
1041:                                        || (lExpectedStructureType == null && lActualStructureType != null)
1042:                                        || (lExpectedStructureType != null
1043:                                                && lActualStructureType != null && lActualStructureType
1044:                                                .equals(lExpectedStructureType) == false))
1045:                                    pViolations
1046:                                            .add(new ConstraintViolationException(
1047:                                                    lReferenceStructureField,
1048:                                                    lReferenceStructureField
1049:                                                            .refMetaObject(),
1050:                                                    "The '"
1051:                                                            + lReferenceFieldName
1052:                                                            + "' field in the Details Structure must be the Key Structure of the entity being referenced."));
1053:                            } else
1054:                                pViolations
1055:                                        .add(new ConstraintViolationException(
1056:                                                lDetailsStructure,
1057:                                                lDetailsStructure
1058:                                                        .refMetaObject(),
1059:                                                "A Details Structure must contain the Entity Reference field for every singular reference in the asociated Entity. The '"
1060:                                                        + lReferenceFieldName
1061:                                                        + "' Field not found."));
1062:                        }
1063:                    }
1064:
1065:                    // Create errors for all unclaimed fields
1066:                    for (Iterator lUnclaimedFieldsIterator = lUnclaimedFields
1067:                            .iterator(); lUnclaimedFieldsIterator.hasNext();) {
1068:                        StructureField lUnclaimedField = (StructureField) lUnclaimedFieldsIterator
1069:                                .next();
1070:                        pViolations
1071:                                .add(new ConstraintViolationException(
1072:                                        lUnclaimedField,
1073:                                        lUnclaimedField.refMetaObject(),
1074:                                        "A Details Structure must only contain fields for all Entity Attributes and Singular references from the asociated Entity. The '"
1075:                                                + lUnclaimedField.getName()
1076:                                                + "' Field is unexpected."));
1077:                    }
1078:                }
1079:            }
1080:
1081:            // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
1082:            void rectifyModel(Servicemodule pServicemodule, Entity pEntity,
1083:                    Collection pUnclaimedStructures) {
1084:                // Check if we have a structure and than just call ensurePresent
1085:                String lDetailsStructureName = StylesheetImpl
1086:                        .getEntityDetailsStructureName(pEntity.getName());
1087:                Structure lDetailsStructure = pServicemodule
1088:                        .findStructure(lDetailsStructureName);
1089:                if (lDetailsStructure != null)
1090:                    pUnclaimedStructures.remove(lDetailsStructure); // Claim the structure    				
1091:                // Now just call ensurePresent
1092:                ensurePresent(pServicemodule, pEntity, pEntity.getName());
1093:            }
1094:
1095:            // This helper renames the key and details structures
1096:            void ensureRenamedPresent(Servicemodule pServicemodule,
1097:                    Entity pEntity, String pOldEntityName, String pNewEntityName) {
1098:                // Note that this method only deals with renaming and than calls the ensure present method  
1099:
1100:                String lOldDetailsStructureName = StylesheetImpl
1101:                        .getEntityDetailsStructureName(pOldEntityName);
1102:                Structure lOldDetailsStructure = pServicemodule
1103:                        .findStructure(lOldDetailsStructureName);
1104:                String lNewDetailsStructureName = StylesheetImpl
1105:                        .getEntityDetailsStructureName(pNewEntityName);
1106:                Structure lNewDetailsStructure = pServicemodule
1107:                        .findStructure(lNewDetailsStructureName);
1108:                // Be relaxed here - allow for all sorts of mishaps
1109:                if (lOldDetailsStructure != null) {
1110:                    if (lNewDetailsStructure != null) {
1111:                        // New and old structures are present - just delete the old one
1112:                        lOldDetailsStructure.refDelete();
1113:                    } else {
1114:                        // Old structure is present - new one is not - rename
1115:                        lOldDetailsStructure.setName(lNewDetailsStructureName);
1116:                    }
1117:                }
1118:
1119:                // Call the ensure present bit
1120:                ensurePresent(pServicemodule, pEntity, pNewEntityName);
1121:            }
1122:
1123:            // This helper makes sure that the key and details structures exist and uptodate
1124:            void ensurePresent(Servicemodule pServicemodule, Entity pEntity,
1125:                    String pEntityName) {
1126:                // Work on the Details structure
1127:                String lDetailsStructureName = StylesheetImpl
1128:                        .getEntityDetailsStructureName(pEntityName);
1129:                String lDetailsStructureDescription = StylesheetImpl
1130:                        .getEntityDetailsStructureDescription(pEntityName);
1131:                Structure lDetailsStructure = pServicemodule
1132:                        .findStructure(lDetailsStructureName);
1133:                if (lDetailsStructure == null) {
1134:                    lDetailsStructure = this .mModelAssistantImpl.mStructureClass
1135:                            .createStructure();
1136:                    lDetailsStructure.setName(lDetailsStructureName);
1137:                    lDetailsStructure.setServicemodule(pServicemodule);
1138:                }
1139:                lDetailsStructure.setDescription(lDetailsStructureDescription);
1140:                // Work on the fields
1141:                if (pEntity != null) {
1142:                    // Copy aside the collection of the fields, so we can delete the unused ones
1143:                    Collection lUnclaimedFields = new ArrayList();
1144:                    lUnclaimedFields.addAll(lDetailsStructure.getFields());
1145:
1146:                    // Work on the instance id field
1147:                    {
1148:                        String lInstanceIdFieldName = StylesheetImpl
1149:                                .getEntityInstanceIdStructureFieldName(
1150:                                        pEntityName,
1151:                                        pEntity
1152:                                                .getInstanceIdAttributeNameOverride());
1153:                        String lInstanceIdFieldDescription = StylesheetImpl
1154:                                .getEntityInstanceIdStructureFieldDescription(pEntityName);
1155:                        StructureField lInstanceIdStructureField = lDetailsStructure
1156:                                .findField(lInstanceIdFieldName);
1157:                        if (lInstanceIdStructureField == null) {
1158:                            lInstanceIdStructureField = mModelAssistantImpl.mStructureFieldClass
1159:                                    .createStructureField();
1160:                            lInstanceIdStructureField
1161:                                    .setName(lInstanceIdFieldName);
1162:                            lInstanceIdStructureField
1163:                                    .setOwnerStructure(lDetailsStructure);
1164:                        } else {
1165:                            // Claim the field
1166:                            lUnclaimedFields.remove(lInstanceIdStructureField);
1167:                        }
1168:                        lInstanceIdStructureField
1169:                                .setDescription(lInstanceIdFieldDescription);
1170:                        lInstanceIdStructureField.setArray(false);
1171:                        lInstanceIdStructureField.setDataType(pEntity
1172:                                .getInstanceIdDataType());
1173:                        lInstanceIdStructureField.setStructureType(null);
1174:                    }
1175:                    // Work on the version id field
1176:                    if (pEntity.isModifiable()) {
1177:                        // Ensure version id field is present
1178:                        String lVersionIdFieldName = StylesheetImpl
1179:                                .getEntityVersionIdStructureFieldName(pEntity
1180:                                        .getName(), pEntity
1181:                                        .getVersionIdAttributeNameOverride());
1182:                        StructureField lVersionIdStructureField = lDetailsStructure
1183:                                .findField(lVersionIdFieldName);
1184:                        if (lVersionIdStructureField == null) {
1185:                            lVersionIdStructureField = mModelAssistantImpl.mStructureFieldClass
1186:                                    .createStructureField();
1187:                            lVersionIdStructureField
1188:                                    .setName(lVersionIdFieldName);
1189:                            lVersionIdStructureField
1190:                                    .setOwnerStructure(lDetailsStructure);
1191:                        } else {
1192:                            // Claim the field
1193:                            lUnclaimedFields.remove(lVersionIdStructureField);
1194:                        }
1195:                        lVersionIdStructureField
1196:                                .setDescription(StylesheetImpl
1197:                                        .getEntityVersionIdStructureFieldDescription(pEntity
1198:                                                .getName()));
1199:                        lVersionIdStructureField.setArray(false);
1200:                        lVersionIdStructureField.setDataType(pEntity
1201:                                .getVersionIdDataType());
1202:                        lVersionIdStructureField.setStructureType(null);
1203:                    }
1204:                    // Work on the state field
1205:                    if (pEntity.getStateMachine() != null) {
1206:                        // Ensure state field is present
1207:                        String lStateFieldName = StylesheetImpl
1208:                                .getEntityStateStructureFieldName(pEntity
1209:                                        .getName(), pEntity
1210:                                        .getStateAttributeNameOverride());
1211:                        StructureField lStateStructureField = lDetailsStructure
1212:                                .findField(lStateFieldName);
1213:                        if (lStateStructureField == null) {
1214:                            lStateStructureField = mModelAssistantImpl.mStructureFieldClass
1215:                                    .createStructureField();
1216:                            lStateStructureField.setName(lStateFieldName);
1217:                            lStateStructureField
1218:                                    .setOwnerStructure(lDetailsStructure);
1219:                        } else {
1220:                            // Claim the field
1221:                            lUnclaimedFields.remove(lStateStructureField);
1222:                        }
1223:                        lStateStructureField
1224:                                .setDescription(StylesheetImpl
1225:                                        .getEntityStateStructureFieldDescription(pEntity
1226:                                                .getName()));
1227:                        lStateStructureField.setArray(false);
1228:                        lStateStructureField.setDataType(pEntity
1229:                                .getStateDataType());
1230:                        lStateStructureField.setStructureType(null);
1231:                    }
1232:
1233:                    // Work on attributes
1234:                    for (Iterator lAttributesIterator = pEntity
1235:                            .getCombinedAttributes().iterator(); lAttributesIterator
1236:                            .hasNext();) {
1237:                        Attribute lAttribute = (Attribute) lAttributesIterator
1238:                                .next();
1239:                        String lAttributeFieldName = StylesheetImpl
1240:                                .getEntityAttributeStructureFieldName(lAttribute
1241:                                        .getName());
1242:                        StructureField lAttributeStructureField = lDetailsStructure
1243:                                .findField(lAttributeFieldName);
1244:                        if (lAttributeStructureField == null) {
1245:                            lAttributeStructureField = mModelAssistantImpl.mStructureFieldClass
1246:                                    .createStructureField();
1247:                            lAttributeStructureField
1248:                                    .setName(lAttributeFieldName);
1249:                            lAttributeStructureField
1250:                                    .setOwnerStructure(lDetailsStructure);
1251:                        } else {
1252:                            // Claim the field
1253:                            lUnclaimedFields.remove(lAttributeStructureField);
1254:                        }
1255:                        lAttributeStructureField.setDescription(StylesheetImpl
1256:                                .getEntityAttributeStructureFieldDescription(
1257:                                        lAttribute.getName(), lAttribute
1258:                                                .getDescription()));
1259:                        lAttributeStructureField.setArray(false);
1260:                        lAttributeStructureField.setDataType(lAttribute
1261:                                .getDataType());
1262:                        lAttributeStructureField.setStructureType(null);
1263:                    }
1264:
1265:                    // Work on refeences
1266:                    for (Iterator lReferencesIterator = pEntity
1267:                            .getCombinedReferences().iterator(); lReferencesIterator
1268:                            .hasNext();) {
1269:                        AssociationRole lReference = (AssociationRole) lReferencesIterator
1270:                                .next();
1271:                        if (lReference.isSingular()) {
1272:                            Entity lReferencedEntity = lReference.getEntity();
1273:                            String lReferenceFieldName = StylesheetImpl
1274:                                    .getEntityReferenceStructureFieldName(lReference
1275:                                            .getName());
1276:                            StructureField lStructureField = lDetailsStructure
1277:                                    .findField(lReferenceFieldName);
1278:                            if (lStructureField == null) {
1279:                                lStructureField = mModelAssistantImpl.mStructureFieldClass
1280:                                        .createStructureField();
1281:                                lStructureField.setName(lReferenceFieldName);
1282:                                lStructureField
1283:                                        .setOwnerStructure(lDetailsStructure);
1284:                            } else {
1285:                                // Claim the field
1286:                                lUnclaimedFields.remove(lStructureField);
1287:                            }
1288:                            lStructureField
1289:                                    .setDescription(StylesheetImpl
1290:                                            .getEntityReferenceStructureFieldDescription(
1291:                                                    lReference.getName(),
1292:                                                    lReference.getDescription()));
1293:                            lStructureField.setArray(false);
1294:                            if (lReferencedEntity != null
1295:                                    && lReferencedEntity.getName() != null)
1296:                                lStructureField
1297:                                        .setStructureType(pServicemodule
1298:                                                .findStructure(StylesheetImpl
1299:                                                        .getEntityKeyStructureName(lReferencedEntity
1300:                                                                .getName())));
1301:                            else
1302:                                lStructureField.setStructureType(null);
1303:                            lStructureField.setDataType(null);
1304:                        }
1305:                    }
1306:
1307:                    // Remove unclaimed fields
1308:                    for (Iterator lUnclaimedFieldsIterator = lUnclaimedFields
1309:                            .iterator(); lUnclaimedFieldsIterator.hasNext();) {
1310:                        StructureField lUnclaimedField = (StructureField) lUnclaimedFieldsIterator
1311:                                .next();
1312:                        lUnclaimedField.refDelete();
1313:                    }
1314:                }
1315:            }
1316:
1317:            // This helper makes sure that the Details and details structures are absent
1318:            void ensureAbsent(Servicemodule pServicemodule, String pEntityName) {
1319:                // Work on the details structure
1320:                Structure lDetailsStructure = pServicemodule
1321:                        .findStructure(StylesheetImpl
1322:                                .getEntityDetailsStructureName(pEntityName));
1323:                if (lDetailsStructure != null)
1324:                    lDetailsStructure.refDelete();
1325:            }
1326:
1327:            // This helper makes sure that the version id attribute is present in the details structure
1328:            void versionIdAttribute_EnsurePresent(Servicemodule pServicemodule,
1329:                    Entity pEntity) {
1330:                String lEntityName = pEntity.getName();
1331:                if (lEntityName == null)
1332:                    return;
1333:                Structure lDetailsStructure = pServicemodule
1334:                        .findStructure(StylesheetImpl
1335:                                .getEntityDetailsStructureName(lEntityName));
1336:                if (lDetailsStructure == null)
1337:                    return; // No structure yet
1338:                String lVersionIdFieldName = StylesheetImpl
1339:                        .getEntityVersionIdStructureFieldName(
1340:                                pEntity.getName(), pEntity
1341:                                        .getVersionIdAttributeNameOverride());
1342:                StructureField lVersionIdStructureField = lDetailsStructure
1343:                        .findField(lVersionIdFieldName);
1344:                if (lVersionIdStructureField == null) {
1345:                    lVersionIdStructureField = mModelAssistantImpl.mStructureFieldClass
1346:                            .createStructureField();
1347:                    lVersionIdStructureField.setName(lVersionIdFieldName);
1348:                    lVersionIdStructureField
1349:                            .setOwnerStructure(lDetailsStructure);
1350:                }
1351:                lVersionIdStructureField.setDescription(StylesheetImpl
1352:                        .getEntityVersionIdStructureFieldDescription(pEntity
1353:                                .getName()));
1354:                lVersionIdStructureField.setArray(false);
1355:                lVersionIdStructureField.setDataType(pEntity
1356:                        .getVersionIdDataType());
1357:                lVersionIdStructureField.setStructureType(null);
1358:            }
1359:
1360:            // This helper makes sure that the version id attribute is absent in the details structure
1361:            void versionIdAttribute_EnsureAbsent(Servicemodule pServicemodule,
1362:                    Entity pEntity) {
1363:                String lEntityName = pEntity.getName();
1364:                if (lEntityName == null)
1365:                    return;
1366:                Structure lDetailsStructure = pServicemodule
1367:                        .findStructure(StylesheetImpl
1368:                                .getEntityDetailsStructureName(lEntityName));
1369:                if (lDetailsStructure == null)
1370:                    return; // No structure yet
1371:                String lVersionIdFieldName = StylesheetImpl
1372:                        .getEntityVersionIdStructureFieldName(
1373:                                pEntity.getName(), pEntity
1374:                                        .getVersionIdAttributeNameOverride());
1375:                StructureField lVersionIdStructureField = lDetailsStructure
1376:                        .findField(lVersionIdFieldName);
1377:                if (lVersionIdStructureField != null)
1378:                    lVersionIdStructureField.refDelete();
1379:            }
1380:
1381:            // This helper makes sure that the version id attribute is present in the details structure
1382:            void stateAttribute_EnsurePresent(Servicemodule pServicemodule,
1383:                    Entity pEntity) {
1384:                String lEntityName = pEntity.getName();
1385:                if (lEntityName == null)
1386:                    return;
1387:                Structure lDetailsStructure = pServicemodule
1388:                        .findStructure(StylesheetImpl
1389:                                .getEntityDetailsStructureName(lEntityName));
1390:                if (lDetailsStructure == null)
1391:                    return; // No structure yet
1392:                String lStateFieldName = StylesheetImpl
1393:                        .getEntityStateStructureFieldName(pEntity.getName(),
1394:                                pEntity.getStateAttributeNameOverride());
1395:                StructureField lStateStructureField = lDetailsStructure
1396:                        .findField(lStateFieldName);
1397:                if (lStateStructureField == null) {
1398:                    lStateStructureField = mModelAssistantImpl.mStructureFieldClass
1399:                            .createStructureField();
1400:                    lStateStructureField.setName(lStateFieldName);
1401:                    lStateStructureField.setOwnerStructure(lDetailsStructure);
1402:                }
1403:                lStateStructureField.setDescription(StylesheetImpl
1404:                        .getEntityStateStructureFieldDescription(pEntity
1405:                                .getName()));
1406:                lStateStructureField.setArray(false);
1407:                lStateStructureField.setDataType(pEntity.getStateDataType());
1408:                lStateStructureField.setStructureType(null);
1409:            }
1410:
1411:            // This helper makes sure that the version id attribute is absent in the details structure
1412:            void stateAttribute_EnsureAbsent(Servicemodule pServicemodule,
1413:                    Entity pEntity) {
1414:                String lEntityName = pEntity.getName();
1415:                if (lEntityName == null)
1416:                    return;
1417:                Structure lDetailsStructure = pServicemodule
1418:                        .findStructure(StylesheetImpl
1419:                                .getEntityDetailsStructureName(lEntityName));
1420:                if (lDetailsStructure == null)
1421:                    return; // No structure yet
1422:                String lStateFieldName = StylesheetImpl
1423:                        .getEntityStateStructureFieldName(pEntity.getName(),
1424:                                pEntity.getStateAttributeNameOverride());
1425:                StructureField lStateStructureField = lDetailsStructure
1426:                        .findField(lStateFieldName);
1427:                if (lStateStructureField != null)
1428:                    lStateStructureField.refDelete();
1429:            }
1430:
1431:            // This helper renames the key and details structures
1432:            void attribute_EnsureRenamedPresent(Servicemodule pServicemodule,
1433:                    Entity pEntity, String pOldAttributeName,
1434:                    String pNewAttributeName, String pAttributeDescription,
1435:                    DataType pAttributeDataType) {
1436:                String lEntityName = pEntity.getName();
1437:                if (lEntityName == null)
1438:                    return;
1439:                Structure lDetailsStructure = pServicemodule
1440:                        .findStructure(StylesheetImpl
1441:                                .getEntityDetailsStructureName(lEntityName));
1442:                if (lDetailsStructure == null)
1443:                    return; // No structure yet
1444:                // Note that this method only deals with renaming and than calls the ensure present method  
1445:                String lOldAttributeName = StylesheetImpl
1446:                        .getEntityAttributeStructureFieldName(pOldAttributeName);
1447:                StructureField lOldAttributeStructureField = lDetailsStructure
1448:                        .findField(lOldAttributeName);
1449:                String lNewAttributeName = StylesheetImpl
1450:                        .getEntityAttributeStructureFieldName(pNewAttributeName);
1451:                StructureField lNewAttributeStructureField = lDetailsStructure
1452:                        .findField(lNewAttributeName);
1453:                // Be relaxed here - allow for all sorts of mishaps
1454:                if (lOldAttributeStructureField != null) {
1455:                    if (lNewAttributeStructureField != null) {
1456:                        // New and old structures are present - just delete the old one
1457:                        lOldAttributeStructureField.refDelete();
1458:                    } else {
1459:                        // Old field is present - new one is not - rename
1460:                        lOldAttributeStructureField.setName(lNewAttributeName);
1461:                    }
1462:                }
1463:                // Call the ensure present bit
1464:                attribute_EnsurePresent(pServicemodule, pEntity,
1465:                        pNewAttributeName, pAttributeDescription,
1466:                        pAttributeDataType);
1467:            }
1468:
1469:            // This helper makes sure that the version id attribute is present in the details structure
1470:            void attribute_EnsurePresent(Servicemodule pServicemodule,
1471:                    Entity pEntity, String pAttributeName,
1472:                    String pAttributeDescription, DataType pAttributeDataType) {
1473:                String lEntityName = pEntity.getName();
1474:                if (lEntityName == null)
1475:                    return;
1476:                Structure lDetailsStructure = pServicemodule
1477:                        .findStructure(StylesheetImpl
1478:                                .getEntityDetailsStructureName(lEntityName));
1479:                if (lDetailsStructure == null)
1480:                    return;
1481:                String lAttributeFieldName = StylesheetImpl
1482:                        .getEntityAttributeStructureFieldName(pAttributeName);
1483:                StructureField lAttributeStructureField = lDetailsStructure
1484:                        .findField(lAttributeFieldName);
1485:                if (lAttributeStructureField == null) {
1486:                    lAttributeStructureField = mModelAssistantImpl.mStructureFieldClass
1487:                            .createStructureField();
1488:                    lAttributeStructureField.setName(lAttributeFieldName);
1489:                    lAttributeStructureField
1490:                            .setOwnerStructure(lDetailsStructure);
1491:                }
1492:                lAttributeStructureField.setDescription(StylesheetImpl
1493:                        .getEntityAttributeStructureFieldDescription(
1494:                                pAttributeName, pAttributeDescription));
1495:                lAttributeStructureField.setArray(false);
1496:                lAttributeStructureField.setDataType(pAttributeDataType);
1497:                lAttributeStructureField.setStructureType(null);
1498:            }
1499:
1500:            // This helper makes sure that the version id attribute is absent in the details structure
1501:            void attribute_EnsureAbsent(Servicemodule pServicemodule,
1502:                    Entity pEntity, String pAttributeName) {
1503:                String lEntityName = pEntity.getName();
1504:                if (lEntityName == null)
1505:                    return;
1506:                Structure lDetailsStructure = pServicemodule
1507:                        .findStructure(StylesheetImpl
1508:                                .getEntityDetailsStructureName(lEntityName));
1509:                if (lDetailsStructure == null)
1510:                    return;
1511:                String lAttributeFieldName = StylesheetImpl
1512:                        .getEntityAttributeStructureFieldName(pAttributeName);
1513:                StructureField lAttributeStructureField = lDetailsStructure
1514:                        .findField(lAttributeFieldName);
1515:                if (lAttributeStructureField != null)
1516:                    lAttributeStructureField.refDelete();
1517:            }
1518:
1519:            // This helper makes sure that the structure field data type is empty
1520:            void attributeDataType_EnsureAbsent(Servicemodule pServicemodule,
1521:                    Entity pEntity, String pAttributeName) {
1522:                String lEntityName = pEntity.getName();
1523:                if (lEntityName == null)
1524:                    return;
1525:                Structure lDetailsStructure = pServicemodule
1526:                        .findStructure(StylesheetImpl
1527:                                .getEntityDetailsStructureName(lEntityName));
1528:                if (lDetailsStructure == null)
1529:                    return;
1530:                String lAttributeFieldName = StylesheetImpl
1531:                        .getEntityAttributeStructureFieldName(pAttributeName);
1532:                StructureField lAttributeStructureField = lDetailsStructure
1533:                        .findField(lAttributeFieldName);
1534:                if (lAttributeStructureField != null)
1535:                    lAttributeStructureField.setDataType(null);
1536:            }
1537:
1538:            // This helper renames the attribute
1539:            void reference_EnsureRenamedPresent(Servicemodule pServicemodule,
1540:                    Entity pEntity, String pOldReferenceName,
1541:                    String pNewReferenceName, String pReferenceDescription,
1542:                    Entity pReferencedEntity) {
1543:                String lEntityName = pEntity.getName();
1544:                if (lEntityName == null)
1545:                    return;
1546:                Structure lDetailsStructure = pServicemodule
1547:                        .findStructure(StylesheetImpl
1548:                                .getEntityDetailsStructureName(lEntityName));
1549:                if (lDetailsStructure == null)
1550:                    return;
1551:                // Note that this method only deals with renaming and than calls the ensure present method  
1552:                String lOldFieldName = StylesheetImpl
1553:                        .getEntityReferenceStructureFieldName(pOldReferenceName);
1554:                StructureField lOldStructureField = lDetailsStructure
1555:                        .findField(lOldFieldName);
1556:                String lNewFieldName = StylesheetImpl
1557:                        .getEntityReferenceStructureFieldName(pNewReferenceName);
1558:                StructureField lNewStructureField = lDetailsStructure
1559:                        .findField(lNewFieldName);
1560:                // Be relaxed here - allow for all sorts of mishaps
1561:                if (lOldStructureField != null) {
1562:                    if (lNewStructureField != null) {
1563:                        // New and old structures are present - just delete the old one
1564:                        lOldStructureField.refDelete();
1565:                    } else {
1566:                        // Old field is present - new one is not - rename
1567:                        lOldStructureField.setName(lNewFieldName);
1568:                    }
1569:                }
1570:                // Call the ensure present bit
1571:                reference_EnsurePresent(pServicemodule, pEntity,
1572:                        pNewReferenceName, pReferenceDescription,
1573:                        pReferencedEntity);
1574:            }
1575:
1576:            // This helper makes sure that the version id attribute is present in the details structure
1577:            void reference_EnsurePresent(Servicemodule pServicemodule,
1578:                    Entity pEntity, String pReferenceName,
1579:                    String pReferenceDescription, Entity pReferencedEntity) {
1580:                String lEntityName = pEntity.getName();
1581:                if (lEntityName == null)
1582:                    return;
1583:                Structure lDetailsStructure = pServicemodule
1584:                        .findStructure(StylesheetImpl
1585:                                .getEntityDetailsStructureName(lEntityName));
1586:                if (lDetailsStructure == null)
1587:                    return;
1588:                String lReferenceFieldName = StylesheetImpl
1589:                        .getEntityReferenceStructureFieldName(pReferenceName);
1590:                StructureField lStructureField = lDetailsStructure
1591:                        .findField(lReferenceFieldName);
1592:                if (lStructureField == null) {
1593:                    lStructureField = mModelAssistantImpl.mStructureFieldClass
1594:                            .createStructureField();
1595:                    lStructureField.setName(lReferenceFieldName);
1596:                    lStructureField.setOwnerStructure(lDetailsStructure);
1597:                }
1598:                lStructureField.setDescription(StylesheetImpl
1599:                        .getEntityReferenceStructureFieldDescription(
1600:                                pReferenceName, pReferenceDescription));
1601:                lStructureField.setArray(false);
1602:                lStructureField.setStructureType(null);
1603:                lStructureField
1604:                        .setDataType(pReferencedEntity != null ? pReferencedEntity
1605:                                .getInstanceIdDataType()
1606:                                : null);
1607:            }
1608:
1609:            // This helper makes sure that the version id attribute is absent in the details structure
1610:            void reference_EnsureAbsent(Servicemodule pServicemodule,
1611:                    Entity pEntity, String pReferenceName) {
1612:                String lEntityName = pEntity.getName();
1613:                if (lEntityName == null)
1614:                    return;
1615:                Structure lDetailsStructure = pServicemodule
1616:                        .findStructure(StylesheetImpl
1617:                                .getEntityDetailsStructureName(lEntityName));
1618:                if (lDetailsStructure == null)
1619:                    return;
1620:                String lReferenceFieldName = StylesheetImpl
1621:                        .getEntityReferenceStructureFieldName(pReferenceName);
1622:                StructureField lStructureField = lDetailsStructure
1623:                        .findField(lReferenceFieldName);
1624:                if (lStructureField != null)
1625:                    lStructureField.refDelete();
1626:            }
1627:        }
w___w_w.__j__av___a___2_s._c__om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.