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 java.util.Collection;
018: import java.util.Properties;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022: import javax.naming.NamingException;
023:
024: import org.apache.tools.ant.BuildException;
025:
026: import com.metaboss.enterprise.bs.BSException;
027: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
028: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
029: import com.metaboss.sdlctools.services.codegeneration.BSGenericGenerator;
030: import com.metaboss.util.ObjectUtils;
031:
032: /** This definition is responsible for invocation of the Generic generator */
033: public class GenericGeneratorInvocationDefinition extends
034: ToolInvocationDefinition {
035: private String mPlanName = null;
036: private Collection mModelElements = null;
037: private Properties mInvocationParameters = new Properties();
038:
039: /** Public constructor for the invocation */
040: public GenericGeneratorInvocationDefinition(
041: MetaBossBuilderTask pOwnerTask) {
042: super (pOwnerTask,
043: "Generate code as per plan for one or more model elements");
044: }
045:
046: /** The setter for the "planname" attribute */
047: public void setPlanName(String pPlanName) {
048: mPlanName = pPlanName;
049: }
050:
051: /** The getter for the "planname" attribute. */
052: public String getPlanName() {
053: if (mPlanName == null)
054: throw new BuildException(
055: "Missing 'PlanName' attribute, which is mandatory for generator invocation.");
056: return mPlanName;
057: }
058:
059: /** The setter for the model elements to use in generation */
060: public void setModelElements(Collection pModelElements) {
061: mModelElements = pModelElements;
062: }
063:
064: /** The getter for the "planname" attribute. */
065: public Collection getModelElements() {
066: if (mModelElements == null)
067: throw new BuildException(
068: "Missing 'ModelElements' collection, which is mandatory for generator invocation.");
069: return mModelElements;
070: }
071:
072: /** The setter for the model elements to use in generation */
073: public void addInvocationParameter(String pParameName,
074: String pParamValue) {
075: mInvocationParameters.setProperty(pParameName, pParamValue);
076: }
077:
078: /** Returns the set of zero or more parameters to be passed to the tool when it is invoked */
079: protected Properties getInvocationParameters() {
080: return mInvocationParameters;
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 GenericGeneratorInvocationDefinition) {
088: GenericGeneratorInvocationDefinition lOther = (GenericGeneratorInvocationDefinition) pOther;
089: if (!ObjectUtils.equals(mPlanName, lOther.mPlanName))
090: return false;
091: if (!ObjectUtils.equals(mModelElements,
092: lOther.mModelElements))
093: return false;
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: // Allow to look for the data type classes in the destination class ditectory
102: String lOriginalProperty = System
103: .setProperty(
104: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
105: getOwnerTask().getClassDir().getAbsolutePath());
106: // Direct invocation
107: try {
108: Context lContext = new InitialContext();
109: BSGenericGenerator lGenerator = (BSGenericGenerator) lContext
110: .lookup(BSGenericGenerator.COMPONENT_URL);
111: lGenerator.generateDirectoryAsPerPlan(getOwnerTask()
112: .getGenDir().getAbsolutePath(), getPlanName(),
113: getModelElements(), getInvocationParameters());
114: } catch (NamingException e) {
115: throw new BuildException(
116: "Unable to locate generic generator. Caught NamingException: "
117: + e.getMessage());
118: } catch (BSException e) {
119: throw new BuildException(
120: "Unable to run generic generator. Caught BSException: "
121: + e.getMessage());
122: } finally {
123: if (lOriginalProperty != null)
124: System
125: .setProperty(
126: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
127: lOriginalProperty);
128: else
129: System
130: .getProperties()
131: .remove(
132: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath");
133: }
134: }
135: }
|