001: /*
002: * <copyright>
003: *
004: * Copyright 2002-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.servicediscovery.description;
028:
029: import java.util.ArrayList;
030: import java.util.Collection;
031: import java.util.Iterator;
032:
033: import com.hp.hpl.jena.rdf.model.RDFException;
034: import com.hp.hpl.jena.rdf.model.RDFNode;
035: import com.hp.hpl.jena.rdf.model.Resource;
036: import com.hp.hpl.jena.rdf.model.Statement;
037: import com.hp.hpl.jena.rdf.model.StmtIterator;
038:
039: /**
040: * Implements ServiceProfile
041: */
042:
043: public class ServiceProfileImpl implements ServiceProfile {
044:
045: private Resource serviceProfile;
046: private Resource serviceGrounding;
047:
048: public ServiceProfileImpl(Resource serviceProfile,
049: Resource serviceGrounding) {
050: this .serviceProfile = serviceProfile;
051: this .serviceGrounding = serviceGrounding;
052: }
053:
054: public Collection getServiceCategories() {
055: ArrayList serviceCategories = new ArrayList();
056: if (serviceProfile != null) {
057: try {
058: if (serviceProfile.hasProperty(Profile.SERVICECATEGORY)) {
059: StmtIterator cats = serviceProfile
060: .listProperties(Profile.SERVICECATEGORY);
061: while (cats.hasNext()) {
062: //can be multiple service categories heres
063: Statement st = cats.nextStatement();
064: RDFNode node = st.getObject();
065: if (node instanceof Resource) {
066: Resource serviceCat = (Resource) node;
067: serviceCategories
068: .add(new ServiceCategoryImpl(
069: serviceCat));
070: }
071: }
072: }
073: } catch (RDFException e) {
074: System.out.println("Failed: " + e);
075: }
076: }
077: return serviceCategories;
078: }
079:
080: public String getServiceProfileID() {
081: String ret = " ";
082: ret = serviceProfile.getURI();
083: ret = ret.substring(1);
084: return ret;
085: }
086:
087: public String getEchelonOfSupport() {
088: String echelonOfSupport = "";
089: try {
090: //get the text description
091: if (serviceProfile.hasProperty(Profile.ECHELONOFSUPPORT)) {
092: StmtIterator echelon = serviceProfile
093: .listProperties(Profile.ECHELONOFSUPPORT);
094: while (echelon.hasNext()) {
095: //should only be one string in this property
096: echelonOfSupport = echelon.nextStatement()
097: .getString();
098: }
099: }
100: } catch (RDFException e) {
101: System.out.println("Failed: " + e);
102: }
103: return echelonOfSupport;
104: }
105:
106: public String getTextDescription() {
107: String textDescription = "";
108: try {
109: //get the text description
110: if (serviceProfile.hasProperty(Profile.TEXTDESCRIPTION)) {
111: StmtIterator descs = serviceProfile
112: .listProperties(Profile.TEXTDESCRIPTION);
113: while (descs.hasNext()) {
114: //should only be one string in this property
115: textDescription = descs.nextStatement().getString();
116: }
117: }
118: } catch (RDFException e) {
119: System.out.println("Failed: " + e);
120: }
121: return textDescription;
122: }
123:
124: public String getServiceGroundingURI() {
125: String uri = "";
126: try {
127: if (serviceGrounding.hasProperty(Profile.WSDLDOCUMENT)) {
128: StmtIterator uris = serviceGrounding
129: .listProperties(Profile.WSDLDOCUMENT);
130: while (uris.hasNext()) {
131: //assume only one of these for now
132: uri = uris.nextStatement().getString();
133: }
134: }
135: } catch (RDFException e) {
136: System.out.println("Failed: " + e);
137: }
138: return uri;
139: }
140:
141: public String getServiceGroundingBindingType() {
142: String bindingType = "SOAP";
143: try {
144: if (serviceGrounding.hasProperty(Profile.BINDINGTYPE)) {
145: StmtIterator bindingTypes = serviceGrounding
146: .listProperties(Profile.BINDINGTYPE);
147: while (bindingTypes.hasNext()) {
148: //assume only one of these for now
149: bindingType = bindingTypes.nextStatement()
150: .getString();
151: }
152: }
153: } catch (RDFException e) {
154: System.out.println("Failed: " + e);
155: }
156: return bindingType;
157:
158: }
159:
160: /*
161: //do we have any inputs
162: if(serviceProfile.hasProperty(Profile.INPUT)){
163: StmtIterator ins = serviceProfile.listProperties(Profile.INPUT);
164: while(ins.hasNext()) {
165: Statement st = ins.next();
166: RDFNode node = st.getObject();
167: if(node instanceof Resource) {
168: Resource input = (Resource)node;
169: System.out.println(input.getLocalName());
170: }
171: }
172: }
173: //do we have any outputs
174: if(serviceProfile.hasProperty(Profile.OUTPUT)){
175: StmtIterator outs = serviceProfile.listProperties(Profile.OUTPUT);
176: while(outs.hasNext()) {
177: Statement st = outs.next();
178: RDFNode node = st.getObject();
179: if(node instanceof Resource) {
180: Resource output = (Resource)node;
181: System.out.println(output.getLocalName());
182: }
183: }
184: }*/
185:
186: public String toString() {
187: String ret = "ServiceProfile " + "ID: "
188: + this .getServiceProfileID() + " (text: "
189: + this .getTextDescription();
190: ret = ret.concat(" wsdl uri: " + this .getServiceGroundingURI());
191: ret = ret.concat(" binding type: "
192: + this .getServiceGroundingBindingType());
193: Iterator it = getServiceCategories().iterator();
194: while (it.hasNext()) {
195: ret = ret.concat(" " + it.next().toString());
196: }
197: ret = ret.concat(")");
198: return ret;
199: }
200:
201: }
|