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.domains.enterprisemodel.impl;
016:
017: import javax.naming.Context;
018: import javax.naming.InitialContext;
019: import javax.naming.NamingException;
020:
021: import com.metaboss.enterprise.bo.BOException;
022: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
023: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
024: import com.metaboss.enterprise.ps.PSException;
025: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BODomainAssociationList;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BODomainEntityList;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BODomainReportList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSDomain;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STDomain;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BODomainImpl extends BOObjectImpl implements BODomain {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BOSystem mSystem = null;
037: private String mDomainRef = null;
038: private STDomain mDetails = null;
039:
040: /* Instance creator */
041: public static BODomain createInstanceForExisting(
042: BOMetaBossDomainImpl pMetaBossDomainImpl, String pDomainRef)
043: throws BOException {
044: // See if we have this object in cache
045: BODomainImpl lImpl = (BODomainImpl) pMetaBossDomainImpl
046: .retrieveExistingBOInstance(BODomain.class, pDomainRef);
047: if (lImpl != null)
048: return lImpl;
049: lImpl = new BODomainImpl();
050: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
051: lImpl.mDomainRef = pDomainRef;
052: lImpl.setupForExisting();
053: pMetaBossDomainImpl.saveNewBOInstance(BODomain.class,
054: pDomainRef, lImpl);
055: return lImpl;
056: }
057:
058: /* Retrieves unique reference */
059: public String getRef() throws BOException {
060: return mDomainRef;
061: }
062:
063: /* Retrieves domain name. Usually last part of the reference.
064: * name is only unique within type, within enteprise */
065: public String getName() throws BOException {
066: String lDomainRef = getRef();
067: return lDomainRef.substring(lDomainRef.lastIndexOf(".") + 1);
068: }
069:
070: /* Retrieves system which owns this servicemodule */
071: public BOSystem getSystem() throws BOException {
072: if (mSystem == null) {
073: String lRef = getRef();
074: if (lRef.lastIndexOf(".") < 0)
075: throw new BOException("Invalid DomainRef: " + lRef);
076: mSystem = BOSystemImpl.createInstanceForExisting(
077: mMetaBossDomainImpl, lRef.substring(0, lRef
078: .lastIndexOf(".")));
079: }
080: return mSystem;
081: }
082:
083: /* Retrieves domain description */
084: public String getDescription() throws BOException {
085: loadDetailsIfNecessary();
086: return mDetails.Description;
087: }
088:
089: /* Retrieves domain's major version number */
090: public int getMajorVersionNum() throws BOException {
091: loadDetailsIfNecessary();
092: return mDetails.Version.MajorNumber;
093: }
094:
095: /* Retrieves domain's minor version number */
096: public int getMinorVersionNum() throws BOException {
097: loadDetailsIfNecessary();
098: return mDetails.Version.MinorNumber;
099: }
100:
101: /* Retrieves list of entities defined in this domain */
102: public BODomainEntityList getEntities() throws BOException {
103: return BODomainEntityListImpl.createInstanceForExisting(
104: mMetaBossDomainImpl, this );
105: }
106:
107: /* Retrieves list of top level associations to entities in this domain */
108: public BODomainAssociationList getAssociations() throws BOException {
109: return BODomainAssociationListImpl.createInstanceForExisting(
110: mMetaBossDomainImpl, this );
111: }
112:
113: /* Retrieves list of reports in this domain */
114: public BODomainReportList getReports() throws BOException {
115: return BODomainReportListImpl.createInstanceForExisting(
116: mMetaBossDomainImpl, this );
117: }
118:
119: // Retrieves implicit datatypes package.
120: public String getImplicitDatatypesPackage() throws BOException {
121: return getSystem().getRef() + ".System." + getName();
122: }
123:
124: protected void loadDetailsIfNecessary() throws BOException {
125: if (mDetails == null) {
126: try {
127: // Get the instance of the enterprise ps home via jndi
128: Context ctx = new InitialContext();
129: PSDomain lPs = (PSDomain) ctx
130: .lookup(PSDomain.COMPONENT_URL);
131:
132: mDetails = lPs.getDomain(mDomainRef);
133: if (mDetails == null)
134: throw new BOException(
135: "Domain not found. (DomainRef:"
136: + mDomainRef + ")");
137: } catch (NamingException e) {
138: throw new BONamingAndDirectoryServiceInvocationException(
139: "", e);
140: } catch (PSException e) {
141: throw new BOPersistenceServiceInvocationException("", e);
142: }
143: }
144: }
145: }
|