📄 bindingelement.java
字号:
/*Copyright (c) 2004-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.model;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.jibx.binding.classes.ClassCache;import org.jibx.binding.util.StringArray;import org.jibx.runtime.BindingDirectory;import org.jibx.runtime.EnumSet;import org.jibx.runtime.IBindingFactory;import org.jibx.runtime.IMarshallingContext;import org.jibx.runtime.IUnmarshallingContext;import org.jibx.runtime.IXMLWriter;import org.jibx.runtime.JiBXException;import org.jibx.runtime.Utility;import org.jibx.runtime.impl.UnmarshallingContext;/** * 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 final Set m_includePaths; /** Map from include path to actual binding. */ private final Map m_includeBindings; /** List of child elements. */ private final ArrayList m_children; /** Set of class names which can be referenced by ID. */ private Set m_idClassSet; /** List of namespace declarations to be added on output (lazy create, <code>null</code> if none). */ private ArrayList m_namespaceDeclares; /** * Default constructor. */ public BindingElement() { super(BINDING_ELEMENT); m_includePaths = new HashSet(); m_includeBindings = new HashMap(); m_children = new ArrayList(); m_isForward = true; } /** * 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; } /** * Set default constructor generation. * * @param add <code>true</code> if constructors should be added, * <code>false</code> if not */ public void setAddConstructors(boolean add) { m_isAddConstructors = add; } /** * 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 base URL */ public URL getBaseUrl() { return m_baseUrl; } /** * Set the correct direction text. This should be used whenever the * individual in and out flags are set, so that modifications are output * correctly when a binding is marshalled. */ private void setDirection() { int direct = m_isInput ? (m_isOutput ? BOTH_BINDING : IN_BINDING) : OUT_BINDING; m_direction = s_directionEnum.getName(direct); } /** * 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; setDirection(); } /** * 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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -