Source Code Cross Referenced for TargetGetAllEntitiesOperationHelper.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) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.sdlctools.models.modelassistant.metabossmodel.domainsupport;
016:
017:        import java.util.ArrayList;
018:        import java.util.Collection;
019:        import java.util.HashSet;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Set;
023:
024:        import javax.jmi.reflect.ConstraintViolationException;
025:        import javax.jmi.reflect.RefObject;
026:
027:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
028:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
029:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
030:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
031:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
032:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
033:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
034:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
035:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
036:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum;
037:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
038:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
039:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
040:        import com.metaboss.util.StringUtils;
041:
042:        /** This class containse helper methods dealing with the Domain Support Servicemodule model element  */
043:        class TargetGetAllEntitiesOperationHelper {
044:            private ModelAssistantImpl mModelAssistantImpl;
045:
046:            TargetGetAllEntitiesOperationHelper(
047:                    ModelAssistantImpl pModelAssistantImpl) {
048:                mModelAssistantImpl = pModelAssistantImpl;
049:
050:                // Add entity lifecycle listener
051:                mModelAssistantImpl.addLifecycleListener(Entity.class,
052:                        new ModelAssistantImpl.ModelElementLifecycleListener() {
053:                            public void onElementJustCreated(
054:                                    RefObject pModelElementJustCreated) {
055:                                Entity lEntity = (Entity) pModelElementJustCreated;
056:                                String lEntityPluralName = lEntity
057:                                        .getPluralName();
058:                                if (lEntityPluralName == null)
059:                                    return; // Entity does not have a plural name
060:                                Domain lDomain = lEntity.getDomain();
061:                                if (lDomain == null)
062:                                    return; // Entity is not associated with domain
063:                                String lDomainName = lDomain.getName();
064:                                if (lDomainName == null)
065:                                    return; // Domain does not have a name
066:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
067:                                        .getSystem();
068:                                if (lSystem == null)
069:                                    return; // Domain is not associated with system
070:                                Servicemodule lServicemodule = lSystem
071:                                        .findServicemodule(StylesheetImpl
072:                                                .getDomainSupportServicemoduleName(lDomainName));
073:                                if (lServicemodule == null)
074:                                    return; // There is no support servicemodule yet
075:                                Service lDomainSupportService = lServicemodule
076:                                        .findService(StylesheetImpl
077:                                                .getDataManagementServiceName(lDomainName));
078:                                if (lDomainSupportService == null)
079:                                    return; // There is no domain support service yet
080:                                // Create associated element
081:                                ensurePresent(lDomainSupportService, lEntity,
082:                                        lEntityPluralName);
083:                            }
084:
085:                            public void onElementBeingDeleted(
086:                                    RefObject pModelElementBeingDeleted) {
087:                                Entity lEntity = (Entity) pModelElementBeingDeleted;
088:                                String lEntityPluralName = lEntity
089:                                        .getPluralName();
090:                                if (lEntityPluralName == null)
091:                                    return; // Entity does not have a plural name
092:                                Domain lDomain = lEntity.getDomain();
093:                                if (lDomain == null)
094:                                    return; // Entity is not associated with domain
095:                                String lDomainName = lDomain.getName();
096:                                if (lDomainName == null)
097:                                    return; // Domain does not have a name
098:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
099:                                        .getSystem();
100:                                if (lSystem == null)
101:                                    return; // Domain is not associated with system
102:                                Servicemodule lServicemodule = lSystem
103:                                        .findServicemodule(StylesheetImpl
104:                                                .getDomainSupportServicemoduleName(lDomainName));
105:                                if (lServicemodule == null)
106:                                    return; // There is no support servicemodule yet
107:                                Service lDomainSupportService = lServicemodule
108:                                        .findService(StylesheetImpl
109:                                                .getDataManagementServiceName(lDomainName));
110:                                if (lDomainSupportService == null)
111:                                    return; // There is no domain support service yet
112:                                // Remove associated element
113:                                ensureAbsent(lDomainSupportService,
114:                                        lEntityPluralName);
115:                            }
116:                        });
117:                // Add entity pluralName attribute change listener
118:                mModelAssistantImpl
119:                        .addAttributeChangeListener(
120:                                Entity.class,
121:                                "pluralName",
122:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
123:                                    public void onAttributeBeingUpdated(
124:                                            RefObject pModelElementBeingUpdated,
125:                                            String pAttributeName,
126:                                            Object pOldValue, Object pNewValue) {
127:                                        Entity lEntity = (Entity) pModelElementBeingUpdated;
128:                                        Domain lDomain = lEntity.getDomain();
129:                                        if (lDomain == null)
130:                                            return; // Entity is not associated with domain
131:                                        String lDomainName = lDomain.getName();
132:                                        if (lDomainName == null)
133:                                            return; // Domain does not have a name
134:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
135:                                                .getSystem();
136:                                        if (lSystem == null)
137:                                            return; // Domain is not associated with system
138:                                        Servicemodule lServicemodule = lSystem
139:                                                .findServicemodule(StylesheetImpl
140:                                                        .getDomainSupportServicemoduleName(lDomainName));
141:                                        if (lServicemodule == null)
142:                                            return; // There is no support servicemodule yet
143:                                        Service lDomainSupportService = lServicemodule
144:                                                .findService(StylesheetImpl
145:                                                        .getDataManagementServiceName(lDomainName));
146:                                        if (lDomainSupportService == null)
147:                                            return; // There is no domain support service yet
148:                                        if (pNewValue == null) {
149:                                            // Only old value is known - ensure that the element is deleted
150:                                            ensureAbsent(lDomainSupportService,
151:                                                    (String) pOldValue);
152:                                        } else {
153:                                            // New value is known - rename or create
154:                                            if (pOldValue != null)
155:                                                ensureRenamedPresent(
156:                                                        lDomainSupportService,
157:                                                        lEntity,
158:                                                        (String) pOldValue,
159:                                                        (String) pNewValue);
160:                                            else
161:                                                ensurePresent(
162:                                                        lDomainSupportService,
163:                                                        lEntity,
164:                                                        (String) pNewValue);
165:                                        }
166:                                    }
167:                                });
168:
169:                // Add attribute usedForOrdering attribute change listener
170:                mModelAssistantImpl
171:                        .addAttributeChangeListener(
172:                                Attribute.class,
173:                                "usedForOrdering",
174:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
175:                                    public void onAttributeBeingUpdated(
176:                                            RefObject pModelElementBeingUpdated,
177:                                            String pAttributeName,
178:                                            Object pOldValue, Object pNewValue) {
179:                                        Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
180:                                        String lAttributeName = lAttribute
181:                                                .getName();
182:                                        if (lAttributeName == null)
183:                                            return; // Attribute does not have a name
184:                                        Entity lEntity = lAttribute.getEntity();
185:                                        if (lEntity == null)
186:                                            return; // Attribute is not associated with entity
187:                                        Domain lDomain = lEntity.getDomain();
188:                                        if (lDomain == null)
189:                                            return; // Entity is not associated with domain
190:                                        String lDomainName = lDomain.getName();
191:                                        if (lDomainName == null)
192:                                            return; // Domain does not have a name
193:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
194:                                                .getSystem();
195:                                        if (lSystem == null)
196:                                            return; // Domain is not associated with system
197:                                        Servicemodule lServicemodule = lSystem
198:                                                .findServicemodule(StylesheetImpl
199:                                                        .getDomainSupportServicemoduleName(lDomainName));
200:                                        if (lServicemodule == null)
201:                                            return; // There is no support servicemodule yet
202:                                        Service lDomainSupportService = lServicemodule
203:                                                .findService(StylesheetImpl
204:                                                        .getDataManagementServiceName(lDomainName));
205:                                        if (lDomainSupportService == null)
206:                                            return; // There is no domain support service yet
207:                                        // We need to manage ordering instruction parameter for this entity and all subtypes
208:                                        Set lAllEntitiesToConsider = new HashSet();
209:                                        lAllEntitiesToConsider.add(lEntity);
210:                                        lAllEntitiesToConsider.addAll(lEntity
211:                                                .getCombinedSubtypes());
212:                                        for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
213:                                                .iterator(); lEntityElementsIterator
214:                                                .hasNext();) {
215:                                            Entity lEntityElement = (Entity) lEntityElementsIterator
216:                                                    .next();
217:                                            if (Boolean.TRUE.equals(pNewValue)) {
218:                                                // Attribute is becoming orderable - ensure that the ordering instructuion is present
219:                                                orderingInstruction_EnsurePresent(
220:                                                        lDomainSupportService,
221:                                                        lEntityElement);
222:                                            } else {
223:                                                // If the attribute is becoming unorderable - we need to ensure that the parameter is present or absent 
224:                                                // What to do will depend on whether there are orderable attibutes apart from this one
225:                                                Collection lAllAttributesUsedForOrdering = new ArrayList();
226:                                                lAllAttributesUsedForOrdering
227:                                                        .addAll(lEntityElement
228:                                                                .getCombinedAttributesUsedForOrdering());
229:                                                lAllAttributesUsedForOrdering
230:                                                        .remove(lAttribute);
231:                                                if (!lAllAttributesUsedForOrdering
232:                                                        .isEmpty())
233:                                                    orderingInstruction_EnsurePresent(
234:                                                            lDomainSupportService,
235:                                                            lEntityElement);
236:                                                else
237:                                                    orderingInstruction_EnsureAbsent(
238:                                                            lDomainSupportService,
239:                                                            lEntityElement);
240:                                            }
241:                                        }
242:                                    }
243:                                });
244:            }
245:
246:            private static String sOperationConstraintTextBase = "A Data Management Service must have Get All Entities operation for every Entity in the corresponding Domain.";
247:            private static String sProposedOrderingInstructionsInputFieldConstraintTextBase = "A Get All Entities Data Management Operation must have well formed Ordering Instructions input parameter carrying the instructions on how to order the set of retrieved Entities.";
248:            private static String sRetrievedEntityDetailsOutputFieldConstraintTextBase = "A Get All Entities Data Management Operation must have well formed Entity Details output parameter carrying the details of all retrieved Entities.";
249:
250:            // This helper verifies constraints which are dealing with entity structures
251:            void verifyConstraints(Collection pViolations,
252:                    Service pDataManagementService, Entity pEntity,
253:                    Collection pUnclaimedOperations) {
254:                String lEntityPluralName = pEntity.getPluralName();
255:                if (lEntityPluralName == null)
256:                    return;
257:                // Work on the Key structure
258:                String lOperationName = suggestOperationName(lEntityPluralName);
259:                Operation lOperation = pDataManagementService
260:                        .findOperation(lOperationName);
261:                if (lOperation == null) {
262:                    pViolations
263:                            .add(new ConstraintViolationException(
264:                                    pDataManagementService,
265:                                    pDataManagementService.refMetaObject(),
266:                                    sOperationConstraintTextBase + " The '"
267:                                            + lOperationName
268:                                            + "' Operation not found."));
269:                    return;
270:                }
271:                pUnclaimedOperations.remove(lOperation); // Claim the operation
272:                // Validate operation details
273:                if (!TransactionPolicyEnum.SUPPORTED.equals(lOperation
274:                        .getTransactionPolicy()))
275:                    pViolations.add(new ConstraintViolationException(
276:                            lOperation, lOperation.refMetaObject(),
277:                            "A Query Data Management Operation must have transaction policy '"
278:                                    + TransactionPolicyEnum.SUPPORTED
279:                                            .toString() + "'. The '"
280:                                    + lOperation.getTransactionPolicy()
281:                                    + "' Transaction policy is unexpected."));
282:                if (!lOperation.isQuery())
283:                    pViolations
284:                            .add(new ConstraintViolationException(
285:                                    lOperation,
286:                                    lOperation.refMetaObject(),
287:                                    "A Query Data Management Operation must have the isQuery attribute set to true."));
288:                // Input Fields
289:                {
290:                    // Only has an ordering instructions input field if entity can be ordered
291:                    if (!pEntity.getCombinedAttributesUsedForOrdering()
292:                            .isEmpty()) {
293:                        String lOperationInputFieldName = suggestInputOrderingInstructionParameterName(lEntityPluralName);
294:                        OperationInputField lInputField = lOperation
295:                                .findInputField(lOperationInputFieldName);
296:                        if (lInputField != null) {
297:                            DataType lOrderingInstructionsDataType = pEntity
298:                                    .getOrderingInstructionDataType();
299:                            if (lOrderingInstructionsDataType != null
300:                                    && lOrderingInstructionsDataType
301:                                            .equals(lInputField.getDataType()) == false)
302:                                pViolations
303:                                        .add(new ConstraintViolationException(
304:                                                lInputField,
305:                                                lInputField.refMetaObject(),
306:                                                sProposedOrderingInstructionsInputFieldConstraintTextBase
307:                                                        + " The '"
308:                                                        + lOperationInputFieldName
309:                                                        + "' input field has wrong type."));
310:                            if (!lInputField.isArray())
311:                                pViolations
312:                                        .add(new ConstraintViolationException(
313:                                                lInputField,
314:                                                lInputField.refMetaObject(),
315:                                                sProposedOrderingInstructionsInputFieldConstraintTextBase
316:                                                        + " The '"
317:                                                        + lOperationInputFieldName
318:                                                        + "' input field is not an array, which is wrong."));
319:                        } else
320:                            pViolations.add(new ConstraintViolationException(
321:                                    lOperation, lOperation.refMetaObject(),
322:                                    sProposedOrderingInstructionsInputFieldConstraintTextBase
323:                                            + " The '"
324:                                            + lOperationInputFieldName
325:                                            + "' input field is missing."));
326:                    }
327:                }
328:                // Output Fields - only verify that the ones that we need exist. The extra ones are allowed
329:                {
330:                    String lOperationOutputFieldName = suggestEntitiesReturnParameterName(lEntityPluralName);
331:                    OperationOutputField lOutputField = lOperation
332:                            .findOutputField(lOperationOutputFieldName);
333:                    if (lOutputField != null) {
334:                        String lEntityName = pEntity.getName();
335:                        if (lEntityName != null) {
336:                            Structure lEntityDetailsStructure = pDataManagementService
337:                                    .getServicemodule() != null ? pDataManagementService
338:                                    .getServicemodule()
339:                                    .findStructure(
340:                                            StylesheetImpl
341:                                                    .getEntityDetailsStructureName(lEntityName))
342:                                    : null;
343:                            if (lEntityDetailsStructure != null
344:                                    && lEntityDetailsStructure
345:                                            .equals(lOutputField
346:                                                    .getStructureType()) == false)
347:                                pViolations
348:                                        .add(new ConstraintViolationException(
349:                                                lOutputField,
350:                                                lOutputField.refMetaObject(),
351:                                                sRetrievedEntityDetailsOutputFieldConstraintTextBase
352:                                                        + " The '"
353:                                                        + lOperationOutputFieldName
354:                                                        + "' output field has wrong type."));
355:                        }
356:                        if (!lOutputField.isArray())
357:                            pViolations
358:                                    .add(new ConstraintViolationException(
359:                                            lOutputField,
360:                                            lOutputField.refMetaObject(),
361:                                            sRetrievedEntityDetailsOutputFieldConstraintTextBase
362:                                                    + " The '"
363:                                                    + lOperationOutputFieldName
364:                                                    + "' output field is not an array, which is wrong."));
365:                    } else
366:                        pViolations.add(new ConstraintViolationException(
367:                                lOperation, lOperation.refMetaObject(),
368:                                sRetrievedEntityDetailsOutputFieldConstraintTextBase
369:                                        + " The '" + lOperationOutputFieldName
370:                                        + "' output field is missing."));
371:                }
372:                // Output Messages - only verify that the ones that we need exist. The extra ones are allowed
373:                {
374:                    // No output messsages
375:                }
376:            }
377:
378:            // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
379:            void rectifyModel(Service pDataManagementService, Entity pEntity,
380:                    Collection pUnclaimedOperations) {
381:                // Check if we have an operation and than just call ensurePresent
382:                String lEntityPluralName = pEntity.getPluralName();
383:                String lOperationName = suggestOperationName(lEntityPluralName);
384:                Operation lOperation = pDataManagementService
385:                        .findOperation(lOperationName);
386:                if (lOperation != null)
387:                    pUnclaimedOperations.remove(lOperation); // Claim the operation    				
388:                // Now just call ensurePresent
389:                ensurePresent(pDataManagementService, pEntity,
390:                        lEntityPluralName);
391:            }
392:
393:            // This helper renames the key and details structures
394:            void ensureRenamedPresent(Service pDataManagementService,
395:                    Entity pEntity, String pOldEntityPluralName,
396:                    String pNewEntityPluralName) {
397:                // Note that this method only deals with renaming and than calls the ensure present method  
398:                String lOldOperationName = suggestOperationName(pOldEntityPluralName);
399:                Operation lOldOperation = pDataManagementService
400:                        .findOperation(lOldOperationName);
401:                String lNewOperationName = suggestOperationName(pNewEntityPluralName);
402:                Operation lNewOperation = pDataManagementService
403:                        .findOperation(lNewOperationName);
404:                // Be relaxed here - allow for all sorts of mishaps
405:                if (lOldOperation != null) {
406:                    if (lNewOperation != null) {
407:                        // New and old structures are present - just delete the old one
408:                        lOldOperation.refDelete();
409:                    } else {
410:                        // Old structure is present - new one is not - rename
411:                        lOldOperation.setName(lNewOperationName);
412:                    }
413:                }
414:                // Call the ensure present bit
415:                ensurePresent(pDataManagementService, pEntity,
416:                        pNewEntityPluralName);
417:            }
418:
419:            // This helper makes sure that the version id attribute is present in the details structure
420:            void ensurePresent(Service pDataManagementService, Entity pEntity,
421:                    String pEntityPluralName) {
422:                // Work on the servicemodule
423:                String lOperationName = suggestOperationName(pEntityPluralName);
424:                Operation lOperation = pDataManagementService
425:                        .findOperation(lOperationName);
426:                if (lOperation == null) {
427:                    lOperation = mModelAssistantImpl.mOperationClass
428:                            .createOperation();
429:                    lOperation.setService(pDataManagementService);
430:                    lOperation.setName(lOperationName);
431:                }
432:                lOperation
433:                        .setDescription(suggestOperationDescription(pEntityPluralName));
434:                lOperation
435:                        .setTransactionPolicy(TransactionPolicyEnum.SUPPORTED);
436:                lOperation.setQuery(true);
437:
438:                // Input Fields
439:                {
440:                    Collection lOperationInputFields = lOperation
441:                            .getInputFields();
442:                    List lUnprocessedInputFields = new ArrayList();
443:                    lUnprocessedInputFields.addAll(lOperationInputFields);
444:
445:                    // Only has an ordering instructions input field if entity can be ordered
446:                    if (!pEntity.getCombinedAttributesUsedForOrdering()
447:                            .isEmpty()) {
448:                        String lOperationInputFieldName = suggestInputOrderingInstructionParameterName(pEntityPluralName);
449:                        OperationInputField lInputField = lOperation
450:                                .findInputField(lOperationInputFieldName);
451:                        if (lInputField == null) {
452:                            lInputField = mModelAssistantImpl.mOperationInputFieldClass
453:                                    .createOperationInputField();
454:                            lInputField.setName(lOperationInputFieldName);
455:                            lInputField.setOperation(lOperation);
456:                        } else {
457:                            lUnprocessedInputFields.remove(lInputField);
458:                        }
459:                        lInputField
460:                                .setDescription(suggestInputOrderingInstructionParameterDescription(pEntityPluralName));
461:                        lInputField.setArray(true);
462:                        lInputField.setDataType(pEntity
463:                                .getOrderingInstructionDataType());
464:                        lInputField.setStructureType(null);
465:                    }
466:
467:                    // Delete all input fields left
468:                    for (Iterator lUnprocessedInputFieldsIterator = lUnprocessedInputFields
469:                            .iterator(); lUnprocessedInputFieldsIterator
470:                            .hasNext();) {
471:                        OperationInputField lInputField = (OperationInputField) lUnprocessedInputFieldsIterator
472:                                .next();
473:                        if (!lInputField.isDerived())
474:                            lInputField.refDelete();
475:                    }
476:                }
477:                // Input constraints
478:                {
479:                    // Copy aside the collection of the constraints, so we can delete the unused ones
480:                    Collection lUnclaimedConstraints = new ArrayList();
481:                    lUnclaimedConstraints.addAll(lOperation
482:                            .getInputConstraints());
483:                    // Remove unclaimed constraints
484:                    for (Iterator lUnclaimedConstraintsIterator = lUnclaimedConstraints
485:                            .iterator(); lUnclaimedConstraintsIterator
486:                            .hasNext();) {
487:                        ModelElementConstraint lUnclaimedConstraint = (ModelElementConstraint) lUnclaimedConstraintsIterator
488:                                .next();
489:                        if (!lUnclaimedConstraint.isDerived())
490:                            lUnclaimedConstraint.refDelete();
491:                    }
492:                }
493:                // Output Fields
494:                {
495:                    Collection lOperationOutputFields = lOperation
496:                            .getOutputFields();
497:                    List lUnprocessedOutputFields = new ArrayList();
498:                    lUnprocessedOutputFields.addAll(lOperationOutputFields);
499:                    {
500:                        String lOperationOutputFieldName = suggestEntitiesReturnParameterName(pEntityPluralName);
501:                        OperationOutputField lOutputField = lOperation
502:                                .findOutputField(lOperationOutputFieldName);
503:                        if (lOutputField == null) {
504:                            lOutputField = mModelAssistantImpl.mOperationOutputFieldClass
505:                                    .createOperationOutputField();
506:                            lOutputField.setName(lOperationOutputFieldName);
507:                            lOperationOutputFields.add(lOutputField);
508:                        } else {
509:                            lUnprocessedOutputFields.remove(lOutputField);
510:                        }
511:                        lOutputField
512:                                .setDescription(suggestEntitiesReturnParameterDescription(pEntityPluralName));
513:                        lOutputField.setArray(true);
514:                        lOutputField.setDataType(null);
515:                        Structure lEntityDetailsStructure = pDataManagementService
516:                                .getServicemodule() != null ? pDataManagementService
517:                                .getServicemodule()
518:                                .findStructure(
519:                                        StylesheetImpl
520:                                                .getEntityDetailsStructureName(pEntity
521:                                                        .getName()))
522:                                : null;
523:                        lOutputField.setStructureType(lEntityDetailsStructure);
524:                    }
525:                    // Delete all output fields left
526:                    for (Iterator lUnprocessedOutputFieldsIterator = lUnprocessedOutputFields
527:                            .iterator(); lUnprocessedOutputFieldsIterator
528:                            .hasNext();) {
529:                        OperationOutputField lOutputField = (OperationOutputField) lUnprocessedOutputFieldsIterator
530:                                .next();
531:                        if (!lOutputField.isDerived())
532:                            lOutputField.refDelete();
533:                    }
534:                }
535:                // Output Messages
536:                {
537:                    Collection lOperationOutputMessages = lOperation
538:                            .getOutputMessages();
539:                    List lUnprocessedOutputMessages = new ArrayList();
540:                    lUnprocessedOutputMessages.addAll(lOperationOutputMessages);
541:
542:                    // No output messsages
543:
544:                    // Delete all output messages left
545:                    for (Iterator lUnprocessedOutputMessagesIterator = lUnprocessedOutputMessages
546:                            .iterator(); lUnprocessedOutputMessagesIterator
547:                            .hasNext();) {
548:                        OperationOutputMessage lOutputMessage = (OperationOutputMessage) lUnprocessedOutputMessagesIterator
549:                                .next();
550:                        if (!lOutputMessage.isDerived())
551:                            lOutputMessage.refDelete();
552:                    }
553:                }
554:            }
555:
556:            // This helper makes sure that the version id attribute is absent in the details structure
557:            void ensureAbsent(Service pDataManagementService,
558:                    String pEntityPluralName) {
559:                // Work on the details structure
560:                Operation lOperation = pDataManagementService
561:                        .findOperation(suggestOperationName(pEntityPluralName));
562:                if (lOperation != null)
563:                    lOperation.refDelete();
564:            }
565:
566:            // This helper makes sure that the version id attribute is present in the details structure
567:            void orderingInstruction_EnsurePresent(
568:                    Service pDataManagementService, Entity pEntity) {
569:                String lEntityPluralName = pEntity.getPluralName();
570:                if (lEntityPluralName == null)
571:                    return; // No plural name yet
572:                // Work on the details structure
573:                Operation lOperation = pDataManagementService
574:                        .findOperation(suggestOperationName(lEntityPluralName));
575:                if (lOperation == null)
576:                    return; // No operation yet
577:                String lOperationInputFieldName = suggestInputOrderingInstructionParameterName(lEntityPluralName);
578:                OperationInputField lInputField = lOperation
579:                        .findInputField(lOperationInputFieldName);
580:                if (lInputField == null) {
581:                    lInputField = mModelAssistantImpl.mOperationInputFieldClass
582:                            .createOperationInputField();
583:                    lInputField.setName(lOperationInputFieldName);
584:                    lInputField.setOperation(lOperation);
585:                }
586:                lInputField
587:                        .setDescription(suggestInputOrderingInstructionParameterDescription(lEntityPluralName));
588:                lInputField.setArray(true);
589:                lInputField.setDataType(pEntity
590:                        .getOrderingInstructionDataType());
591:                lInputField.setStructureType(null);
592:            }
593:
594:            // This helper makes sure that the version id attribute is absent in the details structure
595:            void orderingInstruction_EnsureAbsent(
596:                    Service pDataManagementService, Entity pEntity) {
597:                String lEntityPluralName = pEntity.getPluralName();
598:                if (lEntityPluralName == null)
599:                    return; // No plural name yet
600:                // Work on the details structure
601:                Operation lOperation = pDataManagementService
602:                        .findOperation(suggestOperationName(lEntityPluralName));
603:                if (lOperation == null)
604:                    return; // No operation yet
605:                String lOperationInputFieldName = suggestInputOrderingInstructionParameterName(lEntityPluralName);
606:                OperationInputField lInputField = lOperation
607:                        .findInputField(lOperationInputFieldName);
608:                if (lInputField != null)
609:                    lInputField.refDelete();
610:            }
611:
612:            // Helper. Returns the message name	
613:            private static String suggestOperationName(String pEntityPluralName) {
614:                // Use normalised name here
615:                return "getAll"
616:                        + StringUtils.suggestName(pEntityPluralName, true,
617:                                false);
618:            }
619:
620:            // Helper. Returns the message description	
621:            private static String suggestOperationDescription(
622:                    String pEntityPluralName) {
623:                // Use name 'as is' here
624:                return "Retrieves details of all " + pEntityPluralName
625:                        + " present in the domain.";
626:            }
627:
628:            // Helper. Returns the message name	
629:            private static String suggestInputOrderingInstructionParameterName(
630:                    String pEntityPluralName) {
631:                // Use normalised name here
632:                return "OrderingInstructions";
633:            }
634:
635:            // Helper. Returns the message description	
636:            private static String suggestInputOrderingInstructionParameterDescription(
637:                    String pEntityPluralName) {
638:                // Use name 'as is' here
639:                return "Array of zero or more ordering instructions (weight of the instruction is diminising towards the end of the array). Returned "
640:                        + pEntityPluralName
641:                        + " will be sorted in accordance with these instructions.";
642:            }
643:
644:            // Helper. Returns the message name	
645:            private static String suggestEntitiesReturnParameterName(
646:                    String pEntityPluralName) {
647:                // Use normalised name here
648:                return StringUtils.suggestName(pEntityPluralName, true, false);
649:            }
650:
651:            // Helper. Returns the message description	
652:            private static String suggestEntitiesReturnParameterDescription(
653:                    String pEntityPluralName) {
654:                // Use name 'as is' here
655:                return "Details of all " + pEntityPluralName
656:                        + " found in the domain.";
657:            }
658:        }
w_ww_.j_a___v___a_2_s___.___c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.