📄 utils.java
字号:
} String typeName = param.getType().getName(); MimeInfo mimeInfo = param.getMIMEInfo(); String mimeType = (mimeInfo == null) ? null : mimeInfo.getType(); String mimeDimensions = (mimeInfo == null) ? "" : mimeInfo.getDimensions(); if (mimeType != null) { if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) { return "(java.awt.Image" + mimeDimensions + ") " + var + ";"; } else if (mimeType.equals("text/plain")) { return "(java.lang.String" + mimeDimensions + ") " + var + ";"; } else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) { return "(javax.xml.transform.Source" + mimeDimensions + ") " + var + ";"; } else if (mimeType.startsWith("multipart/")) { return "(javax.mail.internet.MimeMultipart" + mimeDimensions + ") " + var + ";"; } else if (mimeType.startsWith("application/octetstream") || mimeType.startsWith("application/octet-stream")) { //the hyphenated test is new and RFC compliant; the old one was retained //for backwards compatibility. return "(org.apache.axis.attachments.OctetStream" + mimeDimensions + ") " + var + ";"; } else { return "(javax.activation.DataHandler" + mimeDimensions + ") " + var + ";"; } } // If minOccurs="0" and singular or array with nillable underlying // type get the corresponding wrapper type. if ((param.isOmittable() && param.getType().getDimensions().equals("")) || (param.getType() instanceof CollectionType && ((CollectionType) param.getType()).isWrapped()) || param.getType().getUnderlTypeNillable()) { typeName = getWrapperType(param.getType()); } String objType = (String) TYPES.get(typeName); if (objType != null) { return "((" + objType + ") " + var + ")." + typeName + "Value();"; } return "(" + typeName + ") " + var + ";"; } // getResponseString /** * Method isPrimitiveType * * @param type * @return */ public static boolean isPrimitiveType(TypeEntry type) { return TYPES.get(type.getName()) != null; } // isPrimitiveType /** * Return a "wrapper" type for the given type name. In other words, * if it's a primitive type ("int") return the java wrapper class * ("java.lang.Integer"). Otherwise return the type name itself. * * @param type * @return the name of a java wrapper class for the type, or the type's * name if it's not primitive. */ public static String getWrapperType(String type) { String ret = (String)TYPES.get(type); return (ret == null) ? type : ret; } /** * Returns a "wrapper" type for the given TypeEntry. * * @param type * @return the name of a java wrapper class for the type, or the type's * name if it's not a primitive. */ public static String getWrapperType(TypeEntry type) { String dims = type.getDimensions(); if (!dims.equals("")) { TypeEntry te = type.getRefType(); if (te != null && !te.getDimensions().equals("")) { return getWrapperType(te) + dims; } if (te instanceof BaseType || te instanceof DefinedElement && te.getRefType() instanceof BaseType) { return getWrapperType(te) + dims; } } return getWrapperType(type.getName()); } /** * Return the operation QName. The namespace is determined from * the soap:body namespace, if it exists, otherwise it is "". * * @param bindingOper the operation * @param bEntry the symbol table binding entry * @param symbolTable SymbolTable * @return the operation QName */ public static QName getOperationQName(BindingOperation bindingOper, BindingEntry bEntry, SymbolTable symbolTable) { Operation operation = bindingOper.getOperation(); String operationName = operation.getName(); // For the wrapped case, use the part element's name...which is // is the same as the operation name, but may have a different // namespace ? // example: // <part name="paramters" element="ns:myelem"> if ((bEntry.getBindingStyle() == Style.DOCUMENT) && symbolTable.isWrapped()) { Input input = operation.getInput(); if (input != null) { Map parts = input.getMessage().getParts(); if ((parts != null) && !parts.isEmpty()) { Iterator i = parts.values().iterator(); Part p = (Part) i.next(); return p.getElementName(); } } } String ns = null; // Get a namespace from the soap:body tag, if any // example: // <soap:body namespace="this_is_what_we_want" ..> BindingInput bindInput = bindingOper.getBindingInput(); if (bindInput != null) { Iterator it = bindInput.getExtensibilityElements().iterator(); while (it.hasNext()) { ExtensibilityElement elem = (ExtensibilityElement) it.next(); if (elem instanceof SOAPBody) { SOAPBody body = (SOAPBody) elem; ns = body.getNamespaceURI(); if (bEntry.getInputBodyType(operation) == Use.ENCODED && (ns == null || ns.length() == 0)) { log.warn(Messages.getMessage("badNamespaceForOperation00", bEntry.getName(), operation.getName())); } break; } else if (elem instanceof MIMEMultipartRelated) { Object part = null; javax.wsdl.extensions.mime.MIMEMultipartRelated mpr = (javax.wsdl.extensions.mime.MIMEMultipartRelated) elem; List l = mpr.getMIMEParts(); for (int j = 0; (l != null) && (j < l.size()) && (part == null); j++) { javax.wsdl.extensions.mime.MIMEPart mp = (javax.wsdl.extensions.mime.MIMEPart) l.get(j); List ll = mp.getExtensibilityElements(); for (int k = 0; (ll != null) && (k < ll.size()) && (part == null); k++) { part = ll.get(k); if (part instanceof SOAPBody) { SOAPBody body = (SOAPBody) part; ns = body.getNamespaceURI(); if (bEntry.getInputBodyType(operation) == Use.ENCODED && (ns == null || ns.length() == 0)) { log.warn(Messages.getMessage("badNamespaceForOperation00", bEntry.getName(), operation.getName())); } break; } else { part = null; } } } } else if (elem instanceof UnknownExtensibilityElement) { // TODO: After WSDL4J supports soap12, change this code UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) elem; QName name = unkElement.getElementType(); if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("body")) { ns = unkElement.getElement().getAttribute("namespace"); } } } } // If we didn't get a namespace from the soap:body, then // use "". We should probably use the targetNamespace, // but the target namespace of what? binding? portType? // Also, we don't have enough info for to get it. if (ns == null) { ns = ""; } return new QName(ns, operationName); } /** * Return the SOAPAction (if any) of this binding operation * * @param bindingOper the operation to look at * @return the SOAPAction or null if not found */ public static String getOperationSOAPAction(BindingOperation bindingOper) { // Find the SOAPAction. List elems = bindingOper.getExtensibilityElements(); Iterator it = elems.iterator(); boolean found = false; String action = null; while (!found && it.hasNext()) { ExtensibilityElement elem = (ExtensibilityElement) it.next(); if (elem instanceof SOAPOperation) { SOAPOperation soapOp = (SOAPOperation) elem; action = soapOp.getSoapActionURI(); found = true; } else if (elem instanceof UnknownExtensibilityElement) { // TODO: After WSDL4J supports soap12, change this code UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) elem; QName name = unkElement.getElementType(); if (name.getNamespaceURI().equals( Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("operation")) { action = unkElement.getElement().getAttribute( "soapAction"); found = true; } } } return action; } /** * Common code for generating a QName in emitted code. Note that there's * no semicolon at the end, so we can use this in a variety of contexts. * * @param qname * @return */ public static String getNewQName(javax.xml.namespace.QName qname) { return "new javax.xml.namespace.QName(\"" + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart() + "\")"; } public static String getNewQNameWithLastLocalPart(javax.xml.namespace.QName qname) { return "new javax.xml.namespace.QName(\"" + qname.getNamespaceURI() + "\", \"" + getLastLocalPart(qname.getLocalPart()) + "\")"; } /** * Get the parameter type name. If this is a MIME type, then * figure out the appropriate type from the MIME type, otherwise * use the name of the type itself. * * @param parm * @return */ public static String getParameterTypeName(Parameter parm) { String ret; if (parm.getMIMEInfo() == null) { ret = parm.getType().getName(); // If minOccurs="0" and singular or array with nillable underlying // type get the corresponding wrapper type. if ((parm.isOmittable() && parm.getType().getDimensions().equals("")) || (parm.getType() instanceof CollectionType && ((CollectionType) parm.getType()).isWrapped()) || parm.getType().getUnderlTypeNillable()) { ret = getWrapperType(parm.getType()); } } else { String mime = parm.getMIMEInfo().getType(); ret = JavaUtils.mimeToJava(mime); if (ret == null) { ret = parm.getType().getName(); } else { ret += parm.getMIMEInfo().getDimensions(); } } return ret; } // getParameterTypeName /** * Get the QName that could be used in the xsi:type * when serializing an object for this parameter/return * * @param param is a parameter * @return the QName of the parameter's xsi type */ public static QName getXSIType(Parameter param) { if (param.getMIMEInfo() != null) { return getMIMETypeQName(param.getMIMEInfo().getType()); } return getXSIType(param.getType()); } // getXSIType /** * Get the QName that could be used in the xsi:type * when serializing an object of the given type. * * @param te is the type entry * @return the QName of the type's xsi type
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -