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:
019: import javax.xml.bind.JAXBException;
020:
021: import com.metaboss.enterprise.ps.PSDataSourceOperationInvocationException;
022: import com.metaboss.enterprise.ps.PSException;
023: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSMessage;
024: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STMessage;
025: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STMessageField;
026: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageDefType;
027: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageFieldDefListType;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageFieldDefType;
029:
030: public class PSMessageImpl implements PSMessage {
031: /** Returns details entity corresponding to given reference or null struct if definition not found */
032: public STMessage getMessage(String pMessageRef) throws PSException {
033: MessageDefType lMessageDef = Storage.getMessage(pMessageRef);
034: if (lMessageDef == null)
035: return null;
036: STMessage lStruct = new STMessage();
037: lStruct.MessageRef = lMessageDef.getMessageRef();
038: lStruct.Description = lMessageDef.getDescription();
039: lStruct.Type = com.metaboss.sdlctools.types.enterprisemodel.MessageTypeTextHelper
040: .fromTextObject(lMessageDef.getMessageType());
041: lStruct.DefaultText = lMessageDef.getDefaultText();
042: return lStruct;
043: }
044:
045: /* Inserts one or more new message records into the database */
046: public void insert(STMessage[] pNewRecords) throws PSException {
047: try {
048: for (int i = 0; i < pNewRecords.length; i++) {
049: STMessage lMessageToInsert = pNewRecords[i];
050:
051: MessageDefType lMessageDef = Util.getObjectFactory()
052: .createMessageDef();
053: lMessageDef.setMessageRef(lMessageToInsert.MessageRef);
054: lMessageDef
055: .setDescription(lMessageToInsert.Description);
056: lMessageDef
057: .setDefaultText(lMessageToInsert.DefaultText);
058: lMessageDef
059: .setMessageType(com.metaboss.sdlctools.types.enterprisemodel.MessageTypeTextHelper
060: .toTextObject(lMessageToInsert.Type));
061: MessageFieldDefListType lMessageFieldDefList = Util
062: .getObjectFactory().createMessageFieldDefList();
063: lMessageDef
064: .setMessageFieldDefList(lMessageFieldDefList);
065: Storage.insertMessage(lMessageDef);
066: }
067: } catch (JAXBException e) {
068: throw new PSDataSourceOperationInvocationException(e);
069: }
070: }
071:
072: /* Returns list of input fields for the operation with the specified name from specified service */
073: public STMessageField[] getFields(String pMessageRef)
074: throws PSException {
075: MessageDefType lMessageDef = Storage.getMessage(pMessageRef);
076: if (lMessageDef == null)
077: throw new PSException("Message not found. MessageRef : "
078: + pMessageRef);
079: MessageFieldDefListType lMessageFieldDefList = lMessageDef
080: .getMessageFieldDefList();
081: STMessageField[] lReturn = new STMessageField[lMessageFieldDefList
082: .getMessageFieldDef().size()];
083: Iterator lIter = lMessageFieldDefList.getMessageFieldDef()
084: .iterator();
085: for (int j = 0; lIter.hasNext(); j++)
086: lReturn[j] = getMessageField((MessageFieldDefType) lIter
087: .next());
088: return lReturn;
089: }
090:
091: /** inserts field into the structure */
092: public void insertField(String pMessageRef, STMessageField pNewField)
093: throws PSException {
094: MessageDefType lMessageDef = Storage.getMessage(pMessageRef);
095: if (lMessageDef == null)
096: throw new PSException("Message not found. MessageRef : "
097: + pMessageRef);
098: // Make sure that field with the specified name does not exists yet
099: MessageFieldDefListType lMessageFieldDefList = lMessageDef
100: .getMessageFieldDefList();
101: Iterator lIter = lMessageFieldDefList.getMessageFieldDef()
102: .iterator();
103: while (lIter.hasNext()) {
104: MessageFieldDefType lMessageFieldDef = (MessageFieldDefType) lIter
105: .next();
106: if (lMessageFieldDef.getName().equals(pNewField.Name))
107: throw new PSException(
108: "Attempt to insert duplicate field. MessageRef : "
109: + pMessageRef + ". FieldName : "
110: + pNewField.Name);
111: }
112: MessageFieldDefType lNewFieldDef = getMessageFieldDef(pNewField);
113: lMessageFieldDefList.getMessageFieldDef().add(lNewFieldDef);
114: Storage.updateMessage(lMessageDef);
115: }
116:
117: // Helper. Converts xml struct to the PS struct
118: private static STMessageField getMessageField(
119: MessageFieldDefType pMessageFieldDef) {
120: if (pMessageFieldDef == null)
121: return null;
122: STMessageField lStruct = new STMessageField();
123: lStruct.Name = pMessageFieldDef.getName();
124: lStruct.Description = pMessageFieldDef.getDescription();
125: lStruct.DataTypeRef = pMessageFieldDef.getDataTypeRef();
126: return lStruct;
127: }
128:
129: // Helper. Converts PS struct to xml struct
130: private static MessageFieldDefType getMessageFieldDef(
131: STMessageField pMessageField) throws PSException {
132: try {
133: MessageFieldDefType lMessageFieldDef = Util
134: .getObjectFactory().createMessageFieldDef();
135: lMessageFieldDef.setName(pMessageField.Name);
136: lMessageFieldDef.setDescription(pMessageField.Description);
137: lMessageFieldDef.setDataTypeRef(pMessageField.DataTypeRef);
138: return lMessageFieldDef;
139: } catch (JAXBException e) {
140: throw new PSDataSourceOperationInvocationException(e);
141: }
142: }
143: }
|