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

📄 utils.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     */    public static QName getXSIType(TypeEntry te) {        QName xmlType = null;        // If the TypeEntry describes an Element, get        // the referenced Type.        if ((te != null) && (te instanceof Element)                && (te.getRefType() != null)) {            te = te.getRefType();        }        // If the TypeEntry is a CollectionTE, use        // the TypeEntry representing the component Type        // So for example a parameter that takes a        // collection type for        // <element name="A" type="xsd:string" maxOccurs="unbounded"/>        // will be        // new ParameterDesc(<QName of A>, IN,        // <QName of xsd:string>,        // String[])        if ((te != null) && (te instanceof CollectionTE)                && (te.getRefType() != null)) {            te = te.getRefType();        }        if (te != null) {            xmlType = te.getQName();        }        return xmlType;    }    /**     * Given a MIME type, return the AXIS-specific type QName.     *     * @param mimeName the MIME type name     * @return the AXIS-specific QName for the MIME type     */    public static QName getMIMETypeQName(String mimeName) {        if ("text/plain".equals(mimeName)) {            return Constants.MIME_PLAINTEXT;        } else if ("image/gif".equals(mimeName)                || "image/jpeg".equals(mimeName)) {            return Constants.MIME_IMAGE;        } else if ("text/xml".equals(mimeName)                || "applications/xml".equals(mimeName)) {            return Constants.MIME_SOURCE;        } else if ("application/octet-stream".equals(mimeName) ||                   "application/octetstream".equals(mimeName)) {            return Constants.MIME_OCTETSTREAM;        } else if ((mimeName != null) && mimeName.startsWith("multipart/")) {            return Constants.MIME_MULTIPART;        } else {            return Constants.MIME_DATA_HANDLER;        }    }    // getMIMEType    /**     * Are there any MIME parameters in the given binding?     *     * @param bEntry     * @return     */    public static boolean hasMIME(BindingEntry bEntry) {        List operations = bEntry.getBinding().getBindingOperations();        for (int i = 0; i < operations.size(); ++i) {            BindingOperation operation = (BindingOperation) operations.get(i);            if (hasMIME(bEntry, operation)) {                return true;            }        }        return false;    }    // hasMIME    /**     * Are there any MIME parameters in the given binding's operation?     *     * @param bEntry     * @param operation     * @return     */    public static boolean hasMIME(BindingEntry bEntry,                                  BindingOperation operation) {        Parameters parameters = bEntry.getParameters(operation.getOperation());        if (parameters != null) {            for (int idx = 0; idx < parameters.list.size(); ++idx) {                Parameter p = (Parameter) parameters.list.get(idx);                if (p.getMIMEInfo() != null) {                    return true;                }            }        }        return false;    }    // hasMIME    /** Field constructorMap */    private static HashMap constructorMap = new HashMap(50);    /** Field constructorThrowMap */    private static HashMap constructorThrowMap = new HashMap(50);    static {        // Type maps to a valid initialization value for that type        // Type var = new Type(arg)        // Where "Type" is the key and "new Type(arg)" is the string stored        // Used in emitting test cases and server skeletons.        constructorMap.put("int", "0");        constructorMap.put("float", "0");        constructorMap.put("boolean", "true");        constructorMap.put("double", "0");        constructorMap.put("byte", "(byte)0");        constructorMap.put("short", "(short)0");        constructorMap.put("long", "0");        constructorMap.put("java.lang.Boolean", "new java.lang.Boolean(false)");        constructorMap.put("java.lang.Byte", "new java.lang.Byte((byte)0)");        constructorMap.put("java.lang.Double", "new java.lang.Double(0)");        constructorMap.put("java.lang.Float", "new java.lang.Float(0)");        constructorMap.put("java.lang.Integer", "new java.lang.Integer(0)");        constructorMap.put("java.lang.Long", "new java.lang.Long(0)");        constructorMap.put("java.lang.Short", "new java.lang.Short((short)0)");        constructorMap.put("java.math.BigDecimal",                "new java.math.BigDecimal(0)");        constructorMap.put("java.math.BigInteger",                "new java.math.BigInteger(\"0\")");        constructorMap.put("java.lang.Object", "new java.lang.String()");        constructorMap.put("byte[]", "new byte[0]");        constructorMap.put("java.util.Calendar",                "java.util.Calendar.getInstance()");        constructorMap.put(                "javax.xml.namespace.QName",                "new javax.xml.namespace.QName(\"http://double-double\", \"toil-and-trouble\")");        constructorMap.put(                "org.apache.axis.types.NonNegativeInteger",                "new org.apache.axis.types.NonNegativeInteger(\"0\")");        constructorMap.put("org.apache.axis.types.PositiveInteger",                "new org.apache.axis.types.PositiveInteger(\"1\")");        constructorMap.put(                "org.apache.axis.types.NonPositiveInteger",                "new org.apache.axis.types.NonPositiveInteger(\"0\")");        constructorMap.put("org.apache.axis.types.NegativeInteger",                "new org.apache.axis.types.NegativeInteger(\"-1\")");        // These constructors throw exception        constructorThrowMap.put(                "org.apache.axis.types.Time",                "new org.apache.axis.types.Time(\"15:45:45.275Z\")");        constructorThrowMap.put("org.apache.axis.types.UnsignedLong",                "new org.apache.axis.types.UnsignedLong(0)");        constructorThrowMap.put("org.apache.axis.types.UnsignedInt",                "new org.apache.axis.types.UnsignedInt(0)");        constructorThrowMap.put("org.apache.axis.types.UnsignedShort",                "new org.apache.axis.types.UnsignedShort(0)");        constructorThrowMap.put("org.apache.axis.types.UnsignedByte",                "new org.apache.axis.types.UnsignedByte(0)");        constructorThrowMap.put(                "org.apache.axis.types.URI",                "new org.apache.axis.types.URI(\"urn:testing\")");        constructorThrowMap.put("org.apache.axis.types.Year",                "new org.apache.axis.types.Year(2000)");        constructorThrowMap.put("org.apache.axis.types.Month",                "new org.apache.axis.types.Month(1)");        constructorThrowMap.put("org.apache.axis.types.Day",                "new org.apache.axis.types.Day(1)");        constructorThrowMap.put("org.apache.axis.types.YearMonth",                "new org.apache.axis.types.YearMonth(2000,1)");        constructorThrowMap.put("org.apache.axis.types.MonthDay",                "new org.apache.axis.types.MonthDay(1, 1)");    }    /**     * Return a constructor for the provided Parameter     * This string will be suitable for assignment:     * <p/>     * Foo var = <i>string returned</i>     * <p/>     * Handles basic java types (int, float, etc), wrapper types (Integer, etc)     * and certain java.math (BigDecimal, BigInteger) types.     * Will also handle all Axis specific types (org.apache.axis.types.*)     * <p/>     * Caller should expect to wrap the construction in a try/catch block     * if bThrow is set to <i>true</i>.     *     * @param param       info about the parameter we need a constructor for     * @param symbolTable used to lookup enumerations     * @param bThrow      set to true if contructor needs try/catch block     * @return     */    public static String getConstructorForParam(Parameter param,                                                SymbolTable symbolTable,                                                BooleanHolder bThrow) {        String paramType = param.getType().getName();        // For base types that are nillable and are mapped to primitives,        // need to switch to the corresponding wrapper types.        if ((param.isOmittable() && param.getType().getDimensions().equals(""))            || (param.getType() instanceof CollectionType                && ((CollectionType) param.getType()).isWrapped())            || param.getType().getUnderlTypeNillable()) {            paramType = getWrapperType(param.getType());        }        String mimeType = (param.getMIMEInfo() == null)                ? null                : param.getMIMEInfo().getType();        String mimeDimensions = (param.getMIMEInfo() == null)                ? ""                : param.getMIMEInfo().getDimensions();        String out = null;        // Handle mime types        if (mimeType != null) {            if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) {                return "null";            } else if (mimeType.equals("text/xml")                    || mimeType.equals("application/xml")) {                if (mimeDimensions.length() <= 0) {                    return "new javax.xml.transform.stream.StreamSource()";                } else {                    return "new javax.xml.transform.stream.StreamSource[0]";                }            } else if (mimeType.equals("application/octet-stream")||                       mimeType.equals("application/octetstream")) {                if (mimeDimensions.length() <= 0) {                    return "new org.apache.axis.attachments.OctetStream()";                } else {                    return "new org.apache.axis.attachments.OctetStream[0]";                }            } else {                return "new " + Utils.getParameterTypeName(param) + "()";            }        }        // Look up paramType in the table        out = (String) constructorMap.get(paramType);        if (out != null) {            return out;        }        // Look up paramType in the table of constructors that can throw exceptions        out = (String) constructorThrowMap.get(paramType);        if (out != null) {            bThrow.value = true;            return out;        }        // Handle arrays        if (paramType.endsWith("[]")) {            return "new " + JavaUtils.replace(paramType, "[]", "[0]");        }        /** * We have some constructed type. */        // Check for enumeration        Vector v = Utils.getEnumerationBaseAndValues(param.getType().getNode(),                symbolTable);        if (v != null) {            // This constructed type is an enumeration.  Use the first one.            String enumeration =                    (String) JavaEnumTypeWriter.getEnumValueIds(v).get(0);            return paramType + "." + enumeration;        }        if(param.getType().getRefType()!= null){            // Check for enumeration            Vector v2 = Utils.getEnumerationBaseAndValues(param.getType().getRefType().getNode(),                    symbolTable);            if (v2 != null) {                // This constructed type is an enumeration.  Use the first one.                String enumeration =                        (String) JavaEnumTypeWriter.getEnumValueIds(v2).get(0);                return paramType + "." + enumeration;            }        }        // This constructed type is a normal type, instantiate it.        return "new " + paramType + "()";    }    public static boolean shouldEmit(TypeEntry type) {        // 1) Don't register types that are base (primitive) types        //    or attributeGroups or xs:groups.        // If the baseType != null && getRefType() != null this        // is a simpleType that must be registered.        // 2) Don't register the special types for collections        // (indexed properties) or elements        // 3) Don't register types that are not referenced        // or only referenced in a literal context.        return (!(((type.getBaseType() != null) && (type.getRefType() == null))                || (type instanceof CollectionTE)                || (type instanceof Element) || !type.isReferenced()                || type.isOnlyLiteralReferenced()                || ((type.getNode() != null)                && (isXsNode(type.getNode(), "group") ||                        isXsNode(type.getNode(), "attributeGroup")))));    }    /**    * Determines if the DOM Node represents an xs:<node>    */    public static boolean isXsNode (Node node, String nameName)    {		return (node.getLocalName().equals(nameName)                && Constants.isSchemaXSD (node.getNamespaceURI ()));	}    public static QName getItemQName(TypeEntry te) {        if (te instanceof DefinedElement) {            te = te.getRefType();        }        return te.getItemQName();    }    public static QName getItemType(TypeEntry te) {        if (te instanceof DefinedElement) {            te = te.getRefType();        }        return te.getComponentType();    }}    // class Utils

⌨️ 快捷键说明

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