⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaservicedesc.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    private String getUniqueOperationName(String name) {        int i = 1;        String candidate;        do {            candidate = name + i++;        } while (name2OperationsMap.get(candidate) != null);        return candidate;    }    /**     * Look for methods matching this name, and for each one, create an     * OperationDesc (if it's not already in our list).     *     * TODO: Make this more efficient     */    private void createOperationsForName(Class implClass, String methodName)    {        // If we're a Skeleton deployment, skip the statics.        if (isSkeletonClass) {            if (methodName.equals("getOperationDescByName") ||                methodName.equals("getOperationDescs"))                return;        }                Method [] methods = getMethods(implClass);        for (int i = 0; i < methods.length; i++) {            Method method = methods[i];            if (Modifier.isPublic(method.getModifiers()) &&                method.getName().equals(methodName) &&                !isServiceLifeCycleMethod(implClass, method)) {                createOperationForMethod(method);            }        }        Class superClass = implClass.getSuperclass();        if (superClass != null &&                !superClass.getName().startsWith("java.") &&                !superClass.getName().startsWith("javax.") &&                    (stopClasses == null ||                        !stopClasses.contains(superClass.getName()))) {            createOperationsForName(superClass, methodName);        }    }    /**     * Make an OperationDesc from a Java method.     *     * In the absence of deployment metadata, this code will introspect a     * Method and create an appropriate OperationDesc.  If the class     * implements the Skeleton interface, we will use the metadata from there     * in constructing the OperationDesc.  If not, we use parameter names     * from the bytecode debugging info if available, or "in0", "in1", etc.     * if not.     */    private void createOperationForMethod(Method method) {        // If we've already got it, never mind        if (method2OperationMap.get(method) != null) {            return;        }        Class [] paramTypes = method.getParameterTypes();        // And if we've already got an exact match (i.e. an override),        // never mind        ArrayList overloads = name2OperationsMap == null ? null :                (ArrayList)name2OperationsMap.get(method.getName());        if (overloads != null && !overloads.isEmpty()) {            // Search each OperationDesc that already has a Method            // associated with it, and check for parameter type equivalence.            for (int i = 0; i < overloads.size(); i++) {                OperationDesc op = (OperationDesc)overloads.get(i);                Method checkMethod = op.getMethod();                if (checkMethod != null) {                    Class [] others = checkMethod.getParameterTypes();                    if (paramTypes.length == others.length) {                        int j = 0;                        for (; j < others.length; j++) {                            if (!others[j].equals(paramTypes[j]))                                break;                        }                        // If we got all the way through, we have a match.                        if (j == others.length)                            return;                    }                }            }        }        boolean isWSICompliant = JavaUtils.isTrue(                AxisProperties.getProperty(Constants.WSIBP11_COMPAT_PROPERTY));                // Make an OperationDesc, fill in common stuff        OperationDesc operation = new OperationDesc();                // If we're WS-I compliant, we can't have overloaded operation names.        // If we find duplicates, we generate unique names for them and map        // those names to the correct Method.        String name = method.getName();        if (isWSICompliant && name2OperationsMap != null) {            Collection methodNames = name2OperationsMap.keySet();            name = JavaUtils.getUniqueValue(methodNames, name);        }        operation.setName(name);        String defaultNS = "";        if (namespaceMappings != null && !namespaceMappings.isEmpty()) {            // If we have a default namespace mapping, require callers to            // use that namespace.            defaultNS = (String)namespaceMappings.get(0);        }        if(defaultNS.length() == 0) {            defaultNS = Namespaces.makeNamespace(method.getDeclaringClass().getName());        }        operation.setElementQName(new QName(defaultNS, name));        operation.setMethod(method);        // If this is a MESSAGE style service, set up the OperationDesc        // appropriately.        if (style == Style.MESSAGE) {            int messageOperType = checkMessageMethod(method);            if(messageOperType == OperationDesc.MSG_METHOD_NONCONFORMING) return;            if (messageOperType == -1) {                throw new InternalException("Couldn't match method to any of the allowable message-style patterns!");            }            operation.setMessageOperationStyle(messageOperType);            operation.setReturnClass(Object.class);            operation.setReturnType(Constants.XSD_ANYTYPE);        } else {            // For other styles, continue here.            Class retClass = method.getReturnType();            operation.setReturnClass(retClass);            QName typeQName = getTypeQName(retClass);            operation.setReturnType(typeQName);            String [] paramNames = getParamNames(method);            for (int k = 0; k < paramTypes.length; k++) {                Class type = paramTypes[k];                ParameterDesc paramDesc = new ParameterDesc();                // param should be unqualified if we're using rpc style,                // or should use the operation's namespace if its document style                String paramNamespace = (this.style == Style.RPC ? "" : operation.getElementQName().getNamespaceURI());                // If we have a name for this param, use it, otherwise call                // it "in*"                if (paramNames != null && paramNames[k] != null &&                        paramNames[k].length()>0) {                    paramDesc.setQName(new QName(paramNamespace, paramNames[k]));                } else {                    paramDesc.setQName(new QName(paramNamespace, "in" + k));                }                // If it's a Holder, mark it INOUT, and set the XML type QName                // to the held type.  Otherwise it's IN.                Class heldClass = JavaUtils.getHolderValueType(type);                if (heldClass != null) {                    paramDesc.setMode(ParameterDesc.INOUT);                    paramDesc.setTypeQName(getTypeQName(heldClass));                } else {                    paramDesc.setMode(ParameterDesc.IN);                    paramDesc.setTypeQName(getTypeQName(type));                }                paramDesc.setJavaType(type);                operation.addParameter(paramDesc);            }        }        createFaultMetadata(method, operation);        addOperationDesc(operation);        method2OperationMap.put(method, operation);    }    private QName getTypeQName(Class javaClass) {        QName typeQName;        TypeMapping tm = getTypeMapping();        if (style == Style.RPC) {            typeQName = tm.getTypeQName(javaClass);        } else {            typeQName = tm.getTypeQNameExact(javaClass);            if (typeQName == null && javaClass.isArray()) {                typeQName = tm.getTypeQName(javaClass.getComponentType());            } else {                typeQName = tm.getTypeQName(javaClass);            }        }        return typeQName;    }    private void createFaultMetadata(Method method, OperationDesc operation) {        // Create Exception Types        Class[] exceptionTypes = method.getExceptionTypes();        for (int i=0; i < exceptionTypes.length; i++) {            // Every remote method declares a java.rmi.RemoteException            // Only interested in application specific exceptions.            // Ignore java and javax package exceptions.            Class ex = exceptionTypes[i];            if (ex != java.rmi.RemoteException.class &&                ex != org.apache.axis.AxisFault.class &&                !ex.getName().startsWith("java.") &&                !ex.getName().startsWith("javax.")) {                // For JSR 101 v.1.0, there is a simple fault mapping                // and a complexType fault mapping...both mappings                // generate a class that extends (directly or indirectly)                // Exception.                // When converting java back to wsdl it is not possible                // to determine which way to do the mapping,                // so it is always mapped back using the complexType                // fault mapping because it is more useful (i.e. it                // establishes a hierarchy of exceptions).  Note that this                // will not cause any roundtripping problems.                // Rich                /* Old Simple Type Mode                Field[] f = ex.getDeclaredFields();                ArrayList exceptionParams = new ArrayList();                for (int j = 0; j < f.length; j++) {                    int mod = f[j].getModifiers();                    if (Modifier.isPublic(mod) &&                         !Modifier.isStatic(mod)) {                        QName qname = new QName("", f[j].getName());                        QName typeQName = tm.getTypeQName(f[j].getType());                        ParameterDesc param = new ParameterDesc(qname,                                                                ParameterDesc.IN,                                                                typeQName);                        param.setJavaType(f[j].getType());                        exceptionParams.add(param);                    }                }                String pkgAndClsName = ex.getName();                FaultDesc fault = new FaultDesc();                fault.setName(pkgAndClsName);                fault.setParameters(exceptionParams);                operation.addFault(fault);                */                FaultDesc fault = operation.getFaultByClass(ex, false);                boolean isNew;                                // If we didn't find one, create a new one                if (fault == null) {                    fault = new FaultDesc();                    isNew = true;                } else {                    isNew = false;                }                                // Try to fil in any parts of the faultDesc that aren't there                                // XMLType                QName xmlType = fault.getXmlType();                if (xmlType == null) {                    fault.setXmlType(getTypeMapping().getTypeQName(ex));                }                                // Name and Class Name                String pkgAndClsName = ex.getName();                if (fault.getClassName() == null) {                    fault.setClassName(pkgAndClsName);                }                if (fault.getName() == null) {                    String name = pkgAndClsName.substring(                            pkgAndClsName.lastIndexOf('.') + 1,                            pkgAndClsName.length());                    fault.setName(name);                }                                // Parameters                // We add a single parameter which points to the type                if (fault.getParameters() == null) {                    if (xmlType == null) {                        xmlType = getTypeMapping().getTypeQName(ex);                    }                    QName qname = fault.getQName();                    if (qname == null) {                        qname = new QName("", "fault");                    }                    ParameterDesc param = new ParameterDesc(                            qname,                            ParameterDesc.IN,                            xmlType);                    param.setJavaType(ex);                    ArrayList exceptionParams = new ArrayList();                    exceptionParams.add(param);                    fault.setParameters(exceptionParams);                }                                // QName                if (fault.getQName() == null) {                    fault.setQName(new QName(pkgAndClsName));                }                if (isNew) {                    // Add the fault to the operation                    operation.addFault(fault);                }            }        }    }    private String[] getParamNames(Method method) {        synchronized (method2ParamsMap) {            String [] paramNames = (String []) method2ParamsMap.get(method);            if(paramNames != null)                return paramNames;            paramNames = ParamNameExtractor.getParameterNamesFromDebugInfo(method);            method2ParamsMap.put(method, paramNames);            return paramNames;        }    }    public void setNamespaceMappings(List namespaces) {        namespaceMappings = namespaces;    }    public String getDefaultNamespace() {        if (namespaceMappings == null || namespaceMappings.isEmpty())            return null;        return (String)namespaceMappings.get(0);    }    public void setDefaultNamespace(String namespace) {        if (namespaceMappings == null)            namespaceMappings = new ArrayList();        namespaceMappings.add(0, namespace);    }    public void setProperty(String name, Object value) {        if (properties == null) {            properties = new HashMap();        }        properties.put(name, value);    }    public Object getProperty(String name) {        if (properties == null)            return null;        return properties.get(name);    }    public String getEndpointURL() {        return endpointURL;    }    public void setEndpointURL(String endpointURL) {        this.endpointURL = endpointURL;    }    public TypeMappingRegistry getTypeMappingRegistry() {        if (tmr == null) {            tmr = new TypeMappingRegistryImpl(false);        }        return tmr;    }    public void setTypeMappingRegistry(TypeMappingRegistry tmr) {        this.tmr = tmr;    }    public boolean isInitialized() {        return implClass != null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -