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 org.apache.tools.ant.taskdefs.optional.metaboss;
016:
017: import java.io.File;
018: import java.util.Properties;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022:
023: import org.apache.tools.ant.BuildException;
024:
025: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
026: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
028: import com.metaboss.sdlctools.services.codegeneration.BSServiceDistributionGenerator;
029:
030: /** Special Ant task used to generate servicemodule distribution layer */
031: public class ServicemoduleDistributionGeneratorTask extends
032: MetaBossModelToolTask {
033: private File mDestinationDir = null;
034: private String mRef = null;
035: private String mImplementationName = null;
036:
037: public ServicemoduleDistributionGeneratorTask() {
038: // This task uses existing model
039: super (true);
040: }
041:
042: /** The setter for the "ref" attribute */
043: public void setRef(String pRef) {
044: mRef = pRef;
045: }
046:
047: // The getter for the "Ref" attribute. Passed to the destination application as an argument
048: protected String getRef() {
049: if (mRef == null)
050: throw new BuildException(
051: "Missing 'ref' attribute, which is mandatory for <"
052: + getTaskName() + "> task.");
053: return mRef;
054: }
055:
056: /** The setter for the "destinationdir" attribute */
057: public void setDestinationdir(File pDestinationDir) {
058: mDestinationDir = pDestinationDir;
059: }
060:
061: // The getter for the "destinationdir" attribute
062: protected File getDestinationdir() {
063: if (mDestinationDir == null)
064: throw new BuildException(
065: "Missing 'destinationdir' attribute, which is mandatory for <"
066: + getTaskName() + "> task.");
067: return mDestinationDir;
068: }
069:
070: /** The setter for the "implementationname" attribute */
071: public void setImplementationName(String pImplementationName) {
072: mImplementationName = pImplementationName;
073: }
074:
075: /** The getter for the "implementationname" attribute */
076: public String getImplementationName() {
077: return mImplementationName;
078: }
079:
080: // The method executing the tool
081: public void runTool() throws Exception {
082: // Get the domain and storage technology details
083: ModelElement lModelElement = getModelElement(
084: getRef(),
085: new Class[] {
086: Servicemodule.class,
087: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class });
088:
089: // Get generator and run generation
090: // Get generator and run generation
091: Context lContext = null;
092: // Initialise context with the specified implementation if there is one
093: if (getImplementationName() != null
094: && getImplementationName().equals("default") == false) {
095: Properties lContextProps = new Properties();
096: lContextProps
097: .setProperty(
098: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSServiceDistributionGenerator",
099: "com.metaboss.sdlctools.services.codegeneration.servicedistributiongenerator."
100: + getImplementationName());
101: lContext = new InitialContext(lContextProps);
102: } else
103: lContext = new InitialContext();
104: BSServiceDistributionGenerator lGenerator = (BSServiceDistributionGenerator) lContext
105: .lookup(BSServiceDistributionGenerator.COMPONENT_URL);
106:
107: if (lModelElement instanceof Servicemodule)
108: lGenerator
109: .generateImplementationSourceCodeForServicemodule(
110: getDestinationdir().getAbsolutePath(),
111: lModelElement.getRef());
112: else
113: lGenerator.generateImplementationSourceCodeForSystem(
114: getDestinationdir().getAbsolutePath(),
115: lModelElement.getRef());
116: }
117: }
|