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

📄 classcustom.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 2007, Dennis M. SosnoskiAll rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this   list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,   this list of conditions and the following disclaimer in the documentation   and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used   to endorse or promote products derived from this software without specific   prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/package org.jibx.binding.generator;import java.lang.reflect.Modifier;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.jibx.binding.model.IClass;import org.jibx.binding.model.IClassItem;import org.jibx.binding.model.IClassLocator;import org.jibx.runtime.EnumSet;import org.jibx.runtime.IUnmarshallingContext;import org.jibx.runtime.QName;/** * Class customization information. This supports direct class customizations. * (such as the corresponding element name, when building a concrete mapping) * and also acts as a container for individual fields and/or properties. */public class ClassCustom extends NestingBase implements IApply{    /** Element name in XML customization file. */    public static final String ELEMENT_NAME = "class";        // value set information    public static final int DEFAULT_REPRESENTATION = 0;    public static final int CONCRETE_MAPPING_REPRESENTATION = 1;    public static final int ABSTRACT_MAPPING_REPRESENTATION = 2;        public static final EnumSet s_representationEnum =        new EnumSet(DEFAULT_REPRESENTATION,        new String[] { "default", "concrete-mapping", "abstract-mapping" });        // values specific to class level    private String m_name;    private String m_elementName;    private String m_typeName;    private String m_createType;    private String m_factoryMethod;    private int m_form;    private String[] m_includes;    private String[] m_excludes;    private boolean m_useSuper;    private String[] m_requireds;    private String[] m_optionals;        // list of contained items    private final ArrayList m_children;        // values filled in by apply() method    private QName m_typeQName;    private QName m_elementQName;    private IClass m_classInformation;    private Map m_memberMap;        /**     * Constructor.     *      * @param parent     * @param name class simple name (without package)     */    /*package*/ ClassCustom(NestingBase parent, String name) {        super(parent);        m_name = name;        m_children = new ArrayList();        m_useSuper = true;    }    /**     * Get fully-qualified class name.     *     * @return class name     */    public String getName() {        PackageCustom parent = (PackageCustom)getParent();        String pack = parent.getName();        if (pack.length() > 0) {            return pack + '.' + m_name;        } else {            return m_name;        }    }    /**     * Get simple class name.     *     * @return class name     */    public String getSimpleName() {        return m_name;    }    /**     * Get the element name to be used for this class in a concrete mapping.     *     * @return element name     */    public String getElementName() {        return m_elementName;    }    /**     * Get the qualified element name to be used for this class in a concrete     * mapping.     *     * @return element name     */    public QName getElementQName() {        return m_elementQName;    }    /**     * Get the type name to be used for this class in an abstract mapping.     *     * @return type name     */    public String getTypeName() {        return m_typeName;    }    /**     * Get the type name to be used when creating an instance of this class.     *     * @return type name     */    public String getCreateType() {        return m_createType;    }        /**     * Set the type name to be used when creating an instance of this class.     *     * @param type     */    public void setCreateType(String type) {        m_createType = type;    }    /**     * Get the factory method to be used when creating an instance of this     * class.     *     * @return method name     */    public String getFactoryMethod() {        return m_factoryMethod;    }    /**     * Get the qualified type name to be used for this class in an abstract     * mapping.     *     * @return type qname     */    public QName getTypeQName() {        return m_typeQName;    }    /**     * Get the representation code.     *     * @return value from {@link #s_representationEnum} enumeration     */    public int getForm() {        return m_form;    }    /**     * Get list of names to be excluded from class representation.     *     * @return excludes (<code>null</code> if none)     */    public String[] getExcludes() {        return m_excludes;    }    /**     * Get list of names to be included in class representation.     *     * @return includes (<code>null</code> if none)     */    public String[] getIncludes() {        return m_includes;    }        /**     * Check for superclass to be included in binding.     *     * @return <code>true</code> if superclass included, <code>false</code> if     * not     */    public boolean isUseSuper() {        return m_useSuper;    }        /**     * Check if this is a directly instantiable class (not an interface, and not     * abstract)     *     * @return <code>true</code> if instantiable, <code>false</code> if not     */    public boolean isConcrete() {        return !(m_classInformation.isAbstract() ||            m_classInformation.isInterface());    }    /**     * Get list of children.     *     * @return list     */    public List getChildren() {        return m_children;    }        /**     * Add child.     *     * @param child     */    protected void addChild(CustomBase child) {        if (child.getParent() == this) {            m_children.add(child);        } else {            throw new IllegalStateException("Internal error: child not linked");        }    }        /**     * Form set text method. This is intended for use during unmarshalling.     * TODO: add validation     *      * @param text     * @param ictx     */    private void setFormText(String text, IUnmarshallingContext ictx) {        m_form = s_valueStyleEnum.getValue(text);    }        /**     * Form get text method. This is intended for use during marshalling.     *      * @return text     */    private String getFormText() {        return s_valueStyleEnum.getName(m_form);    }    /**     * Build map from member names to read access methods. This assumes that     * each no-argument method which returns a value and has a name beginning     * with "get" or "is" is a property read access method. It maps the     * corresponding property name to the method, and returns the map.     *     * @param methods     * @param inclset set of member names to be included (<code>null</code>     * if not specified)     * @param exclset set of member names to be excluded (<code>null</code>     * if not specified, ignored if inclset is non-<code>null</code>)     * @return map     */    private Map mapPropertyReadMethods(IClassItem[] methods, Set inclset,        Set exclset) {                // check all methods for property read access matches        HashMap getmap = new HashMap();        for (int i = 0; i < methods.length; i++) {            IClassItem item = methods[i];            String name = item.getName();            if (item.getArgumentCount() == 0 &&                ((name.startsWith("get") && !item.getTypeName().equals("void")) ||                (name.startsWith("is") && item.getTypeName().equals("boolean")))) {                                // have what appears to be a getter, check if it should be used                String memb = MemberCustom.memberNameFromGetMethod(name);                boolean use = true;                if (inclset != null) {                    use = inclset.contains(memb.toLowerCase());                } else if (exclset != null) {                    use = !exclset.contains(memb.toLowerCase());                }                if (use) {                    getmap.put(memb, item);                }                            }        }        return getmap;    }    /**     * Build map from member names to write access methods. This assumes that     * each single-argument method which returns void and has a name beginning     * with "set" is a property write access method. It maps the corresponding     * property name to the method, and returns the map.     *     * @param methods     * @param inclset set of member names to be included (<code>null</code>     * if not specified)     * @param exclset set of member names to be excluded (<code>null</code>     * if not specified, ignored if inclset is non-<code>null</code>)     * @return map     */    private Map mapPropertyWriteMethods(IClassItem[] methods, Set inclset,        Set exclset) {                // check all methods for property write access matches        HashMap setmap = new HashMap();

⌨️ 快捷键说明

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