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.BSServiceImplementationGenerator;
023:
024: /** This definition is responsible for invocation of the SystemCore generator */
025: public class ServiceImplementationGeneratorInvocationDefinition extends
026: ToolInvocationDefinition {
027: private String mServiceRef = null;
028: private String mType = null;
029: private BSServiceImplementationGenerator mGenerator = null;
030:
031: /** Public constructor for the invocation */
032: public ServiceImplementationGeneratorInvocationDefinition(
033: MetaBossBuilderTask pOwnerTask) {
034: super (pOwnerTask,
035: "Generate implementation 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 super .getToolInvocationName();
042: return "Generate " + getType()
043: + " implementation code for the " + getServiceRef()
044: + " service";
045: }
046:
047: /** Setter for the ServiceRef attribute */
048: public void setServiceRef(String pServiceRef) {
049: mServiceRef = pServiceRef;
050: }
051:
052: /** Getter for the ServiceRef attribute */
053: public String getServiceRef() {
054: if (mServiceRef == null)
055: throw new BuildException(
056: "Missing 'ServiceRef' attribute, which is mandatory for Service implementation generator invocation.");
057: return mServiceRef;
058: }
059:
060: /** Setter for the Type attribute */
061: public void setType(String pType) {
062: mType = pType;
063: }
064:
065: /** Getter for the Type attribute */
066: public String getType() {
067: if (mType == null)
068: throw new BuildException(
069: "Missing 'Type' attribute, which is mandatory for generator invocation.");
070: return mType;
071: }
072:
073: /** Setter for the Generator */
074: public void setGenerator(BSServiceImplementationGenerator pGenerator) {
075: mGenerator = pGenerator;
076: }
077:
078: /** Getter for the Generator */
079: public BSServiceImplementationGenerator getGenerator() {
080: if (mGenerator == null)
081: throw new BuildException(
082: "Missing Generator service, which is mandatory for generation.");
083: return mGenerator;
084: }
085:
086: /** Overridden to compare details of the invocation */
087: public boolean equals(Object pOther) {
088: if (this == pOther)
089: return true;
090: if (pOther instanceof ServiceImplementationGeneratorInvocationDefinition) {
091: ServiceImplementationGeneratorInvocationDefinition lOther = (ServiceImplementationGeneratorInvocationDefinition) pOther;
092: if (getServiceRef().equals(lOther.getServiceRef())
093: && getType().equals(lOther.getType()))
094: return true;
095: }
096: return false;
097: }
098:
099: /** This method will have to invoke the generator */
100: public void invoke() throws BuildException {
101: try {
102: // Direct invocation
103: getGenerator().generateSourceCodeForService(
104: getOwnerTask().getGenDir().getAbsolutePath(),
105: getServiceRef());
106: } catch (BSException e) {
107: throw new BuildException(
108: "Unable to run generator for the service implementation. Caught BSException: "
109: + e.getMessage());
110: }
111: }
112: }
|