📄 types.java
字号:
qName = new QName(targetNamespace, arrayTypePrefix + cqName.getLocalPart()); } else { String pre = namespaces.getCreatePrefix(cqName.getNamespaceURI()); qName = new QName(targetNamespace, arrayTypePrefix + "_" + pre + "_" + cqName.getLocalPart()); } return qName; } // If a qName was not found construct one using the // class name information. if (qName == null) { String pkg = getPackageNameFromFullName(javaType.getName()); String lcl = getLocalNameFromFullName(javaType.getName()); String ns = namespaces.getCreate(pkg); namespaces.getCreatePrefix(ns); String localPart = lcl.replace('$', '_'); qName = new QName(ns, localPart); } return qName; } /** * Return a string suitable for representing a given QName in the context * of this WSDL document. If the namespace of the QName is not yet * registered, we will register it up in the Definitions. * * @param qname a QName (typically a type) * @return a String containing a standard "ns:localPart" rep of the QName */ public String getQNameString(QName qname) { String prefix = namespaces.getCreatePrefix(qname.getNamespaceURI()); return prefix + ":" + qname.getLocalPart(); } /** * Utility method to get the package name from a fully qualified java class name * * @param full input class name * @return package name */ public static String getPackageNameFromFullName(String full) { if (full.lastIndexOf('.') < 0) { return ""; } else { return full.substring(0, full.lastIndexOf('.')); } } /** * Utility method to get the local class name from a fully qualified java class name * * @param full input class name * @return package name */ public static String getLocalNameFromFullName(String full) { String end = ""; if (full.startsWith("[L")) { end = "[]"; full = full.substring(3, full.length() - 1); } if (full.lastIndexOf('.') < 0) { return full + end; } else { return full.substring(full.lastIndexOf('.') + 1) + end; } } /** * Method writeSchemaTypeDecl * * @param qname * @param element * @throws AxisFault */ public void writeSchemaTypeDecl(QName qname, Element element) throws AxisFault { writeSchemaElement(qname.getNamespaceURI(), element); } /** * Method writeSchemaElementDecl * * @param qname * @param element * @throws AxisFault */ public void writeSchemaElementDecl(QName qname, Element element) throws AxisFault { if (writtenElementQNames.contains(qname)) { throw new AxisFault( Constants.FAULT_SERVER_GENERAL, Messages.getMessage( "duplicateSchemaElement", qname.toString()), null, null); } writeSchemaElement(qname.getNamespaceURI(), element); writtenElementQNames.add(qname); } /** * @deprecated * Please use writeSchemaElement(String namespaceURI, Element element) * * @param qName qName to get the namespace of the schema node * @param element the Element to append to the Schema node * @throws AxisFault */ public void writeSchemaElement(QName qName, Element element) throws AxisFault { writeSchemaElement(qName.getNamespaceURI(), element); } /** * Write out the given Element into the appropriate schema node. * If need be create the schema node as well * * @param namespaceURI namespace this node should get dropped into * @param element the Element to append to the Schema node * @throws AxisFault */ public void writeSchemaElement(String namespaceURI, Element element) throws AxisFault { if (wsdlTypesElem == null) { try { writeWsdlTypesElement(); } catch (Exception e) { log.error(e); return; } } if ((namespaceURI == null) || namespaceURI.equals("")) { throw new AxisFault( Constants.FAULT_SERVER_GENERAL, Messages.getMessage("noNamespace00", namespaceURI), null, null); } Element schemaElem = null; NodeList nl = wsdlTypesElem.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { NamedNodeMap attrs = nl.item(i).getAttributes(); if (attrs != null) { for (int n = 0; n < attrs.getLength(); n++) { Attr a = (Attr) attrs.item(n); if (a.getName().equals("targetNamespace") && a.getValue().equals(namespaceURI)) { schemaElem = (Element) nl.item(i); } } } } if (schemaElem == null) { schemaElem = docHolder.createElement("schema"); wsdlTypesElem.appendChild(schemaElem); schemaElem.setAttribute("xmlns", Constants.URI_DEFAULT_SCHEMA_XSD); schemaElem.setAttribute("targetNamespace", namespaceURI); // Add SOAP-ENC namespace import if necessary if (serviceDesc.getStyle() == Style.RPC) { Element importElem = docHolder.createElement("import"); schemaElem.appendChild(importElem); importElem.setAttribute("namespace", Constants.URI_DEFAULT_SOAP_ENC); } SOAPService service = null; if(MessageContext.getCurrentContext() != null) { service = MessageContext.getCurrentContext().getService(); } if(service != null && isPresent((String) service.getOption("schemaQualified"), namespaceURI)){ schemaElem.setAttribute("elementFormDefault", "qualified"); } else if(service != null && isPresent((String) service.getOption("schemaUnqualified"), namespaceURI)){ // DO nothing..default is unqualified. } else if ((serviceDesc.getStyle() == Style.DOCUMENT) || (serviceDesc.getStyle() == Style.WRAPPED)) { schemaElem.setAttribute("elementFormDefault", "qualified"); } writeTypeNamespace(namespaceURI); } schemaElem.appendChild(element); } /** * check if the namespace is present in the list. * @param list * @param namespace * @return */ private boolean isPresent(String list, String namespace) { if(list == null || list.length()==0) return false; String[] array = StringUtils.split(list,','); for(int i=0;i<array.length;i++){ if(array[i].equals(namespace)) return true; } return false; } /** * Get the Types element for the WSDL document. If not present, create one */ private void writeWsdlTypesElement() { if (wsdlTypesElem == null) { // Create a <wsdl:types> element corresponding to the wsdl namespaces. wsdlTypesElem = docHolder.createElementNS(Constants.NS_URI_WSDL11, "types"); wsdlTypesElem.setPrefix(Constants.NS_PREFIX_WSDL); } } /** * Write a schema representation for the given <code>Class</code>. Recurse * through all the public fields as well as fields represented by java * bean compliant accessor methods. * <p/> * Then return the qualified string representation of the generated type * * @param type Class for which to generate schema * @return a prefixed string for the schema type * @throws AxisFault */ public String writeType(Class type) throws AxisFault { return writeType(type, null); } /** * Write a schema representation for the given <code>Class</code>. Recurse * through all the public fields as well as fields represented by java * bean compliant accessor methods. * <p/> * Then return the qualified string representation of the generated type * * @param type Class for which to generate schema * @param qName of the type to write * @return a prefixed string for the schema type or null if problems occur * @throws AxisFault */ public String writeType(Class type, QName qName) throws AxisFault { // Get a corresponding QName if one is not provided if ((qName == null) || Constants.equals(Constants.SOAP_ARRAY, qName)) { qName = getTypeQName(type); } if (!makeTypeElement(type, qName, null)) { return null; } return getQNameString(qName); } /** * Method createArrayElement * * @param componentTypeName * @return */ public Element createArrayElement(String componentTypeName) { SOAPConstants constants; MessageContext mc = MessageContext.getCurrentContext(); if(mc==null||mc.getSOAPConstants()==null){ constants = SOAPConstants.SOAP11_CONSTANTS; } else { constants = mc.getSOAPConstants(); } String prefix = namespaces.getCreatePrefix(constants.getEncodingURI()); // ComplexType representation of array Element complexType = docHolder.createElement("complexType"); Element complexContent = docHolder.createElement("complexContent"); complexType.appendChild(complexContent); Element restriction = docHolder.createElement("restriction"); complexContent.appendChild(restriction); restriction.setAttribute("base", prefix + ":Array"); Element attribute = docHolder.createElement("attribute"); restriction.appendChild(attribute); attribute.setAttribute("ref", prefix + ":arrayType"); prefix = namespaces.getCreatePrefix(Constants.NS_URI_WSDL11); attribute.setAttribute(prefix + ":arrayType", componentTypeName); return complexType; } /** * Create an array which is a wrapper type for "item" elements * of a component type. This is basically the unencoded parallel to * a SOAP-encoded array. * * @param componentType * @param itemName the QName of the inner element (right now we only use the localPart) * @return */ public Element createLiteralArrayElement(String componentType, QName itemName) { String itemLocalName = "item"; if (itemName != null) { itemLocalName = itemName.getLocalPart(); } Element complexType = docHolder.createElement("complexType"); Element sequence = docHolder.createElement("sequence"); complexType.appendChild(sequence); Element elem = docHolder.createElement("element"); elem.setAttribute("name", itemLocalName); elem.setAttribute("type", componentType); elem.setAttribute("minOccurs", "0"); elem.setAttribute("maxOccurs", "unbounded"); sequence.appendChild(elem); return complexType; } /** * Returns true if indicated type matches the JAX-RPC enumeration class. * Note: supports JSR 101 version 0.6 Public Draft * * @param cls * @return */ public static boolean isEnumClass(Class cls) { try { java.lang.reflect.Method m = cls.getMethod("getValue", null); java.lang.reflect.Method m2 = cls.getMethod("toString", null); if ((m != null) && (m2 != null)) { java.lang.reflect.Method m3 = cls.getDeclaredMethod("fromString", new Class[]{ java.lang.String.class}); java.lang.reflect.Method m4 = cls.getDeclaredMethod("fromValue", new Class[]{ m.getReturnType()}); if ((m3 != null) && Modifier.isStatic(m3.getModifiers())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -