📄 utils.java
字号:
/* * 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.wsdl.toJava;import org.apache.axis.Constants;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.utils.JavaUtils;import org.apache.axis.utils.Messages;import org.apache.axis.wsdl.symbolTable.*;import org.apache.commons.logging.Log;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import javax.wsdl.BindingInput;import javax.wsdl.BindingOperation;import javax.wsdl.Input;import javax.wsdl.Message;import javax.wsdl.Operation;import javax.wsdl.Part;import javax.wsdl.extensions.ExtensibilityElement;import javax.wsdl.extensions.UnknownExtensibilityElement;import javax.wsdl.extensions.mime.MIMEMultipartRelated;import javax.wsdl.extensions.soap.SOAPBody;import javax.wsdl.extensions.soap.SOAPOperation;import javax.xml.namespace.QName;import javax.xml.rpc.holders.BooleanHolder;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import java.util.Vector;/** * Class Utils * * @version %I%, %G% */public class Utils extends org.apache.axis.wsdl.symbolTable.Utils { /** Field log */ protected static Log log = LogFactory.getLog(Utils.class.getName()); /** * @see #holder(Parameter, Emitter) */ public static String holder(TypeEntry type, Emitter emitter) { Parameter arg = new Parameter(); // For other fields the default values will do. arg.setType(type); return holder(arg, emitter); } /** * Given a type, return the Java mapping of that type's holder. * * @param p parameter whose holder class name we want to obtain. * @param emitter the only {@link Emitter} object embodying the running * instance of WSDL2Java. * @return the name of the holder class for <tt>p</tt>. */ public static String holder(Parameter p, Emitter emitter) { String mimeType = (p.getMIMEInfo() == null) ? null : p.getMIMEInfo().getType(); String mimeDimensions = (mimeType == null) ? "" : p.getMIMEInfo().getDimensions(); // Add the holders that JAX-RPC forgot about - the MIME type holders. if (mimeType != null) { if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) { return "org.apache.axis.holders.ImageHolder" + mimeDimensions; } else if (mimeType.equals("text/plain")) { return "javax.xml.rpc.holders.StringHolder" + mimeDimensions; } else if (mimeType.startsWith("multipart/")) { return "org.apache.axis.holders.MimeMultipartHolder" + mimeDimensions; } else if (mimeType.startsWith("application/octetstream") || mimeType.startsWith("application/octet-stream")) { return "org.apache.axis.holders.OctetStreamHolder" + mimeDimensions; } else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) { return "org.apache.axis.holders.SourceHolder" + mimeDimensions; } else { return "org.apache.axis.holders.DataHandlerHolder" + mimeDimensions; } } TypeEntry type = p.getType(); String typeValue = type.getName(); // For base types that are nillable and are mapped to primitives, // need to switch to the corresponding wrapper types. if ((p.isOmittable() && p.getType().getDimensions().equals("")) || (p.getType() instanceof CollectionType && ((CollectionType) p.getType()).isWrapped()) || p.getType().getUnderlTypeNillable()) { typeValue = getWrapperType(type); } // byte[] has a reserved holders. if (typeValue.equals("byte[]") && type.isBaseType()) { return "javax.xml.rpc.holders.ByteArrayHolder"; } // Anything else with [] gets its holder from the qname else if (typeValue.endsWith("[]")) { String name = emitter.getJavaName(type.getQName()); String packagePrefix = ""; // Make sure that holders for arrays of either primitive Java types // or their wrappers are generated at a predictable location. if ((type instanceof CollectionType) && (type.getRefType() instanceof BaseType)) { String uri = type.getRefType().getQName().getNamespaceURI(); // Capitalize the first character for primitive type // array holder classes if (TYPES.get(JavaUtils.replace(name,"[]","")) != null) { name = capitalizeFirstChar(name); } // For wrapped primitive array holder classes append 'Wrapper' to name if (((CollectionType) type).isWrapped() && !typeValue.equals(type.getName())) { name = name + "Wrapper"; } packagePrefix = emitter.getNamespaces().getCreate(uri, false); if (packagePrefix == null) { packagePrefix = ""; } else { packagePrefix += '.'; } } name = JavaUtils.replace(name, "java.lang.", ""); // This could be a special QName for a indexed property. // If so, change the [] to Array. name = JavaUtils.replace(name, "[]", "Array"); name = addPackageName(name, "holders"); return packagePrefix + name + "Holder"; } // String also has a reserved holder else if (typeValue.equals("String")) { return "javax.xml.rpc.holders.StringHolder"; } else if (typeValue.equals("java.lang.String")) { return "javax.xml.rpc.holders.StringHolder"; } // Object also has a reserved holder else if (typeValue.equals("Object")) { return "javax.xml.rpc.holders.ObjectHolder"; } else if (typeValue.equals("java.lang.Object")) { return "javax.xml.rpc.holders.ObjectHolder"; } // Java primitive types have reserved holders else if (typeValue.equals("int") || typeValue.equals("long") || typeValue.equals("short") || typeValue.equals("float") || typeValue.equals("double") || typeValue.equals("boolean") || typeValue.equals("byte")) { return "javax.xml.rpc.holders." + capitalizeFirstChar(typeValue) + "Holder"; } // Java language classes have reserved holders (with ClassHolder) else if (typeValue.startsWith("java.lang.")) { return "javax.xml.rpc.holders" + typeValue.substring(typeValue.lastIndexOf(".")) + "WrapperHolder"; } else if (typeValue.indexOf(".") < 0) { return "javax.xml.rpc.holders" + typeValue + "WrapperHolder"; } // The classes have reserved holders because they // represent schema/soap encoding primitives else if (typeValue.equals("java.math.BigDecimal")) { return "javax.xml.rpc.holders.BigDecimalHolder"; } else if (typeValue.equals("java.math.BigInteger")) { return "javax.xml.rpc.holders.BigIntegerHolder"; } else if (typeValue.equals("java.util.Date")) { return "org.apache.axis.holders.DateHolder"; } else if (typeValue.equals("java.util.Calendar")) { return "javax.xml.rpc.holders.CalendarHolder"; } else if (typeValue.equals("javax.xml.namespace.QName")) { return "javax.xml.rpc.holders.QNameHolder"; } else if (typeValue.equals("javax.activation.DataHandler")) { return "org.apache.axis.holders.DataHandlerHolder"; } // Check for Axis specific types and return their holders else if (typeValue.startsWith("org.apache.axis.types.")) { int i = typeValue.lastIndexOf('.'); String t = typeValue.substring(i + 1); return "org.apache.axis.holders." + t + "Holder"; } // For everything else add "holders" package and append // holder to the class name. else { return addPackageName(typeValue, "holders") + "Holder"; } } // holder /** * Add package to name * * @param className full name of the class. * @param newPkg name of the package to append * @return String name with package name added */ public static String addPackageName(String className, String newPkg) { int index = className.lastIndexOf("."); if (index >= 0) { return className.substring(0, index) + "." + newPkg + className.substring(index); } else { return newPkg + "." + className; } } /** * Given a fault message, return the fully qualified Java class name * of the exception to be generated from this fault * * @param faultMessage The WSDL fault message * @param symbolTable the current symbol table * @return A Java class name for the fault */ public static String getFullExceptionName(Message faultMessage, SymbolTable symbolTable) { MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); return (String) me.getDynamicVar( JavaGeneratorFactory.EXCEPTION_CLASS_NAME); } // getFullExceptionName /** * Given a fault message, return the XML type of the exception data. * * @param faultMessage The WSDL fault message object * @param symbolTable the current symbol table * @return A QName for the XML type of the data */ public static QName getFaultDataType(Message faultMessage, SymbolTable symbolTable) { MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); return (QName) me.getDynamicVar( JavaGeneratorFactory.EXCEPTION_DATA_TYPE); } // getFaultDataType /** * Given a fault message, return TRUE if the fault is a complex type fault * * @param faultMessage The WSDL fault message object * @param symbolTable the current symbol table * @return A Java class name for the fault */ public static boolean isFaultComplex(Message faultMessage, SymbolTable symbolTable) { MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); Boolean ret = (Boolean) me.getDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT); if (ret != null) { return ret.booleanValue(); } else { return false; } } // isFaultComplex /** * If the specified node represents a supported JAX-RPC enumeration, * a Vector is returned which contains the base type and the enumeration values. * The first element in the vector is the base type (an TypeEntry). * Subsequent elements are values (Strings). * If this is not an enumeration, null is returned. * * @param node * @param symbolTable * @return */ public static Vector getEnumerationBaseAndValues(Node node, SymbolTable symbolTable) { if (node == null) { return null; } // If the node kind is an element, dive into it. QName nodeKind = Utils.getNodeQName(node); if ((nodeKind != null) && nodeKind.getLocalPart().equals("element") && Constants.isSchemaXSD(nodeKind.getNamespaceURI())) { NodeList children = node.getChildNodes(); Node simpleNode = null; for (int j = 0; (j < children.getLength()) && (simpleNode == null); j++) { QName simpleKind = Utils.getNodeQName(children.item(j)); if ((simpleKind != null) && simpleKind.getLocalPart().equals("simpleType") && Constants.isSchemaXSD( simpleKind.getNamespaceURI())) { simpleNode = children.item(j); node = simpleNode; } } } // Get the node kind, expecting a schema simpleType nodeKind = Utils.getNodeQName(node);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -