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.BODomain;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BODomainEntityList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSDomain;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public class BODomainEntityListImpl extends BOObjectImpl implements
034: BODomainEntityList {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BODomain mDomain = null;
037:
038: /* Instance creator */
039: public static BODomainEntityList createInstanceForExisting(
040: BOMetaBossDomainImpl pMetaBossDomainImpl, BODomain pDomain)
041: throws BOException {
042: BODomainEntityListImpl lImpl = new BODomainEntityListImpl();
043: lImpl.initialiseForExisting(pMetaBossDomainImpl, pDomain);
044: return lImpl;
045: }
046:
047: /* Private constructor restricts instance creation from outside */
048: private BODomainEntityListImpl() throws BOException {
049: }
050:
051: /* Instance initialisation */
052: private void initialiseForExisting(
053: BOMetaBossDomainImpl pMetaBossDomainImpl, BODomain pDomain)
054: throws BOException {
055: mMetaBossDomainImpl = pMetaBossDomainImpl;
056: mDomain = pDomain;
057: setupForExisting();
058: }
059:
060: /** Retrieves all entities defined in this domain */
061: public BOEntity[] getAllEntities() throws BOException {
062: try {
063: // Get the instance of the enterprise ps home via jndi
064: Context ctx = new InitialContext();
065: PSDomain lPs = (PSDomain) ctx
066: .lookup(PSDomain.COMPONENT_URL);
067:
068: String[] lEntityRefs = lPs.getAllEntityRefs(mDomain
069: .getRef());
070: if (lEntityRefs == null || lEntityRefs.length == 0)
071: return new BOEntity[0];
072: BOEntity[] lReturn = new BOEntity[lEntityRefs.length];
073: for (int i = 0; i < lEntityRefs.length; i++) {
074: lReturn[i] = BOEntityImpl.createInstanceForExisting(
075: mMetaBossDomainImpl, lEntityRefs[i]);
076: }
077: return lReturn;
078: } catch (NamingException e) {
079: throw new BONamingAndDirectoryServiceInvocationException(
080: "", e);
081: } catch (PSException e) {
082: throw new BOPersistenceServiceInvocationException("", e);
083: }
084: }
085:
086: /* Retrieves an entity with the given reference */
087: public BOEntity getEntity(String pEntityRef) throws BOException {
088: try {
089: // Get the instance of the enterprise ps home via jndi
090: Context ctx = new InitialContext();
091: PSDomain lPs = (PSDomain) ctx
092: .lookup(PSDomain.COMPONENT_URL);
093:
094: String[] lEntityRefs = lPs.getAllEntityRefs(mDomain
095: .getRef());
096: if (lEntityRefs == null || lEntityRefs.length == 0)
097: return null;
098: for (int i = 0; i < lEntityRefs.length; i++) {
099: if (lEntityRefs[i].equals(pEntityRef))
100: return BOEntityImpl.createInstanceForExisting(
101: mMetaBossDomainImpl, pEntityRef);
102: }
103: return null;
104: } catch (NamingException e) {
105: throw new BONamingAndDirectoryServiceInvocationException(
106: "", e);
107: } catch (PSException e) {
108: throw new BOPersistenceServiceInvocationException("", e);
109: }
110: }
111:
112: /** Creates a new entity with the given reference */
113: public BOEntity createEntity(String pEntityRef) throws BOException {
114: // Check if this servicemodule even belongs to this enteprise
115: if (!pEntityRef.startsWith(mDomain.getRef() + "."))
116: throw new BOIllegalArgumentException(
117: "EntityRef is not valid not valid within domain. EntityRef: "
118: + pEntityRef + " DomainRef: "
119: + mDomain.getRef());
120: if (!isBeingEdited())
121: throw new BOInvalidOperationForReadOnlyObjectException();
122: return BOEntityImpl.createInstanceForNew(fetchTransaction(),
123: mMetaBossDomainImpl, pEntityRef);
124: }
125: }
|