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.BOIllegalArgumentException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BODatatype;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemDatatypeList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSDatatype;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSSystem;
032: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STDatatype;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOSystemDatatypeListImpl extends BOObjectImpl implements
036: BOSystemDatatypeList {
037: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
038: private BOSystem mSystem = null;
039:
040: /* Instance creator */
041: public static BOSystemDatatypeList createInstanceForExisting(
042: BOMetaBossDomainImpl pMetaBossDomainImpl, BOSystem pSystem)
043: throws BOException {
044: BOSystemDatatypeListImpl lImpl = new BOSystemDatatypeListImpl();
045: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
046: lImpl.mSystem = pSystem;
047: lImpl.setupForExisting();
048: return lImpl;
049: }
050:
051: /* Private constructor restricts instance creation from outside */
052: private BOSystemDatatypeListImpl() throws BOException {
053: }
054:
055: /** Retrieves all entities defined in this domain */
056: public BODatatype[] getAllDatatypes() throws BOException {
057: try {
058: // Get the instance of the enterprise ps home via jndi
059: Context ctx = new InitialContext();
060: PSSystem lPs = (PSSystem) ctx
061: .lookup(PSSystem.COMPONENT_URL);
062:
063: String[] lDatatypeRefs = lPs.getAllDatatypeRefs(mSystem
064: .getRef());
065: if (lDatatypeRefs == null || lDatatypeRefs.length == 0)
066: return new BODatatype[0];
067: BODatatype[] lReturn = new BODatatype[lDatatypeRefs.length];
068: for (int i = 0; i < lDatatypeRefs.length; i++) {
069: lReturn[i] = BODatatypeImpl.createInstanceForExisting(
070: mMetaBossDomainImpl, lDatatypeRefs[i]);
071: }
072: return lReturn;
073: } catch (NamingException e) {
074: throw new BONamingAndDirectoryServiceInvocationException(
075: "Error while loading all datatypes. SystemRef: "
076: + mSystem.getRef(), e);
077: } catch (PSException e) {
078: throw new BOPersistenceServiceInvocationException(
079: "Error while loading all datatypes. SystemRef: "
080: + mSystem.getRef(), e);
081: }
082: }
083:
084: /** Retrieves the datatype corresponding to given reference from this enteprise */
085: public BODatatype getDatatype(String pDatatypeRef)
086: throws BOException {
087: if (pDatatypeRef == null
088: || pDatatypeRef.startsWith(mSystem.getRef() + ".") == false)
089: return null; // No way this enteprise has given datatype
090: return BODatatypeImpl.createInstanceForExisting(
091: mMetaBossDomainImpl, pDatatypeRef);
092: }
093:
094: // Returns true if this enterprise contains this datatype
095: public boolean containsDatatype(String pDatatypeRef)
096: throws BOException {
097: if (pDatatypeRef == null
098: || pDatatypeRef.startsWith(mSystem.getRef() + ".") == false)
099: return false; // No way this enteprise has given datatype
100: try {
101: // Get the instance of the enterprise ps home via jndi
102: Context ctx = new InitialContext();
103: PSDatatype lPs = (PSDatatype) ctx
104: .lookup(PSDatatype.COMPONENT_URL);
105: STDatatype lDetails = lPs.getDatatype(pDatatypeRef);
106: return lDetails != null;
107: } catch (NamingException e) {
108: throw new BONamingAndDirectoryServiceInvocationException(
109: "", e);
110: } catch (PSException e) {
111: throw new BOPersistenceServiceInvocationException("", e);
112: }
113: }
114:
115: // Creates the datatype in this enterprise
116: public BODatatype createDatatype(String pDatatypeRef)
117: throws BOException {
118: if (!isBeingEdited())
119: throw new BOInvalidOperationForReadOnlyObjectException();
120: if (pDatatypeRef == null
121: || pDatatypeRef.startsWith(mSystem.getRef() + ".") == false)
122: throw new BOIllegalArgumentException("Datatype with Ref "
123: + pDatatypeRef
124: + " can not be a part of this system. SystemRef : "
125: + mSystem.getRef());
126: return BODatatypeImpl.createInstanceForNew(fetchTransaction(),
127: mMetaBossDomainImpl, pDatatypeRef);
128: }
129:
130: // Deletes the datatype from the enterprise.
131: public void deleteDatatype(BODatatype pDatatype) throws BOException {
132: if (!isBeingEdited())
133: throw new BOInvalidOperationForReadOnlyObjectException();
134: if (pDatatype == null
135: || pDatatype.getRef()
136: .startsWith(mSystem.getRef() + ".") == false)
137: throw new BOIllegalArgumentException(
138: "Datatype with Ref "
139: + pDatatype.getRef()
140: + " is not part of this system and can not be deleted from it. SystemRef : "
141: + mSystem.getRef());
142: pDatatype.delete(fetchTransaction());
143: }
144: }
|