Source Code Cross Referenced for TargetDeleteEntityOperationHelper.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.Structure;
029:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
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.Domain;
038:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
039:        import com.metaboss.util.StringUtils;
040:
041:        /** This class containse helper methods dealing with the Domain Support Servicemodule model element  */
042:        class TargetDeleteEntityOperationHelper {
043:            private ModelAssistantImpl mModelAssistantImpl;
044:
045:            TargetDeleteEntityOperationHelper(
046:                    ModelAssistantImpl pModelAssistantImpl) {
047:                mModelAssistantImpl = pModelAssistantImpl;
048:
049:                // Add entity lifecycle listener
050:                mModelAssistantImpl.addLifecycleListener(Entity.class,
051:                        new ModelAssistantImpl.ModelElementLifecycleListener() {
052:                            public void onElementJustCreated(
053:                                    RefObject pModelElementJustCreated) {
054:                                Entity lEntity = (Entity) pModelElementJustCreated;
055:                                String lEntityName = lEntity.getName();
056:                                if (lEntityName == null)
057:                                    return; // Domain does not have a name
058:                                Domain lDomain = lEntity.getDomain();
059:                                if (lDomain == null)
060:                                    return; // Entity is not associated with domain
061:                                String lDomainName = lDomain.getName();
062:                                if (lDomainName == null)
063:                                    return; // Domain does not have a name
064:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
065:                                        .getSystem();
066:                                if (lSystem == null)
067:                                    return; // Domain is not associated with system
068:                                Servicemodule lServicemodule = lSystem
069:                                        .findServicemodule(StylesheetImpl
070:                                                .getDomainSupportServicemoduleName(lDomainName));
071:                                if (lServicemodule == null)
072:                                    return; // There is no support servicemodule yet
073:                                Service lDomainSupportService = lServicemodule
074:                                        .findService(StylesheetImpl
075:                                                .getDataManagementServiceName(lDomainName));
076:                                if (lDomainSupportService == null)
077:                                    return; // There is no domain support service yet
078:                                // Create associated element
079:                                ensurePresent(lDomainSupportService, lEntity,
080:                                        lEntityName);
081:                            }
082:
083:                            public void onElementBeingDeleted(
084:                                    RefObject pModelElementBeingDeleted) {
085:                                Entity lEntity = (Entity) pModelElementBeingDeleted;
086:                                String lEntityName = lEntity.getName();
087:                                if (lEntityName == null)
088:                                    return; // Domain does not have a name
089:                                Domain lDomain = lEntity.getDomain();
090:                                if (lDomain == null)
091:                                    return; // Entity is not associated with domain
092:                                String lDomainName = lDomain.getName();
093:                                if (lDomainName == null)
094:                                    return; // Domain does not have a name
095:                                com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
096:                                        .getSystem();
097:                                if (lSystem == null)
098:                                    return; // Domain is not associated with system
099:                                Servicemodule lServicemodule = lSystem
100:                                        .findServicemodule(StylesheetImpl
101:                                                .getDomainSupportServicemoduleName(lDomainName));
102:                                if (lServicemodule == null)
103:                                    return; // There is no support servicemodule yet
104:                                Service lDomainSupportService = lServicemodule
105:                                        .findService(StylesheetImpl
106:                                                .getDataManagementServiceName(lDomainName));
107:                                if (lDomainSupportService == null)
108:                                    return; // There is no domain support service yet
109:                                // Remove associated element always
110:                                ensureAbsent(lDomainSupportService, lEntityName);
111:                            }
112:                        });
113:
114:                // Add entity Name attribute change listener
115:                mModelAssistantImpl
116:                        .addAttributeChangeListener(
117:                                Entity.class,
118:                                "Name",
119:                                new ModelAssistantImpl.ModelElementAttributeChangeListener() {
120:                                    public void onAttributeBeingUpdated(
121:                                            RefObject pModelElementBeingUpdated,
122:                                            String pAttributeName,
123:                                            Object pOldValue, Object pNewValue) {
124:                                        Entity lEntity = (Entity) pModelElementBeingUpdated;
125:                                        Domain lDomain = lEntity.getDomain();
126:                                        if (lDomain == null)
127:                                            return; // Entity is not associated with domain
128:                                        String lDomainName = lDomain.getName();
129:                                        if (lDomainName == null)
130:                                            return; // Domain does not have a name
131:                                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
132:                                                .getSystem();
133:                                        if (lSystem == null)
134:                                            return; // Domain is not associated with system
135:                                        Servicemodule lServicemodule = lSystem
136:                                                .findServicemodule(StylesheetImpl
137:                                                        .getDomainSupportServicemoduleName(lDomainName));
138:                                        if (lServicemodule == null)
139:                                            return; // There is no support servicemodule yet
140:                                        Service lDomainSupportService = lServicemodule
141:                                                .findService(StylesheetImpl
142:                                                        .getDataManagementServiceName(lDomainName));
143:                                        if (lDomainSupportService == null)
144:                                            return; // There is no domain support service yet
145:                                        if (pNewValue == null) {
146:                                            // Only old value is known - ensure that the element is deleted
147:                                            ensureAbsent(lDomainSupportService,
148:                                                    (String) pOldValue);
149:                                        } else {
150:                                            // The element must be present - rename or create
151:                                            if (pOldValue != null)
152:                                                ensureRenamedPresent(
153:                                                        lDomainSupportService,
154:                                                        lEntity,
155:                                                        (String) pOldValue,
156:                                                        (String) pNewValue);
157:                                            else
158:                                                ensurePresent(
159:                                                        lDomainSupportService,
160:                                                        lEntity,
161:                                                        (String) pNewValue);
162:                                        }
163:                                    }
164:                                });
165:            }
166:
167:            private static final String sOperationConstraintTextBase = "A Data Management Service must have Delete Entity operation for every Entity in the Domain.";
168:            private static final String sProposedInstancKeyInputFieldConstraintTextBase = "A Delete Entity Data Management Operation must have well formed Entity Key input parameter carrying identification information for the Entity to be deleted.";
169:            private static final String sEntityNotFoundErrorOutputMessageConstraintTextBase = "A Delete Entity Data Management Operation must have well formed Entity Not Found output message, one for each reference, which is a part of the primary key.";
170:            private static final String sOperationInputConstraintTextBase = "A Delete Entity Data Management Operation must have well formed Input Constraints performing sanity check on the input data.";
171:
172:            // This helper verifies constraints
173:            void verifyConstraints(Collection pViolations,
174:                    Service pDataManagementService, Entity pEntity,
175:                    Collection pUnclaimedOperations) {
176:                String lEntityName = pEntity.getName();
177:                if (lEntityName == null)
178:                    return;
179:                // Work on the Key structure
180:                String lOperationName = suggestOperationName(lEntityName);
181:                Operation lOperation = pDataManagementService
182:                        .findOperation(lOperationName);
183:                if (lOperation == null) {
184:                    pViolations
185:                            .add(new ConstraintViolationException(
186:                                    pDataManagementService,
187:                                    pDataManagementService.refMetaObject(),
188:                                    sOperationConstraintTextBase + " The '"
189:                                            + lOperationName
190:                                            + "' Operation not found."));
191:                    return;
192:                }
193:                pUnclaimedOperations.remove(lOperation); // Claim the operation
194:                // Validate operation details
195:                if (!TransactionPolicyEnum.REQUIRED.equals(lOperation
196:                        .getTransactionPolicy()))
197:                    pViolations.add(new ConstraintViolationException(
198:                            lOperation, lOperation.refMetaObject(),
199:                            "Delete Entity Operation must have transaction policy '"
200:                                    + TransactionPolicyEnum.REQUIRED.toString()
201:                                    + "'. The '"
202:                                    + lOperation.getTransactionPolicy()
203:                                    + "' Transaction policy is unexpected."));
204:                if (lOperation.isQuery())
205:                    pViolations
206:                            .add(new ConstraintViolationException(lOperation,
207:                                    lOperation.refMetaObject(),
208:                                    "Delete Entity Operation must have the isQuery attribute set to false."));
209:                // Input Fields - only verify that the ones that we need exist. The extra ones are allowed
210:                {
211:                    String lOperationInputFieldName = StylesheetImpl
212:                            .getEntityKeyOperationInputParameterName(lEntityName);
213:                    OperationInputField lInputField = lOperation
214:                            .findInputField(lOperationInputFieldName);
215:                    if (lInputField != null) {
216:                        Structure lEntityKeyStructure = pDataManagementService
217:                                .getServicemodule() != null ? pDataManagementService
218:                                .getServicemodule()
219:                                .findStructure(
220:                                        StylesheetImpl
221:                                                .getEntityKeyStructureName(lEntityName))
222:                                : null;
223:                        if (lEntityKeyStructure != null
224:                                && lEntityKeyStructure.equals(lInputField
225:                                        .getStructureType()) == false)
226:                            pViolations.add(new ConstraintViolationException(
227:                                    lInputField, lInputField.refMetaObject(),
228:                                    sProposedInstancKeyInputFieldConstraintTextBase
229:                                            + " The '"
230:                                            + lOperationInputFieldName
231:                                            + "' input field has wrong type."));
232:                        if (lInputField.isArray())
233:                            pViolations
234:                                    .add(new ConstraintViolationException(
235:                                            lInputField,
236:                                            lInputField.refMetaObject(),
237:                                            sProposedInstancKeyInputFieldConstraintTextBase
238:                                                    + " The '"
239:                                                    + lOperationInputFieldName
240:                                                    + "' input field is an array, which is wrong."));
241:                    } else
242:                        pViolations.add(new ConstraintViolationException(
243:                                lOperation, lOperation.refMetaObject(),
244:                                sProposedInstancKeyInputFieldConstraintTextBase
245:                                        + " The '" + lOperationInputFieldName
246:                                        + "' input field is missing."));
247:                }
248:                // Input constraints - only verify that the ones that we need exist. The extra ones are allowed
249:                {
250:                    // Work on the entity key validation constraint.
251:                    {
252:                        String lEntityKeyInputFieldName = StylesheetImpl
253:                                .getEntityKeyOperationInputParameterName(lEntityName);
254:                        String lConstraintName = lEntityKeyInputFieldName
255:                                + "FieldPresenceConstraint";
256:                        ModelElementConstraint lModelElementConstraint = lOperation
257:                                .findInputConstraint(lConstraintName);
258:                        if (lModelElementConstraint == null)
259:                            pViolations
260:                                    .add(new ConstraintViolationException(
261:                                            lOperation,
262:                                            lOperation.refMetaObject(),
263:                                            sOperationInputConstraintTextBase
264:                                                    + " The '"
265:                                                    + lConstraintName
266:                                                    + "' Input Constraint is missing."));
267:                    }
268:                }
269:                // Output Fields - only verify that the ones that we need exist. The extra ones are allowed
270:                {
271:                    // No output fields here
272:                }
273:                // Output Messages
274:                {
275:                    // When instance is being loaded (gets and delete operations) instance not found message can be returned for this entity instance
276:                    // and all primary key associations entities (definitely will have at least our own)
277:                    Set lEntitiesWhichMayBeNotFoundWhenLoadingInstance = new HashSet();
278:                    lEntitiesWhichMayBeNotFoundWhenLoadingInstance.add(pEntity);
279:                    Util.collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
280:                            pEntity,
281:                            lEntitiesWhichMayBeNotFoundWhenLoadingInstance);
282:                    for (Iterator lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenLoadingInstance
283:                            .iterator(); lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
284:                            .hasNext();) {
285:                        Entity lEntityElement = (Entity) lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
286:                                .next();
287:                        // We need to use entity name parameter for the entity which is passed as a parameter.
288:                        String lEntityElementName = lEntityElement
289:                                .equals(pEntity) ? lEntityName : lEntityElement
290:                                .getName();
291:                        if (lEntityElementName == null)
292:                            continue;
293:                        String lOperationOutputMessageName = StylesheetImpl
294:                                .getEntityNotFoundOperationOutputMessageName(lEntityElementName);
295:                        OperationOutputMessage lOutputMessage = lOperation
296:                                .findOutputMessage(lOperationOutputMessageName);
297:                        if (lOutputMessage != null) {
298:                            Message lEntityNotFoundMessage = pDataManagementService
299:                                    .getServicemodule() != null ? pDataManagementService
300:                                    .getServicemodule()
301:                                    .findMessage(
302:                                            StylesheetImpl
303:                                                    .getEntityInstanceNotFoundMessageName(lEntityElementName))
304:                                    : null;
305:                            if (lEntityNotFoundMessage != null
306:                                    && lEntityNotFoundMessage
307:                                            .equals(lOutputMessage
308:                                                    .getMessageType()) == false)
309:                                pViolations
310:                                        .add(new ConstraintViolationException(
311:                                                lOutputMessage,
312:                                                lOutputMessage.refMetaObject(),
313:                                                sEntityNotFoundErrorOutputMessageConstraintTextBase
314:                                                        + " The '"
315:                                                        + lOperationOutputMessageName
316:                                                        + "' output message has wrong type."));
317:                            if (lOutputMessage.isArray())
318:                                pViolations
319:                                        .add(new ConstraintViolationException(
320:                                                lOutputMessage,
321:                                                lOutputMessage.refMetaObject(),
322:                                                sEntityNotFoundErrorOutputMessageConstraintTextBase
323:                                                        + " The '"
324:                                                        + lOperationOutputMessageName
325:                                                        + "' output message is an array, which is wrong."));
326:                        } else
327:                            pViolations.add(new ConstraintViolationException(
328:                                    lOperation, lOperation.refMetaObject(),
329:                                    sEntityNotFoundErrorOutputMessageConstraintTextBase
330:                                            + " The '"
331:                                            + lOperationOutputMessageName
332:                                            + "' output message is missing."));
333:                    }
334:                }
335:            }
336:
337:            // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
338:            void rectifyModel(Service pDataManagementService, Entity pEntity,
339:                    Collection pUnclaimedOperations) {
340:                // Check if we have an operation and than just call ensurePresent
341:                String lEntityName = pEntity.getName();
342:                String lOperationName = suggestOperationName(lEntityName);
343:                Operation lOperation = pDataManagementService
344:                        .findOperation(lOperationName);
345:                if (lOperation != null)
346:                    pUnclaimedOperations.remove(lOperation); // Claim the operation    				
347:                // Now just call ensurePresent
348:                ensurePresent(pDataManagementService, pEntity, lEntityName);
349:            }
350:
351:            // This helper renames and ensures that the element is present
352:            void ensureRenamedPresent(Service pDataManagementService,
353:                    Entity pEntity, String pOldEntityName, String pNewEntityName) {
354:                // Note that this method only deals with renaming and than calls the ensure present method  
355:                String lOldOperationName = suggestOperationName(pOldEntityName);
356:                Operation lOldOperation = pDataManagementService
357:                        .findOperation(lOldOperationName);
358:                String lNewOperationName = suggestOperationName(pNewEntityName);
359:                Operation lNewOperation = pDataManagementService
360:                        .findOperation(lNewOperationName);
361:                // Be relaxed here - allow for all sorts of mishaps
362:                if (lOldOperation != null) {
363:                    if (lNewOperation != null) {
364:                        // New and old structures are present - just delete the old one
365:                        lOldOperation.refDelete();
366:                    } else {
367:                        // Old structure is present - new one is not - rename
368:                        lOldOperation.setName(lNewOperationName);
369:                    }
370:                }
371:                // Call the ensure present bit
372:                ensurePresent(pDataManagementService, pEntity, pNewEntityName);
373:            }
374:
375:            // This helper makes sure that the version id attribute is present in the details structure
376:            void ensurePresent(Service pDataManagementService, Entity pEntity,
377:                    String pEntityName) {
378:                // Work on the servicemodule
379:                String lOperationName = suggestOperationName(pEntityName);
380:                Operation lOperation = pDataManagementService
381:                        .findOperation(lOperationName);
382:                if (lOperation == null) {
383:                    lOperation = mModelAssistantImpl.mOperationClass
384:                            .createOperation();
385:                    lOperation.setService(pDataManagementService);
386:                    lOperation.setName(lOperationName);
387:                }
388:                lOperation
389:                        .setDescription(suggestOperationDescription(pEntityName));
390:                lOperation.setTransactionPolicy(TransactionPolicyEnum.REQUIRED);
391:                lOperation.setQuery(false);
392:                // Input Fields
393:                {
394:                    Collection lOperationInputFields = lOperation
395:                            .getInputFields();
396:                    List lUnprocessedInputFields = new ArrayList();
397:                    lUnprocessedInputFields.addAll(lOperationInputFields);
398:                    {
399:                        String lOperationInputFieldName = StylesheetImpl
400:                                .getEntityKeyOperationInputParameterName(pEntityName);
401:                        OperationInputField lInputField = lOperation
402:                                .findInputField(lOperationInputFieldName);
403:                        if (lInputField == null) {
404:                            lInputField = mModelAssistantImpl.mOperationInputFieldClass
405:                                    .createOperationInputField();
406:                            lInputField.setName(lOperationInputFieldName);
407:                            lInputField.setOperation(lOperation);
408:                        } else {
409:                            lUnprocessedInputFields.remove(lInputField);
410:                        }
411:                        lInputField
412:                                .setDescription(suggestUniqueKeyInputParameterDescription(pEntityName));
413:                        lInputField.setArray(false);
414:                        lInputField.setDataType(null);
415:                        Structure lEntityKeyStructure = pDataManagementService
416:                                .getServicemodule() != null ? pDataManagementService
417:                                .getServicemodule()
418:                                .findStructure(
419:                                        StylesheetImpl
420:                                                .getEntityKeyStructureName(pEntityName))
421:                                : null;
422:                        lInputField.setStructureType(lEntityKeyStructure);
423:                    }
424:                    // Delete all input fields left
425:                    for (Iterator lUnprocessedInputFieldsIterator = lUnprocessedInputFields
426:                            .iterator(); lUnprocessedInputFieldsIterator
427:                            .hasNext();) {
428:                        OperationInputField lInputField = (OperationInputField) lUnprocessedInputFieldsIterator
429:                                .next();
430:                        if (!lInputField.isDerived())
431:                            lInputField.refDelete();
432:                    }
433:                }
434:                // Input constraints
435:                {
436:                    // Copy aside the collection of the constraints, so we can delete the unused ones
437:                    Collection lUnclaimedConstraints = new ArrayList();
438:                    lUnclaimedConstraints.addAll(lOperation
439:                            .getInputConstraints());
440:                    // Work on the entity key validation constraint.
441:                    {
442:                        String lEntityKeyInputFieldName = StylesheetImpl
443:                                .getEntityKeyOperationInputParameterName(pEntityName);
444:                        String lEntityKeyOCLFieldName = lEntityKeyInputFieldName
445:                                .substring(0, 1).toLowerCase()
446:                                + lEntityKeyInputFieldName.substring(1);
447:                        String lConstraintName = lEntityKeyInputFieldName
448:                                + "FieldPresenceConstraint";
449:                        ModelElementConstraint lModelElementConstraint = lOperation
450:                                .findInputConstraint(lConstraintName);
451:                        if (lModelElementConstraint == null) {
452:                            lModelElementConstraint = mModelAssistantImpl.mModelElementConstraintClass
453:                                    .createModelElementConstraint();
454:                            lModelElementConstraint.setName(lConstraintName);
455:                            lOperation.getInputConstraints().add(
456:                                    lModelElementConstraint);
457:                        } else {
458:                            // Claim the field
459:                            lUnclaimedConstraints
460:                                    .remove(lModelElementConstraint);
461:                        }
462:                        lModelElementConstraint
463:                                .setDescription("Verifies that the "
464:                                        + lEntityKeyInputFieldName
465:                                        + " input field is not empty in the operation input");
466:                        lModelElementConstraint.setDefaultErrorText("The '"
467:                                + lEntityKeyInputFieldName
468:                                + "' input field must not be empty.");
469:                        lModelElementConstraint.setOclExpression("not "
470:                                + lEntityKeyOCLFieldName + ".oclIsUndefined()");
471:                    }
472:                    // Remove unclaimed constraints
473:                    for (Iterator lUnclaimedConstraintsIterator = lUnclaimedConstraints
474:                            .iterator(); lUnclaimedConstraintsIterator
475:                            .hasNext();) {
476:                        ModelElementConstraint lUnclaimedConstraint = (ModelElementConstraint) lUnclaimedConstraintsIterator
477:                                .next();
478:                        if (!lUnclaimedConstraint.isDerived())
479:                            lUnclaimedConstraint.refDelete();
480:                    }
481:                }
482:                // Output Fields
483:                {
484:                    Collection lOperationOutputFields = lOperation
485:                            .getOutputFields();
486:                    List lUnprocessedOutputFields = new ArrayList();
487:                    lUnprocessedOutputFields.addAll(lOperationOutputFields);
488:
489:                    // No output fields here
490:
491:                    // Delete all output fields left
492:                    for (Iterator lUnprocessedOutputFieldsIterator = lUnprocessedOutputFields
493:                            .iterator(); lUnprocessedOutputFieldsIterator
494:                            .hasNext();) {
495:                        OperationOutputField lOutputField = (OperationOutputField) lUnprocessedOutputFieldsIterator
496:                                .next();
497:                        if (!lOutputField.isDerived())
498:                            lOutputField.refDelete();
499:                    }
500:                }
501:                // Output Messages
502:                {
503:                    Collection lOperationOutputMessages = lOperation
504:                            .getOutputMessages();
505:                    List lUnprocessedOutputMessages = new ArrayList();
506:                    lUnprocessedOutputMessages.addAll(lOperationOutputMessages);
507:
508:                    // When instance is being loaded (gets and delete operations) instance not found message can be returned for this entity instance
509:                    // and all primary key associations entities (definitely will have at least our own)
510:                    Set lEntitiesWhichMayBeNotFoundWhenLoadingInstance = new HashSet();
511:                    lEntitiesWhichMayBeNotFoundWhenLoadingInstance.add(pEntity);
512:                    Util.collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
513:                            pEntity,
514:                            lEntitiesWhichMayBeNotFoundWhenLoadingInstance);
515:                    for (Iterator lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenLoadingInstance
516:                            .iterator(); lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
517:                            .hasNext();) {
518:                        Entity lEntityElement = (Entity) lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
519:                                .next();
520:                        // We need to use entity name parameter for the entity which is passed as a parameter.
521:                        String lEntityElementName = lEntityElement
522:                                .equals(pEntity) ? pEntityName : lEntityElement
523:                                .getName();
524:                        if (lEntityElementName == null)
525:                            continue;
526:                        String lOperationOutputMessageName = StylesheetImpl
527:                                .getEntityNotFoundOperationOutputMessageName(lEntityElementName);
528:                        OperationOutputMessage lOutputMessage = lOperation
529:                                .findOutputMessage(lOperationOutputMessageName);
530:                        if (lOutputMessage == null) {
531:                            lOutputMessage = mModelAssistantImpl.mOperationOutputMessageClass
532:                                    .createOperationOutputMessage();
533:                            lOutputMessage.setName(lOperationOutputMessageName);
534:                            lOutputMessage.setOperation(lOperation);
535:                        } else {
536:                            lUnprocessedOutputMessages.remove(lOutputMessage);
537:                        }
538:                        lOutputMessage
539:                                .setDescription(StylesheetImpl
540:                                        .getEntityNotFoundOperationOutputMessageDescription(lEntityElementName));
541:                        lOutputMessage.setArray(false);
542:                        Message lEntityNotFoundMessage = pDataManagementService
543:                                .getServicemodule() != null ? pDataManagementService
544:                                .getServicemodule()
545:                                .findMessage(
546:                                        StylesheetImpl
547:                                                .getEntityInstanceNotFoundMessageName(lEntityElementName))
548:                                : null;
549:                        lOutputMessage.setMessageType(lEntityNotFoundMessage);
550:                    }
551:
552:                    // Delete all output messages left
553:                    for (Iterator lUnprocessedOutputMessagesIterator = lUnprocessedOutputMessages
554:                            .iterator(); lUnprocessedOutputMessagesIterator
555:                            .hasNext();) {
556:                        OperationOutputMessage lOutputMessage = (OperationOutputMessage) lUnprocessedOutputMessagesIterator
557:                                .next();
558:                        if (!lOutputMessage.isDerived())
559:                            lOutputMessage.refDelete();
560:                    }
561:                }
562:            }
563:
564:            // This helper makes sure that the version id attribute is absent in the details structure
565:            void ensureAbsent(Service pDataManagementService, String pEntityName) {
566:                // Work on the details structure
567:                Operation lOperation = pDataManagementService
568:                        .findOperation(suggestOperationName(pEntityName));
569:                if (lOperation != null)
570:                    lOperation.refDelete();
571:            }
572:
573:            // Helper. Returns the message name	
574:            private static String suggestOperationName(String pEntityName) {
575:                // Use normalised name here
576:                return "delete"
577:                        + StringUtils.suggestName(pEntityName, true, false);
578:            }
579:
580:            // Helper. Returns the message description	
581:            private static String suggestOperationDescription(String pEntityName) {
582:                // Use name 'as is' here
583:                return "Deletes existing instance of " + pEntityName
584:                        + " in the domain.";
585:            }
586:
587:            // Helper. Returns the description	
588:            private static String suggestUniqueKeyInputParameterDescription(
589:                    String pEntityName) {
590:                // Use name 'as is' here
591:                return "The unique key referring to the instance of "
592:                        + pEntityName + " to be deleted.";
593:            }
594:        }
www___.__j__ava__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.