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;
16:
17: import java.io.InputStream;
18: import java.util.Properties;
19:
20: import com.metaboss.sdlctools.models.ModelRepository;
21:
22: /** Repository factory implementation. Uses static getter, which in turn ensures that there is
23: * one and only one repository open at the time */
24: public class ModelRepositoryFactory implements
25: javax.naming.spi.ObjectFactory {
26: private static final String sUMLMetaModelURIString = "/org/omg/uml/resources/01-02-15_Diff.xml";
27: private static final String sMetaBossMetaModelURIString = "/com/metaboss/sdlctools/models/metabossmodel/MetaBossMOFModel.xmi.xml";
28: private static final String sDefaultMetaBossMetaModelPartitioningPropertiesURIString = "/com/metaboss/sdlctools/models/impl/metabossmodel/defaultmodelstorage.properties";
29:
30: /* Returns the instance of the service */
31: public Object getObjectInstance(Object obj, javax.naming.Name name,
32: javax.naming.Context nameCtx,
33: java.util.Hashtable environment) throws Exception {
34: ModelRepository lRepository = ModelRepositoryImpl
35: .getRepository();
36: // Preload MetaBossMetaModel from the jar itself
37: if (!lRepository
38: .containsMetaModel(ModelRepository.METAMODEL_NAME_METABOSS)) {
39: InputStream lMetaModelInputStream = null;
40: try {
41: lMetaModelInputStream = getClass().getResourceAsStream(
42: sMetaBossMetaModelURIString);
43: String lURL = getClass().getResource(
44: sMetaBossMetaModelURIString).toString();
45: InputStream lDefaultPartitioningPropertiesInputStream = null;
46: try {
47: Properties lDefaultPartitioningProperties = new Properties();
48: lDefaultPartitioningPropertiesInputStream = getClass()
49: .getResourceAsStream(
50: sDefaultMetaBossMetaModelPartitioningPropertiesURIString);
51: lDefaultPartitioningProperties
52: .load(lDefaultPartitioningPropertiesInputStream);
53: lRepository.loadMetaModel(
54: ModelRepository.METAMODEL_NAME_METABOSS,
55: lMetaModelInputStream, lURL,
56: "MetaBossModel",
57: lDefaultPartitioningProperties);
58: } finally {
59: if (lDefaultPartitioningPropertiesInputStream != null)
60: lDefaultPartitioningPropertiesInputStream
61: .close();
62: }
63: } finally {
64: if (lMetaModelInputStream != null)
65: lMetaModelInputStream.close();
66: }
67: }
68: // Preload MetaBossMetaModel from the jar itself
69: if (!lRepository
70: .containsMetaModel(ModelRepository.METAMODEL_NAME_UML)) {
71: InputStream lMetaModelInputStream = null;
72: try {
73: lMetaModelInputStream = getClass().getResourceAsStream(
74: sUMLMetaModelURIString);
75: String lURL = getClass().getResource(
76: sUMLMetaModelURIString).toString();
77: lRepository.loadMetaModel(
78: ModelRepository.METAMODEL_NAME_UML,
79: lMetaModelInputStream, lURL, "UML", null);
80: } finally {
81: if (lMetaModelInputStream != null)
82: lMetaModelInputStream.close();
83: }
84: }
85: return lRepository;
86: }
87: }
|