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.genericgenerator;
016:
017: import java.io.File;
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import javax.naming.Context;
022: import javax.naming.InitialContext;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.apache.log4j.PropertyConfigurator;
027:
028: import com.metaboss.enterprise.BaseException;
029: import com.metaboss.sdlctools.models.ModelRepository;
030: import com.metaboss.sdlctools.models.ModelValidationException;
031: import com.metaboss.sdlctools.services.codegeneration.BSGenericGenerator;
032: import com.metaboss.util.MetaBossSpecificUtils;
033:
034: /*
035: * Created on 23/10/2003
036: *
037: * To change the template for this generated file go to
038: * Window>Preferences>Java>Code Generation>Code and Comments
039: */
040:
041: /**
042: * @author Rost
043: *
044: * To change the template for this generated type comment go to
045: * Window>Preferences>Java>Code Generation>Code and Comments
046: */
047: public class TestHarness {
048: // Commons Logging instance.
049: private static final Log sLogger;
050: static {
051: // Read metaboss installation specific properties
052: MetaBossSpecificUtils.setupSystemProperties();
053: // Configure logger as early as possible
054: PropertyConfigurator.configure(System.getProperties());
055: sLogger = LogFactory.getLog(TestHarness.class);
056: }
057:
058: // Initialise enterprise model properties
059: private static File sEnterpriseModelRootFile = new File(
060: "c:\\MetaBoss-1.4\\example\\EnterpriseModel\\HatMaker\\Model.xml");
061:
062: public static void main(String[] args) {
063: try {
064: ModelRepository lModelRepository = null;
065: try {
066: Context lContext = new InitialContext();
067: lModelRepository = (ModelRepository) lContext
068: .lookup(ModelRepository.COMPONENT_URL);
069: sLogger.info("Opening HatMaker model...");
070: lModelRepository.openModel(sEnterpriseModelRootFile
071: .getAbsolutePath(), sEnterpriseModelRootFile,
072: ModelRepository.METAMODEL_NAME_METABOSS);
073: lModelRepository
074: .setDefaultModel(sEnterpriseModelRootFile
075: .getAbsolutePath());
076: sLogger.info("Testing if we can do generation...");
077: Context ctx = new InitialContext();
078: BSGenericGenerator lGenerator = (BSGenericGenerator) ctx
079: .lookup(BSGenericGenerator.COMPONENT_URL);
080: Map lGenerationContext = new HashMap();
081: // lGenerator.generateAsPerPlan("c:\\temp\\docs","documentation.metadoc",lGenerationContext);
082: lGenerator.generateDirectoryAsPerPlan("c:\\temp\\code",
083: "implementation.enterprise.java.types",
084: lGenerationContext);
085: } finally {
086: if (lModelRepository != null)
087: lModelRepository.close();
088: }
089: } catch (Throwable t) {
090: handleException(t);
091: }
092: }
093:
094: // This helper must be called from all tools when exception has been caught
095: // it will print the exception in the best possible manner
096: static void handleException(Throwable pThrowable) {
097: System.out.println("Caught exception "
098: + pThrowable.getClass().getName());
099: if (pThrowable instanceof BaseException) {
100: pThrowable.printStackTrace(System.out);
101: Throwable t = pThrowable.getCause();
102: while (t != null) {
103: System.out.println();
104: System.out.println();
105: System.out.println("Cause : " + t.getClass().getName());
106: t.printStackTrace(System.out);
107: // Special case for model validation exception - it has explanation
108: if (t instanceof ModelValidationException) {
109: System.out.println(((ModelValidationException) t)
110: .getFullExplanation());
111: break;
112: } else if (t instanceof BaseException) {
113: t = ((BaseException) t).getCause();
114: } else
115: break;
116: }
117: } else {
118: System.out.println(pThrowable.getMessage());
119: pThrowable.printStackTrace(System.out);
120: }
121: }
122: }
|