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

📄 typedesc.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2002-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.description;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.utils.BeanPropertyDescriptor;import org.apache.axis.utils.BeanUtils;import org.apache.axis.utils.Messages;import org.apache.axis.utils.cache.MethodCache;import org.apache.commons.logging.Log;import javax.xml.namespace.QName;import java.io.Serializable;import java.lang.ref.WeakReference;import java.lang.reflect.Method;import java.util.Collections;import java.util.HashMap;import java.util.Hashtable;import java.util.Map;import java.util.WeakHashMap;/** * A TypeDesc represents a Java<->XML data binding.  It is essentially * a collection of FieldDescs describing how to map each field in a Java * class to XML. * * @author Glen Daniels (gdaniels@apache.org) */public class TypeDesc implements Serializable {    public static final Class [] noClasses = new Class [] {};    public static final Object[] noObjects = new Object[] {};        /** A map of {class -> TypeDesc}} */    private static Map classMap = Collections.synchronizedMap(new WeakHashMap());    /** Have we already introspected for the special "any" property desc? */    private boolean lookedForAny = false;    /** Can this instance search for metadata in parents of the type it describes? */    private boolean canSearchParents = true;    private boolean hasSearchedParents = false;        /** My superclass TypeDesc */    private TypeDesc parentDesc = null;    protected static Log log =        LogFactory.getLog(TypeDesc.class.getName());    /**     * Creates a new <code>TypeDesc</code> instance.  The type desc can search     * the metadata of its type'sparent classes.     *     * @param javaClass a <code>Class</code> value     */    public TypeDesc(Class javaClass) {        this(javaClass, true);    }        /**     * Creates a new <code>TypeDesc</code> instance.     *     * @param javaClass a <code>Class</code> value     * @param canSearchParents whether the type desc can search the metadata of     * its type's parent classes.     */    public TypeDesc(Class javaClass, boolean canSearchParents) {        this.javaClassRef = new WeakReference(javaClass);        this.canSearchParents = canSearchParents;        Class cls = javaClass.getSuperclass();        if (cls != null && !cls.getName().startsWith("java.")) {            parentDesc = getTypeDescForClass(cls);        }            }    /**     * Static function to explicitly register a type description for     * a given class.     *      * @param cls the Class we're registering metadata about     * @param td the TypeDesc containing the metadata     */     public static void registerTypeDescForClass(Class cls, TypeDesc td)    {        classMap.put(cls, td);    }    /**     * Static function for centralizing access to type metadata for a     * given class.       *     * This checks for a static getTypeDesc() method on the     * class or _Helper class.     * Eventually we may extend this to provide for external     * metadata config (via files sitting in the classpath, etc).     *     */    public static TypeDesc getTypeDescForClass(Class cls)    {        // First see if we have one explicitly registered        // or cached from previous lookup        TypeDesc result = (TypeDesc)classMap.get(cls);        if (result == null) {            try {                Method getTypeDesc =                     MethodCache.getInstance().getMethod(cls,                                                         "getTypeDesc",                                                         noClasses);                if (getTypeDesc != null) {                    result = (TypeDesc)getTypeDesc.invoke(null, noObjects);                    if (result != null) {                        classMap.put(cls, result);                    }                }            } catch (Exception e) {            }        }                return result;    }    /** WeakReference to the Java class for this type */    private WeakReference javaClassRef = null;    /** The XML type QName for this type */    private QName xmlType = null;    /** The various fields in here */    private FieldDesc [] fields;    /** A cache of FieldDescs by name */    private HashMap fieldNameMap = new HashMap();        /** A cache of FieldDescs by Element QName */    private HashMap fieldElementMap = null;        /** Are there any fields which are serialized as attributes? */    private boolean _hasAttributes = false;    /** Introspected property descriptors */    private BeanPropertyDescriptor[] propertyDescriptors = null;    /** Map with key = property descriptor name, value = descriptor */    private Map propertyMap = null;    /**     * Indication if this type has support for xsd:any.     */    private BeanPropertyDescriptor anyDesc = null;    public BeanPropertyDescriptor getAnyDesc() {        return anyDesc;    }    /**     * Obtain the current array of FieldDescs     */    public FieldDesc[] getFields() {        return fields;    }    public FieldDesc[] getFields(boolean searchParents) {        // note that if canSearchParents is false, this is identical        // to getFields(), because the parent type's metadata is off        // limits for restricted types which are required to provide a        // complete description of their content model in their own        // metadata, per the XML schema rules for        // derivation-by-restriction        if (canSearchParents && searchParents && !hasSearchedParents) {            // check superclasses if they exist            if (parentDesc != null) {                FieldDesc [] parentFields = parentDesc.getFields(true);// START FIX http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17188                if (parentFields != null) {                    if (fields != null) {                        FieldDesc [] ret = new FieldDesc[parentFields.length + fields.length];                        System.arraycopy(parentFields, 0, ret, 0, parentFields.length);                        System.arraycopy(fields, 0, ret, parentFields.length, fields.length);                        fields = ret;                    } else {                        FieldDesc [] ret = new FieldDesc[parentFields.length];                        System.arraycopy(parentFields, 0, ret, 0, parentFields.length);                        fields = ret;                    }// END FIX http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17188                }            }                        hasSearchedParents = true;        }        return fields;    }    /**     * Replace the array of FieldDescs, making sure we keep our convenience     * caches in sync.     */    public void setFields(FieldDesc [] newFields)    {        fieldNameMap = new HashMap();        fields = newFields;        _hasAttributes = false;        fieldElementMap = null;                for (int i = 0; i < newFields.length; i++) {            FieldDesc field = newFields[i];            if (!field.isElement()) {                _hasAttributes = true;            }            fieldNameMap.put(field.getFieldName(), field);        }    }    /**     * Add a new FieldDesc, keeping the convenience fields in sync.     */    public void addFieldDesc(FieldDesc field)    {        if (field == null) {            throw new IllegalArgumentException(                    Messages.getMessage("nullFieldDesc"));        }                int numFields = 0;        if (fields != null) {            numFields = fields.length;        }        FieldDesc [] newFields = new FieldDesc[numFields + 1];        if (fields != null) {            System.arraycopy(fields, 0, newFields, 0, numFields);        }        newFields[numFields] = field;        fields = newFields;                // Keep track of the field by name for fast lookup        fieldNameMap.put(field.getFieldName(), field);                if (!_hasAttributes && !field.isElement())            _hasAttributes = true;    }

⌨️ 快捷键说明

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