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.BSAdapterGenerator;
023: import com.metaboss.util.ObjectUtils;
024:
025: /** This definition is responsible for invocation of the SystemCore generator */
026: public class AdapterGeneratorInvocationDefinition extends
027: ToolInvocationDefinition {
028: private String mServicemoduleRef = null;
029: private String mDataDictionaryRef = null;
030: private String mType = null;
031: private BSAdapterGenerator mGenerator = null;
032:
033: /** Public constructor for the invocation */
034: public AdapterGeneratorInvocationDefinition(
035: MetaBossBuilderTask pOwnerTask) {
036: super (pOwnerTask, "Generate adapter 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 "Generate " + getType() + " adapter code for the "
043: + getServicemoduleRef() + " servicemodule";
044: else if (mType != null && mDataDictionaryRef != null)
045: return "Generate " + getType() + " adapter code for the "
046: + getDataDictionaryRef() + " data dictionary";
047: return super .getToolInvocationName();
048: }
049:
050: /** Setter for the ServicemoduleRef attribute */
051: public void setServicemoduleRef(String pServicemoduleRef) {
052: mServicemoduleRef = pServicemoduleRef;
053: }
054:
055: /** Setter for the DataDictionaryRef attribute */
056: public void setDataDictionaryRef(String pDataDictionaryRef) {
057: mDataDictionaryRef = pDataDictionaryRef;
058: }
059:
060: /** Getter for the ServicemoduleRef attribute */
061: public String getServicemoduleRef() {
062: return mServicemoduleRef;
063: }
064:
065: /** Getter for the DataDictionaryRef attribute */
066: public String getDataDictionaryRef() {
067: return mDataDictionaryRef;
068: }
069:
070: /** Setter for the Type attribute */
071: public void setType(String pType) {
072: mType = pType;
073: }
074:
075: /** Getter for the Type attribute */
076: public String getType() {
077: if (mType == null)
078: throw new BuildException(
079: "Missing 'Type' attribute, which is mandatory for generator invocation.");
080: return mType;
081: }
082:
083: /** Setter for the Generator */
084: public void setGenerator(BSAdapterGenerator pGenerator) {
085: mGenerator = pGenerator;
086: }
087:
088: /** Getter for the Generator */
089: public BSAdapterGenerator getGenerator() {
090: if (mGenerator == null)
091: throw new BuildException(
092: "Missing Generator service, which is mandatory for generation.");
093: return mGenerator;
094: }
095:
096: /** Overridden to compare details of the invocation */
097: public boolean equals(Object pOther) {
098: if (this == pOther)
099: return true;
100: if (pOther instanceof AdapterGeneratorInvocationDefinition) {
101: AdapterGeneratorInvocationDefinition lOther = (AdapterGeneratorInvocationDefinition) pOther;
102: if (ObjectUtils.equals(getServicemoduleRef(), lOther
103: .getServicemoduleRef())
104: && ObjectUtils.equals(getDataDictionaryRef(),
105: lOther.getDataDictionaryRef())
106: && ObjectUtils.equals(getType(), 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: // Allow to look for the data type classes in the destination class ditectory
115: String lOriginalProperty = System
116: .setProperty(
117: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
118: getOwnerTask().getClassDir().getAbsolutePath());
119: // Run inprocess
120: try {
121: if (getServicemoduleRef() != null)
122: getGenerator().generateSourceCodeForServicemodule(
123: getOwnerTask().getGenDir().getAbsolutePath(),
124: getServicemoduleRef());
125: else if (getDataDictionaryRef() != null)
126: getGenerator().generateSourceCodeForDataDictionary(
127: getOwnerTask().getGenDir().getAbsolutePath(),
128: getDataDictionaryRef());
129: else
130: throw new BuildException(
131: "Missing either 'ServicemoduleRef' or 'DataDictionaryRef' attribute. One and only one of them must be defined for generator invocation.");
132: } catch (BSException e) {
133: throw new BuildException(
134: "Unable to run generator for the adapter. Caught BSException: "
135: + e.getMessage());
136: } finally {
137: if (lOriginalProperty != null)
138: System
139: .setProperty(
140: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
141: lOriginalProperty);
142: else
143: System
144: .getProperties()
145: .remove(
146: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath");
147: }
148: }
149: }
|