bindingelement.java
来自「JiBX是一个为Java提供的XML数据绑定框架。它可以和现存的类一起运行」· Java 代码 · 共 707 行 · 第 1/2 页
JAVA
707 行
/*Copyright (c) 2004-2005, 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.model;//import java.io.File;//import java.io.FileInputStream;//import java.io.FileOutputStream;//import java.io.FileReader;import java.io.InputStream;import java.net.URL;import java.util.ArrayList;import java.util.HashSet;import java.util.Iterator;import org.jibx.binding.classes.ClassCache;//import org.jibx.binding.classes.ClassFile;import org.jibx.binding.util.StringArray;//import org.jibx.extras.DocumentComparator;import org.jibx.runtime.BindingDirectory;import org.jibx.runtime.EnumSet;import org.jibx.runtime.IBindingFactory;import org.jibx.runtime.QName;//import org.jibx.runtime.IMarshallingContext;import org.jibx.runtime.IUnmarshallingContext;import org.jibx.runtime.JiBXException;/** * Model component for <b>binding</b> element. * * @author Dennis M. Sosnoski * @version 1.0 */ public class BindingElement extends NestingElementBase{ /** Enumeration of allowed attribute names */ public static final StringArray s_allowedAttributes = new StringArray(new String[] { "add-constructors", "direction", "force-classes", "forwards", "name", "package", "track-source" }, NestingElementBase.s_allowedAttributes); // // Value set information public static final int IN_BINDING = 0; public static final int OUT_BINDING = 1; public static final int BOTH_BINDING = 2; /*package*/ static final EnumSet s_directionEnum = new EnumSet(IN_BINDING, new String[] { "input", "output", "both" }); // // Instance data /** Binding name. */ private String m_name; /** Binding direction. */ private String m_direction; /** Input binding flag. */ private boolean m_isInput; /** Output binding flag. */ private boolean m_isOutput; /** Support forward references to IDs flag. */ private boolean m_isForward; /** Generate souce tracking interface flag. */ private boolean m_isTrackSource; /** Generate souce tracking interface flag. */ private boolean m_isForceClasses; /** Add default constructors where needed flag. */ private boolean m_isAddConstructors; /** Package for generated context factory. */ private String m_targetPackage; /** Base URL for use with relative include paths. */ private URL m_baseUrl; /** Set of paths for includes. */ private HashSet m_includePaths; /** List of child elements. */ private ArrayList m_children; /** Set of class names which can be referenced by ID. */ private HashSet m_idClassSet; /** * Default constructor. */ public BindingElement() { super(BINDING_ELEMENT); m_includePaths = new HashSet(); m_children = new ArrayList(); } /** * Set binding name. * * @param name binding definition name */ public void setName(String name) { m_name = name; } /** * Get binding name. * * @return binding definition name */ public String getName() { return m_name; } /** * Set forward references to IDs be supported in XML. * * @param forward <code>true</code> if forward references supported, * <code>false</code> if not */ public void setForward(boolean forward) { m_isForward = forward; } /** * Check if forward references to IDs must be supported in XML. * * @return <code>true</code> if forward references required, * <code>false</code> if not */ public boolean isForward() { return m_isForward; } /** * Set source position tracking for unmarshalling. * * @param track <code>true</code> if source position tracking enabled, * <code>false</code> if not */ public void setTrackSource(boolean track) { m_isTrackSource = track; } /** * Check if source position tracking enabled for unmarshalling. * * @return <code>true</code> if source position tracking enabled, * <code>false</code> if not */ public boolean isTrackSource() { return m_isTrackSource; } /** * Set force marshaller/unmarshaller class creation for top-level non-base * abstract mappings. * * @param force <code>true</code> if class generation forced, * <code>false</code> if not */ public void setForceClasses(boolean force) { m_isForceClasses = force; } /** * Check if marshaller/unmarshaller class creation for top-level non-base * abstract mappings is forced. * * @return <code>true</code> if class generation forced, * <code>false</code> if not */ public boolean isForceClasses() { return m_isForceClasses; } /** * Check if default constructor generation is enabled. * * @return <code>true</code> if default constructor generation enabled, * <code>false</code> if not */ public boolean isAddConstructors() { return m_isAddConstructors; } /** * Set package for generated context factory class. * * @param pack generated context factory package */ public void setTargetPackage(String pack) { m_targetPackage = pack; } /** * Get package for generated context factory class. * * @return package for generated context factory */ public String getTargetPackage() { return m_targetPackage; } /** * Set base URL for relative include paths. * * @param base */ public void setBaseUrl(URL base) { m_baseUrl = base; } /** * Get base URL for relative include paths. * * @return */ public URL getBaseUrl() { return m_baseUrl; } /** * Set binding component applies for marshalling XML. * * @param out <code>true</code> if binding supports output, * <code>false</code> if not */ public void setOutBinding(boolean out) { m_isOutput = out; } /** * Check if this binding component applies for marshalling XML. * * @return <code>true</code> if binding supports output, <code>false</code> * if not */ public boolean isOutBinding() { return m_isOutput; } /** * Set binding component applies for unmarshalling XML. * * @param in <code>true</code> if binding supports input, * <code>false</code> if not */ public void setInBinding(boolean in) { m_isInput = in; } /** * Check if this binding component applies for unmarshalling XML. * * @return <code>true</code> if binding supports input, <code>false</code> * if not */ public boolean isInBinding() { return m_isInput; } /** * Add include path to set processed. * * @return <code>true</code> if new path, <code>false</code> if duplicate */ public boolean addIncludePath(String path) { return m_includePaths.add(path); } /** * Add a class defined with a ID value. This is used to track the classes * with ID values for validating ID references in the binding. If the * binding uses global IDs, the actual ID class is added to the table along * with all interfaces implemented by the class and all superclasses, since * instances of the ID class can be referenced in any of those forms. If the * binding does not use global IDs, only the actual ID class is added, since * references must be type-specific. * * @param clas information for class with ID value */ public void addIdClass(IClass clas) { // create the set if not already present if (m_idClassSet == null) { m_idClassSet = new HashSet(); } // add the class if not already present if (m_idClassSet.add(clas.getName())) { // new class, add all interfaces if not previously defined String[] inames = clas.getInterfaces(); for (int i = 0; i < inames.length; i++) { m_idClassSet.add(inames[i]); } while (clas != null && m_idClassSet.add(clas.getName())) { clas = clas.getSuperClass(); } } } /** * Check if a class can be referenced by ID. This just checks if any classes * compatible with the reference type are bound with ID values. * * @param name fully qualified name of class * @return <code>true</code> if class is bound with an ID, * <code>false</code> if not */ public boolean isIdClass(String name) { if (m_idClassSet == null) { return false; } else { return m_idClassSet.contains(name); } } /** * Add top-level child element. * TODO: should be ElementBase argument, but JiBX doesn't allow yet
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?