001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.anttasks.builder.tools;
016:
017: import org.apache.tools.ant.BuildException;
018:
019: import com.metaboss.enterprise.bs.BSException;
020: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
021: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
022: import com.metaboss.sdlctools.services.codegeneration.BSServiceProxyGenerator;
023:
024: /** This definition is responsible for invocation of the SystemCore generator */
025: public class ProxyGeneratorInvocationDefinition extends
026: ToolInvocationDefinition {
027: private String mServicemoduleRef = null;
028: private String mServiceRef = null;
029: private String mType = null;
030: private BSServiceProxyGenerator mGenerator = null;
031:
032: /** Public constructor for the invocation */
033: public ProxyGeneratorInvocationDefinition(
034: MetaBossBuilderTask pOwnerTask) {
035: super (pOwnerTask, "Generate proxy code for the service");
036: }
037:
038: // Override to return better description if possible
039: public String getToolInvocationName() {
040: if (mType != null && mServiceRef != null)
041: return "Generate " + getType() + " proxy code for the "
042: + getServiceRef() + " service";
043: else if (mType != null && mServicemoduleRef != null)
044: return "Generate " + getType() + " proxy code for the "
045: + getServicemoduleRef() + " servicemodule";
046: return super .getToolInvocationName();
047: }
048:
049: /** Setter for the ServicemoduleRef attribute */
050: public void setServicemoduleRef(String pServicemoduleRef) {
051: mServicemoduleRef = pServicemoduleRef;
052: }
053:
054: /** Getter for the ServicemoduleRef attribute */
055: public String getServicemoduleRef() {
056: return mServicemoduleRef;
057: }
058:
059: /** Setter for the ServicemoduleRef attribute */
060: public void setServiceRef(String pServiceRef) {
061: mServiceRef = pServiceRef;
062: }
063:
064: /** Getter for the ServicemoduleRef attribute */
065: public String getServiceRef() {
066: return mServiceRef;
067: }
068:
069: /** Setter for the Type attribute */
070: public void setType(String pType) {
071: mType = pType;
072: }
073:
074: /** Getter for the Type attribute */
075: public String getType() {
076: if (mType == null)
077: throw new BuildException(
078: "Missing 'Type' attribute, which is mandatory for generator invocation.");
079: return mType;
080: }
081:
082: /** Setter for the Generator */
083: public void setGenerator(BSServiceProxyGenerator pGenerator) {
084: mGenerator = pGenerator;
085: }
086:
087: /** Getter for the Generator */
088: public BSServiceProxyGenerator getGenerator() {
089: if (mGenerator == null)
090: throw new BuildException(
091: "Missing Generator service, which is mandatory for generation.");
092: return mGenerator;
093: }
094:
095: /** Overridden to compare details of the invocation */
096: public boolean equals(Object pOther) {
097: if (this == pOther)
098: return true;
099: if (pOther instanceof ProxyGeneratorInvocationDefinition) {
100: ProxyGeneratorInvocationDefinition lOther = (ProxyGeneratorInvocationDefinition) pOther;
101: if (((getServiceRef() == null && lOther.getServiceRef() == null) || getServiceRef()
102: .equals(lOther.getServiceRef()))
103: && ((getServicemoduleRef() == null && lOther
104: .getServicemoduleRef() == null) || getServicemoduleRef()
105: .equals(lOther.getServicemoduleRef()))
106: && getType().equals(lOther.getType()))
107: return true;
108: }
109: return false;
110: }
111:
112: /** This method will have to invoke the generator */
113: public void invoke() throws BuildException {
114: try {
115: if (getServicemoduleRef() != null)
116: getGenerator().generateSourceCodeForServicemodule(
117: getOwnerTask().getGenDir().getAbsolutePath(),
118: getServicemoduleRef());
119: else if (getServiceRef() != null)
120: getGenerator().generateSourceCodeForService(
121: getOwnerTask().getGenDir().getAbsolutePath(),
122: getServiceRef());
123: else
124: throw new BuildException(
125: "Missing 'ServiceRef' and 'ServicemoduleRef' attributes. One of them must be present for generator invocation.");
126: } catch (BSException e) {
127: throw new BuildException(
128: "Unable to run generator for the adapter. Caught BSException: "
129: + e.getMessage());
130: }
131: }
132: }
|