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.BOState;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOStateTransition;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOStateTransitionList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STStateTransition;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public class BOStateTransitionListImpl extends BOObjectImpl implements
034: BOStateTransitionList {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BOEntity mEntity = null;
037: private BOState mState = null;
038:
039: /* Instance creator */
040: public static BOStateTransitionList createInstanceForExisting(
041: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity,
042: BOState pState) throws BOException {
043: BOStateTransitionListImpl lImpl = new BOStateTransitionListImpl();
044: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
045: lImpl.mEntity = pEntity;
046: lImpl.mState = pState;
047: lImpl.setupForExisting();
048: return lImpl;
049: }
050:
051: /* Private constructor restricts instance creation from outside */
052: private BOStateTransitionListImpl() throws BOException {
053: }
054:
055: /* Returns owner entity */
056: public BOEntity getEntity() throws BOException {
057: return mEntity;
058: }
059:
060: /** Retrieves state this transition list belongs to */
061: public BOState getState() throws BOException {
062: return mState;
063: }
064:
065: /* Retrieves number of all states defined for this entity */
066: public int size() throws BOException {
067: try {
068: // Get the instance of the enterprise ps home via jndi
069: Context ctx = new InitialContext();
070: PSEntity lPs = (PSEntity) ctx
071: .lookup(PSEntity.COMPONENT_URL);
072: return lPs.getStateTransitionsCount(mEntity.getRef(),
073: mState.getName());
074: } catch (NamingException e) {
075: throw new BONamingAndDirectoryServiceInvocationException(
076: "", e);
077: } catch (PSException e) {
078: throw new BOPersistenceServiceInvocationException("", e);
079: }
080: }
081:
082: /* Retrieves all transitions defined for this state */
083: public BOStateTransition[] getAllTransitions() throws BOException {
084: try {
085: // Get the instance of the enterprise ps home via jndi
086: Context ctx = new InitialContext();
087: PSEntity lPs = (PSEntity) ctx
088: .lookup(PSEntity.COMPONENT_URL);
089:
090: STStateTransition[] lTransitions = lPs.getStateTransitions(
091: mEntity.getRef(), mState.getName());
092: if (lTransitions == null || lTransitions.length == 0)
093: return new BOStateTransition[0];
094: BOStateTransition[] lReturn = new BOStateTransition[lTransitions.length];
095: for (int i = 0; i < lTransitions.length; i++) {
096: lReturn[i] = BOStateTransitionImpl
097: .createInstanceForExisting(mMetaBossDomainImpl,
098: mEntity, mState, lTransitions[i]);
099: }
100: return lReturn;
101: } catch (NamingException e) {
102: throw new BONamingAndDirectoryServiceInvocationException(
103: "", e);
104: } catch (PSException e) {
105: throw new BOPersistenceServiceInvocationException("", e);
106: }
107: }
108: }
|