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.BOIllegalArgumentException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOService;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOServiceimplementation;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSService;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STServiceimplementation;
031: import com.metaboss.sdlctools.types.enterprisemodel.ZipArchive;
032: import com.oldboss.framework.bo.BOTransaction;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOServiceimplementationImpl extends BOObjectImpl implements
036: BOServiceimplementation {
037: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
038: private BOService mOwnerService = null;
039: private STServiceimplementation mDetails = null;
040: private ZipArchive mImplementationSource = null;
041: private boolean mImplementationSourcesNeedsUpdating = false;
042:
043: /* Instance creator */
044: public static BOServiceimplementation createInstanceForExisting(
045: BOMetaBossDomainImpl pMetaBossDomainImpl,
046: BOService pOwnerService, STServiceimplementation pDetails)
047: throws BOException {
048: if (pDetails == null)
049: throw new BOException("Empty details structure");
050: if (!pDetails.ServiceimplementationRef.startsWith(pOwnerService
051: .getRef()
052: + "."))
053: throw new BOException(
054: "Service Reference and Serviceimplementation reference mismatch");
055: BOServiceimplementationImpl lImpl = new BOServiceimplementationImpl();
056: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
057: lImpl.mOwnerService = pOwnerService;
058: lImpl.mDetails = pDetails;
059: lImpl.setupForExisting();
060: return lImpl;
061: }
062:
063: /* Instance creator */
064: public static BOServiceimplementation createInstanceForNew(
065: BOTransaction pTransaction,
066: BOMetaBossDomainImpl pMetaBossDomainImpl,
067: BOService pOwnerService, String pServiceimplementationRef)
068: throws BOException {
069: if (pServiceimplementationRef == null
070: || pServiceimplementationRef.length() == 0)
071: throw new BOException("Empty Serviceimplementation Ref");
072: if (!pServiceimplementationRef.startsWith(pOwnerService
073: .getRef()
074: + "."))
075: throw new BOException(
076: "Service Reference and Serviceimplementation reference mismatch");
077: BOServiceimplementationImpl lImpl = new BOServiceimplementationImpl();
078: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
079: lImpl.mOwnerService = pOwnerService;
080: lImpl.mDetails = new STServiceimplementation();
081: lImpl.mDetails.ServiceimplementationRef = pServiceimplementationRef;
082: lImpl.setupForNew(pTransaction);
083: return lImpl;
084: }
085:
086: /* Private constructor restricts instance creation from outside */
087: private BOServiceimplementationImpl() throws BOException {
088: }
089:
090: /* Retrieves unique reference */
091: public String getRef() throws BOException {
092: return mDetails.ServiceimplementationRef;
093: }
094:
095: /* Retrieves element's name. Name is only unique within parent entity */
096: public String getName() throws BOException {
097: String lRef = getRef();
098: return lRef.substring(lRef.lastIndexOf(".") + 1);
099: }
100:
101: /* Returns element's description */
102: public String getDescription() throws BOException {
103: return mDetails.Description;
104: }
105:
106: /** Sets description */
107: public void setDescription(String pDescription) throws BOException {
108: if (!isBeingEdited())
109: throw new BOInvalidOperationForReadOnlyObjectException();
110: mDetails.Description = pDescription;
111: }
112:
113: /* Retrieves the service this operation belongs to */
114: public BOService getService() throws BOException {
115: return mOwnerService;
116: }
117:
118: /* Returns the implementation source for the particular implementation */
119: public ZipArchive getSource() throws BOException {
120: loadImplementationSourceIfNecessary();
121: return mImplementationSource;
122: }
123:
124: /* Sets implementation source for the service, name of the archive is inside archive itself */
125: public void setSource(ZipArchive pSourceArchive) throws BOException {
126: if (!isBeingEdited())
127: throw new BOInvalidOperationForReadOnlyObjectException();
128: if (pSourceArchive.isEmpty() == false
129: && pSourceArchive.isConcealed() == false) {
130: if (!pSourceArchive.getName().equals(getName()))
131: throw new BOIllegalArgumentException(
132: "Source Archive name and Service Implementation name mismatch. ServiceimplementationRef : "
133: + mDetails.ServiceimplementationRef
134: + " Source archive name : "
135: + pSourceArchive.getName());
136: }
137: mImplementationSource = pSourceArchive;
138: mImplementationSourcesNeedsUpdating = true;
139: }
140:
141: /* Encapsulates commit action by this object */
142: protected void onCommitCreation() throws BOException {
143: try {
144: // Get the instance of the enterprise ps home via jndi
145: Context ctx = new InitialContext();
146: PSService lPs = (PSService) ctx
147: .lookup(PSService.COMPONENT_URL);
148: lPs.insertImplementation(mOwnerService.getRef(), mDetails);
149: if (mImplementationSourcesNeedsUpdating)
150: lPs.updateImplementationSource(mOwnerService.getRef(),
151: mImplementationSource);
152: } catch (NamingException e) {
153: throw new BONamingAndDirectoryServiceInvocationException(
154: "", e);
155: } catch (PSException e) {
156: throw new BOPersistenceServiceInvocationException("", e);
157: }
158: }
159:
160: protected void onCommitUpdate() throws BOException {
161: try {
162: // Get the instance of the enterprise ps home via jndi
163: Context ctx = new InitialContext();
164: PSService lPs = (PSService) ctx
165: .lookup(PSService.COMPONENT_URL);
166: lPs.updateImplementation(mOwnerService.getRef(), mDetails);
167: if (mImplementationSourcesNeedsUpdating)
168: lPs.updateImplementationSource(mOwnerService.getRef(),
169: mImplementationSource);
170: } catch (NamingException e) {
171: throw new BONamingAndDirectoryServiceInvocationException(
172: "", e);
173: } catch (PSException e) {
174: throw new BOPersistenceServiceInvocationException("", e);
175: }
176: }
177:
178: /* Encapsulates an action after successfull commit */
179: public void onCommitSucceeded() throws BOException {
180: mImplementationSourcesNeedsUpdating = false;
181: }
182:
183: private void loadImplementationSourceIfNecessary()
184: throws BOException {
185: if (mImplementationSource == null) {
186: try {
187: // Get the instance of the enterprise ps home via jndi
188: Context ctx = new InitialContext();
189: PSService lPs = (PSService) ctx
190: .lookup(PSService.COMPONENT_URL);
191: mImplementationSource = lPs.getImplementationSource(
192: mOwnerService.getRef(),
193: mDetails.ServiceimplementationRef);
194: if (mImplementationSource == null)
195: throw new BOException(
196: "Implementation source not found. SourceimplementationRef : "
197: + getRef());
198: } catch (NamingException e) {
199: throw new BONamingAndDirectoryServiceInvocationException(
200: "", e);
201: } catch (PSException e) {
202: throw new BOPersistenceServiceInvocationException(
203: "Exception caught during processing of Serviceimplementation. SourceimplementationRef : "
204: + getRef(), e);
205: }
206: }
207: }
208: }
|