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: * <p>Title: </p>
041: * <p>Description: </p>
042: * <p>Copyright: Copyright (c) 2002</p>
043: * <p>Company: </p>
044: */
045:
046: public class ServiceCategoryImpl implements ServiceCategory {
047: private Resource serviceCategory;
048:
049: public ServiceCategoryImpl(Resource serviceCategory) {
050: this .serviceCategory = serviceCategory;
051: }
052:
053: public String getCategoryName() {
054: String name = "";
055: if (serviceCategory != null) {
056: try {
057: if (serviceCategory.hasProperty(Profile.SERVICENAME)) {
058: name = serviceCategory.getProperty(
059: Profile.SERVICENAME).getString();
060: }
061: } catch (RDFException e) {
062: System.out.println("Failed: " + e);
063: }
064: }
065: return name;
066: }
067:
068: public String getCategoryCode() {
069: String code = "";
070: if (serviceCategory != null) {
071: try {
072: if (serviceCategory.hasProperty(Profile.SERVICECODE)) {
073: code = serviceCategory.getProperty(
074: Profile.SERVICECODE).getString();
075: } else {
076: code = this .getCategoryName();
077: }
078: } catch (RDFException e) {
079: System.out.println("Failed: " + e);
080: }
081: }
082: return code;
083: }
084:
085: public String getCategorySchemeName() {
086: String namingScheme = "";
087: if (serviceCategory != null) {
088: try {
089: if (serviceCategory.hasProperty(Profile.SERVICESCHEME)) {
090: namingScheme = serviceCategory.getProperty(
091: Profile.SERVICESCHEME).getString();
092: }
093: } catch (RDFException e) {
094: System.out.println("Failed: " + e);
095: }
096: }
097: return namingScheme;
098: }
099:
100: public Collection getAdditionalQualifications() {
101: ArrayList additionalQualifications = new ArrayList();
102: if (serviceCategory != null) {
103: try {
104: if (serviceCategory
105: .hasProperty(Profile.ADDITIONALQUALIFICATIONS)) {
106: StmtIterator quals = serviceCategory
107: .listProperties(Profile.ADDITIONALQUALIFICATIONS);
108:
109: while (quals.hasNext()) {
110: //there may be multiples
111: Statement st2 = quals.nextStatement();
112: RDFNode node2 = st2.getObject();
113: if (node2 instanceof Resource) {
114: Resource currentQual = (Resource) node2;
115: additionalQualifications
116: .add(new AdditionalQualificationRecord(
117: currentQual));
118: }
119: }
120: }
121: } catch (RDFException e) {
122: System.out.println("Failed: " + e);
123: }
124: }
125: return additionalQualifications;
126: }
127:
128: public String toString() {
129: String ret = "ServiceCategory(scheme: "
130: + this .getCategorySchemeName() + " name: "
131: + this .getCategoryName() + " code: "
132: + this .getCategoryCode();
133: Iterator it = this .getAdditionalQualifications().iterator();
134: while (it.hasNext()) {
135: ret = ret.concat(" " + it.next().toString() + " ");
136: }
137: ret = ret.concat(")");
138: return ret;
139: }
140: }
|