01: package com.peewee.pamda.mda;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.List;
06:
07: import org.apache.commons.jxpath.ri.compiler.Expression.ValueIterator;
08:
09: import com.pavelvlasov.uml.Association;
10: import com.pavelvlasov.uml.AssociationEnd;
11: import com.pavelvlasov.uml.TaggedValue;
12: import com.pavelvlasov.uml.TaggedValues;
13:
14: /**
15: * @author Peter Welkenbach
16: * @since 26.01.2004
17: */
18: public class ObjectTypeHelper {
19:
20: public static int getParamCount(ValueIterator list) {
21: if (list == null)
22: return 0;
23:
24: int i = 0;
25: while (list.hasNext()) {
26: list.next();
27: i++;
28: }
29: return i;
30: }
31:
32: /**
33: *
34: * @param list input unordered Collection of AssociationEnd objects
35: * @return new list ordered by value of tagged value <order>
36: */
37: public static Collection getOrderedNestedAssociations(
38: ValueIterator list) throws Exception {
39: int count = 30;
40: Object[] items = new Object[count];
41:
42: List newList = new ArrayList();
43:
44: while (list.hasNext()) {
45: AssociationEnd theEnd = (AssociationEnd) list.next();
46: Association theAssoc = theEnd.getAssociation();
47:
48: TaggedValues tags = theAssoc.getToolTaggedValues();
49: TaggedValue value = tags.getValue("ea_type");
50:
51: if ((value != null)
52: && (value.getValue().equalsIgnoreCase("Nesting"))) {
53: TaggedValue value2 = tags.getValue("order");
54:
55: if (value2 == null) {
56: System.err
57: .println("WARNING: Missing tagged value <order> for classifier <"
58: + theEnd.getOtherEnd()
59: .getClassifier()
60: .getStereotype() + ">");
61: } else {
62: String orderValue = value2.getValue();
63: int idx = Integer.parseInt(orderValue);
64: items[idx] = theEnd;
65: }
66: }
67: }
68:
69: for (int i = 0; i < count; i++) {
70: if (items[i] != null)
71: newList.add(items[i]);
72: }
73:
74: return newList;
75: }
76:
77: } // class
|