01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.drapgen.ast;
17:
18: import java.util.List;
19:
20: import nu.xom.Elements;
21:
22: import static org.directwebremoting.drapgen.ast.SerializationStrings.*;
23:
24: /**
25: * An abstract parent for {@link Method}s and {@link Constructor}s
26: * @author Joe Walker [joe at getahead dot ltd dot uk]
27: */
28: public abstract class Subroutine extends Element {
29: /**
30: * All {@link Subroutine}s need a parent {@link Type}
31: * @param parent the type of which we are a part
32: */
33: protected Subroutine(Type parent) {
34: if (parent == null) {
35: throw new NullPointerException("parent");
36: }
37:
38: this .parent = parent;
39: }
40:
41: /**
42: * @return the parameters
43: */
44: public List<Parameter> getParameters() {
45: return parameters;
46: }
47:
48: /**
49: * @param parameters the parameters to set
50: */
51: public void setParameters(List<Parameter> parameters) {
52: this .parameters = parameters;
53: }
54:
55: /**
56: * Create a XOM Element from this
57: * @return a Element representing this Type
58: */
59: protected nu.xom.Element toXomElement(String name) {
60: nu.xom.Element element = new nu.xom.Element(name);
61: writeDocumentation(element);
62:
63: for (Parameter parameter : parameters) {
64: element.appendChild(parameter.toXomElement(PARAM));
65: }
66:
67: return element;
68: }
69:
70: /**
71: * Load this type with data from the given document
72: * @param element The element to load from
73: */
74: protected void fromXomDocument(nu.xom.Element element) {
75: readDocumentation(element);
76:
77: Elements childElements = element.getChildElements(PARAM);
78: parameters.clear();
79: for (int i = 0; i < childElements.size(); i++) {
80: nu.xom.Element childElement = childElements.get(i);
81: Parameter parameter = new Parameter(getParent()
82: .getProject());
83: parameter.fromXomDocument(childElement);
84: parameters.add(parameter);
85: }
86: }
87:
88: /**
89: * @return the parent
90: */
91: public Type getParent() {
92: return parent;
93: }
94:
95: private final Type parent;
96:
97: private List<Parameter> parameters;
98: }
|