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

📄 rpcelement.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-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.message;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.Message;import org.apache.axis.MessageContext;import org.apache.axis.description.OperationDesc;import org.apache.axis.description.ParameterDesc;import org.apache.axis.description.ServiceDesc;import org.apache.axis.encoding.DeserializationContext;import org.apache.axis.encoding.SerializationContext;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.wsdl.toJava.Utils;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import javax.xml.namespace.QName;import javax.xml.soap.SOAPElement;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;import java.util.Iterator;import java.util.List;import java.util.Collection;public class RPCElement extends SOAPBodyElement{    //protected Vector params2 = new Vector();    protected boolean needDeser = false;    OperationDesc [] operations = null;    public RPCElement(String namespace,                      String localName,                      String prefix,                      Attributes attributes,                      DeserializationContext context,                      OperationDesc [] operations) throws AxisFault    {        super(namespace, localName, prefix, attributes, context);        // This came from parsing XML, so we need to deserialize it sometime        needDeser = true;        // Obtain our possible operations        if (operations == null) {            updateOperationsByName();        } else {            this.operations = operations;        }    }    public RPCElement(String namespace, String methodName, Object [] args)    {        this.setNamespaceURI(namespace);        this.name = methodName;        for (int i = 0; args != null && i < args.length; i++) {            if (args[i] instanceof RPCParam) {                addParam((RPCParam)args[i]);            } else {                String name = null;                if (name == null) name = "arg" + i;                addParam(new RPCParam(namespace, name, args[i]));            }        }    }    public RPCElement(String methodName)    {        this.name = methodName;    }    public void updateOperationsByName() throws AxisFault    {        if (context == null) {            return;        }        MessageContext msgContext = context.getMessageContext();        if (msgContext == null) {            return;        }        // Obtain our possible operations        SOAPService service = msgContext.getService();        if (service == null) {            return;        }        ServiceDesc serviceDesc =            service.getInitializedServiceDesc(msgContext);        String lc = Utils.xmlNameToJava(name);        if (serviceDesc == null) {            throw AxisFault.makeFault(                   new ClassNotFoundException(                           Messages.getMessage("noClassForService00",                                               lc)));        }        this.operations = serviceDesc.getOperationsByName(lc);    }    public void updateOperationsByQName() throws AxisFault    {        if (context == null) {            return;        }        MessageContext msgContext = context.getMessageContext();        if (msgContext == null) {            return;        }        this.operations = msgContext.getPossibleOperationsByQName(getQName());    }    public OperationDesc[] getOperations()    {        return this.operations;    }    public String getMethodName()    {        return name;    }    public void setNeedDeser(boolean needDeser) {        this.needDeser = needDeser;    }    public void deserialize() throws SAXException    {        needDeser = false;        MessageContext msgContext = context.getMessageContext();        // Figure out if we should be looking for out params or in params        // (i.e. is this message a response?)        Message msg = msgContext.getCurrentMessage();        SOAPConstants soapConstants = msgContext.getSOAPConstants();        boolean isResponse = ((msg != null) &&                              Message.RESPONSE.equals(msg.getMessageType()));        // We're going to need this below, so create one.        RPCHandler rpcHandler = new RPCHandler(this, isResponse);        if (operations != null) {            int numParams = (getChildren() == null) ? 0 : getChildren().size();            SAXException savedException = null;            // By default, accept missing parameters as nulls, and            // allow the message context to override.            boolean acceptMissingParams = msgContext.isPropertyTrue(                    MessageContext.ACCEPTMISSINGPARAMS,                    true);            // We now have an array of all operations by this name.  Try to            // find the right one.  For each matching operation which has an            // equal number of "in" parameters, try deserializing.  If we            // don't succeed for any of the candidates, punt.            for (int i = 0; i < operations.length; i++) {                OperationDesc operation = operations[i];                // See if any information is coming from a header                boolean needHeaderProcessing =                    needHeaderProcessing(operation, isResponse);                // Make a quick check to determine if the operation                // could be a match.                //  1) The element is the first param, DOCUMENT, (i.e.                //     don't know the operation name or the number                //     of params, so try all operations).                //  or (2) Style is literal                //     If the Style is LITERAL, the numParams may be inflated                //     as in the following case:                //     <getAttractions xmlns="urn:CityBBB">                //         <attname>Christmas</attname>                //         <attname>Xmas</attname>                //     </getAttractions>                //   for getAttractions(String[] attName)                //   numParams will be 2 and and operation.getNumInParams=1                //  or (3) Number of expected params is                //         >= num params in message                if (operation.getStyle() == Style.DOCUMENT ||                    operation.getStyle() == Style.WRAPPED ||                    operation.getUse() == Use.LITERAL ||                    (acceptMissingParams ?                        (operation.getNumInParams() >= numParams) :                        (operation.getNumInParams() == numParams))) {                    boolean isEncoded = operation.getUse() == Use.ENCODED;                    rpcHandler.setOperation(operation);                    try {                        // If no operation name and more than one                        // parameter is expected, don't                        // wrap the rpcHandler in an EnvelopeHandler.                         if ( ( msgContext.isClient() &&                               operation.getStyle() == Style.DOCUMENT ) ||                            ( !msgContext.isClient() &&                               operation.getStyle() == Style.DOCUMENT &&                               operation.getNumInParams() > 0 ) ) {                            context.pushElementHandler(rpcHandler);                            context.setCurElement(null);                        } else {                            context.pushElementHandler(                                    new EnvelopeHandler(rpcHandler));                            context.setCurElement(this);                        }                        publishToHandler((org.xml.sax.ContentHandler) context);                        // If parameter values are located in headers,                        // get the information and publish the header                        // elements to the rpc handler.                        if (needHeaderProcessing) {                            processHeaders(operation, isResponse,                                           context, rpcHandler);                        }                        // Check if the RPCParam's value match the signature of the                        // param in the operation.                        boolean match = true;                        List params = getParams2();                        for ( int j = 0 ; j < params.size() && match ; j++ ) {                            RPCParam rpcParam = (RPCParam)params.get(j);                            Object value = rpcParam.getObjectValue();                            // first check the type on the paramter                            ParameterDesc paramDesc = rpcParam.getParamDesc();                            // if we found some type info try to make sure the value type is                            // correct.  For instance, if we deserialized a xsd:dateTime in                            // to a Calendar and the service takes a Date, we need to convert                            if (paramDesc != null && paramDesc.getJavaType() != null) {                                // Get the type in the signature (java type or its holder)                                Class sigType = paramDesc.getJavaType();                                // if the type is an array but the value is not                                // an array or Collection, put it into an                                // ArrayList so that we correctly recognize it                                // as convertible                                if (sigType.isArray()) {                                    if (value != null &&                                            JavaUtils.isConvertable(value,                                               sigType.getComponentType()) &&                                          !(value.getClass().isArray()) &&                                          !(value instanceof Collection)) {                                        ArrayList list = new ArrayList();                                        list.add(value);                                        value = list;                                        rpcParam.setObjectValue(value);                                    }

⌨️ 快捷键说明

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