Mercurial > repos > ganjoo > webservice_toolsuite
comparison WebServiceToolWorkflow/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/ModelReferenceImpl.java @ 0:d5cd409b8a18 default tip
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
| author | ganjoo |
|---|---|
| date | Tue, 07 Jun 2011 18:00:50 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d5cd409b8a18 |
|---|---|
| 1 package edu.uga.cs.lsdis.meteors.wadls; | |
| 2 | |
| 3 import java.net.URI; | |
| 4 import java.net.URISyntaxException; | |
| 5 import java.util.ArrayList; | |
| 6 import java.util.List; | |
| 7 | |
| 8 import javax.wadls.Application; | |
| 9 import javax.wadls.ModelReference; | |
| 10 import javax.wadls.WADLSException; | |
| 11 | |
| 12 /** | |
| 13 * This class represents a ModelReference. | |
| 14 * | |
| 15 * @author Zixin Wu (wuzixin@uga.edu) | |
| 16 * | |
| 17 */ | |
| 18 public class ModelReferenceImpl implements ModelReference { | |
| 19 | |
| 20 /** | |
| 21 * The URI of the ontology used in the model reference | |
| 22 */ | |
| 23 protected URI namespace; | |
| 24 | |
| 25 /** | |
| 26 * The parent WSDL-S element of this model reference | |
| 27 */ | |
| 28 protected Object parent; | |
| 29 | |
| 30 /** | |
| 31 * The NS Prefix of the model reference | |
| 32 */ | |
| 33 protected String prefix; | |
| 34 | |
| 35 /** | |
| 36 * The ontology concept of this model reference | |
| 37 */ | |
| 38 protected String concept; | |
| 39 | |
| 40 /** | |
| 41 * Get the concept of this modelReference. | |
| 42 * @return The concept of this modelReference. | |
| 43 */ | |
| 44 public String getConcept(){ | |
| 45 return this.concept; | |
| 46 } | |
| 47 | |
| 48 /** | |
| 49 * Set the concept of this modelReference | |
| 50 * @param concept The desired concept of this modelReference | |
| 51 */ | |
| 52 public void setConcept(String concept){ | |
| 53 this.concept = concept; | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * Get the prefix of this modelReference | |
| 58 * @return The prefix of this modelReference | |
| 59 */ | |
| 60 public String getPrefix(){ | |
| 61 return this.prefix; | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Set the prefix of the ontology used in this modelReference | |
| 66 * @param prefix The desired prefix of the ontology used in this modelReference | |
| 67 */ | |
| 68 public void setPrefix(String prefix){ | |
| 69 this.prefix = prefix; | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Get the namespace of the ontology used in this modelReference | |
| 74 * @return The namespace of the ontology used in this modelReference | |
| 75 */ | |
| 76 public URI getNamespace(){ | |
| 77 return this.namespace; | |
| 78 } | |
| 79 | |
| 80 /** | |
| 81 * Set the namespace of the ontology used in this modelReference | |
| 82 * @param nameSpace The desired namespace of the ontology used in this modelReference | |
| 83 */ | |
| 84 public void setNamespace(String nameSpace) | |
| 85 throws URISyntaxException{ | |
| 86 //System.out.println("namespace is "+nameSpace); | |
| 87 this.namespace = new URI(nameSpace); | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * Get the parent object of this modelReference | |
| 92 * @return The parent object of this modelReference | |
| 93 */ | |
| 94 public Object getParent(){ | |
| 95 return this.parent; | |
| 96 } | |
| 97 | |
| 98 /** | |
| 99 * Set the parent object of this modelReference | |
| 100 * @param parent The desired parent object of this modelReference | |
| 101 */ | |
| 102 public void setParent(Object parent){ | |
| 103 this.parent = parent; | |
| 104 } | |
| 105 | |
| 106 /** | |
| 107 * Return a formatted string representing this modelReference. | |
| 108 * @return A formatted string representing this modelReference. | |
| 109 */ | |
| 110 public String value(){ | |
| 111 if (this.concept == null || this.namespace == null) | |
| 112 return null; | |
| 113 return (this.namespace + "#" + this.concept); | |
| 114 } | |
| 115 | |
| 116 public String toString(){ | |
| 117 if (this.concept == null) | |
| 118 return null; | |
| 119 if (this.prefix != null){ //use the prefix | |
| 120 return (this.prefix + "#" + this.concept); | |
| 121 } | |
| 122 else if (this.namespace != null){ //use the namespace | |
| 123 return (this.namespace + "#" + this.concept); | |
| 124 } | |
| 125 else | |
| 126 return null; | |
| 127 } | |
| 128 | |
| 129 public static List<ModelReference> getModelReferences(String mrefs, Application app) throws URISyntaxException, WADLSException { | |
| 130 String[] refs = mrefs.split(" "); | |
| 131 List<ModelReference> list = new ArrayList<ModelReference>(refs.length); | |
| 132 for(String ref : refs) { | |
| 133 ModelReference mr = app.createModelReference(); | |
| 134 mr.valueOf(ref, app); | |
| 135 list.add(mr); | |
| 136 } | |
| 137 return list; | |
| 138 } | |
| 139 | |
| 140 public void valueOf(String modelReferenceAsString, Application app) throws URISyntaxException, WADLSException{ | |
| 141 int index = modelReferenceAsString.indexOf('#'); | |
| 142 String prefix = (index != -1) | |
| 143 ? modelReferenceAsString.substring(0, index) | |
| 144 : null; | |
| 145 String namespaceURI = prefix; | |
| 146 String localPart = null; | |
| 147 | |
| 148 //System.out.println("Namespace URI:"+namespaceURI); | |
| 149 //assume the user give prefix#localName | |
| 150 if (prefix != null){ | |
| 151 //try to find a namespaceURI for that prefix | |
| 152 String tmpNamespaceURI = app.getNamespace(prefix); | |
| 153 //System.out.println("Temp Namespace URI:"+tmpNamespaceURI); | |
| 154 if(tmpNamespaceURI != null) { //the user did give prefix | |
| 155 namespaceURI = tmpNamespaceURI.substring(0, tmpNamespaceURI.length()); | |
| 156 } | |
| 157 else{ //the user gave namespaceURI instead of prefix | |
| 158 //try to find a prefix for that namespaceURI | |
| 159 prefix = app.getPrefix(namespaceURI); | |
| 160 if (prefix == null) | |
| 161 prefix = app.getPrefix(namespaceURI+"#"); | |
| 162 } | |
| 163 localPart = modelReferenceAsString.substring(index + 1); | |
| 164 } | |
| 165 else if (!prefix.equals("")){ //no prefix or namespaceURI is given, but '#' is included | |
| 166 //use target namespace | |
| 167 namespaceURI = app.getTargetNamespace(); | |
| 168 prefix = app.getPrefix(namespaceURI); | |
| 169 localPart = modelReferenceAsString.substring(1); | |
| 170 } | |
| 171 else{ | |
| 172 throw new IllegalArgumentException( | |
| 173 "No Namespace URI is provided for this modelReference: " + | |
| 174 modelReferenceAsString | |
| 175 + "."); | |
| 176 } | |
| 177 | |
| 178 if (namespaceURI != null){ | |
| 179 System.out.println("namespaceURI is "+namespaceURI); | |
| 180 this.setNamespace(namespaceURI); | |
| 181 //System.out.println("Concept:"+localPart); | |
| 182 this.setConcept(localPart); | |
| 183 this.setPrefix(prefix); | |
| 184 } | |
| 185 else{ | |
| 186 String faultCode = (prefix == null) | |
| 187 ? WADLSException.NO_PREFIX_SPECIFIED | |
| 188 : WADLSException.UNBOUND_PREFIX; | |
| 189 | |
| 190 WADLSException wadlExc = new WADLSException(faultCode, | |
| 191 "Unable to determine " + | |
| 192 "namespace of '" + | |
| 193 modelReferenceAsString + "'."); | |
| 194 | |
| 195 throw wadlExc; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 /** | |
| 200 * Equals method overriden to compare two modelreferences. | |
| 201 * We campare the namespace and the concept name (literally) | |
| 202 * @param obj | |
| 203 */ | |
| 204 public boolean equals(Object obj) { | |
| 205 if (!(obj instanceof ModelReference)){ | |
| 206 return false; | |
| 207 }else{ | |
| 208 ModelReference ref = (ModelReference)obj; | |
| 209 return (concept.equals(ref.getConcept()) && | |
| 210 namespace.equals(ref.getNamespace())); | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 public int hashCode(){ | |
| 215 return this.value().hashCode(); | |
| 216 } | |
| 217 } |
