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;
016:
017: import java.util.HashSet;
018: import java.util.Set;
019:
020: import com.metaboss.enterprise.bo.BOException;
021: import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;
022: import com.metaboss.enterprise.bs.BSException;
023: import com.metaboss.enterprise.bs.BSUnexpectedProgramConditionException;
024:
025: /** Set of useful utilites operating on elements of the enterprise model */
026: public class Util {
027: /** Returns array of all servicemodules referenced by particular servicemodule. (excludes the module we are investigating) */
028: public static BOServicemodule[] getReferencedServicemodules(
029: BOServicemodule pServicemodule) throws BSException {
030: try {
031: String lServicemoduleRef = pServicemodule.getRef();
032: try {
033: Set lReferencedServicemodulesSet = new HashSet();
034: // Go through all structures. Structure might reference the structure in the other servicemodule
035: BOStructure[] lStructures = pServicemodule
036: .getStructures().getAllStructures();
037: for (int i = 0; i < lStructures.length; i++) {
038: BOField[] lFields = lStructures[i].getFields()
039: .getAllFields();
040: for (int k = 0; k < lFields.length; k++) {
041: Object lFieldType = lFields[k].getType();
042: if (lFieldType instanceof BOStructure) {
043: BOStructure lStructure = (BOStructure) lFieldType;
044: BOServicemodule lStructureServicemodule = lStructure
045: .getServicemodule();
046: if (pServicemodule
047: .equals(lStructureServicemodule) == false
048: && lReferencedServicemodulesSet
049: .contains(lStructureServicemodule) == false)
050: lReferencedServicemodulesSet
051: .add(lStructureServicemodule);
052: }
053: }
054: }
055: // Go through all services. Operation inputs or outputs might reference other servicemodules
056: BOService[] lServices = pServicemodule.getServices()
057: .getAllServices();
058: for (int i = 0; i < lServices.length; i++) {
059: BOOperation[] lOperations = lServices[i]
060: .getOperations().getAllOperations();
061: for (int k = 0; k < lOperations.length; k++) {
062: // Go through input fields
063: {
064: BOField[] lInputFields = lOperations[k]
065: .getInputFields().getAllFields();
066: for (int l = 0; l < lInputFields.length; l++) {
067: Object lFieldType = lInputFields[l]
068: .getType();
069: if (lFieldType instanceof BOStructure) {
070: BOStructure lStructure = (BOStructure) lFieldType;
071: BOServicemodule lStructureServicemodule = lStructure
072: .getServicemodule();
073: if (pServicemodule
074: .equals(lStructureServicemodule) == false
075: && lReferencedServicemodulesSet
076: .contains(lStructureServicemodule) == false)
077: lReferencedServicemodulesSet
078: .add(lStructureServicemodule);
079: }
080: }
081: }
082: // Go through output fields
083: {
084: BOField[] lOutputFields = lOperations[k]
085: .getOutputFields().getAllFields();
086: for (int l = 0; l < lOutputFields.length; l++) {
087: Object lFieldType = lOutputFields[l]
088: .getType();
089: if (lFieldType instanceof BOStructure) {
090: BOStructure lStructure = (BOStructure) lFieldType;
091: BOServicemodule lStructureServicemodule = lStructure
092: .getServicemodule();
093: if (pServicemodule
094: .equals(lStructureServicemodule) == false
095: && lReferencedServicemodulesSet
096: .contains(lStructureServicemodule) == false)
097: lReferencedServicemodulesSet
098: .add(lStructureServicemodule);
099: }
100: }
101: BOOutputMessage[] lOutputMessages = lOperations[k]
102: .getOutputMessages()
103: .getAllOutputMessages();
104: for (int l = 0; l < lOutputMessages.length; l++) {
105: BOServicemodule lMessageServicemodule = lOutputMessages[l]
106: .getMessage()
107: .getServicemodule();
108: if (pServicemodule
109: .equals(lMessageServicemodule) == false
110: && lReferencedServicemodulesSet
111: .contains(lMessageServicemodule) == false)
112: lReferencedServicemodulesSet
113: .add(lMessageServicemodule);
114: }
115: }
116: }
117: }
118: return (BOServicemodule[]) lReferencedServicemodulesSet
119: .toArray(new BOServicemodule[lReferencedServicemodulesSet
120: .size()]);
121: } catch (BOException e) {
122: throw new BSDomainObjectInvocationException(
123: "Unable to collect servicemodules referenced from a particular servicemodule. ServicemoduleRef: "
124: + lServicemoduleRef, e);
125: }
126: } catch (BOException e) {
127: throw new BSUnexpectedProgramConditionException(
128: "Unable to get servicemodule ref", e);
129: }
130: }
131: }
|