001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file ../GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.classes;
017:
018: import org.griphyn.vdl.classes.*;
019: import java.io.IOException;
020: import java.io.Writer;
021: import java.io.Serializable;
022:
023: /**
024: * This class encapsulates a single formal argument that is passed
025: * from a {@link Derivation} to a {@link Transformation}.
026: *
027: * @author Jens-S. Vöckler
028: * @author Yong Zhao
029: * @version $Revision: 50 $
030: *
031: * @see Value
032: */
033: public class Pass extends VDL implements Cloneable, Serializable {
034: /**
035: * Each actual argument must bind to a formal argument. Binding
036: * is done via the name of the formal argument, as stored in the
037: * binding variable.
038: */
039: private String m_bind;
040:
041: /**
042: * Each actual argument does have a value. This attributes store
043: * the current state of a value.
044: */
045: private Value m_value;
046:
047: /**
048: * Creates and returns a copy of this object.
049: * @return a new instance, semi-deep copy
050: */
051: public Object clone() {
052: return new Pass(this .m_bind, (Value) this .m_value.clone());
053: }
054:
055: /**
056: * Ctor.
057: */
058: public Pass() {
059: super ();
060: }
061:
062: /**
063: * Convenience ctor: Establishes a binding with an empty value.
064: * Note that the value is still null, and must be set explicitely.
065: *
066: * @param bind is the name of the formal argument to bind to.
067: * @see #setValue(Value)
068: */
069: public Pass(String bind) {
070: super ();
071: this .m_bind = bind;
072: }
073:
074: /**
075: * Convencience ctor: Establishes a binding with a value.
076: *
077: * @param bind is the name of the formal argument to bind to.
078: * @param value is the value to pass to a {@link Transformation}.
079: */
080: public Pass(String bind, Value value) {
081: super ();
082: this .m_bind = bind;
083: this .m_value = value;
084: }
085:
086: /**
087: * Accessor: Gets the current bound variable name.
088: *
089: * @return the name of the variable bound to. May return null on an
090: * default constructed object.
091: * @see #setBind( java.lang.String )
092: */
093: public String getBind() {
094: return this .m_bind;
095: }
096:
097: /**
098: * Accessor: Gets the current value to be passed. Note that each
099: * {@link Value} is either a {@link Scalar} or {@link List}.
100: *
101: * @return the value that is to be passed to a {@link Transformation}.
102: * @see #setValue( Value )
103: */
104: public Value getValue() {
105: return this .m_value;
106: }
107:
108: /**
109: * Accessor: Sets a new binding with a formal argument.
110: *
111: * @param bind is the new binding name.
112: * @see #getBind()
113: */
114: public void setBind(String bind) {
115: this .m_bind = bind;
116: }
117:
118: /**
119: * Accessor: Sets a new value for a bound variable.
120: *
121: * @param value is the new value, which can be a {@link Scalar} or
122: * a {@link List}.
123: * @see #getValue()
124: */
125: public void setValue(Value value) {
126: this .m_value = value;
127: }
128:
129: /**
130: * Converts the active state into something meant for human consumption.
131: * The method will be called when recursively traversing the instance
132: * tree.
133: *
134: * @param stream is a stream opened and ready for writing. This can also
135: * be a string stream for efficient output.
136: * @exception IOException if something fishy happens to the stream.
137: */
138: public void toString(Writer stream) throws IOException {
139: // stream.write( escape(this.m_bind) );
140: stream.write(this .m_bind);
141: stream.write('=');
142: this .m_value.toString(stream);
143: }
144:
145: /**
146: * Dump the state of the current element as XML output. This function
147: * traverses all sibling classes as necessary, and converts the data
148: * into pretty-printed XML output. The stream interface should be able
149: * to handle large output efficiently, if you use a buffered writer.
150: *
151: * @param stream is a stream opened and ready for writing. This can also
152: * be a string stream for efficient output.
153: * @param indent is a <code>String</code> of spaces used for pretty
154: * printing. The initial amount of spaces should be an empty string.
155: * The parameter is used internally for the recursive traversal.
156: * @param namespace is the XML schema namespace prefix. If neither
157: * empty nor null, each element will be prefixed with this prefix,
158: * and the root element will map the XML namespace.
159: * @exception IOException if something fishy happens to the stream.
160: */
161: public void toXML(Writer stream, String indent, String namespace)
162: throws IOException {
163: String tag = (namespace != null && namespace.length() > 0) ? namespace
164: + ":pass"
165: : "pass";
166: String newline = System.getProperty("line.separator", "\r\n");
167:
168: // open tag
169: if (indent != null && indent.length() > 0)
170: stream.write(indent);
171: stream.write('<');
172: stream.write(tag);
173: writeAttribute(stream, " bind=\"", this .m_bind);
174: stream.write('>');
175: if (indent != null)
176: stream.write(newline);
177:
178: // write content
179: String newindent = indent == null ? null : indent + " ";
180: this .m_value.toXML(stream, newindent, namespace);
181:
182: // close tag
183: if (indent != null && indent.length() > 0)
184: stream.write(indent);
185: stream.write("</");
186: stream.write(tag);
187: stream.write('>');
188: if (indent != null)
189: stream.write(newline);
190: }
191: }
|