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.java2wsdl.processor;
019:
020: import java.lang.reflect.Method;
021: import java.lang.reflect.Modifier;
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import javax.jws.WebMethod;
026: import javax.jws.WebParam;
027: import javax.jws.WebService;
028: import javax.jws.soap.SOAPBinding;
029: import javax.xml.ws.WebServiceProvider;
030:
031: import org.apache.cxf.tools.java2wsdl.processor.internal.jaxws.WrapperUtil;
032: import org.apache.cxf.tools.util.AnnotationUtil;
033:
034: public final class FrontendFactory {
035: private static FrontendFactory instance;
036: private Class serviceClass;
037: private List<Method> wsMethods;
038: private Class[] annotations = new Class[] { SOAPBinding.class,
039: WebService.class, WebServiceProvider.class };
040:
041: public enum Style {
042: Jaxws, Simple
043: }
044:
045: private FrontendFactory() {
046: }
047:
048: public static FrontendFactory getInstance() {
049: if (instance == null) {
050: instance = new FrontendFactory();
051: }
052: return instance;
053: }
054:
055: @SuppressWarnings("unchecked")
056: private boolean isJaxws() {
057: if (serviceClass == null) {
058: return true;
059: }
060: for (Class annotation : annotations) {
061: if (serviceClass.getAnnotation(annotation) != null) {
062: return true;
063: }
064: }
065: if (isJAXWSAnnotationExists()) {
066: return true;
067: }
068: return false;
069: }
070:
071: private boolean isJAXWSAnnotationExists() {
072: for (Method method : wsMethods) {
073: if (WrapperUtil.isWrapperClassExists(method)) {
074: return true;
075: }
076: WebParam param = AnnotationUtil.getPrivMethodAnnotation(
077: method, WebParam.class);
078: if (param != null) {
079: return true;
080: }
081: }
082: return false;
083: }
084:
085: private List<Method> getWSMethods() {
086: List<Method> methods = new ArrayList<Method>();
087: for (Method method : serviceClass.getMethods()) {
088: if (method.getDeclaringClass().equals(Object.class)
089: || !Modifier.isPublic(method.getModifiers())
090: || isExcluced(method)) {
091: continue;
092: }
093: methods.add(method);
094: }
095: return methods;
096: }
097:
098: private boolean isExcluced(Method method) {
099: WebMethod webMethod = AnnotationUtil.getPrivMethodAnnotation(
100: method, WebMethod.class);
101: if (webMethod != null && webMethod.exclude()) {
102: return true;
103: }
104: return false;
105: }
106:
107: public Style discoverStyle() {
108: if (isJaxws()) {
109: return Style.Jaxws;
110: }
111: return Style.Simple;
112: }
113:
114: public void setServiceClass(Class c) {
115: this.serviceClass = c;
116: if (c != null) {
117: this.wsMethods = getWSMethods();
118: }
119: }
120: }
|