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.client.api.repository;
046:
047: import org.obe.xpdl.model.data.ExternalReference;
048: import org.obe.xpdl.model.data.FormalParameter;
049: import org.xml.sax.EntityResolver;
050:
051: import java.util.Arrays;
052:
053: /**
054: * Describes a user-defined tool agent. Different tool types extend this class
055: * with the additional meta data required to instantiate the tool agent itself.
056: *
057: * @author Adrian Price
058: */
059: public abstract class ToolAgentMetaData extends AbstractMetaData {
060: private static final long serialVersionUID = -429157659267364196L;
061: protected FormalParameter[] _formalParameters;
062:
063: protected ToolAgentMetaData() {
064: }
065:
066: /**
067: * Constructs tool meta-data.
068: *
069: * @param id The tool ID.
070: * @param displayName The display name.
071: * @param description Textual description of this tool.
072: * @param docUrl URL for documentation.
073: * @param author Author's name.
074: * @param threadsafe <code>true</code> if instances of
075: * <code>impClass</code>
076: */
077: protected ToolAgentMetaData(String id, String displayName,
078: String description, String docUrl, String author,
079: boolean threadsafe) {
080:
081: super (id, displayName, description, docUrl, author, threadsafe);
082: }
083:
084: public Object createInstance(EntityResolver entityResolver)
085: throws RepositoryException {
086:
087: // The design pattern for stateless tool agent instantiation requires a
088: // public constructor that accepts the appropriate ToolAgentMetaData subclass.
089: return createInstance(new Object[] { this });
090: }
091:
092: public Object createInstance(EntityResolver entityResolver,
093: Object args) throws RepositoryException {
094:
095: // The design pattern for stateful tool agent instantiation requires a
096: // public constructor that accepts the appropriate ToolAgentMetaData subclass
097: // and (optionally) the parameters to pass to the tool agent.
098: return createInstance(getImplCtorSig().length == 2 ? new Object[] {
099: this , args }
100: : new Object[] { this });
101: }
102:
103: public FormalParameter[] getFormalParameter() {
104: return _formalParameters != null ? _formalParameters
105: : _type == null || !allowInheritance ? null
106: : ((ToolAgentMetaData) _type)
107: .getFormalParameter();
108: }
109:
110: public void setFormalParameter(FormalParameter[] formalParameters) {
111: _formalParameters = formalParameters;
112: }
113:
114: /**
115: * Provides an opportunity for metadata classes to perform post-load
116: * initialization. The <code>ToolAgentFactory</code> calls this method on
117: * each <code>ToolAgentMetaData</code> object registered with it as part
118: * of the final phase of initialization. <em>Client code should not call
119: * this method.</em>
120: */
121: public void init() {
122: }
123:
124: /**
125: * Introspects a reference to an externally defined tool or service. If the
126: * associated tool agent type can handle the reference, the method returns
127: * the meta-data required to instantiate such a tool agent.
128: *
129: * @param extRef The external tool reference.
130: * @param entityResolver
131: * @return Configured tool meta-data, or <code>null</code> if this tool type
132: * cannot handle this reference.
133: */
134: public abstract ToolAgentMetaData introspect(
135: ExternalReference extRef, EntityResolver entityResolver)
136: throws RepositoryException;
137:
138: public String toString() {
139: String className = getClass().getName();
140: className = className.substring(className.lastIndexOf('.') + 1);
141: return className
142: + "[id='"
143: + _id
144: + "',displayName='"
145: + _displayName
146: + "',description='"
147: + _description
148: + "',docUrl='"
149: + _docUrl
150: + "',author='"
151: + _author
152: + "',threadsafe="
153: + _threadsafe
154: + ",type="
155: + _type
156: + ",formalParameters="
157: + (_formalParameters == null ? null : Arrays
158: .asList(_formalParameters)) + ']';
159: }
160: }
|