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.services.codegeneration.servicemoduleadaptergenerator.soap.tomcatjwsdp;
016:
017: import java.util.HashMap;
018: import java.util.Map;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022: import javax.naming.NamingException;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: import com.metaboss.enterprise.bs.BSException;
028: import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
029: import com.metaboss.enterprise.bs.BSServiceProviderException;
030: import com.metaboss.sdlctools.frameworks.generation.internal.GenerationPlan;
031: import com.metaboss.sdlctools.frameworks.generation.internal.Generator;
032: import com.metaboss.sdlctools.models.ModelRepository;
033: import com.metaboss.sdlctools.models.ModelRepositoryException;
034: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
036: import com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator;
037: import com.metaboss.sdlctools.services.codegeneration.CodeGenerationStylesheetAccessor;
038: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDataDictionaryStylesheet;
039: import com.metaboss.sdlctools.services.codegenerationstylesheet.STServicemoduleStylesheet;
040: import com.metaboss.util.DirectoryUtils;
041:
042: /** Generator of adapter from Apache Tomcat SOAP server using Sun's Java Web Servies Development Pack */
043: public class BSAdapterGeneratorImpl implements BSAdapterGenerator {
044: // Commons Logging instance.
045: private static final Log sLogger = LogFactory
046: .getLog(BSAdapterGeneratorImpl.class);
047: // Class name of the generated internal class
048: private static final String sXMLUtilitiesClassName = "XMLUtilities";
049: // Default context to pass to every generator
050: private Map mDefaultContext = new HashMap();
051:
052: public BSAdapterGeneratorImpl(java.util.Hashtable pEnvironment) {
053: }
054:
055: /* @return array of names of adapters, which are required by this adapter,
056: * may be zero length array if this adapter is not relying on any other one. */
057: public String[] getRequiredAdapters() throws BSException {
058: return new String[0];
059: }
060:
061: // Generates servicemodules adapter sourcecode for the particular servicemodule within particular enterprise
062: public void generateSourceCodeForServicemodule(
063: String pDestinationDirectory, String pServicemoduleRef)
064: throws BSException {
065: try {
066: sLogger
067: .info("Generating SOAP adapter implementation based on Tomcat and JWSDP for "
068: + pServicemoduleRef + " servicemodule...");
069: // Obtain model repository
070: Context lContext = new InitialContext();
071: ModelRepository lModelRepository = (ModelRepository) lContext
072: .lookup(ModelRepository.COMPONENT_URL);
073: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
074: .getDefaultModelExtent();
075: Servicemodule lServicemodule = (Servicemodule) lMetaBossModelPackage
076: .getModelElement().getByRef(pServicemoduleRef);
077: GenerationPlan lGenerationPlan = new GenerationPlanImpl(); // Set of generation instructions
078: // Ensure that directory exists
079: DirectoryUtils
080: .ensureThereIsDirectory(pDestinationDirectory);
081: // First do the copying of resources
082: long lNumberOfCreatedFiles = Generator.doCopying(
083: pDestinationDirectory, lGenerationPlan);
084: // Now perform generation
085: lNumberOfCreatedFiles += Generator
086: .doGenerationForElementTree(pDestinationDirectory,
087: lServicemodule, lGenerationPlan,
088: mDefaultContext);
089: sLogger.info("Created " + lNumberOfCreatedFiles
090: + " files. Generation complete.");
091: } catch (ModelRepositoryException e) {
092: throw new BSServiceProviderException(
093: "Caught repository exeption. Generation aborted.",
094: e);
095: } catch (NamingException e) {
096: throw new BSNamingAndDirectoryServiceInvocationException(
097: "Caught naming exeption. Generation aborted.", e);
098: }
099: }
100:
101: /* Returns the name of the package where adapter code is generated to */
102: public String getPackageNameForServicemoduleServices(
103: String pServicemoduleRef) throws BSException {
104: // This is a standard adapter - so stylesheet dictates the package name
105: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
106: .getServicemoduleStylesheet(pServicemoduleRef);
107: return lServicemoduleStylesheet.getAdaptersRootPackageName()
108: + ".soap.tomcatjwsdp.services."
109: + lServicemoduleStylesheet.getSystemSubPackageName();
110: }
111:
112: public String getPackageNameForServicemoduleEventPublishers(
113: String pServicemoduleRef) throws BSException {
114: // This is a standard adapter - so stylesheet dictates the package name
115: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
116: .getServicemoduleStylesheet(pServicemoduleRef);
117: return lServicemoduleStylesheet.getAdaptersRootPackageName()
118: + ".soap.tomcatjwsdp.eventpublishers."
119: + lServicemoduleStylesheet.getSystemSubPackageName();
120: }
121:
122: /** Generates adapter implementation sourcecode for the particular data dictionary
123: * @param pGenerationDirectoryPath directory to generate code to
124: * @param pDataDictionaryRef identifier of the datadictionary to generate the code for
125: */
126: public void generateSourceCodeForDataDictionary(
127: String pGenerationDirectoryPath, String pDataDictionaryRef)
128: throws BSException {
129: //TODO: Generate
130: // throw new BSUnsupportedOperationException("Opperation generateSourceCodeForDataDictionary() is not yet supported.");
131: }
132:
133: /** Returns the name of the package where adapter code is generated to
134: * @param pDataDictionaryRef identifier of the datadictionary to generate the code for
135: */
136: public String getPackageNameForDataDictionary(
137: String pDataDictionaryRef) throws BSException {
138: STDataDictionaryStylesheet lDataDictionaryStylesheet = CodeGenerationStylesheetAccessor
139: .getDataDictionaryStylesheet(pDataDictionaryRef);
140: return lDataDictionaryStylesheet.getAdaptersRootPackageName()
141: + ".soap.tomcatjwsdp";
142: }
143: }
|