📄 structureelement.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.util.ArrayList;import org.jibx.binding.util.StringArray;import org.jibx.runtime.IMarshallingContext;import org.jibx.runtime.IUnmarshallingContext;import org.jibx.runtime.JiBXException;import org.jibx.runtime.QName;/** * Model component for <b>structure</b> element of binding definition. * * @author Dennis M. Sosnoski */public class StructureElement extends StructureElementBase{ /** Enumeration of allowed attribute names */ public static final StringArray s_allowedAttributes = new StringArray(new String[] { "map-as" }, StructureElementBase.s_allowedAttributes); /** Mapping type name to use for this object. */ private String m_mapAsName; /** Mapping qualified type name to use for this object. */ private QName m_mapAsQName; /** Flag for structure has a concrete mapping, possibly indeterminant. */ private boolean m_hasMappingName; /** Binding to use for this object. */ private TemplateElementBase m_effectiveMapping; /** * Default constructor. */ public StructureElement() { super(STRUCTURE_ELEMENT); } /** * Get name of mapping type. * * @return mapping type name (or <code>null</code> if none) */ public String getMapAsName() { return m_mapAsName; } /** * Set name of mapping type. This method changes the qualified name to * match the mapping type. * * @param name mapping type name (or <code>null</code> if none) */ public void setMapAsName(String name) { m_mapAsName = name; m_mapAsQName = (name == null) ? null : new QName(name); } /** * Get qualified name of mapping type. * * @return mapping qualified type name (or <code>null</code> if none) */ public QName getMapAsQName() { return m_mapAsQName; } /** * Set qualified name of mapping type. This method changes the mapping name * to match the qualified name. * * @param name mapping qualified type name (or <code>null</code> if none) */ public void setMapAsQName(QName name) { m_mapAsQName = name; m_mapAsName = (name == null) ? null : name.toString(); } /** * Get actual type mapping. This call is only meaningful after validation. * * @return actual type mapping (or <code>null</code> if none) */ public TemplateElementBase getEffectiveMapping() { return m_effectiveMapping; } // // Overrides of base class methods /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasName() */ public boolean hasName() { if (m_effectiveMapping instanceof MappingElement) { if (((MappingElement)m_effectiveMapping).getName() != null) { return true; } } else if (m_hasMappingName) { return true; } return super.hasName(); } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#getName() */ public String getName() { if (m_effectiveMapping instanceof MappingElement) { String name = ((MappingElement)m_effectiveMapping).getName(); if (name != null) { return name; } } else if (m_hasMappingName) { return "#" + getType().getName(); } return super.getName(); } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#getUri() */ public String getUri() { if (m_effectiveMapping instanceof MappingElement) { String uri = ((MappingElement)m_effectiveMapping).getUri(); if (uri != null) { return uri; } } return super.getUri(); } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasAttribute() */ public boolean hasAttribute() { if (hasName()) { return false; } else if (m_effectiveMapping != null) { return m_effectiveMapping.name() == null && m_effectiveMapping.getAttributeComponents().size() > 0; } else { return super.hasAttribute(); } } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasContent() */ public boolean hasContent() { if (hasName()) { return true; } else if (m_effectiveMapping != null) { return m_effectiveMapping.name() != null || m_effectiveMapping.getContentComponents().size() > 0; } else { return super.hasContent(); } } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#getType() */ public IClass getType() { if (m_effectiveMapping == null) { return super.getType(); } else { return m_effectiveMapping.getHandledClass(); } } // // Validation methods /** * JiBX access method to set mapping type name as qualified name. * * @param text mapping name text (<code>null</code> if none) * @param ictx unmarshalling context * @throws JiBXException on deserialization error */ private void setQualifiedMapAs(String text, IUnmarshallingContext ictx) throws JiBXException { m_mapAsName = text; m_mapAsQName = QName.deserialize(text, ictx); } /** * JiBX access method to get mapping type name as qualified name. * * @param ictx marshalling context * @return mapping type name text (<code>null</code> if none) * @throws JiBXException on deserialization error */ private String getQualifiedMapAs(IMarshallingContext ictx) throws JiBXException { return QName.serialize(m_mapAsQName, ictx); } /** * Make sure all attributes are defined. * * @param uctx unmarshalling context * @exception JiBXException on unmarshalling error */ private void preSet(IUnmarshallingContext uctx) throws JiBXException { validateAttributes(uctx, s_allowedAttributes); } /** * Merge namespaces from an implicit context to those defined for a * reference. * * @param defc context supplying namespaces to be merged
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -