1 package xdoclet.sdk.xgg;
2
3 import java.beans.Introspector;
4 import java.util.ArrayList;
5 import java.util.Iterator;
6 import java.util.List;
7
8 import xdoclet.sdk.xgg.binding.Attribute;
9 import xdoclet.sdk.xgg.binding.Cardinality;
10 import xdoclet.sdk.xgg.binding.Child;
11
12 /***
13 * This class represents a method in the generated sources. It holds information
14 * about what versions of a DTD/XSD it is valid for.
15 *
16 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
17 * @author <a href="mailto:letiemble at users.sourceforge.net">Laurent Etiemble</a>
18 * @created 7 mai 2003
19 * @version $Revision: 1.4 $
20 */
21 public final class MergedMethod {
22 private final List _children = new ArrayList();
23 private final boolean _isAttribute;
24 private int _index;
25
26
27 /***
28 * Constructor for the MergedMethod object
29 *
30 * @param child Description of the Parameter
31 */
32 public MergedMethod(Child child) {
33 _isAttribute = child.isAttribute();
34 addChild(child);
35 }
36
37
38 /***
39 * Adds a child to this method model
40 *
41 * @param child The child to add
42 */
43 public void addChild(Child child) {
44 if (_isAttribute != child.isAttribute()) {
45 throw new IllegalStateException("Panic! Can't be both attribute and element!");
46 }
47 _children.add(child);
48 }
49
50
51 /***
52 * Gets the cardinality related to the first child
53 *
54 * @return The cardinality holder
55 */
56 public Cardinality getCardinality() {
57 Child child0 = (Child) getChildren().get(0);
58 return child0.getCardinality();
59 }
60
61
62 /***
63 * Gets all the children.
64 *
65 * @return a Collection of {@link Child}.
66 */
67 public List getChildren() {
68 return _children;
69 }
70
71
72 /***
73 * Gets the Java name of the first child
74 *
75 * @return The Java name
76 */
77 public String getJavaName() {
78 Child child0 = (Child) getChildren().get(0);
79 return child0.getJavaName();
80 }
81
82
83 /***
84 * Gets the Java type of the first child
85 *
86 * @return The Java type
87 */
88 public String getJavaType() {
89 Child child0 = (Child) getChildren().get(0);
90 return child0.getJavaType();
91 }
92
93
94 /***
95 * Gets the Java name of the property extracted from the Java name
96 *
97 * @return The Java name of the property
98 */
99 public String getJavaVariableName() {
100 return Introspector.decapitalize(getJavaName());
101 }
102
103
104 /***
105 * Gets the regular expression pattern used for validation
106 *
107 * @return The regular expression pattern
108 */
109 public String getRegexp() {
110 Child child0 = (Child) getChildren().get(0);
111 if (child0.isAttribute()) {
112 return ((Attribute) child0).getRegexp();
113 }
114 return null;
115 }
116
117
118 /***
119 * This will return the XML name of the first child. This should
120 * be the actual XML name of the first child as would be seen in an XML
121 * document.
122 *
123 * @return the XML name of the first child.
124 */
125 public String getXmlName() {
126 Child child0 = (Child) getChildren().get(0);
127 return child0.getXmlName();
128 }
129
130
131 /***
132 * Returns whether or not this sub element is an attribute
133 *
134 * @return True if it is an attribute
135 */
136 public boolean isAttribute() {
137 Child child0 = (Child) getChildren().get(0);
138 return child0.isAttribute();
139 }
140
141
142 /***
143 * Returns true if this child is a many element. Considered to be true
144 * if at least one of the children (from various versions) are many.
145 *
146 * @return true if this method corresponds to a many child.
147 */
148 public boolean isMany() {
149 boolean result = false;
150 for (Iterator iterator = getChildren().iterator(); iterator.hasNext(); ) {
151 Child child = (Child) iterator.next();
152 if (child.isMany()) {
153 result = true;
154 break;
155 }
156 }
157 return result;
158 }
159
160 public void setIndex( int index ) {
161 _index = index;
162 }
163
164 public int getIndex() {
165 return _index;
166 }
167 }
This page was automatically generated by Maven