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.BOPropertyDescriptorList;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOTypetemplate;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSTypeTemplate;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STTypeTemplate;
030: import com.metaboss.sdlctools.types.enterprisemodel.TemplateSourceType;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public class BOTypetemplateImpl extends BOObjectImpl implements
034: BOTypetemplate {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private String mTypeTemplateRef = null;
037: private STTypeTemplate mDetails = null;
038: private String mSource = null;
039: private boolean mSourceHasBeenLoaded = false;
040: private boolean mSourceHasChanged = false;
041:
042: /* Instance creator */
043: public static BOTypetemplate createInstanceForExisting(
044: BOMetaBossDomainImpl pMetaBossDomainImpl,
045: String pTypeTemplateRef) throws BOException {
046: BOTypetemplateImpl lImpl = new BOTypetemplateImpl();
047: lImpl.initialiseForExisting(pMetaBossDomainImpl,
048: pTypeTemplateRef);
049: return lImpl;
050: }
051:
052: /* Private constructor restricts instance creation from outside */
053: private BOTypetemplateImpl() throws BOException {
054: }
055:
056: /* Instance initialisation */
057: private void initialiseForExisting(
058: BOMetaBossDomainImpl pMetaBossDomainImpl,
059: String pTypeTemplateRef) throws BOException {
060: mMetaBossDomainImpl = pMetaBossDomainImpl;
061: mTypeTemplateRef = pTypeTemplateRef;
062: setupForExisting();
063: }
064:
065: /* Retrieves unique reference */
066: public String getRef() throws BOException {
067: return mTypeTemplateRef;
068: }
069:
070: /* Retrieves typetemplate name. Usually last part of the reference.
071: * name is only unique within its package */
072: public String getName() throws BOException {
073: String lRef = getRef();
074: return lRef.substring(lRef.lastIndexOf(".") + 1);
075: }
076:
077: /* Retrieves description */
078: public String getDescription() throws BOException {
079: loadDetailsIfNecessary();
080: return mDetails.Description;
081: }
082:
083: /* Retrieves property descriptors */
084: public BOPropertyDescriptorList getPropertyDescriptors()
085: throws BOException {
086: loadDetailsIfNecessary();
087: return BOPropertyDescriptorListImpl
088: .createInstanceForExisting(mMetaBossDomainImpl, null,
089: mDetails.PropertyDescriptors);
090: }
091:
092: /* Retrieves the type of the template source */
093: public TemplateSourceType getSourceType() throws BOException {
094: loadDetailsIfNecessary();
095: return mDetails.SourceType;
096: }
097:
098: /* Retrieves the data type property or null if none exists */
099: public String getSource() throws BOException {
100: loadDetailsIfNecessary();
101: loadSourceIfNecessary();
102: return mSource;
103: }
104:
105: /** Sets the source to be used for the template */
106: public void setSource(String pSource) throws BOException {
107: if (!isInTransaction())
108: throw new BOInvalidOperationForReadOnlyObjectException();
109: mSource = pSource;
110: mSourceHasChanged = true;
111: }
112:
113: protected void onBeginEdit() throws BOException {
114: // Fully load the object
115: loadDetailsIfNecessary();
116: loadSourceIfNecessary();
117: }
118:
119: protected void onCommitUpdate() throws BOException {
120: if (mSourceHasChanged) {
121: try {
122: // Get the instance of the enterprise ps home via jndi
123: Context ctx = new InitialContext();
124: PSTypeTemplate lPs = (PSTypeTemplate) ctx
125: .lookup(PSTypeTemplate.COMPONENT_URL);
126: lPs.updateTypeTemplateSource(mTypeTemplateRef, mSource);
127: } catch (NamingException e) {
128: throw new BONamingAndDirectoryServiceInvocationException(
129: "", e);
130: } catch (PSException e) {
131: throw new BOPersistenceServiceInvocationException("", e);
132: }
133: }
134: }
135:
136: public void onCommitSucceeded() throws BOException {
137: mSourceHasChanged = false;
138: }
139:
140: protected void onRollbackUpdate() throws BOException {
141: // Unload the lot
142: mDetails = null;
143: mSource = null;
144: mSourceHasBeenLoaded = false;
145: mSourceHasChanged = false;
146: }
147:
148: private void loadDetailsIfNecessary() throws BOException {
149: if (mDetails == null) {
150: try {
151: // Get the instance of the enterprise ps home via jndi
152: Context ctx = new InitialContext();
153: PSTypeTemplate lPs = (PSTypeTemplate) ctx
154: .lookup(PSTypeTemplate.COMPONENT_URL);
155:
156: mDetails = lPs.getTypeTemplate(mTypeTemplateRef);
157: if (mDetails == null)
158: throw new BOException(
159: "TypeTemplate not found. TypeTemplateRef: "
160: + mTypeTemplateRef);
161: } catch (NamingException e) {
162: throw new BONamingAndDirectoryServiceInvocationException(
163: "", e);
164: } catch (PSException e) {
165: throw new BOPersistenceServiceInvocationException(
166: "Exception caught during loading of Type Template. TypeTemplateRef : "
167: + mTypeTemplateRef, e);
168: }
169: }
170: }
171:
172: private void loadSourceIfNecessary() throws BOException {
173: if (!mSourceHasBeenLoaded) {
174: try {
175: // Get the instance of the enterprise ps home via jndi
176: Context ctx = new InitialContext();
177: PSTypeTemplate lPs = (PSTypeTemplate) ctx
178: .lookup(PSTypeTemplate.COMPONENT_URL);
179: mSource = lPs.getTypeTemplateSource(mTypeTemplateRef);
180: mSourceHasBeenLoaded = true;
181: // Null means that there is no source, which is ok
182: } catch (NamingException e) {
183: throw new BONamingAndDirectoryServiceInvocationException(
184: "", e);
185: } catch (PSException e) {
186: throw new BOPersistenceServiceInvocationException("", e);
187: }
188: }
189: }
190: }
|