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.BSServiceDistributionGenerator;
023: import com.metaboss.util.ObjectUtils;
024:
025: /** This definition is responsible for invocation of the Servicemodule distribution generator */
026: public class ServiceDistributionGeneratorInvocationDefinition extends
027: ToolInvocationDefinition {
028: private String mServicemoduleRef = null;
029: private String mType = null;
030: private BSServiceDistributionGenerator mGenerator = null;
031:
032: /** Public constructor for the invocation */
033: public ServiceDistributionGeneratorInvocationDefinition(
034: MetaBossBuilderTask pOwnerTask) {
035: super (pOwnerTask,
036: "Generate distribution code for the servicemodule");
037: }
038:
039: // Override to return better description if possible
040: public String getToolInvocationName() {
041: if (mType == null || mServicemoduleRef == null)
042: return super .getToolInvocationName();
043: return "Generate " + getType() + " distribution code for the "
044: + getServicemoduleRef() + " servicemodule";
045: }
046:
047: /** Setter for the ServicemoduleRef attribute */
048: public void setServicemoduleRef(String pServicemoduleRef) {
049: mServicemoduleRef = pServicemoduleRef;
050: }
051:
052: /** Getter for the ServicemoduleRef attribute */
053: public String getServicemoduleRef() {
054: return mServicemoduleRef;
055: }
056:
057: /** Setter for the Type attribute */
058: public void setType(String pType) {
059: mType = pType;
060: }
061:
062: /** Getter for the Type attribute */
063: public String getType() {
064: if (mType == null)
065: throw new BuildException(
066: "Missing 'Type' attribute, which is mandatory for generator invocation.");
067: return mType;
068: }
069:
070: /** Setter for the Generator */
071: public void setGenerator(BSServiceDistributionGenerator pGenerator) {
072: mGenerator = pGenerator;
073: }
074:
075: /** Getter for the Generator */
076: public BSServiceDistributionGenerator getGenerator() {
077: if (mGenerator == null)
078: throw new BuildException(
079: "Missing Generator service, which is mandatory for generation.");
080: return mGenerator;
081: }
082:
083: /** Overridden to compare details of the invocation */
084: public boolean equals(Object pOther) {
085: if (this == pOther)
086: return true;
087: if (pOther instanceof ServiceDistributionGeneratorInvocationDefinition) {
088: ServiceDistributionGeneratorInvocationDefinition lOther = (ServiceDistributionGeneratorInvocationDefinition) pOther;
089: if (ObjectUtils.equals(getServicemoduleRef(), lOther
090: .getServicemoduleRef())
091: && getType().equals(lOther.getType()))
092: return true;
093: }
094: return false;
095: }
096:
097: /** This method will have to invoke the generator */
098: public void invoke() throws BuildException {
099: // Allow to look for the data type classes in the destination class ditectory
100: String lOriginalProperty = System
101: .setProperty(
102: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
103: getOwnerTask().getClassDir().getAbsolutePath());
104: try {
105: // Direct invocation
106: if (getServicemoduleRef() != null)
107: getGenerator()
108: .generateImplementationSourceCodeForServicemodule(
109: getOwnerTask().getGenDir()
110: .getAbsolutePath(),
111: getServicemoduleRef());
112: else
113: throw new BuildException(
114: "Missing ServicemoduleRef attribute. Presence of this attribute is mandatory.");
115: } catch (BSException e) {
116: throw new BuildException(
117: "Unable to run generator for the servicemodule distribution. Caught BSException: "
118: + e.getMessage());
119: } finally {
120: if (lOriginalProperty != null)
121: System
122: .setProperty(
123: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
124: lOriginalProperty);
125: else
126: System
127: .getProperties()
128: .remove(
129: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath");
130: }
131: }
132: }
|