01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.models.impl.metabossmodel;
16:
17: import javax.naming.Context;
18: import javax.naming.InitialContext;
19: import javax.naming.NamingException;
20:
21: import com.metaboss.sdlctools.models.ModelAlreadyLoadedException;
22: import com.metaboss.sdlctools.models.ModelRepository;
23: import com.metaboss.sdlctools.models.ModelRepositoryException;
24: import com.metaboss.sdlctools.models.ModelRepositoryNotFoundException;
25:
26: /** This is a utility class which creates MetaBoss UML Profile in the specified model */
27: public final class MetaBossUMLProfileCreator {
28: // This clas is used to pass down the context of the conversion
29: private static class ConversionContext {
30: public ModelRepository mModelRepository = null;
31: public String mTargetModelName = null;
32: public org.omg.uml.UmlPackage mUMLModelExtent = null;
33: public org.omg.uml.modelmanagement.Model mEnterpriseModel = null;
34: /** Stereotype used to mark the profile package */
35: public org.omg.uml.foundation.core.Stereotype mProfilePackageStereotype = null;
36: public org.omg.uml.modelmanagement.UmlPackage mMetaBossModelProfilePackage = null;
37: public UMLStylesheet.UMLMetaBossProfile mMetaBossProfile = null;
38: }
39:
40: public static void doCreation(String pTargetUMLModelName)
41: throws ModelRepositoryException {
42: try {
43: ConversionContext lConversionContext = new ConversionContext();
44: Context lContext = new InitialContext();
45: lConversionContext.mModelRepository = (ModelRepository) lContext
46: .lookup(ModelRepository.COMPONENT_URL);
47: // Create target model package
48: if (lConversionContext.mModelRepository
49: .containsModel(pTargetUMLModelName))
50: throw new ModelAlreadyLoadedException(
51: pTargetUMLModelName);
52: try {
53: lConversionContext.mModelRepository.createModel(
54: pTargetUMLModelName, null,
55: ModelRepository.METAMODEL_NAME_UML, null);
56: lConversionContext.mTargetModelName = pTargetUMLModelName;
57: lConversionContext.mModelRepository.beginTransaction();
58: lConversionContext.mUMLModelExtent = (org.omg.uml.UmlPackage) lConversionContext.mModelRepository
59: .getModelExtent(lConversionContext.mTargetModelName);
60: lConversionContext.mEnterpriseModel = lConversionContext.mUMLModelExtent
61: .getModelManagement().getModel().createModel();
62: lConversionContext.mEnterpriseModel
63: .setName(UMLStylesheet.mModelName);
64: // Create standard MetaBoss profile
65: lConversionContext.mMetaBossProfile = UMLStylesheet
66: .createMetaBossProfile(
67: lConversionContext.mModelRepository,
68: lConversionContext.mEnterpriseModel);
69: lConversionContext.mModelRepository.commitTransaction();
70: } finally {
71: if (lConversionContext.mModelRepository
72: .isInTransaction())
73: lConversionContext.mModelRepository
74: .rollbackTransaction();
75: }
76: } catch (NamingException e) {
77: throw new ModelRepositoryNotFoundException(e);
78: }
79: }
80: }
|