001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.xpdl.model.application;
046:
047: import org.obe.xpdl.PackageVisitor;
048: import org.obe.xpdl.model.XPDLProperties;
049: import org.obe.xpdl.model.data.ExternalReference;
050: import org.obe.xpdl.model.data.FormalParameter;
051: import org.obe.xpdl.model.misc.AbstractWFElement;
052: import org.obe.xpdl.model.misc.Invokable;
053:
054: import java.beans.PropertyVetoException;
055: import java.util.Arrays;
056:
057: /**
058: * Implementation of the XPDL Application element.
059: *
060: * @author Adrian Price
061: */
062: public final class Application extends AbstractWFElement implements
063: Invokable {
064: private static final long serialVersionUID = -8057216217821358435L;
065: public static final String EXTERNAL_REFERENCE = XPDLProperties.EXTERNAL_REFERENCE;
066: public static final String FORMAL_PARAMETER = XPDLProperties.FORMAL_PARAMETER;
067: private static final FormalParameter[] EMPTY_FORMAL_PARM = {};
068: private static final String[] _indexedPropertyNames = { FORMAL_PARAMETER };
069: private static final Object[] _indexedPropertyValues = { EMPTY_FORMAL_PARM };
070: private static final int FORMAL_PARAMETER_IDX = 0;
071:
072: private ExternalReference _externalReference;
073: private FormalParameter[] _formalParameter = EMPTY_FORMAL_PARM;
074:
075: public Application() {
076: super (_indexedPropertyNames, _indexedPropertyValues);
077: }
078:
079: /**
080: * Construct a new application.
081: *
082: * @param id The application id
083: * @param name The application name
084: */
085: public Application(String id, String name) {
086: super (_indexedPropertyNames, _indexedPropertyValues, id, name);
087: }
088:
089: public void accept(PackageVisitor visitor) {
090: visitor.visit(this );
091: for (int i = 0; i < _formalParameter.length; i++)
092: _formalParameter[i].accept(visitor);
093: }
094:
095: public void add(FormalParameter formalParameter)
096: throws PropertyVetoException {
097:
098: _formalParameter = (FormalParameter[]) add(
099: FORMAL_PARAMETER_IDX, formalParameter);
100: }
101:
102: public void remove(FormalParameter formalParameter)
103: throws PropertyVetoException {
104:
105: _formalParameter = (FormalParameter[]) remove(
106: FORMAL_PARAMETER_IDX, formalParameter);
107: }
108:
109: /**
110: * Return a List of all FormalParameters for the tool.
111: *
112: * @return A List of FormalParameter objects
113: */
114: public FormalParameter[] getFormalParameter() {
115: return (FormalParameter[]) get(FORMAL_PARAMETER_IDX);
116: }
117:
118: public FormalParameter getFormalParameter(int i) {
119: return _formalParameter[i];
120: }
121:
122: public FormalParameter getFormalParameter(String id) {
123: if (_formalParameter != null) {
124: for (int i = 0; i < _formalParameter.length; i++) {
125: FormalParameter fp = _formalParameter[i];
126: if (fp.getId().equals(id))
127: return fp;
128: }
129: }
130: return null;
131: }
132:
133: public void setFormalParameter(FormalParameter[] formalParameters)
134: throws PropertyVetoException {
135:
136: set(
137: FORMAL_PARAMETER_IDX,
138: _formalParameter = formalParameters == null ? EMPTY_FORMAL_PARM
139: : formalParameters);
140: }
141:
142: public void setFormalParameter(int i,
143: FormalParameter formalParameter)
144: throws PropertyVetoException {
145:
146: set(FORMAL_PARAMETER_IDX, i, formalParameter);
147: }
148:
149: /**
150: * Get an ExternalReference for the tool. This may be used if the tool is
151: * accessible through a URI (for example, a web service). This method may
152: * return null if the formal parameters are specified.
153: *
154: * @return The ExternalReference
155: */
156: public ExternalReference getExternalReference() {
157: return _externalReference;
158: }
159:
160: /**
161: * Set an ExternalReference for the tool. This may be used if the tool is
162: * accessible through a URI (for example, a web service).
163: *
164: * @param externalReference The ExternalReference
165: */
166: public void setExternalReference(ExternalReference externalReference) {
167: _externalReference = externalReference;
168: _formalParameter = null;
169: }
170:
171: public String toString() {
172: return "Application[id="
173: + getId()
174: + ", name="
175: + getName()
176: + ", formalParameters="
177: + (_formalParameter == null ? null : Arrays
178: .asList(_formalParameter))
179: + ", externalReference=" + _externalReference + ']';
180: }
181: }
|