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.BOApplication;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
027: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSApplication;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STApplication;
029: import com.oldboss.framework.bo.impl.BOObjectImpl;
030:
031: public class BOApplicationImpl extends BOObjectImpl implements
032: BOApplication {
033: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
034: private BOSystem mSystem = null;
035: private String mApplicationRef = null;
036: private STApplication mDetails = null;
037:
038: /* Instance creator */
039: public static BOApplication createInstanceForExisting(
040: BOMetaBossDomainImpl pMetaBossDomainImpl,
041: String pApplicationRef) throws BOException {
042: BOApplicationImpl lImpl = new BOApplicationImpl();
043: lImpl.initialiseForExisting(pMetaBossDomainImpl,
044: pApplicationRef);
045: return lImpl;
046: }
047:
048: private BOApplicationImpl() throws BOException {
049: }
050:
051: /* Instance initialisation */
052: private void initialiseForExisting(
053: BOMetaBossDomainImpl pMetaBossDomainImpl,
054: String pApplicationRef) throws BOException {
055: mMetaBossDomainImpl = pMetaBossDomainImpl;
056: mApplicationRef = pApplicationRef;
057: setupForExisting();
058: }
059:
060: /* Retrieves unique reference */
061: public String getRef() throws BOException {
062: return mApplicationRef;
063: }
064:
065: /* Retrieves application name. Usually last part of the reference.
066: * name is only unique within type, within enteprise */
067: public String getName() throws BOException {
068: String lApplicationName = getRef();
069: if (lApplicationName.lastIndexOf(".") >= 0)
070: lApplicationName = lApplicationName
071: .substring(lApplicationName.lastIndexOf(".") + 1);
072: return lApplicationName;
073: }
074:
075: /* Retrieves system which owns this application */
076: public BOSystem getSystem() throws BOException {
077: if (mSystem == null) {
078: String lRef = getRef();
079: if (lRef.lastIndexOf(".") < 0)
080: throw new BOException("Invalid ApplicationRef: " + lRef);
081: mSystem = BOSystemImpl.createInstanceForExisting(
082: mMetaBossDomainImpl, lRef.substring(0, lRef
083: .lastIndexOf(".")));
084: }
085: return mSystem;
086: }
087:
088: /* Retrieves description */
089: public String getDescription() throws BOException {
090: loadDetailsIfNecessary();
091: return mDetails.Description;
092: }
093:
094: /* Retrieves list of urls this application consists of. */
095: public String[] getPartsURLs() throws BOException {
096: try {
097: // Get the instance of the enterprise ps home via jndi
098: Context lCtx = new InitialContext();
099: PSApplication lPs = (PSApplication) lCtx
100: .lookup(PSApplication.COMPONENT_URL);
101:
102: String[] lURLs = lPs.getPartsURLs(mApplicationRef);
103: return lURLs;
104: } catch (NamingException e) {
105: throw new BONamingAndDirectoryServiceInvocationException(
106: "", e);
107: } catch (PSException e) {
108: throw new BOPersistenceServiceInvocationException("", e);
109: }
110: }
111:
112: private void loadDetailsIfNecessary() throws BOException {
113: if (mDetails == null) {
114: try {
115: // Get the instance of the enterprise ps home via jndi
116: Context lCtx = new InitialContext();
117: PSApplication lPs = (PSApplication) lCtx
118: .lookup(PSApplication.COMPONENT_URL);
119:
120: mDetails = lPs.getApplication(mApplicationRef);
121: if (mDetails == null)
122: throw new BOException(
123: "Application not found. ApplicationRef:"
124: + mApplicationRef);
125: } catch (NamingException e) {
126: throw new BONamingAndDirectoryServiceInvocationException(
127: "", e);
128: } catch (PSException e) {
129: throw new BOPersistenceServiceInvocationException("", e);
130: }
131: }
132: }
133: }
|