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.applications.designstudio.userobjects;
016:
017: import java.io.File;
018:
019: import javax.swing.Icon;
020:
021: import com.metaboss.applications.designstudio.Application;
022: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
023: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
024: import com.metaboss.sdlctools.models.metabossmodel.ModelUtils;
025: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryClass;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryModelPackage;
027: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
028: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryClass;
029: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryModelPackage;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseClass;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
033: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibrary;
034: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryClass;
035: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryModelPackage;
036: import com.metaboss.util.DirectoryUtils;
037:
038: /* MetaBoss model user object */
039:
040: public class ModelUserObject {
041: public static final String MODEL_NAME = "MetaBossMetaModel";
042:
043: private MetaBossModelPackage mPackage = null;
044: private String mFileName = null;
045: private boolean mIsSystem = false;
046:
047: public ModelUserObject(String pFileName, boolean pCreate,
048: boolean pIsSystem) throws Exception {
049: mFileName = pFileName;
050: mIsSystem = pIsSystem;
051:
052: if (pCreate)
053: createModel();
054: else
055: openModel();
056: }
057:
058: public MetaBossModelPackage getPackage() {
059: return mPackage;
060: }
061:
062: public String getModelName() {
063: ModelElement lElement = getRootElement();
064: /*if (lElement instanceof DesignLibrary)
065: return Application.getString("designlib_node");
066: else
067: if (lElement instanceof TechnologyLibrary)
068: return Application.getString("techlib_node");
069: else*/
070: return (lElement != null) ? lElement.getName() : "???";
071: }
072:
073: public String getFileName() {
074: return mFileName;
075: }
076:
077: public ModelElement getRootElement() {
078: ModelElement lElement = null;
079: try {
080: lElement = ModelUtils.getRootElement(getFileName());
081: } catch (Exception e) {
082: e.printStackTrace();
083: }
084: return lElement;
085: }
086:
087: public Icon getModelIcon() {
088: ModelElement lElement = getRootElement();
089: if (lElement != null) {
090: if (lElement instanceof Enterprise)
091: return Application.ENTERPRISE_ICON;
092: else if (lElement instanceof DesignLibrary)
093: return Application.DESIGNLIB_ICON;
094: else if (lElement instanceof TechnologyLibrary)
095: return Application.TECHLIB_ICON;
096: }
097: return null;
098: }
099:
100: public String getToolTip() {
101: String lCaption = "";
102: ModelElement lElement = getRootElement();
103: if (lElement != null) {
104: if (lElement instanceof Enterprise)
105: lCaption = Application.getString("enterprise");
106: else if (lElement instanceof DesignLibrary)
107: lCaption = Application.getString("designlib_node");
108: else if (lElement instanceof TechnologyLibrary)
109: lCaption = Application.getString("techlib_node");
110: }
111: if (lCaption.length() > 0)
112: lCaption += " - ";
113: lCaption += getFileName();
114: return lCaption;
115: }
116:
117: public boolean isModified() {
118: boolean lResult = false;
119: try {
120: lResult = Application.sModelRepository
121: .isModelModified(getFileName());
122: } catch (Exception e) {
123: lResult = false;
124: }
125: return lResult;
126: }
127:
128: public boolean isSystem() {
129: //ModelElement lElement = getRootElement();
130: //return !(lElement!=null && lElement instanceof Enterprise);
131: return mIsSystem;
132: }
133:
134: public boolean isDesignLib() {
135: ModelElement lElement = getRootElement();
136: return (lElement != null && lElement instanceof DesignLibrary);
137: }
138:
139: public boolean isTechLib() {
140: ModelElement lElement = getRootElement();
141: return (lElement != null && lElement instanceof TechnologyLibrary);
142: }
143:
144: // open existing model
145: public void openModel() throws Exception {
146: Application.sModelRepository.openModel(mFileName, new File(
147: mFileName), MODEL_NAME);
148: mPackage = (MetaBossModelPackage) Application.sModelRepository
149: .getModelExtent(mFileName);
150: Application.sModelRepository.registerModelListener(mFileName,
151: Application.sModelListener);
152: }
153:
154: // create new model
155: public void createModel() throws Exception {
156: File lFile = new File(mFileName);
157: DirectoryUtils.ensureNewCleanDirectory(lFile.getParentFile()
158: .getAbsolutePath());
159:
160: Application.sModelRepository.createModel(mFileName, lFile,
161: MODEL_NAME, null);
162: mPackage = (MetaBossModelPackage) Application.sModelRepository
163: .getModelExtent(mFileName);
164: Application.sModelRepository.registerModelListener(mFileName,
165: Application.sModelListener);
166:
167: Application.beginTransaction();
168: try {
169: addEnterprise(mPackage);
170: Application.commit();
171: } finally {
172: Application.checkAndRollback();
173: }
174: }
175:
176: // close model
177: public void closeModel() throws Exception {
178: Application.properties.addToReopen(getFileName());
179: Application.sModelRepository.unregisterModelListener(
180: getFileName(), Application.sModelListener);
181: Application.removeModelErrors(this );
182: Application.fireOnModelClosed(this );
183: Application.sModels.remove(this );
184: Application.fireCloseModel(this );
185: }
186:
187: // add Enterprise into the new model
188: private void addEnterprise(MetaBossModelPackage pRootModel)
189: throws Exception {
190: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
191: .getEnterpriseModel();
192: EnterpriseClass lEntepriseClass = lEnterpriseModelPackage
193: .getEnterprise();
194: DesignLibraryModelPackage lDesignLibraryModelPackage = pRootModel
195: .getDesignLibraryModel();
196: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
197: .getDataDictionaryModel();
198: TechnologyLibraryModelPackage lTechnologyLibraryModelPackage = pRootModel
199: .getTechnologyLibraryModel();
200: DesignLibraryClass lDesignLibraryClass = lDesignLibraryModelPackage
201: .getDesignLibrary();
202: DataDictionaryClass lDataDictionaryClass = lDataDictionaryModelPackage
203: .getDataDictionary();
204: TechnologyLibraryClass lTechnologyLibraryClass = lTechnologyLibraryModelPackage
205: .getTechnologyLibrary();
206:
207: EnterpriseUserObject lEnterprise = EnterpriseUserObject
208: .addNewEnterprise(pRootModel);
209: if (lEnterprise != null) {
210: /*Enterprise lTargetEnterprise = lEnterprise.getEnterprise();
211: // Create and populate data dictionary in the enterprise meta library
212: {
213: DesignLibrary lEntepriseDesignLibrary = lDesignLibraryClass.createDesignLibrary();
214: lEntepriseDesignLibrary.setName("Default");
215: lEntepriseDesignLibrary.setDescription("Enterprise wide library of reuseable model elements");
216: lTargetEnterprise.setDesignLibrary(lEntepriseDesignLibrary);
217: DataDictionary lDictionary = lDataDictionaryClass.createDataDictionary();
218: lDictionary.setName("Default");
219: lDictionary.setDescription("Data dictionary of the types reused throughout enteprise");
220: lEntepriseDesignLibrary.setDataDictionary(lDictionary);
221: }
222: // Create technology library and populate it if necessary
223: {
224: TechnologyLibrary lEntepriseTechnologyLibrary = lTechnologyLibraryClass.createTechnologyLibrary();
225: lEntepriseTechnologyLibrary.setName("Default");
226: lEntepriseTechnologyLibrary.setDescription("Enterprise wide library of technology definitions utilised in the enterprise.");
227: lTargetEnterprise.setTechnologyLibrary(lEntepriseTechnologyLibrary);
228: }*/
229: }
230: }
231: }
|