001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.tools.common.model;
019:
020: import java.util.*;
021: import javax.jws.soap.SOAPBinding;
022:
023: import org.w3c.dom.Element;
024:
025: import org.apache.cxf.tools.common.ToolException;
026:
027: public class JavaInterface implements JavaAnnotatable {
028:
029: private String name;
030: private String packageName;
031: private String namespace;
032: private String location;
033: private JavaModel model;
034: private SOAPBinding.Style soapStyle;
035: private SOAPBinding.Use soapUse;
036: private SOAPBinding.ParameterStyle soapParameterStyle;
037:
038: private final List<JavaMethod> methods = new ArrayList<JavaMethod>();
039: private final List<String> annotations = new ArrayList<String>();
040: private final Set<String> imports = new TreeSet<String>();
041:
042: private String webserviceName;
043: private Element handlerChains;
044:
045: public JavaInterface() {
046: }
047:
048: public JavaInterface(JavaModel m) {
049: this .model = m;
050: }
051:
052: public void setWebServiceName(String wsn) {
053: this .webserviceName = wsn;
054: }
055:
056: public String getWebServiceName() {
057: return this .webserviceName;
058: }
059:
060: public void setSOAPStyle(SOAPBinding.Style s) {
061: this .soapStyle = s;
062: }
063:
064: public SOAPBinding.Style getSOAPStyle() {
065: return this .soapStyle;
066: }
067:
068: public void setSOAPUse(SOAPBinding.Use u) {
069: this .soapUse = u;
070: }
071:
072: public SOAPBinding.Use getSOAPUse() {
073: return this .soapUse;
074: }
075:
076: public void setSOAPParameterStyle(SOAPBinding.ParameterStyle p) {
077: this .soapParameterStyle = p;
078: }
079:
080: public SOAPBinding.ParameterStyle getSOAPParameterStyle() {
081: return this .soapParameterStyle;
082: }
083:
084: public JavaModel getJavaModel() {
085: return this .model;
086: }
087:
088: public void setName(String n) {
089: this .name = n;
090: }
091:
092: public String getName() {
093: return name;
094: }
095:
096: public void setLocation(String l) {
097: this .location = l;
098: }
099:
100: public String getLocation() {
101: return this .location;
102: }
103:
104: public List<JavaMethod> getMethods() {
105: return methods;
106: }
107:
108: public boolean hasMethod(JavaMethod method) {
109: if (method != null) {
110: String signature = method.getSignature();
111: for (int i = 0; i < methods.size(); i++) {
112: if (signature.equals(methods.get(i).getSignature())) {
113: return true;
114: }
115: }
116: }
117: return false;
118: }
119:
120: public int indexOf(JavaMethod method) {
121: if (method != null) {
122: String signature = method.getSignature();
123: for (int i = 0; i < methods.size(); i++) {
124: if (signature.equals(methods.get(i).getSignature())) {
125: return i;
126: }
127: }
128: }
129: return -1;
130: }
131:
132: public int removeMethod(JavaMethod method) {
133: int index = indexOf(method);
134: if (index > -1) {
135: methods.remove(index);
136: }
137: return index;
138: }
139:
140: public void replaceMethod(JavaMethod method) {
141: int index = removeMethod(method);
142: methods.add(index, method);
143: }
144:
145: public void addMethod(JavaMethod method) throws ToolException {
146: if (hasMethod(method)) {
147: replaceMethod(method);
148: } else {
149: methods.add(method);
150: }
151: }
152:
153: public String getPackageName() {
154: return this .packageName;
155: }
156:
157: public void setPackageName(String pn) {
158: this .packageName = pn;
159: }
160:
161: public String getNamespace() {
162: return this .namespace;
163: }
164:
165: public void setNamespace(String ns) {
166: this .namespace = ns;
167: }
168:
169: public void addAnnotation(String annotation) {
170: this .annotations.add(annotation);
171: }
172:
173: public List<String> getAnnotations() {
174: return this .annotations;
175: }
176:
177: public void addImport(String i) {
178: imports.add(i);
179: }
180:
181: public Iterator<String> getImports() {
182: return imports.iterator();
183: }
184:
185: public void setJavaModel(JavaModel jm) {
186: this .model = jm;
187: }
188:
189: public void annotate(Annotator annotator) {
190: annotator.annotate(this );
191: }
192:
193: public Element getHandlerChains() {
194: return this .handlerChains;
195: }
196:
197: public void setHandlerChains(Element elem) {
198: this .handlerChains = elem;
199: }
200:
201: public void setFullClassName(String fullName) {
202: int index = fullName.lastIndexOf(".");
203: setPackageName(fullName.substring(0, index));
204: setName(fullName.substring(index + 1, fullName.length()));
205: }
206:
207: public String getFullClassName() {
208: StringBuffer sb = new StringBuffer();
209: sb.append(getPackageName());
210: sb.append(".");
211: sb.append(getName());
212: return sb.toString();
213: }
214:
215: public String toString() {
216: StringBuffer sb = new StringBuffer();
217: for (String anno : annotations) {
218: sb.append(anno);
219: sb.append("\n");
220: }
221: sb.append(getFullClassName());
222: return sb.toString();
223: }
224: }
|