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.BOEntity;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntityStateList;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOState;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STState;
030: import com.oldboss.framework.bo.impl.BOObjectImpl;
031:
032: public class BOEntityStateListImpl extends BOObjectImpl implements
033: BOEntityStateList {
034: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
035: private BOEntity mEntity = null;
036:
037: /* Instance creator */
038: public static BOEntityStateList createInstanceForExisting(
039: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity)
040: throws BOException {
041: BOEntityStateListImpl lImpl = new BOEntityStateListImpl();
042: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
043: lImpl.mEntity = pEntity;
044: lImpl.setupForExisting();
045: return lImpl;
046: }
047:
048: /* Private constructor restricts instance creation from outside */
049: private BOEntityStateListImpl() throws BOException {
050: }
051:
052: /* Returns owner entity */
053: public BOEntity getEntity() throws BOException {
054: return mEntity;
055: }
056:
057: /** Retrieves an attribute object by it's name or null if none exists */
058: public BOState getState(String pName) throws BOException {
059: try {
060: // Get the instance of the enterprise ps home via jndi
061: Context ctx = new InitialContext();
062: PSEntity lPs = (PSEntity) ctx
063: .lookup(PSEntity.COMPONENT_URL);
064:
065: STState lState = lPs.getState(mEntity.getRef(), pName);
066: if (lState == null)
067: return null;
068: return BOStateImpl.createInstanceForExisting(
069: mMetaBossDomainImpl, mEntity, lState);
070: } catch (NamingException e) {
071: throw new BONamingAndDirectoryServiceInvocationException(
072: "", e);
073: } catch (PSException e) {
074: throw new BOPersistenceServiceInvocationException("", e);
075: }
076: }
077:
078: /* Retrieves number of all states defined for this entity */
079: public int size() throws BOException {
080: try {
081: // Get the instance of the enterprise ps home via jndi
082: Context ctx = new InitialContext();
083: PSEntity lPs = (PSEntity) ctx
084: .lookup(PSEntity.COMPONENT_URL);
085: return lPs.getStatesCount(mEntity.getRef());
086: } catch (NamingException e) {
087: throw new BONamingAndDirectoryServiceInvocationException(
088: "", e);
089: } catch (PSException e) {
090: throw new BOPersistenceServiceInvocationException("", e);
091: }
092: }
093:
094: /* Retrieves all states in this entity */
095: public BOState[] getAllStates() throws BOException {
096: try {
097: // Get the instance of the enterprise ps home via jndi
098: Context ctx = new InitialContext();
099: PSEntity lPs = (PSEntity) ctx
100: .lookup(PSEntity.COMPONENT_URL);
101:
102: STState[] lStates = lPs.getStates(mEntity.getRef());
103: if (lStates == null || lStates.length == 0)
104: return new BOState[0];
105: BOState[] lReturn = new BOState[lStates.length];
106: for (int i = 0; i < lStates.length; i++) {
107: lReturn[i] = BOStateImpl.createInstanceForExisting(
108: mMetaBossDomainImpl, mEntity, lStates[i]);
109: }
110: return lReturn;
111: } catch (NamingException e) {
112: throw new BONamingAndDirectoryServiceInvocationException(
113: "", e);
114: } catch (PSException e) {
115: throw new BOPersistenceServiceInvocationException("", e);
116: }
117: }
118: }
|