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.BOService;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemodule;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemoduleServiceList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSServicemodule;
030: import com.oldboss.framework.bo.impl.BOObjectImpl;
031:
032: public class BOServicemoduleServiceListImpl extends BOObjectImpl
033: implements BOServicemoduleServiceList {
034: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
035: private BOServicemodule mServicemodule = null;
036:
037: /* Instance creator */
038: public static BOServicemoduleServiceList createInstanceForExisting(
039: BOMetaBossDomainImpl pMetaBossDomainImpl,
040: BOServicemodule pServicemodule) throws BOException {
041: BOServicemoduleServiceListImpl lImpl = new BOServicemoduleServiceListImpl();
042: lImpl
043: .initialiseForExisting(pMetaBossDomainImpl,
044: pServicemodule);
045: return lImpl;
046: }
047:
048: /* Private constructor restricts instance creation from outside */
049: private BOServicemoduleServiceListImpl() throws BOException {
050: }
051:
052: /* Instance initialisation */
053: private void initialiseForExisting(
054: BOMetaBossDomainImpl pMetaBossDomainImpl,
055: BOServicemodule pServicemodule) throws BOException {
056: mMetaBossDomainImpl = pMetaBossDomainImpl;
057: mServicemodule = pServicemodule;
058: setupForExisting();
059: }
060:
061: /** Retrieves all services defined in this domain */
062: public BOService[] getAllServices() throws BOException {
063: try {
064: // Get the instance of the enterprise ps home via jndi
065: Context ctx = new InitialContext();
066: PSServicemodule lPs = (PSServicemodule) ctx
067: .lookup(PSServicemodule.COMPONENT_URL);
068:
069: String[] lServiceRefs = lPs
070: .getServicemoduleServiceRefs(mServicemodule
071: .getRef());
072: if (lServiceRefs == null || lServiceRefs.length == 0)
073: return new BOService[0];
074: BOService[] lReturn = new BOService[lServiceRefs.length];
075: for (int i = 0; i < lServiceRefs.length; i++) {
076: lReturn[i] = BOServiceImpl.createInstanceForExisting(
077: mMetaBossDomainImpl, lServiceRefs[i]);
078: }
079: return lReturn;
080: } catch (NamingException e) {
081: throw new BONamingAndDirectoryServiceInvocationException(
082: "", e);
083: } catch (PSException e) {
084: throw new BOPersistenceServiceInvocationException("", e);
085: }
086: }
087:
088: /* Gets contained existing service */
089: public BOService get(String pServiceRef) throws BOException {
090: return BOServiceImpl.createInstanceForExisting(
091: mMetaBossDomainImpl, pServiceRef);
092: }
093:
094: /** Creates new service */
095: public BOService create(String pServiceRef) throws BOException {
096: if (!isBeingEdited())
097: throw new BOInvalidOperationForReadOnlyObjectException();
098: return BOServiceImpl.createInstanceForNew(fetchTransaction(),
099: mMetaBossDomainImpl, pServiceRef);
100: }
101: }
|