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

📄 types.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    public static boolean isNullable(Class type) {        if (type.isPrimitive()) {            return false;        } else {            return true;        }    }    /**     * todo ravi: Get rid of Doccument fragment and import node stuuf,     * once I have a handle on the wsdl4j mechanism to get at types.     * <p/>     * Switch over notes: remove docHolder, docFragment in favor of wsdl4j Types     * <p/>     * DocumentFragment docFragment;     * <p/>     * DocumentFragment docFragment;     * <p/>     * DocumentFragment docFragment;     * <p/>     * DocumentFragment docFragment;     */    // DocumentFragment docFragment;    Document docHolder;    /**     * Method createDocumentFragment     */    private void createDocumentFragment() {        try {            this.docHolder = XMLUtils.newDocument();        } catch (ParserConfigurationException e) {            // This should not occur            throw new InternalException(e);        }    }    /**     * Method updateNamespaces     */    public void updateNamespaces() {        Namespaces namespaces = getNamespaces();        Iterator nspIterator = namespaces.getNamespaces();        while (nspIterator.hasNext()) {            String nsp = (String) nspIterator.next();            String pref = def.getPrefix(nsp);            if (pref == null) {                def.addNamespace(namespaces.getCreatePrefix(nsp), nsp);            }        }    }    /**     * Inserts the type fragment into the given wsdl document and ensures     * that definitions from each embedded schema are allowed to reference     * schema components from the other sibling schemas.     * @param doc     */    public void insertTypesFragment(Document doc) {        updateNamespaces();        if (wsdlTypesElem == null)            return;        // Make sure that definitions from each embedded schema are allowed        // to reference schema components from the other sibling schemas.        Element schemaElem = null;        String tns = null;        NodeList nl = wsdlTypesElem.getChildNodes();        for (int i = 0; i < nl.getLength(); i++) {            NamedNodeMap attrs = nl.item(i).getAttributes();            if (attrs == null) continue; // Should never happen.            for (int n = 0; n < attrs.getLength(); n++) {                Attr a = (Attr) attrs.item(n);                if (a.getName().equals("targetNamespace")) {                    tns = a.getValue();                    schemaElem = (Element) nl.item(i);                    break;                }            }            // Ignore what appears to be a not namespace-qualified            // schema definition.            if (tns != null && !"".equals(tns.trim())) {                // By now we know that an import element might be necessary                // for some sibling schemas. However, in the absence of                // a symbol table proper, the best we can do is add one                // for each sibling schema.                Iterator it = schemaTypes.keySet().iterator();                String otherTns;                Element importElem;                while (it.hasNext()) {                    if (!tns.equals(otherTns = (String) it.next())) {                        importElem = docHolder.createElement("import");                        importElem.setAttribute("namespace", otherTns);                        schemaElem.insertBefore(importElem,                                schemaElem.getFirstChild());                    }                }            }            schemaElem = null;            tns = null;        }        // Import the wsdlTypesElement into the doc.        org.w3c.dom.Node node = doc.importNode(wsdlTypesElem, true);        // Insert the imported element at the beginning of the document        doc.getDocumentElement().                insertBefore(node,                        doc.getDocumentElement().getFirstChild());    }    /**     * Return the list of classes that we should not emit WSDL for.     *     * @return     */    public List getStopClasses() {        return stopClasses;    }    /**     * Create a DOM Element in this context     *     * @param elementName     * @return     */    public Element createElement(String elementName) {        return docHolder.createElement(elementName);    }    /**     * isBeanCompatible     *     * @param javaType    Class     * @param issueErrors if true, issue messages if not compatible     *                    Returns true if it appears that this class is a bean and     *                    can be mapped to a complexType     * @return     */    protected boolean isBeanCompatible(Class javaType, boolean issueErrors) {        // Must be a non-primitive and non array        if (javaType.isArray() || javaType.isPrimitive()) {            if (issueErrors && !beanCompatErrs.contains(javaType)) {                log.warn(Messages.getMessage("beanCompatType00",                        javaType.getName()));                beanCompatErrs.add(javaType);            }            return false;        }        // Anything in the java or javax package that        // does not have a defined mapping is excluded.        if (javaType.getName().startsWith("java.")                || javaType.getName().startsWith("javax.")) {            if (issueErrors && !beanCompatErrs.contains(javaType)) {                log.warn(Messages.getMessage("beanCompatPkg00",                        javaType.getName()));                beanCompatErrs.add(javaType);            }            return false;        }        // Return true if appears to be an enum class        if (JavaUtils.isEnumClass(javaType)) {            return true;        }        // Must have a default public constructor if not        // Throwable        if (!java.lang.Throwable.class.isAssignableFrom(javaType)) {            try {                javaType.getConstructor(new Class[]{                });            } catch (java.lang.NoSuchMethodException e) {                if (issueErrors && !beanCompatErrs.contains(javaType)) {                    log.warn(Messages.getMessage("beanCompatConstructor00",                            javaType.getName()));                    beanCompatErrs.add(javaType);                }                return false;            }        }        // Make sure superclass is compatible        Class superClass = javaType.getSuperclass();        if ((superClass != null) && (superClass != java.lang.Object.class)                && (superClass != java.lang.Exception.class)                && (superClass != java.lang.Throwable.class)                && (superClass != java.rmi.RemoteException.class)                && (superClass != org.apache.axis.AxisFault.class)                && ((stopClasses == null)                || !(stopClasses.contains(superClass.getName())))) {            if (!isBeanCompatible(superClass, false)) {                if (issueErrors && !beanCompatErrs.contains(javaType)) {                    log.warn(Messages.getMessage("beanCompatExtends00",                            javaType.getName(),                            superClass.getName(),                            javaType.getName()));                    beanCompatErrs.add(javaType);                }                return false;            }        }        return true;    }    /**     * Write an &lt;element&gt; with an anonymous internal ComplexType     *     * @param elementName     * @param fieldType     * @param omittable     * @param ownerDocument     * @return     * @throws AxisFault     */    public Element createElementWithAnonymousType(String elementName,                                                  Class fieldType,                                                  boolean omittable,                                                  Document ownerDocument)            throws AxisFault {        Element element = docHolder.createElement("element");        element.setAttribute("name", elementName);        if (isNullable(fieldType)) {            element.setAttribute("nillable", "true");        }        if (omittable) {            element.setAttribute("minOccurs", "0");            element.setAttribute("maxOccurs", "1");        }        makeTypeElement(fieldType, null, element);        return element;    }    /**     * Create a schema type element (either simpleType or complexType) for     * the particular type/qName combination.  If the type is named, we     * handle inserting the new type into the appropriate &lt;schema&gt;     * in the WSDL types section.  If the type is anonymous, we append the     * definition underneath the Element which was passed as the container     * (typically a field of a higher-level type or a parameter in a wrapped     * operation).     *     * @param type              Java type to write     * @param qName             the desired type QName     * @param containingElement a schema element ("element" or "attribute")     *                          which should either receive a type="" attribute decoration     *                          (for named types) or a child element defining an anonymous     *                          type     * @return true if the type was already present or was added, false if there was a problem     * @throws AxisFault     */    private boolean makeTypeElement(Class type,                                    QName qName,                                    Element containingElement)            throws AxisFault {        // Get a corresponding QName if one is not provided        if ((qName == null) || Constants.equals(Constants.SOAP_ARRAY, qName)) {            qName = getTypeQName(type);        }        boolean anonymous = isAnonymousType(qName);        // Can't have an anonymous type outside of a containing element        if (anonymous && (containingElement == null)) {            throw new AxisFault(                    Messages.getMessage(                            "noContainerForAnonymousType", qName.toString()));        }        // If we've already got this type (because it's a native type or        // because we've already written it), just add the type="" attribute        // (if appropriate) and return.        if (!addToTypesList(qName) && !anonymous) {            if (containingElement != null) {                containingElement.setAttribute("type", getQNameString(qName));            }            return true;        }        // look up the serializer in the TypeMappingRegistry        SerializerFactory factory;        factory = (SerializerFactory) tm.getSerializer(type, qName);        // If no factory is found, use the BeanSerializerFactory        // if applicable, otherwise issue errors and treat as an anyType        if (factory == null) {            if (isEnumClass(type)) {                factory = new EnumSerializerFactory(type, qName);            } else if (isBeanCompatible(type, true)) {                factory = new BeanSerializerFactory(type, qName);            } else {                return false;            }        }        // factory is not null        Serializer ser = (Serializer) factory.getSerializerAs(Constants.AXIS_SAX);        // if we can't get a serializer, that is bad.        if (ser == null) {            throw new AxisFault(Messages.getMessage("NoSerializer00",                    type.getName()));        }        Element typeEl;        try {            typeEl = ser.writeSchema(type, this);        } catch (Exception e) {            throw AxisFault.makeFault(e);        }        // If this is an anonymous type, just make the type element a child        // of containingElement.  If not, set the "type" attribute of        // containingElement to the right QName, and make sure the type is        // correctly written into the appropriate <schema> element.        if (anonymous) {            if (typeEl == null) {                containingElement.setAttribute("type", getQNameString(getTypeQName(type)));            } else {                containingElement.appendChild(typeEl);            }        } else {            if (typeEl != null) {                typeEl.setAttribute("name", qName.getLocalPart());                // Write the type in the appropriate <schema>                writeSchemaTypeDecl(qName, typeEl);            }            if (containingElement != null) {                containingElement.setAttribute("type", getQNameString(qName));            }        }        // store the mapping of type qname and its correspoding java type	        if (emitter != null) {            emitter.getQName2ClassMap().put(qName, type);        }        return true;    }    /**     * return the service description     * @return     */    public ServiceDesc getServiceDesc() {        return serviceDesc;    }}

⌨️ 快捷键说明

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