KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencrx > kernel > layer > application > Models


1 /*
2  * ====================================================================
3  * Project: opencrx, http://www.opencrx.org/
4  * Name: $Id: Models.java,v 1.8 2006/03/18 00:32:17 wfro Exp $
5  * Description: openCRX application plugin
6  * Revision: $Revision: 1.8 $
7  * Owner: CRIXP AG, Switzerland, http://www.crixp.com
8  * Date: $Date: 2006/03/18 00:32:17 $
9  * ====================================================================
10  *
11  * This software is published under the BSD license
12  * as listed below.
13  *
14  * Copyright (c) 2004-2005, CRIXP Corp., Switzerland
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * * Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  *
24  * * Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in
26  * the documentation and/or other materials provided with the
27  * distribution.
28  *
29  * * Neither the name of CRIXP Corp. nor the names of the contributors
30  * to openCRX may be used to endorse or promote products derived
31  * from this software without specific prior written permission
32  *
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
35  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
39  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
41  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
43  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46  * POSSIBILITY OF SUCH DAMAGE.
47  *
48  * ------------------
49  *
50  * This product includes software developed by the Apache Software
51  * Foundation (http://www.apache.org/).
52  *
53  * This product includes software developed by contributors to
54  * openMDX (http://www.openmdx.org/)
55  */

56
57 package org.opencrx.kernel.layer.application;
58
59 import java.util.ArrayList JavaDoc;
60 import java.util.Collections JavaDoc;
61 import java.util.HashMap JavaDoc;
62 import java.util.Iterator JavaDoc;
63 import java.util.List JavaDoc;
64 import java.util.Map JavaDoc;
65
66 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0;
67 import org.openmdx.base.exception.ServiceException;
68 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSelectors;
69 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSpecifier;
70 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject;
71 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject_1_0;
72 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderReply;
73 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderReplyContexts;
74 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderRequest;
75 import org.openmdx.compatibility.base.dataprovider.cci.Directions;
76 import org.openmdx.compatibility.base.dataprovider.cci.Orders;
77 import org.openmdx.compatibility.base.dataprovider.cci.RequestCollection;
78 import org.openmdx.compatibility.base.dataprovider.cci.ServiceHeader;
79 import org.openmdx.compatibility.base.dataprovider.cci.SystemAttributes;
80 import org.openmdx.compatibility.base.naming.Path;
81 import org.openmdx.compatibility.base.query.FilterOperators;
82 import org.openmdx.compatibility.base.query.FilterProperty;
83 import org.openmdx.compatibility.base.query.Quantors;
84 import org.openmdx.model1.accessor.basic.cci.Model_1_0;
85 import org.openmdx.uses.org.apache.commons.collections.MapUtils;
86
87 public class Models {
88
89     //-----------------------------------------------------------------------
90
public Models(
91         Model_1_0 model,
92         OpenCrxKernel_1 plugin,
93         RequestCollection delegation,
94         RefPackage_1_0 rootPkg
95     ) {
96         this.model = model;
97         this.plugin = plugin;
98         this.delegation = delegation;
99         this.rootPkg = rootPkg;
100     }
101
102     //-------------------------------------------------------------------------
103
private void getEditableElement(
104         DataproviderObject editableElement,
105         DataproviderObject_1_0 element
106     ) {
107         editableElement.values("name").addAll(element.values("name"));
108         editableElement.values("elementOrder").addAll(element.values("elementOrder"));
109         editableElement.values("multiplicity").addAll(element.values("multiplicity"));
110         editableElement.values("upperBound").addAll(element.values("upperBound"));
111         editableElement.values("direction").addAll(element.values("direction"));
112         editableElement.values("maxLength").addAll(element.values("maxLength"));
113         editableElement.values("tagValue").addAll(element.values("tagValue"));
114         // Only get first sentence/line of annotation
115
String JavaDoc annotation = (String JavaDoc)element.values("annotation").get(0);
116         if(annotation != null) {
117             annotation = annotation.indexOf("\n") >= 0
118                 ? annotation.substring(0, annotation.indexOf("\n"))
119                 : annotation;
120             annotation = annotation.indexOf(".") >= 0
121                 ? annotation.substring(0, annotation.indexOf("."))
122                 : annotation;
123             editableElement.values("annotation").add(annotation);
124         }
125         editableElement.values("basedOn").add(element.path());
126         editableElement.values("owningUser").addAll(element.values("owningUser"));
127         editableElement.values("owningGroup").addAll(element.values("owningGroup"));
128         editableElement.values(SystemAttributes.OBJECT_IDENTITY).add(editableElement.path().toXri());
129         editableElement.values(SystemAttributes.CREATED_AT).addAll(element.values(SystemAttributes.CREATED_AT));
130         editableElement.values(SystemAttributes.MODIFIED_AT).addAll(element.values(SystemAttributes.MODIFIED_AT));
131         editableElement.values(SystemAttributes.CREATED_BY).addAll(element.values(SystemAttributes.CREATED_BY));
132         editableElement.values(SystemAttributes.MODIFIED_BY).addAll(element.values(SystemAttributes.MODIFIED_BY));
133     }
134     
135     //-------------------------------------------------------------------------
136
private void getEditableTypedElement(
137         DataproviderObject editableElement,
138         DataproviderObject_1_0 element
139     ) {
140         this.getEditableElement(
141             editableElement,
142             element
143         );
144         editableElement.values("type").addAll(element.values("type"));
145         try {
146             if((element.getValues("type") != null) && (element.values("type").size() > 0)) {
147                 DataproviderObject_1_0 type = this.plugin.retrieveObjectFromDelegation((Path)element.values("type").get(0));
148                 editableElement.values("typeName").addAll(type.values("qualifiedName"));
149             }
150         } catch(Exception JavaDoc e) {}
151     }
152     
153     //-------------------------------------------------------------------------
154
private DataproviderObject getEditableStructureField(
155         Path reference,
156         DataproviderObject_1_0 structureField
157     ) {
158         DataproviderObject editableStructureField = new DataproviderObject(
159             reference.getChild(structureField.path().getBase())
160         );
161         editableStructureField.values(SystemAttributes.OBJECT_CLASS).add(
162             "org:opencrx:kernel:model1:EditableStructureField"
163         );
164         this.getEditableTypedElement(
165             editableStructureField,
166             structureField
167         );
168         return editableStructureField;
169     }
170     
171     //-------------------------------------------------------------------------
172
private DataproviderObject getEditablePackage(
173         Path reference,
174         DataproviderObject_1_0 _package
175     ) {
176         DataproviderObject editablePackage = new DataproviderObject(
177             reference.getChild(_package.path().getBase())
178         );
179         editablePackage.values(SystemAttributes.OBJECT_CLASS).add(
180             "org:opencrx:kernel:model1:EditablePackage"
181         );
182         this.getEditableElement(
183             editablePackage,
184             _package
185         );
186         return editablePackage;
187     }
188     
189     //-------------------------------------------------------------------------
190
private DataproviderObject getEditableClass(
191         Path reference,
192         DataproviderObject_1_0 _class
193     ) {
194         DataproviderObject editableClass = new DataproviderObject(
195             reference.getChild(_class.path().getBase())
196         );
197         editableClass.values(SystemAttributes.OBJECT_CLASS).add(
198             "org:opencrx:kernel:model1:EditableClass"
199         );
200         this.getEditableElement(
201             editableClass,
202             _class
203         );
204         return editableClass;
205     }
206     
207     //-------------------------------------------------------------------------
208
private DataproviderObject getEditableStructureType(
209         Path reference,
210         DataproviderObject_1_0 structureType
211     ) {
212         DataproviderObject editableStructureType = new DataproviderObject(
213             reference.getChild(structureType.path().getBase())
214         );
215         editableStructureType.values(SystemAttributes.OBJECT_CLASS).add(
216             "org:opencrx:kernel:model1:EditableStructureType"
217         );
218         this.getEditableElement(
219             editableStructureType,
220             structureType
221         );
222         return editableStructureType;
223     }
224     
225     //-------------------------------------------------------------------------
226
private DataproviderObject getEditableOperationTag(
227         Path reference,
228         DataproviderObject_1_0 tag
229     ) {
230         DataproviderObject editableOperationTag = new DataproviderObject(
231             reference.getChild(tag.path().getBase())
232         );
233         editableOperationTag.values(SystemAttributes.OBJECT_CLASS).add(
234             "org:opencrx:kernel:model1:EditableOperationTag"
235         );
236         this.getEditableElement(
237             editableOperationTag,
238             tag
239         );
240         return editableOperationTag;
241     }
242     
243     //-------------------------------------------------------------------------
244
private DataproviderObject getEditableAttribute(
245         Path reference,
246         DataproviderObject_1_0 attribute
247     ) {
248         DataproviderObject editableAttribute = new DataproviderObject(
249             reference.getChild(attribute.path().getBase())
250         );
251         editableAttribute.values(SystemAttributes.OBJECT_CLASS).add(
252             "org:opencrx:kernel:model1:EditableAttribute"
253         );
254         this.getEditableTypedElement(
255             editableAttribute,
256             attribute
257         );
258         return editableAttribute;
259     }
260     
261     //-------------------------------------------------------------------------
262
private DataproviderObject getEditableParameter(
263         Path reference,
264         DataproviderObject_1_0 parameter
265     ) {
266         DataproviderObject editableParameter = new DataproviderObject(
267             reference.getChild(parameter.path().getBase())
268         );
269         editableParameter.values(SystemAttributes.OBJECT_CLASS).add(
270             "org:opencrx:kernel:model1:EditableParameter"
271         );
272         this.getEditableTypedElement(
273             editableParameter,
274             parameter
275         );
276         return editableParameter;
277     }
278     
279     //-------------------------------------------------------------------------
280
private String JavaDoc getOperationSignature(
281         DataproviderObject_1_0 operation
282     ) throws ServiceException {
283         // Calculate operation signature
284
List JavaDoc parameters = this.delegation.addFindRequest(
285             operation.path().getPrefix(5).getChild("element"),
286             new FilterProperty[]{
287                 new FilterProperty(
288                     Quantors.THERE_EXISTS,
289                     "container",
290                     FilterOperators.IS_IN,
291                     new Object JavaDoc[]{operation.path().getPrefix(7)}
292                 ),
293                 new FilterProperty(
294                     Quantors.THERE_EXISTS,
295                     SystemAttributes.OBJECT_CLASS,
296                     FilterOperators.IS_IN,
297                     new Object JavaDoc[]{"org:opencrx:kernel:model1:Parameter"}
298                 )
299             },
300             AttributeSelectors.ALL_ATTRIBUTES,
301             new AttributeSpecifier[]{
302                 new AttributeSpecifier("elementOrder", 0, Orders.ASCENDING)
303             },
304             0,
305             Integer.MAX_VALUE,
306             Directions.ASCENDING
307         );
308         String JavaDoc signature = operation.values("name").get(0) + "(";
309         int ii = 0;
310         for(
311             Iterator JavaDoc i = parameters.iterator();
312             i.hasNext();
313             ii++
314         ) {
315             DataproviderObject_1_0 parameter = (DataproviderObject_1_0)i.next();
316             DataproviderObject_1_0 type = null;
317             try {
318                 type = this.plugin.retrieveObjectFromDelegation(
319                     (Path)parameter.values("type").get(0)
320                 );
321             } catch(Exception JavaDoc e) {}
322             if(ii > 0) signature += ",";
323             signature += "\n ";
324             String JavaDoc typeName = type == null
325                 ? "void"
326                 : (String JavaDoc)type.values("qualifiedName").get(0);
327             signature +=
328                 PARAMETER_DIRECTIONS[((Number JavaDoc)parameter.values("direction").get(0)).intValue()] + " " +
329                 typeName + " " +
330                 "[" + MULTIPLICITIES[((Number JavaDoc)parameter.values("multiplicity").get(0)).intValue()] + "] " +
331                 parameter.values("name").get(0) + " ";
332         }
333         signature += "\n);";
334         return signature;
335     }
336     
337     //-------------------------------------------------------------------------
338
private DataproviderObject getEditableOperation(
339         Path reference,
340         DataproviderObject_1_0 operation
341     ) throws ServiceException {
342         DataproviderObject editableOperation = new DataproviderObject(
343             reference.getChild(operation.path().getBase())
344         );
345         editableOperation.values(SystemAttributes.OBJECT_CLASS).add(
346             "org:opencrx:kernel:model1:EditableOperation"
347         );
348         this.getEditableElement(
349             editableOperation,
350             operation
351         );
352         String JavaDoc signature = this.getOperationSignature(operation);
353         editableOperation.values("signature").add(signature);
354         
355         return editableOperation;
356     }
357     
358     //-------------------------------------------------------------------------
359
public DataproviderReply getEditableElements(
360         DataproviderRequest request,
361         String JavaDoc elementType,
362         String JavaDoc editableElementType
363     ) throws ServiceException {
364         DataproviderReply reply = null;
365         boolean isObjectRetrieval = request.path().size() % 2 == 1;
366         List JavaDoc elements = this.delegation.addFindRequest(
367             request.path().getPrefix(5).getChild("element"),
368             new FilterProperty[]{
369                 new FilterProperty(
370                     Quantors.THERE_EXISTS,
371                     "container",
372                     FilterOperators.IS_IN,
373                     new Object JavaDoc[]{request.path().getPrefix(7)}
374                 ),
375                 new FilterProperty(
376                     Quantors.THERE_EXISTS,
377                     SystemAttributes.OBJECT_CLASS,
378                     FilterOperators.IS_IN,
379                     new Object JavaDoc[]{elementType}
380                 )
381             },
382             AttributeSelectors.ALL_ATTRIBUTES,
383             new AttributeSpecifier[]{
384                 new AttributeSpecifier("elementOrder", 0, Orders.ASCENDING)
385             },
386             0,
387             Integer.MAX_VALUE,
388             Directions.ASCENDING
389         );
390         Map JavaDoc editableElements = MapUtils.orderedMap(new HashMap JavaDoc());
391         for(
392             Iterator JavaDoc i = elements.iterator();
393             i.hasNext();
394         ) {
395             DataproviderObject_1_0 element = (DataproviderObject_1_0)i.next();
396             DataproviderObject editableElement = null;
397             if("org:opencrx:kernel:model1:EditableOperation".equals(editableElementType)) {
398                 editableElement = this.plugin.models.getEditableOperation(
399                     request.path().getPrefix(8),
400                     element
401                 );
402             }
403             else if("org:opencrx:kernel:model1:EditableParameter".equals(editableElementType)) {
404                 editableElement = this.plugin.models.getEditableParameter(
405                     request.path().getPrefix(8),
406                     element
407                 );
408             }
409             else if("org:opencrx:kernel:model1:EditableAttribute".equals(editableElementType)) {
410                 editableElement = this.plugin.models.getEditableAttribute(
411                     request.path().getPrefix(8),
412                     element
413                 );
414             }
415             else if("org:opencrx:kernel:model1:EditableStructureField".equals(editableElementType)) {
416                 editableElement = this.plugin.models.getEditableStructureField(
417                     request.path().getPrefix(8),
418                     element
419                 );
420             }
421             else if("org:opencrx:kernel:model1:EditablePackage".equals(editableElementType)) {
422                 editableElement = this.plugin.models.getEditablePackage(
423                     request.path().getPrefix(8),
424                     element
425                 );
426             }
427             else if("org:opencrx:kernel:model1:EditableClass".equals(editableElementType)) {
428                 editableElement = this.plugin.models.getEditableClass(
429                     request.path().getPrefix(8),
430                     element
431                 );
432             }
433             else if("org:opencrx:kernel:model1:EditableStructureType".equals(editableElementType)) {
434                 editableElement = this.plugin.models.getEditableStructureType(
435                     request.path().getPrefix(8),
436                     element
437                 );
438             }
439             else if("org:opencrx:kernel:model1:EditableOperationTag".equals(editableElementType)) {
440                 editableElement = this.plugin.models.getEditableOperationTag(
441                     request.path().getPrefix(8),
442                     element
443                 );
444             }
445             editableElements.put(
446                 editableElement.path(),
447                 editableElement
448             );
449         }
450         if(isObjectRetrieval) {
451             if(editableElements.containsKey(request.path())) {
452                 reply = new DataproviderReply(
453                     new DataproviderObject(
454                         (DataproviderObject_1_0)editableElements.get(request.path())
455                     )
456                 );
457             }
458         }
459         else {
460             reply = new DataproviderReply(
461                 new ArrayList JavaDoc(editableElements.values())
462             );
463             reply.context(
464                 DataproviderReplyContexts.HAS_MORE
465             ).set(0, Boolean.FALSE);
466             reply.context(
467                 DataproviderReplyContexts.TOTAL
468             ).set(0, new Integer JavaDoc(editableElements.size()));
469         }
470         return reply;
471     }
472
473     //-------------------------------------------------------------------------
474
public void updateModelElement(
475         ServiceHeader header,
476         DataproviderObject object,
477         DataproviderObject_1_0 oldValues
478     ) throws ServiceException {
479         if(this.plugin.isModelElement(object)) {
480             DataproviderObject_1_0 container = null;
481             if((oldValues != null) && (oldValues.values("container").size() > 0)) {
482                 container = this.plugin.retrieveObjectFromLocal(header, (Path)oldValues.values("container").get(0));
483             }
484             else if((object.getValues("container") != null) && (object.values("container").size() > 0)) {
485                 container = this.plugin.retrieveObjectFromLocal(header, (Path)object.values("container").get(0));
486             }
487             String JavaDoc name = oldValues == null
488                 ? (String JavaDoc)object.values("name").get(0)
489                 : object.getValues("name") == null ? (String JavaDoc)oldValues.values("name").get(0) : (String JavaDoc)object.values("name").get(0);
490             object.clearValues("qualifiedName").add(
491                 container == null
492                     ? name
493                     : container.values("qualifiedName").get(0) + ":" + name
494             );
495         }
496     }
497             
498     //-------------------------------------------------------------------------
499
public void updateType(
500         ServiceHeader header,
501         DataproviderObject typedElement,
502         DataproviderObject editableTypedElement
503     ) throws ServiceException {
504         if((editableTypedElement.getValues("type") != null) && (editableTypedElement.values("type").size() > 0)) {
505             typedElement.clearValues("type").addAll(editableTypedElement.values("type"));
506         }
507         else if((editableTypedElement.getValues("typeName") != null) && (editableTypedElement.values("typeName").size() > 0)) {
508             List JavaDoc types = this.delegation.addFindRequest(
509                 editableTypedElement.path().getPrefix(6),
510                 new FilterProperty[]{
511                     new FilterProperty(
512                         Quantors.THERE_EXISTS,
513                         "qualifiedName",
514                         FilterOperators.IS_IN,
515                         new Object JavaDoc[]{editableTypedElement.values("typeName").get(0)}
516                     )
517                 },
518                 AttributeSelectors.ALL_ATTRIBUTES,
519                 new AttributeSpecifier[]{
520                     new AttributeSpecifier("elementOrder", 0, Orders.ASCENDING)
521                 },
522                 0,
523                 Integer.MAX_VALUE,
524                 Directions.ASCENDING
525             );
526             if(types.size() > 0) {
527                 DataproviderObject_1_0 type = (DataproviderObject_1_0)types.iterator().next();
528                 typedElement.clearValues("type").add(type.path());
529             }
530         }
531     }
532     
533     //-------------------------------------------------------------------------
534
public void createAttribute(
535         ServiceHeader header,
536         DataproviderObject editableAttribute
537     ) throws ServiceException {
538         DataproviderObject attribute = new DataproviderObject(
539             editableAttribute.path().getPrefix(6).getChild(editableAttribute.path().getBase())
540         );
541         attribute.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Attribute");
542         attribute.values("container").add(editableAttribute.path().getPrefix(7));
543         attribute.values("name").addAll(editableAttribute.values("name"));
544         attribute.values("elementOrder").addAll(editableAttribute.values("elementOrder"));
545         attribute.values("annotation").addAll(editableAttribute.values("annotation"));
546         attribute.values("stereotype").addAll(editableAttribute.values("stereotype"));
547         attribute.values("scope").addAll(editableAttribute.values("scope"));
548         attribute.values("visibility").addAll(editableAttribute.values("visibility"));
549         attribute.values("multiplicity").addAll(editableAttribute.values("multiplicity"));
550         attribute.values("isChangeable").addAll(editableAttribute.values("isChangeable"));
551         attribute.values("upperBound").addAll(editableAttribute.values("upperBound"));
552         attribute.values("isDerived").addAll(editableAttribute.values("isDerived"));
553         attribute.values("maxLength").addAll(editableAttribute.values("maxLength"));
554         this.updateType(
555             header,
556             attribute,
557             editableAttribute
558         );
559         this.updateModelElement(
560             header,
561             attribute,
562             null
563         );
564         this.delegation.addCreateRequest(
565             attribute
566         );
567     }
568     
569     //-------------------------------------------------------------------------
570
public void createOperation(
571         ServiceHeader header,
572         DataproviderObject editableOperation
573     ) throws ServiceException {
574         DataproviderObject operation = new DataproviderObject(
575             editableOperation.path().getPrefix(6).getChild(editableOperation.path().getBase())
576         );
577         operation.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Operation");
578         operation.values("container").add(editableOperation.path().getPrefix(7));
579         operation.values("name").addAll(editableOperation.values("name"));
580         operation.values("elementOrder").addAll(editableOperation.values("elementOrder"));
581         operation.values("annotation").addAll(editableOperation.values("annotation"));
582         operation.values("stereotype").addAll(editableOperation.values("stereotype"));
583         operation.values("scope").addAll(editableOperation.values("scope"));
584         operation.values("visibility").addAll(editableOperation.values("visibility"));
585         operation.values("isQuery").addAll(editableOperation.values("isQuery"));
586         operation.values("semantics").addAll(editableOperation.values("semantics"));
587         this.updateModelElement(
588             header,
589             operation,
590             null
591         );
592         this.delegation.addCreateRequest(
593             operation
594         );
595     }
596
597     //-------------------------------------------------------------------------
598
public void createParameter(
599         ServiceHeader header,
600         DataproviderObject editableParameter
601     ) throws ServiceException {
602         DataproviderObject parameter = new DataproviderObject(
603             editableParameter.path().getPrefix(6).getChild(editableParameter.path().getBase())
604         );
605         parameter.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Parameter");
606         parameter.values("container").add(editableParameter.path().getPrefix(7));
607         parameter.values("name").addAll(editableParameter.values("name"));
608         parameter.values("elementOrder").addAll(editableParameter.values("elementOrder"));
609         parameter.values("annotation").addAll(editableParameter.values("annotation"));
610         parameter.values("stereotype").addAll(editableParameter.values("stereotype"));
611         parameter.values("scope").addAll(editableParameter.values("scope"));
612         parameter.values("visibility").addAll(editableParameter.values("visibility"));
613         parameter.values("direction").addAll(editableParameter.values("direction"));
614         parameter.values("multiplicity").addAll(editableParameter.values("multiplicity"));
615         parameter.values("upperBound").addAll(editableParameter.values("upperBound"));
616         this.updateType(
617             header,
618             parameter,
619             editableParameter
620         );
621         this.updateModelElement(
622             header,
623             parameter,
624             null
625         );
626         this.delegation.addCreateRequest(
627             parameter
628         );
629     }
630
631     //-------------------------------------------------------------------------
632
public void createStructureField(
633         ServiceHeader header,
634         DataproviderObject editableStructureField
635     ) throws ServiceException {
636         DataproviderObject structureField = new DataproviderObject(
637             editableStructureField.path().getPrefix(6).getChild(editableStructureField.path().getBase())
638         );
639         structureField.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:StructureField");
640         structureField.values("container").add(editableStructureField.path().getPrefix(7));
641         structureField.values("name").addAll(editableStructureField.values("name"));
642         structureField.values("elementOrder").addAll(editableStructureField.values("elementOrder"));
643         structureField.values("annotation").addAll(editableStructureField.values("annotation"));
644         structureField.values("stereotype").addAll(editableStructureField.values("stereotype"));
645         structureField.values("scope").addAll(editableStructureField.values("scope"));
646         structureField.values("visibility").addAll(editableStructureField.values("visibility"));
647         structureField.values("multiplicity").addAll(editableStructureField.values("multiplicity"));
648         structureField.values("upperBound").addAll(editableStructureField.values("upperBound"));
649         structureField.values("maxLength").addAll(editableStructureField.values("maxLength"));
650         this.updateType(
651             header,
652             structureField,
653             editableStructureField
654         );
655         this.updateModelElement(
656             header,
657             structureField,
658             null
659         );
660         this.delegation.addCreateRequest(
661             structureField
662         );
663     }
664     
665     //-------------------------------------------------------------------------
666
public void createPackage(
667         ServiceHeader header,
668         DataproviderObject editablePackage
669     ) throws ServiceException {
670         DataproviderObject _package = new DataproviderObject(
671             editablePackage.path().getPrefix(6).getChild(editablePackage.path().getBase())
672         );
673         _package.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Package");
674         _package.values("container").add(editablePackage.path().getPrefix(7));
675         _package.values("name").addAll(editablePackage.values("name"));
676         _package.values("elementOrder").addAll(editablePackage.values("elementOrder"));
677         _package.values("annotation").addAll(editablePackage.values("annotation"));
678         _package.values("visibility").addAll(editablePackage.values("visibility"));
679         this.updateModelElement(
680             header,
681             _package,
682             null
683         );
684         this.delegation.addCreateRequest(
685             _package
686         );
687     }
688     
689     //-------------------------------------------------------------------------
690
public void createClass(
691         ServiceHeader header,
692         DataproviderObject editableClass
693     ) throws ServiceException {
694         DataproviderObject _class = new DataproviderObject(
695             editableClass.path().getPrefix(6).getChild(editableClass.path().getBase())
696         );
697         _class.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Class");
698         _class.values("container").add(editableClass.path().getPrefix(7));
699         _class.values("name").addAll(editableClass.values("name"));
700         _class.values("elementOrder").addAll(editableClass.values("elementOrder"));
701         _class.values("annotation").addAll(editableClass.values("annotation"));
702         _class.values("visibility").addAll(editableClass.values("visibility"));
703         this.updateModelElement(
704             header,
705             _class,
706             null
707         );
708         this.delegation.addCreateRequest(
709             _class
710         );
711     }
712     
713     //-------------------------------------------------------------------------
714
public void createStructureType(
715         ServiceHeader header,
716         DataproviderObject editableStructureType
717     ) throws ServiceException {
718         DataproviderObject structureType = new DataproviderObject(
719             editableStructureType.path().getPrefix(6).getChild(editableStructureType.path().getBase())
720         );
721         structureType.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:StructureType");
722         structureType.values("container").add(editableStructureType.path().getPrefix(7));
723         structureType.values("name").addAll(editableStructureType.values("name"));
724         structureType.values("elementOrder").addAll(editableStructureType.values("elementOrder"));
725         structureType.values("annotation").addAll(editableStructureType.values("annotation"));
726         structureType.values("visibility").addAll(editableStructureType.values("visibility"));
727         this.updateModelElement(
728             header,
729             structureType,
730             null
731         );
732         this.delegation.addCreateRequest(
733             structureType
734         );
735     }
736     
737     //-------------------------------------------------------------------------
738
public void createTag(
739         ServiceHeader header,
740         DataproviderObject editableTag
741     ) throws ServiceException {
742         DataproviderObject tag = new DataproviderObject(
743             editableTag.path().getPrefix(6).getChild(editableTag.path().getBase())
744         );
745         tag.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:model1:Tag");
746         tag.values("container").add(editableTag.path().getPrefix(7));
747         tag.values("name").addAll(editableTag.values("name"));
748         tag.values("elementOrder").addAll(editableTag.values("elementOrder"));
749         tag.values("annotation").addAll(editableTag.values("annotation"));
750         this.updateModelElement(
751             header,
752             tag,
753             null
754         );
755         this.delegation.addCreateRequest(
756             tag
757         );
758     }
759     
760     //-------------------------------------------------------------------------
761
public List JavaDoc completeElement(
762         ServiceHeader header,
763         DataproviderObject_1_0 object
764     ) throws ServiceException {
765         String JavaDoc objectClass = (String JavaDoc)object.values(SystemAttributes.OBJECT_CLASS).get(0);
766         if("org:opencrx:kernel:model1:Operation".equals(objectClass)) {
767             object.clearValues("signature").add(
768                 this.getOperationSignature(object)
769             );
770         }
771         return Collections.EMPTY_LIST;
772     }
773     
774     //-------------------------------------------------------------------------
775
public void removeOperation(
776         ServiceHeader header,
777         Path editableOperation
778     ) throws ServiceException {
779         // The editable element and the (basedOn) element have the same qualifier
780
this.plugin.removeObject(
781             editableOperation.getPrefix(6).getChild(editableOperation.getBase())
782         );
783     }
784     
785     //-------------------------------------------------------------------------
786
public void removeParameter(
787         ServiceHeader header,
788         Path editableParameter
789     ) throws ServiceException {
790         // The editable element and the (basedOn) element have the same qualifier
791
this.plugin.removeObject(
792             editableParameter.getPrefix(6).getChild(editableParameter.getBase())
793         );
794     }
795     
796     //-------------------------------------------------------------------------
797
public void removeAttribute(
798         ServiceHeader header,
799         Path editableAttribute
800     ) throws ServiceException {
801         // The editable element and the (basedOn) element have the same qualifier
802
this.plugin.removeObject(
803             editableAttribute.getPrefix(6).getChild(editableAttribute.getBase())
804         );
805     }
806     
807     //-------------------------------------------------------------------------
808
public void removeStructureField(
809         ServiceHeader header,
810         Path editableStructureField
811     ) throws ServiceException {
812         // The editable element and the (basedOn) element have the same qualifier
813
this.plugin.removeObject(
814             editableStructureField.getPrefix(6).getChild(editableStructureField.getBase())
815         );
816     }
817     
818     //-------------------------------------------------------------------------
819
public void removePackage(
820         ServiceHeader header,
821         Path editablePackage
822     ) throws ServiceException {
823         // The editable element and the (basedOn) element have the same qualifier
824
this.plugin.removeObject(
825             editablePackage.getPrefix(6).getChild(editablePackage.getBase())
826         );
827     }
828     
829     //-------------------------------------------------------------------------
830
public void removeClass(
831         ServiceHeader header,
832         Path editableClass
833     ) throws ServiceException {
834         // The editable element and the (basedOn) element have the same qualifier
835
this.plugin.removeObject(
836             editableClass.getPrefix(6).getChild(editableClass.getBase())
837         );
838     }
839     
840     //-------------------------------------------------------------------------
841
public void removeStructureType(
842         ServiceHeader header,
843         Path editableStructureType
844     ) throws ServiceException {
845         // The editable element and the (basedOn) element have the same qualifier
846
this.plugin.removeObject(
847             editableStructureType.getPrefix(6).getChild(editableStructureType.getBase())
848         );
849     }
850     
851     //-------------------------------------------------------------------------
852
public void removeOperationTag(
853         ServiceHeader header,
854         Path editableOperationTag
855     ) throws ServiceException {
856         // The editable element and the (basedOn) element have the same qualifier
857
this.plugin.removeObject(
858             editableOperationTag.getPrefix(6).getChild(editableOperationTag.getBase())
859         );
860     }
861     
862     //-------------------------------------------------------------------------
863
private void replaceElementAnnotation(
864         DataproviderObject element,
865         String JavaDoc annotation
866     ) throws ServiceException {
867         String JavaDoc existingAnnotation = (String JavaDoc)element.values("annotation").get(0);
868         if(existingAnnotation == null) {
869             element.clearValues("annotation").add(annotation);
870         }
871         // Replace first sentence of element's annotation by new annotation
872
else {
873             int posNewLine = existingAnnotation.indexOf("\n");
874             posNewLine = posNewLine < 0 ? existingAnnotation.length() : posNewLine;
875             int posDot = existingAnnotation.indexOf(".");
876             posDot = posDot < 0 ? existingAnnotation.length() : posDot;
877             int pos = Math.min(posNewLine, posDot);
878             element.clearValues("annotation").add(
879                 annotation + existingAnnotation.substring(pos)
880             );
881         }
882     }
883     
884     //-------------------------------------------------------------------------
885
public void replaceOperation(
886         ServiceHeader header,
887         DataproviderRequest request
888     ) throws ServiceException {
889         DataproviderObject modificationRequest = request.object();
890         // The editable element and the (basedOn) element have the same qualifier
891
DataproviderObject modifiedOperation = this.plugin.retrieveObjectForModification(
892             request.path().getPrefix(6).getChild(request.path().getBase())
893         );
894         if(modificationRequest.attributeNames().contains("name")) {
895             modifiedOperation.clearValues("name").addAll(modificationRequest.values("name"));
896         }
897         if(modificationRequest.attributeNames().contains("annotation")) {
898             this.replaceElementAnnotation(
899                 modifiedOperation,
900                 (String JavaDoc)modificationRequest.values("annotation").get(0)
901             );
902         }
903         if(modificationRequest.attributeNames().contains("elementOrder")) {
904             modifiedOperation.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
905         }
906     }
907         
908     //-------------------------------------------------------------------------
909
public void replaceParameter(
910         ServiceHeader header,
911         DataproviderRequest request
912     ) throws ServiceException {
913         DataproviderObject modificationRequest = request.object();
914         // The editable element and the (basedOn) element have the same qualifier
915
DataproviderObject modifiedParameter = this.plugin.retrieveObjectForModification(
916             request.path().getPrefix(6).getChild(request.path().getBase())
917         );
918         if(modificationRequest.attributeNames().contains("name")) {
919             modifiedParameter.clearValues("name").addAll(modificationRequest.values("name"));
920         }
921         if(modificationRequest.attributeNames().contains("annotation")) {
922             this.replaceElementAnnotation(
923                 modifiedParameter,
924                 (String JavaDoc)modificationRequest.values("annotation").get(0)
925             );
926         }
927         if(modificationRequest.attributeNames().contains("elementOrder")) {
928             modifiedParameter.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
929         }
930         if(modificationRequest.attributeNames().contains("direction")) {
931             modifiedParameter.clearValues("direction").addAll(modificationRequest.values("direction"));
932         }
933         if(modificationRequest.attributeNames().contains("multiplicity")) {
934             modifiedParameter.clearValues("multiplicity").addAll(modificationRequest.values("multiplicity"));
935         }
936         if(modificationRequest.attributeNames().contains("upperBound")) {
937             modifiedParameter.clearValues("upperBound").addAll(modificationRequest.values("upperBound"));
938         }
939         this.updateType(
940             header,
941             modifiedParameter,
942             request.object()
943         );
944     }
945         
946     //-------------------------------------------------------------------------
947
public void replaceAttribute(
948         ServiceHeader header,
949         DataproviderRequest request
950     ) throws ServiceException {
951         DataproviderObject modificationRequest = request.object();
952         // The editable element and the (basedOn) element have the same qualifier
953
DataproviderObject modifiedAttribute = this.plugin.retrieveObjectForModification(
954             request.path().getPrefix(6).getChild(request.path().getBase())
955         );
956         if(modificationRequest.attributeNames().contains("name")) {
957             modifiedAttribute.clearValues("name").addAll(modificationRequest.values("name"));
958         }
959         if(modificationRequest.attributeNames().contains("annotation")) {
960             this.replaceElementAnnotation(
961                 modifiedAttribute,
962                 (String JavaDoc)modificationRequest.values("annotation").get(0)
963             );
964         }
965         if(modificationRequest.attributeNames().contains("elementOrder")) {
966             modifiedAttribute.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
967         }
968         if(modificationRequest.attributeNames().contains("maxLength")) {
969             modifiedAttribute.clearValues("maxLength").addAll(modificationRequest.values("maxLength"));
970         }
971         if(modificationRequest.attributeNames().contains("multiplicity")) {
972             modifiedAttribute.clearValues("multiplicity").addAll(modificationRequest.values("multiplicity"));
973         }
974         if(modificationRequest.attributeNames().contains("upperBound")) {
975             modifiedAttribute.clearValues("upperBound").addAll(modificationRequest.values("upperBound"));
976         }
977         this.updateType(
978             header,
979             modifiedAttribute,
980             request.object()
981         );
982     }
983         
984     //-------------------------------------------------------------------------
985
public void replaceStructureField(
986         ServiceHeader header,
987         DataproviderRequest request
988     ) throws ServiceException {
989         DataproviderObject modificationRequest = request.object();
990         // The editable element and the (basedOn) element have the same qualifier
991
DataproviderObject modifiedStructureField = this.plugin.retrieveObjectForModification(
992             request.path().getPrefix(6).getChild(request.path().getBase())
993         );
994         if(modificationRequest.attributeNames().contains("name")) {
995             modifiedStructureField.clearValues("name").addAll(modificationRequest.values("name"));
996         }
997         if(modificationRequest.attributeNames().contains("annotation")) {
998             this.replaceElementAnnotation(
999                 modifiedStructureField,
1000                (String JavaDoc)modificationRequest.values("annotation").get(0)
1001            );
1002        }
1003        if(modificationRequest.attributeNames().contains("elementOrder")) {
1004            modifiedStructureField.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
1005        }
1006        if(modificationRequest.attributeNames().contains("maxLength")) {
1007            modifiedStructureField.clearValues("maxLength").addAll(modificationRequest.values("maxLength"));
1008        }
1009        if(modificationRequest.attributeNames().contains("multiplicity")) {
1010            modifiedStructureField.clearValues("multiplicity").addAll(modificationRequest.values("multiplicity"));
1011        }
1012        if(modificationRequest.attributeNames().contains("upperBound")) {
1013            modifiedStructureField.clearValues("upperBound").addAll(modificationRequest.values("upperBound"));
1014        }
1015        this.updateType(
1016            header,
1017            modifiedStructureField,
1018            request.object()
1019        );
1020    }
1021        
1022    //-------------------------------------------------------------------------
1023
public void replacePackage(
1024        ServiceHeader header,
1025        DataproviderRequest request
1026    ) throws ServiceException {
1027        DataproviderObject modificationRequest = request.object();
1028        // The editable element and the (basedOn) element have the same qualifier
1029
DataproviderObject modifiedPackage = this.plugin.retrieveObjectForModification(
1030            request.path().getPrefix(6).getChild(request.path().getBase())
1031        );
1032        if(modificationRequest.attributeNames().contains("name")) {
1033            modifiedPackage.clearValues("name").addAll(modificationRequest.values("name"));
1034        }
1035        if(modificationRequest.attributeNames().contains("annotation")) {
1036            this.replaceElementAnnotation(
1037                modifiedPackage,
1038                (String JavaDoc)modificationRequest.values("annotation").get(0)
1039            );
1040        }
1041        if(modificationRequest.attributeNames().contains("elementOrder")) {
1042            modifiedPackage.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
1043        }
1044    }
1045        
1046    //-------------------------------------------------------------------------
1047
public void replaceClass(
1048        ServiceHeader header,
1049        DataproviderRequest request
1050    ) throws ServiceException {
1051        DataproviderObject modificationRequest = request.object();
1052        // The editable element and the (basedOn) element have the same qualifier
1053
DataproviderObject modifiedClass = this.plugin.retrieveObjectForModification(
1054            request.path().getPrefix(6).getChild(request.path().getBase())
1055        );
1056        if(modificationRequest.attributeNames().contains("name")) {
1057            modifiedClass.clearValues("name").addAll(modificationRequest.values("name"));
1058        }
1059        if(modificationRequest.attributeNames().contains("annotation")) {
1060            this.replaceElementAnnotation(
1061                modifiedClass,
1062                (String JavaDoc)modificationRequest.values("annotation").get(0)
1063            );
1064        }
1065        if(modificationRequest.attributeNames().contains("elementOrder")) {
1066            modifiedClass.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
1067        }
1068    }
1069        
1070    //-------------------------------------------------------------------------
1071
public void replaceStructureType(
1072        ServiceHeader header,
1073        DataproviderRequest request
1074    ) throws ServiceException {
1075        DataproviderObject modificationRequest = request.object();
1076        // The editable element and the (basedOn) element have the same qualifier
1077
DataproviderObject modifiedStructureType = this.plugin.retrieveObjectForModification(
1078            request.path().getPrefix(6).getChild(request.path().getBase())
1079        );
1080        if(modificationRequest.attributeNames().contains("name")) {
1081            modifiedStructureType.clearValues("name").addAll(modificationRequest.values("name"));
1082        }
1083        if(modificationRequest.attributeNames().contains("annotation")) {
1084            this.replaceElementAnnotation(
1085                modifiedStructureType,
1086                (String JavaDoc)modificationRequest.values("annotation").get(0)
1087            );
1088        }
1089        if(modificationRequest.attributeNames().contains("elementOrder")) {
1090            modifiedStructureType.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
1091        }
1092    }
1093        
1094    //-------------------------------------------------------------------------
1095
public void replaceOperationTag(
1096        ServiceHeader header,
1097        DataproviderRequest request
1098    ) throws ServiceException {
1099        DataproviderObject modificationRequest = request.object();
1100        // The editable element and the (basedOn) element have the same qualifier
1101
DataproviderObject modifiedOperationTag = this.plugin.retrieveObjectForModification(
1102            request.path().getPrefix(6).getChild(request.path().getBase())
1103        );
1104        if(modificationRequest.attributeNames().contains("name")) {
1105            modifiedOperationTag.clearValues("name").addAll(modificationRequest.values("name"));
1106        }
1107        if(modificationRequest.attributeNames().contains("annotation")) {
1108            this.replaceElementAnnotation(
1109                modifiedOperationTag,
1110                (String JavaDoc)modificationRequest.values("annotation").get(0)
1111            );
1112        }
1113        if(modificationRequest.attributeNames().contains("elementOrder")) {
1114            modifiedOperationTag.clearValues("elementOrder").addAll(modificationRequest.values("elementOrder"));
1115        }
1116        if(modificationRequest.attributeNames().contains("tagValue")) {
1117            modifiedOperationTag.clearValues("tagValue").addAll(modificationRequest.values("tagValue"));
1118        }
1119    }
1120        
1121    //-------------------------------------------------------------------------
1122
// Members
1123
//-------------------------------------------------------------------------
1124
private final Model_1_0 model;
1125    private final OpenCrxKernel_1 plugin;
1126    private final RequestCollection delegation;
1127    private final RefPackage_1_0 rootPkg;
1128    
1129    private static final String JavaDoc[] PARAMETER_DIRECTIONS = {"N/A", "in", "out", "inout", "return"};
1130    private static final String JavaDoc[] MULTIPLICITIES = {"N/A", "0..*", "0..1", "1", "1..*", "set", "sparsearray"};
1131        
1132}
1133
1134//--- End of File -----------------------------------------------------------
1135
Popular Tags