📄 javaservicedesc.java
字号:
/* * Copyright 2002-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.description;import org.apache.axis.AxisServiceConfig;import org.apache.axis.Constants;import org.apache.axis.InternalException;import org.apache.axis.AxisProperties;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.encoding.*;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.message.SOAPBodyElement;import org.apache.axis.message.SOAPEnvelope;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.utils.bytecode.ParamNameExtractor;import org.apache.axis.wsdl.Skeleton;import org.apache.axis.wsdl.fromJava.Namespaces;import org.apache.commons.logging.Log;import org.w3c.dom.Document;import org.w3c.dom.Element;import javax.xml.namespace.QName;import javax.xml.rpc.holders.Holder;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.StringTokenizer;/** * A ServiceDesc is an abstract description of a service. * * ServiceDescs contain OperationDescs, which are descriptions of operations. * The information about a service's operations comes from one of two places: * 1) deployment, or 2) introspection. * * @author Glen Daniels (gdaniels@apache.org) */public class JavaServiceDesc implements ServiceDesc { protected static Log log = LogFactory.getLog(JavaServiceDesc.class.getName()); /** The name of this service */ private String name = null; /** The documentation of this service */ private String documentation = null; /** Style/Use */ private Style style = Style.RPC; private Use use = Use.ENCODED; // Style and Use are related. By default, if Style==RPC, Use should be // ENCODED. But if Style==DOCUMENT, Use should be LITERAL. So we want // to keep the defaults synced until someone explicitly sets the Use. private boolean useSet = false; /** Our operations - a list of OperationDescs */ private ArrayList operations = new ArrayList(); /** A collection of namespaces which will map to this service */ private List namespaceMappings = null; /** * Where does our WSDL document live? If this is non-null, the "?WSDL" * generation will automatically return this file instead of dynamically * creating a WSDL. BE CAREFUL because this means that Handlers will * not be able to add to the WSDL for extensions/headers.... */ private String wsdlFileName = null; /** * An endpoint URL which someone has specified for this service. If * this is set, WSDL generation will pick it up instead of defaulting * to the transport URL. */ private String endpointURL = null; /** Place to store user-extensible service-related properties */ private HashMap properties = null; /** Lookup caches */ private HashMap name2OperationsMap = null; private HashMap qname2OperationsMap = null; private transient HashMap method2OperationMap = new HashMap(); // THE FOLLOWING STUFF IS ALL JAVA-SPECIFIC, AND WILL BE FACTORED INTO // A JAVA-SPECIFIC SUBCLASS. --Glen /** List of allowed methods */ /** null allows everything, an empty ArrayList allows nothing */ private List allowedMethods = null; /** List if disallowed methods */ private List disallowedMethods = null; /** Implementation class */ private Class implClass = null; /** * Is the implementation a Skeleton? If this is true, it will generate * a Fault to provide OperationDescs via WSDD. */ private boolean isSkeletonClass = false; /** Cached copy of the skeleton "getOperationDescByName" method */ private transient Method skelMethod = null; /** Classes at which we should stop looking up the inheritance chain * when introspecting */ private ArrayList stopClasses = null; /** Lookup caches */ private transient HashMap method2ParamsMap = new HashMap(); private OperationDesc messageServiceDefaultOp = null; /** Method names for which we have completed any introspection necessary */ private ArrayList completedNames = new ArrayList(); /** Our typemapping for resolving Java<->XML type issues */ private TypeMapping tm = null; private TypeMappingRegistry tmr = null; private boolean haveAllSkeletonMethods = false; private boolean introspectionComplete = false; /** * Default constructor */ public JavaServiceDesc() { } /** * What kind of service is this? * @return */ public Style getStyle() { return style; } public void setStyle(Style style) { this.style = style; if (!useSet) { // Use hasn't been explicitly set, so track style use = style == Style.RPC ? Use.ENCODED : Use.LITERAL; } } /** * What kind of use is this? * @return */ public Use getUse() { return use; } public void setUse(Use use) { useSet = true; this.use = use; } /** * Determine whether or not this is a "wrapped" invocation, i.e. whether * the outermost XML element of the "main" body element represents a * method call, with the immediate children of that element representing * arguments to the method. * * @return true if this is wrapped (i.e. RPC or WRAPPED style), * false otherwise */ public boolean isWrapped() { return ((style == Style.RPC) || (style == Style.WRAPPED)); } /** * the wsdl file of the service. * When null, it means that the wsdl should be autogenerated * @return filename or null */ public String getWSDLFile() { return wsdlFileName; } /** * set the wsdl file of the service; this causes the named * file to be returned on a ?wsdl, probe, not introspection * generated wsdl. * @param wsdlFileName filename or null to re-enable introspection */ public void setWSDLFile(String wsdlFileName) { this.wsdlFileName = wsdlFileName; } public List getAllowedMethods() { return allowedMethods; } public void setAllowedMethods(List allowedMethods) { this.allowedMethods = allowedMethods; } public Class getImplClass() { return implClass; } /** * set the implementation class * <p> * Warning: You cannot call getInitializedServiceDesc() after setting this * as it uses this to indicate its work has already been done. * * @param implClass * @throws IllegalArgumentException if the implementation class is already * set */ public void setImplClass(Class implClass) { if (this.implClass != null) throw new IllegalArgumentException( Messages.getMessage("implAlreadySet")); this.implClass = implClass; if (Skeleton.class.isAssignableFrom(implClass)) { isSkeletonClass = true; loadSkeletonOperations(); } } private void loadSkeletonOperations() { Method method = null; try { method = implClass.getDeclaredMethod("getOperationDescs", new Class [] {}); } catch (NoSuchMethodException e) { } catch (SecurityException e) { } if (method == null) { // FIXME : Throw an error? return; } try { Collection opers = (Collection)method.invoke(implClass, null); for (Iterator i = opers.iterator(); i.hasNext();) { OperationDesc skelDesc = (OperationDesc)i.next(); addOperationDesc(skelDesc); } } catch (IllegalAccessException e) { if(log.isDebugEnabled()) { log.debug(Messages.getMessage("exception00"), e); } return; } catch (IllegalArgumentException e) { if(log.isDebugEnabled()) { log.debug(Messages.getMessage("exception00"), e); } return; } catch (InvocationTargetException e) { if(log.isDebugEnabled()) { log.debug(Messages.getMessage("exception00"), e); } return; } haveAllSkeletonMethods = true; } public TypeMapping getTypeMapping() { if(tm == null) { return DefaultTypeMappingImpl.getSingletonDelegate();// throw new RuntimeException(Messages.getMessage("noDefaultTypeMapping00")); } return tm; } public void setTypeMapping(TypeMapping tm) { this.tm = tm; } /** * the name of the service */ public String getName() { return name; } /** * the name of the service * @param name */ public void setName(String name) { this.name = name; } /** * get the documentation for the service */ public String getDocumentation() { return documentation; } /** * set the documentation for the service */ public void setDocumentation(String documentation) { this.documentation = documentation; } public ArrayList getStopClasses() { return stopClasses; } public void setStopClasses(ArrayList stopClasses) { this.stopClasses = stopClasses; } public List getDisallowedMethods() { return disallowedMethods; } public void setDisallowedMethods(List disallowedMethods) { this.disallowedMethods = disallowedMethods; } public void removeOperationDesc(OperationDesc operation) { operations.remove(operation); operation.setParent(null); if (name2OperationsMap != null) { String name = operation.getName(); ArrayList overloads = (ArrayList)name2OperationsMap.get(name); if (overloads != null) { overloads.remove(operation); if (overloads.size() == 0) { name2OperationsMap.remove(name); } } } if (qname2OperationsMap != null) { QName qname = operation.getElementQName(); ArrayList list = (ArrayList)qname2OperationsMap.get(qname); if (list != null) { list.remove(operation); } } if (method2OperationMap != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -