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