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.storage.xmlfileimpl;
016:
017: import java.util.Iterator;
018: import java.util.List;
019: import java.util.StringTokenizer;
020:
021: import javax.xml.bind.JAXBException;
022:
023: import com.metaboss.enterprise.ps.PSDataSourceOperationInvocationException;
024: import com.metaboss.enterprise.ps.PSException;
025: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSServicemodule;
026: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STServicemodule;
027: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageDefListType;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServiceDefListType;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServicemoduleDefType;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.StructureDefListType;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.SystemDefType;
032:
033: public class PSServicemoduleImpl implements PSServicemodule {
034: /** Returns details entity corresponding to given reference or null struct if definition not found */
035: public STServicemodule getServicemodule(String pServicemoduleRef)
036: throws PSException {
037: ServicemoduleDefType lServicemoduleDef = Storage
038: .getServicemodule(pServicemoduleRef);
039: if (lServicemoduleDef == null)
040: return null;
041: STServicemodule lStruct = new STServicemodule();
042: lStruct.ServicemoduleRef = lServicemoduleDef
043: .getServicemoduleRef();
044: lStruct.Description = lServicemoduleDef.getDescription();
045: return lStruct;
046: }
047:
048: /* Returns list of all services comprising given service module */
049: public String[] getServicemoduleServiceRefs(String pServicemoduleRef)
050: throws PSException {
051: return Storage.getServicemoduleServiceRefs(pServicemoduleRef);
052: }
053:
054: /* Returns list of all structures declared within given service module */
055: public String[] getServicemoduleStructureRefs(
056: String pServicemoduleRef) throws PSException {
057: return Storage.getServicemoduleStructureRefs(pServicemoduleRef);
058: }
059:
060: /* Returns list of all messages declared within given service module */
061: public String[] getServicemoduleMessageRefs(String pServicemoduleRef)
062: throws PSException {
063: return Storage.getServicemoduleMessageRefs(pServicemoduleRef);
064: }
065:
066: /** Inserts one or more new structure records into the database */
067: public void insertServicemodule(STServicemodule pNewRecord)
068: throws PSException {
069: try {
070: ServicemoduleDefType lServicemoduleDef = Util
071: .getObjectFactory().createServicemoduleDef();
072: lServicemoduleDef
073: .setServicemoduleRef(pNewRecord.ServicemoduleRef);
074: lServicemoduleDef.setDescription(pNewRecord.Description);
075: StructureDefListType lStructureDefList = Util
076: .getObjectFactory().createStructureDefList();
077: lServicemoduleDef.setStructureDefList(lStructureDefList);
078: ServiceDefListType lServiceDefList = Util
079: .getObjectFactory().createServiceDefList();
080: lServicemoduleDef.setServiceDefList(lServiceDefList);
081: MessageDefListType lMessageDefList = Util
082: .getObjectFactory().createMessageDefList();
083: lServicemoduleDef.setMessageDefList(lMessageDefList);
084: Storage.insertServicemodule(lServicemoduleDef);
085:
086: // Now find out the system this servicemodule belongs to and insert reference to this servicemodule
087: // Servicemodule ref consists of three parts - enterprise name . system name . servicemodule name
088: StringTokenizer lTokenizer = new StringTokenizer(
089: pNewRecord.ServicemoduleRef, ".", false);
090: SystemDefType lSystemDef = Storage.getSystem(lTokenizer
091: .nextToken()
092: + "." + lTokenizer.nextToken());
093: lSystemDef.getServicemoduleRefList().getServicemoduleRef()
094: .add(pNewRecord.ServicemoduleRef);
095: Storage.updateSystem(lSystemDef);
096: } catch (JAXBException e) {
097: throw new PSDataSourceOperationInvocationException(e);
098: }
099: }
100:
101: // Updates serviicemodule details in the database
102: public void updateServicemodule(STServicemodule pUpdatedRecord)
103: throws PSException {
104: ServicemoduleDefType lServicemoduleDef = Storage
105: .getServicemodule(pUpdatedRecord.ServicemoduleRef);
106: if (lServicemoduleDef == null)
107: throw new PSException(
108: "Servicemodule not found. ServicemoduleRef : "
109: + pUpdatedRecord.ServicemoduleRef);
110: lServicemoduleDef.setDescription(pUpdatedRecord.Description);
111: Storage.updateServicemodule(lServicemoduleDef);
112: // Now find out the system this servicemodule belongs to and update it
113: // Servicemodule ref consists of three parts - enterprise name . system name . servicemodule name
114: StringTokenizer lTokenizer = new StringTokenizer(
115: pUpdatedRecord.ServicemoduleRef, ".", false);
116: SystemDefType lSystemDef = Storage.getSystem(lTokenizer
117: .nextToken()
118: + "." + lTokenizer.nextToken());
119: Storage.updateSystem(lSystemDef);
120: }
121:
122: // Deletes existing servicemodule
123: public void deleteServicemodule(String pServicemoduleRef)
124: throws PSException {
125: Storage.deleteServicemodule(pServicemoduleRef);
126: // Now find out the system this servicemodule belongs to and delete reference to this servicemodule
127: // Servicemodule ref consists of three parts - enterprise name . system name . servicemodule name
128: StringTokenizer lTokenizer = new StringTokenizer(
129: pServicemoduleRef, ".", false);
130: SystemDefType lSystemDef = Storage.getSystem(lTokenizer
131: .nextToken()
132: + "." + lTokenizer.nextToken());
133: List lServicemoduleRefList = lSystemDef
134: .getServicemoduleRefList().getServicemoduleRef();
135: Iterator lIter = lServicemoduleRefList.iterator();
136: for (int i = 0; lIter.hasNext(); i++) {
137: String lServicemoduleRef = (String) lIter.next();
138: if (lServicemoduleRef.equals(pServicemoduleRef)) {
139: lServicemoduleRefList.remove(i);
140: Storage.updateSystem(lSystemDef);
141: break;
142: }
143: }
144: }
145: }
|