001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.jaxwsruntimemodel;
043:
044: import java.io.IOException;
045: import java.net.URLEncoder;
046: import java.util.ArrayList;
047: import java.util.Collections;
048: import java.util.List;
049: import java.util.Map;
050: import java.util.Map.Entry;
051: import java.util.Set;
052: import java.util.StringTokenizer;
053: import javax.lang.model.element.AnnotationMirror;
054: import javax.lang.model.element.AnnotationValue;
055: import javax.lang.model.element.Element;
056: import javax.lang.model.element.ExecutableElement;
057: import javax.lang.model.element.Modifier;
058: import javax.lang.model.element.Name;
059: import javax.lang.model.element.TypeElement;
060: import javax.lang.model.type.ArrayType;
061: import javax.lang.model.type.TypeKind;
062: import javax.lang.model.type.TypeMirror;
063: import javax.lang.model.util.ElementFilter;
064: import javax.xml.namespace.QName;
065: import org.netbeans.api.java.source.CompilationController;
066: import org.netbeans.api.java.source.JavaSource;
067: import org.netbeans.modules.websvc.wsitconf.util.AbstractTask;
068: import org.netbeans.modules.websvc.wsitconf.util.SourceUtils;
069: import org.openide.filesystems.FileObject;
070: import org.openide.util.Exceptions;
071:
072: /**
073: * This class is compiled from:
074: * com.sun.xml.ws.model.RuntimeModeler
075: * com.sun.xml.ws.model.SEIModel
076: * com.sun.xml.ws.model.AbstractSEIModelImpl
077: * com.sun.xml.ws.wsdl.writer.WSDLGenerator
078: * in JAX-WS component.
079: * @author Martin Grebac
080: */
081: public class JavaWsdlMapper {
082:
083: public static final String RESPONSE = "Response"; //NOI18N
084: public static final String RETURN = "return"; //NOI18N
085: public static final String BEAN = "Bean"; //NOI18N
086: public static final String SERVICE = "Service"; //NOI18N
087: public static final String PORT = "Port"; //NOI18N
088: public static final String PORT_TYPE = "PortType"; //NOI18N
089: public static final String BINDING = "Binding"; //NOI18N
090:
091: private static final String JAVAX_JWS_WEBSERVICE = "javax.jws.WebService";
092: private static final String UTF8 = "UTF-8";
093:
094: /** Creates a new instance of JavaWsdlMapper */
095: public JavaWsdlMapper() {
096: }
097:
098: /**
099: * gets the namespace <code>String</code> for a given <code>packageName</code>
100: * @param packageName the name of the package used to find a namespace
101: * @return the namespace for the specified <code>packageName</code>
102: */
103: public static String getNamespace(String packageName) {
104: if (packageName == null || packageName.length() == 0) {
105: return null;
106: }
107:
108: StringTokenizer tokenizer = new StringTokenizer(packageName,
109: ".");
110: String[] tokens;
111: if (tokenizer.countTokens() == 0) {
112: tokens = new String[0];
113: } else {
114: tokens = new String[tokenizer.countTokens()];
115: for (int i = tokenizer.countTokens() - 1; i >= 0; i--) {
116: tokens[i] = tokenizer.nextToken();
117: }
118: }
119: StringBuilder namespace = new StringBuilder("http://"); //NOI18N
120: for (int i = 0; i < tokens.length; i++) {
121: if (i != 0) {
122: namespace.append('.');
123: }
124: namespace.append(tokens[i]);
125: }
126: namespace.append('/');
127: return namespace.toString();
128: }
129:
130: /**
131: * gets the <code>wsdl:serviceName</code> for a given implementation class
132: * @param implClass the implementation class
133: * @return the <code>wsdl:serviceName</code> for the <code>implClass</code>
134: */
135: public static QName getServiceName(FileObject implClass) {
136:
137: final java.lang.String[] serviceNameQNameARR = new String[2];
138: if (implClass == null) {
139: return null;
140: }
141: try {
142: JavaSource js = JavaSource.forFileObject(implClass);
143: js.runUserActionTask(
144: new AbstractTask<CompilationController>() {
145: public void run(CompilationController controller)
146: throws java.io.IOException {
147: controller
148: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
149: SourceUtils sourceUtils = SourceUtils
150: .newInstance(controller);
151: TypeElement te = sourceUtils
152: .getTypeElement();
153:
154: serviceNameQNameARR[0] = te.getSimpleName()
155: .toString()
156: + SERVICE;
157: String packageName = getPackageFromClass(te
158: .getQualifiedName().toString());
159: serviceNameQNameARR[1] = getNamespace(packageName);
160:
161: List<? extends AnnotationMirror> annotations = te
162: .getAnnotationMirrors();
163: for (AnnotationMirror m : annotations) {
164: Name qualifiedName = ((TypeElement) m
165: .getAnnotationType()
166: .asElement())
167: .getQualifiedName();
168: if (qualifiedName
169: .contentEquals(JAVAX_JWS_WEBSERVICE)) { //NOI18N
170: String serviceNameAnnot = null;
171: String targetNamespaceAnnot = null;
172:
173: @SuppressWarnings("unchecked")
174: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) m
175: .getElementValues();
176: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
177: .entrySet()) {
178: ExecutableElement el = ex
179: .getKey();
180: String val = (String) ex
181: .getValue().getValue();
182: if (el.getSimpleName()
183: .contentEquals(
184: "serviceName")) { //NOI18N
185: serviceNameAnnot = val;
186: if (serviceNameAnnot != null) {
187: serviceNameAnnot = URLEncoder
188: .encode(
189: serviceNameAnnot,
190: UTF8); //NOI18N
191: }
192: } else if (el
193: .getSimpleName()
194: .contentEquals(
195: "targetNamespace")) { //NOI18N
196: targetNamespaceAnnot = val;
197: if (targetNamespaceAnnot != null) {
198: targetNamespaceAnnot = URLEncoder
199: .encode(
200: targetNamespaceAnnot,
201: UTF8); //NOI18N
202: }
203: }
204: if (targetNamespaceAnnot != null
205: && serviceNameAnnot != null)
206: break;
207: }
208: if (serviceNameAnnot != null) {
209: serviceNameQNameARR[0] = serviceNameAnnot;
210: }
211: if (targetNamespaceAnnot != null) {
212: serviceNameQNameARR[1] = targetNamespaceAnnot;
213: }
214: }
215: }
216: }
217: }, true);
218: } catch (IOException ex) {
219: Exceptions.printStackTrace(ex);
220: }
221: return new QName(serviceNameQNameARR[1], serviceNameQNameARR[0]);
222: }
223:
224: /**
225: * gets the <code>wsdl:portName</code> for a given implementation class
226: * @param implClass the implementation class
227: * @param targetNamespace Namespace URI for service name
228: * @return the <code>wsdl:portName</code> for the <code>implClass</code>
229: */
230: public static String getBindingName(FileObject implClass,
231: String targetNamespace) {
232: QName portName = getPortName(implClass, targetNamespace);
233: if (portName != null) {
234: return (portName.getLocalPart() + BINDING);
235: }
236: return null;
237: }
238:
239: public static final int UNKNOWN = -1;
240: public static final int OUTPUTINPUT = 0;
241: public static final int OUTPUT = 1;
242: public static final int INPUT = 2;
243:
244: @SuppressWarnings("unchecked")
245: public static List<String> getOperationFaults(FileObject implClass,
246: final String operationName) {
247: if ((implClass == null) || (operationName == null)) {
248: return Collections.EMPTY_LIST;
249: }
250:
251: final List<String> faults = new ArrayList<String>();
252: try {
253: JavaSource js = JavaSource.forFileObject(implClass);
254: js.runUserActionTask(
255: new AbstractTask<CompilationController>() {
256: public void run(CompilationController controller)
257: throws java.io.IOException {
258: controller
259: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
260: SourceUtils sourceUtils = SourceUtils
261: .newInstance(controller);
262: TypeElement te = sourceUtils
263: .getTypeElement();
264: List<? extends Element> members = te
265: .getEnclosedElements();
266: List<ExecutableElement> methods = ElementFilter
267: .methodsIn(members);
268: for (ExecutableElement method : methods) {
269: Set<Modifier> modifiers = method
270: .getModifiers();
271: if (modifiers.contains(Modifier.PUBLIC)) {
272: List<? extends AnnotationMirror> annotations = method
273: .getAnnotationMirrors();
274: boolean hasWebMethodAnnotation = false;
275: String nameAnnot = null;
276: for (AnnotationMirror an : annotations) {
277: TypeElement webMethodEl = controller
278: .getElements()
279: .getTypeElement(
280: "javax.jws.WebMethod"); //NOI18N
281: if (webMethodEl != null
282: && controller
283: .getTypes()
284: .isSameType(
285: webMethodEl
286: .asType(),
287: an
288: .getAnnotationType())) {
289: hasWebMethodAnnotation = true;
290: @SuppressWarnings("unchecked")
291: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) an
292: .getElementValues();
293: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
294: .entrySet()) {
295: ExecutableElement el = ex
296: .getKey();
297: String val = (String) ex
298: .getValue()
299: .getValue();
300: if (el
301: .getSimpleName()
302: .contentEquals(
303: "operationName")) { //NOI18N
304: nameAnnot = val;
305: if (nameAnnot != null)
306: nameAnnot = URLEncoder
307: .encode(
308: nameAnnot,
309: UTF8); //NOI18N
310: }
311: if (nameAnnot != null)
312: break;
313: }
314: break;
315: }
316: }
317: String opName = method
318: .getSimpleName().toString();
319: if ((hasWebMethodAnnotation)
320: && (nameAnnot != null)) {
321: opName = nameAnnot;
322: }
323: if (operationName.equals(opName)) {
324: List<? extends TypeMirror> excs = method
325: .getThrownTypes();
326: for (TypeMirror ex : excs) {
327: String tName = getTypeName(
328: controller, ex);
329: if (tName != null) {
330: faults.add(tName);
331: }
332: }
333: }
334: }
335: }
336: }
337: }, true);
338: } catch (IOException ex) {
339: Exceptions.printStackTrace(ex);
340: }
341: return faults;
342: }
343:
344: static String getTypeName(CompilationController controller,
345: TypeMirror typeMirror) {
346: TypeKind typeKind = typeMirror.getKind();
347: switch (typeKind) {
348: case BOOLEAN:
349: return "boolean"; // NOI18N
350: case BYTE:
351: return "byte"; // NOI18N
352: case CHAR:
353: return "char"; // NOI18N
354: case DOUBLE:
355: return "double"; // NOI18N
356: case FLOAT:
357: return "float"; // NOI18N
358: case INT:
359: return "int"; // NOI18N
360: case LONG:
361: return "long"; // NOI18N
362: case SHORT:
363: return "short"; // NOI18N
364: case VOID:
365: return "void"; // NOI18N
366: case DECLARED:
367: Element element = controller.getTypes().asElement(
368: typeMirror);
369: return ((TypeElement) element).getSimpleName().toString();
370: case ARRAY:
371: ArrayType arrayType = (ArrayType) typeMirror;
372: Element componentTypeElement = controller.getTypes()
373: .asElement(arrayType.getComponentType());
374: return ((TypeElement) componentTypeElement).getSimpleName()
375: .toString()
376: + "[]";
377: case ERROR:
378: case EXECUTABLE:
379: case NONE:
380: case NULL:
381: case OTHER:
382: case PACKAGE:
383: case TYPEVAR:
384: case WILDCARD:
385: default:
386: break;
387: }
388: return null;
389: }
390:
391: public static List<String> getOperationNames(FileObject implClass) {
392: final List<String> operations = new ArrayList<String>();
393: if (implClass == null)
394: return null;
395: try {
396: JavaSource js = JavaSource.forFileObject(implClass);
397: js.runUserActionTask(
398: new AbstractTask<CompilationController>() {
399: public void run(CompilationController controller)
400: throws java.io.IOException {
401: controller
402: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
403: SourceUtils sourceUtils = SourceUtils
404: .newInstance(controller);
405: TypeElement te = sourceUtils
406: .getTypeElement();
407:
408: List<? extends Element> members = te
409: .getEnclosedElements();
410: List<ExecutableElement> methods = ElementFilter
411: .methodsIn(members);
412: boolean foundWebMethodAnnotation = false;
413: for (ExecutableElement method : methods) {
414: Set<Modifier> modifiers = method
415: .getModifiers();
416: if (modifiers.contains(Modifier.PUBLIC)) {
417: List<? extends AnnotationMirror> annotations = method
418: .getAnnotationMirrors();
419: boolean hasWebMethodAnnotation = false;
420: String nameAnnot = null;
421: for (AnnotationMirror an : annotations) {
422: TypeElement webMethodEl = controller
423: .getElements()
424: .getTypeElement(
425: "javax.jws.WebMethod"); //NOI18N
426: if (webMethodEl != null
427: && controller
428: .getTypes()
429: .isSameType(
430: webMethodEl
431: .asType(),
432: an
433: .getAnnotationType())) {
434: hasWebMethodAnnotation = true;
435: @SuppressWarnings("unchecked")
436: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) an
437: .getElementValues();
438: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
439: .entrySet()) {
440: ExecutableElement el = ex
441: .getKey();
442: String val = (String) ex
443: .getValue()
444: .getValue();
445: if (el
446: .getSimpleName()
447: .contentEquals(
448: "operationName")) { //NOI18N
449: nameAnnot = val;
450: if (nameAnnot != null)
451: nameAnnot = URLEncoder
452: .encode(
453: nameAnnot,
454: UTF8); //NOI18N
455: }
456: if (nameAnnot != null)
457: break;
458: }
459: break;
460: }
461: }
462: if (hasWebMethodAnnotation) {
463: if (!foundWebMethodAnnotation) {
464: foundWebMethodAnnotation = true;
465: // remove all methods added before because only annotated methods should be added
466: if (!operations.isEmpty())
467: operations.clear();
468: }
469: if (nameAnnot != null) {
470: operations.add(nameAnnot);
471: } else {
472: operations.add(method
473: .getSimpleName()
474: .toString());
475: }
476: } else {
477: // there are only non-annotated methods present until now
478: operations.add(method
479: .getSimpleName()
480: .toString());
481: }
482: }
483: }
484: }
485: }, true);
486: } catch (IOException ex) {
487: Exceptions.printStackTrace(ex);
488: }
489: return operations;
490: }
491:
492: public static QName getPortTypeName(FileObject implClass) {
493: final java.lang.String[] portTypeQNameARR = new String[2];
494: if (implClass == null)
495: return null;
496: try {
497: JavaSource js = JavaSource.forFileObject(implClass);
498: js.runUserActionTask(
499: new AbstractTask<CompilationController>() {
500: public void run(CompilationController controller)
501: throws java.io.IOException {
502: controller
503: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
504: SourceUtils sourceUtils = SourceUtils
505: .newInstance(controller);
506: TypeElement te = sourceUtils
507: .getTypeElement();
508: portTypeQNameARR[0] = te.getSimpleName()
509: .toString();
510:
511: List<? extends AnnotationMirror> annotations = te
512: .getAnnotationMirrors();
513: for (AnnotationMirror m : annotations) {
514: Name qualifiedName = ((TypeElement) m
515: .getAnnotationType()
516: .asElement())
517: .getQualifiedName();
518: if (qualifiedName
519: .contentEquals(JAVAX_JWS_WEBSERVICE)) { //NOI18N
520: String nameAnnot = null;
521: String targetNamespaceAnnot = null;
522:
523: @SuppressWarnings("unchecked")
524: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) m
525: .getElementValues();
526: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
527: .entrySet()) {
528: ExecutableElement el = ex
529: .getKey();
530: String val = (String) ex
531: .getValue().getValue();
532: if (el.getSimpleName()
533: .contentEquals("name")) { //NOI18N
534: nameAnnot = val;
535: if (nameAnnot != null)
536: nameAnnot = URLEncoder
537: .encode(
538: nameAnnot,
539: UTF8); //NOI18N
540: } else if (el
541: .getSimpleName()
542: .contentEquals(
543: "targetNamespace")) { //NOI18N
544: targetNamespaceAnnot = val;
545: if (targetNamespaceAnnot != null)
546: targetNamespaceAnnot = URLEncoder
547: .encode(
548: targetNamespaceAnnot,
549: UTF8); //NOI18N
550: }
551: if (targetNamespaceAnnot != null
552: && nameAnnot != null)
553: break;
554: }
555:
556: if ((nameAnnot != null)
557: && (nameAnnot.length() > 0)) {
558: portTypeQNameARR[0] = nameAnnot;
559: }
560:
561: String pkg = getPackageFromClass(te
562: .getQualifiedName()
563: .toString());
564:
565: String targetNamespace = targetNamespaceAnnot;
566: if ((targetNamespace == null)
567: || (targetNamespace
568: .length() == 0)) {
569: targetNamespace = getNamespace(pkg);
570: }
571:
572: portTypeQNameARR[1] = targetNamespace;
573: }
574: }
575: }
576: }, true);
577: } catch (IOException ex) {
578: Exceptions.printStackTrace(ex);
579: }
580: return new QName(portTypeQNameARR[1], portTypeQNameARR[0]);
581: }
582:
583: public static String getWsdlLocation(FileObject implClass) {
584: final java.lang.String[] wsdlLocARR = new String[1];
585: try {
586: if (implClass == null)
587: return null;
588:
589: JavaSource js = JavaSource.forFileObject(implClass);
590: js.runUserActionTask(
591: new AbstractTask<CompilationController>() {
592: public void run(CompilationController controller)
593: throws java.io.IOException {
594: controller
595: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
596: SourceUtils sourceUtils = SourceUtils
597: .newInstance(controller);
598: TypeElement te = sourceUtils
599: .getTypeElement();
600: List<? extends AnnotationMirror> annotations = te
601: .getAnnotationMirrors();
602: for (AnnotationMirror m : annotations) {
603: Name qualifiedName = ((TypeElement) m
604: .getAnnotationType()
605: .asElement())
606: .getQualifiedName();
607: if (qualifiedName
608: .contentEquals(JAVAX_JWS_WEBSERVICE)) { //NOI18N
609: String wsdlLoc = null;
610: @SuppressWarnings("unchecked")
611: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) m
612: .getElementValues();
613: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
614: .entrySet()) {
615: ExecutableElement el = ex
616: .getKey();
617: String val = (String) ex
618: .getValue().getValue();
619: if (el.getSimpleName()
620: .contentEquals(
621: "wsdlLocation")) { //NOI18N
622: wsdlLoc = val;
623: if (wsdlLoc != null)
624: wsdlLoc = URLEncoder
625: .encode(
626: wsdlLoc,
627: UTF8); //NOI18N
628: }
629: if (wsdlLoc != null)
630: break;
631: }
632: wsdlLocARR[1] = wsdlLoc;
633: }
634: }
635: }
636: }, true);
637: } catch (IOException ex) {
638: Exceptions.printStackTrace(ex);
639: }
640: return wsdlLocARR[0];
641: }
642:
643: /**
644: * gets the <code>wsdl:portName</code> for a given implementation class
645: * @param implClass the implementation class
646: * @param targetNamespace Namespace URI for service name
647: * @return the <code>wsdl:portName</code> for the <code>implClass</code>
648: */
649: public static QName getPortName(FileObject implClass,
650: final String targetNamespace) {
651:
652: final java.lang.String[] portNameQNameARR = new String[2];
653: if (implClass == null)
654: return null;
655: try {
656: JavaSource js = JavaSource.forFileObject(implClass);
657: js.runUserActionTask(
658: new AbstractTask<CompilationController>() {
659: public void run(CompilationController controller)
660: throws java.io.IOException {
661: controller
662: .toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
663: SourceUtils sourceUtils = SourceUtils
664: .newInstance(controller);
665: TypeElement te = sourceUtils
666: .getTypeElement();
667: String className = te.getSimpleName()
668: .toString();
669: List<? extends AnnotationMirror> annotations = te
670: .getAnnotationMirrors();
671: for (AnnotationMirror m : annotations) {
672: Name qualifiedName = ((TypeElement) m
673: .getAnnotationType()
674: .asElement())
675: .getQualifiedName();
676: if (qualifiedName
677: .contentEquals(JAVAX_JWS_WEBSERVICE)) { //NOI18N
678: String portNameAnnot = null;
679: String nameAnnot = null;
680: String targetNamespaceAnnot = null;
681:
682: @SuppressWarnings("unchecked")
683: Map<ExecutableElement, AnnotationValue> expressions = (Map<ExecutableElement, AnnotationValue>) m
684: .getElementValues();
685: for (Entry<ExecutableElement, AnnotationValue> ex : expressions
686: .entrySet()) {
687: ExecutableElement el = ex
688: .getKey();
689: String val = (String) ex
690: .getValue().getValue();
691: if (el.getSimpleName()
692: .contentEquals("name")) { //NOI18N
693: nameAnnot = val;
694: if (nameAnnot != null)
695: nameAnnot = URLEncoder
696: .encode(
697: nameAnnot,
698: UTF8); //NOI18N
699: } else if (el.getSimpleName()
700: .contentEquals(
701: "portName")) { //NOI18N
702: portNameAnnot = val;
703: if (portNameAnnot != null)
704: portNameAnnot = URLEncoder
705: .encode(
706: portNameAnnot,
707: UTF8); //NOI18N
708: } else if (el
709: .getSimpleName()
710: .contentEquals(
711: "targetNamespace")) { //NOI18N
712: targetNamespaceAnnot = val;
713: if (targetNamespaceAnnot != null)
714: targetNamespaceAnnot = URLEncoder
715: .encode(
716: targetNamespaceAnnot,
717: UTF8); //NOI18N
718: }
719: if (targetNamespaceAnnot != null
720: && nameAnnot != null
721: && portNameAnnot != null)
722: break;
723: }
724:
725: if ((portNameAnnot != null)
726: && (portNameAnnot.length() > 0)) {
727: portNameQNameARR[0] = portNameAnnot;
728: } else if ((nameAnnot != null)
729: && (nameAnnot.length() > 0)) {
730: portNameQNameARR[0] = nameAnnot
731: + PORT;
732: } else {
733: portNameQNameARR[0] = className
734: + PORT;
735: }
736:
737: if (targetNamespace == null) {
738: if ((targetNamespaceAnnot != null)
739: && (targetNamespaceAnnot
740: .length() > 0)) {
741: portNameQNameARR[1] = targetNamespaceAnnot;
742: } else {
743: String packageName = getPackageFromClass(className);
744: portNameQNameARR[1] = getNamespace(packageName);
745: }
746: }
747: }
748: }
749: }
750: }, true);
751: } catch (IOException ex) {
752: Exceptions.printStackTrace(ex);
753: }
754: return new QName(portNameQNameARR[1], portNameQNameARR[0]);
755: }
756:
757: private static String getPackageFromClass(String fqClassName) {
758: return fqClassName.substring(0, fqClassName.lastIndexOf('.'));
759: }
760:
761: }
|