001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.drapgen.ast;
017:
018: import nu.xom.Attribute;
019:
020: import static org.directwebremoting.drapgen.ast.SerializationStrings.*;
021:
022: /**
023: * @author Joe Walker [joe at getahead dot ltd dot uk]
024: */
025: public class Parameter extends Element {
026: /**
027: * All {@link Parameter}s need a parent {@link Type}
028: * @param project the Project of which we are a part
029: */
030: public Parameter(Project project) {
031: this .project = project;
032: }
033:
034: /**
035: * @return the name
036: */
037: public String getName() {
038: return name;
039: }
040:
041: /**
042: * @param name the name to set
043: */
044: public void setName(String name) {
045: this .name = name;
046: }
047:
048: /**
049: * @return the type
050: */
051: public Type getType() {
052: return type;
053: }
054:
055: /**
056: * @param type the type to set
057: */
058: public void setType(Type type) {
059: this .type = type;
060: }
061:
062: /**
063: * Create a XOM Element from this
064: * @param elementName The name so we can use return type parameters
065: * @return a Element representing this Type
066: */
067: protected nu.xom.Element toXomElement(String elementName) {
068: nu.xom.Element element = new nu.xom.Element(elementName);
069: writeDocumentation(element);
070:
071: if (name != null) {
072: element.addAttribute(new Attribute(NAME, name));
073: }
074:
075: element.addAttribute(new Attribute(TYPE, type.getFullName()));
076:
077: return element;
078: }
079:
080: /**
081: * Load this type with data from the given document
082: * @param element The element to load from
083: */
084: protected void fromXomDocument(nu.xom.Element element) {
085: readDocumentation(element);
086:
087: name = element.getAttributeValue(NAME);
088: type = project.getType(element.getAttributeValue(TYPE));
089: }
090:
091: /* (non-Javadoc)
092: * @see java.lang.Object#toString()
093: */
094: @Override
095: public String toString() {
096: return "(" + type.toString() + " " + name + ")";
097: }
098:
099: private Project project;
100:
101: private String name;
102:
103: private Type type;
104: }
|