📄 schemamappingdetail.java
字号:
package org.jibx.binding.generator;import org.jibx.binding.model.MappingElement;import org.jibx.runtime.QName;/** * Holder for the details of how a mapping is to be represented in a schema. * Each mapping is converted to a complex type, but the complex type may be * either global or local to a containing global element. In the case of a * mapping used as the base for one or more extension types, both a global * complex type and a global element that references the type are required. * This also tracks the content form for the complex type definition. * * Should the binding representation of polymorphism use both abstract mappings * with type names, and concrete mappings with element names that reference the * abstract mapping? Then use two complete separate hierarchies? But in order to * do the * * book ----\ * -----item * dvd -----/ * * So the concrete <mapping> for book extends the concrete mapping for item, as * does the concrete mapping for dvd. If book is not extended, there's no need * to have a separate BookType. There is the need for a separate abstract * mapping for ItemType, which the concrete mapping for item then uses. On the * other hand, the way I've changed the code to work there's no need have any * additional mappings - the book and dvd mappings can each just invoke the item * mapping directly. * * Now what if I want to extend the book mapping? So I have an arts book type * that adds more details, say the number of plates. Ideally, I'd like to have * the artBook mapping extend the concrete book mapping. But then how do I * distinguish between the artBook <struct map-as='book'/> and the reference to * a book that's meant to be a <book> element? Here's the logical structure of * what I want: * * book --\ * artBook ---------- BookType ---\ * ----- ItemType * dvd -----/ * * But the extends structure is: * * artBook ---------- book ---\ * ----- item * dvd -----/ * * Should the BookType abstract mapping in the top diagram extend ItemType? I * don't think that's necessary, as long as the first component of the BookType * definition is a structure reference to ItemType. * * So concrete <mapping>s can be extended to represent substitution groups. If * the base of a <mapping> extension is an abstract <mapping>, I'll add an * abstract element definition for that <mapping> just to serve as a base for * the substitution group. Abstract <mapping> extensions in the future can be * used for type substitution, but that requires named types for the whol * hierarchy. * * If I do it this way, there's no need to allow for names on abstract mappings, * and each abstract mapping corresponds directly to a complexType while each * concrete mapping corresponds directly to an element. Note that the extends * relationship between <mapping> elements may or may not carry over to the * schema; if a <mapping> uses extends='...' but doesn't have the structure * reference to the extended type as the first component, or if the reference * uses a name, the extends relationship cannot go into the schema and the user * should get a warning. On the other hand, if the first component is a * structure reference to a <mapping> with no name, this should be reflected in * the schame as an extends relationship for the complexTypes. <mapping>s which * are used as groups of elements and/or attributes should be modeled in the * schema as <group>s and <attributeGroup>s. * * What about customizations for schema generation? It seems like this would be * very useful, but the issue here is that the structure doesn't match the form * of the customizations used for going from Java (class-structured). I'd * instead want to make schema customizations follow the structure of a binding * definition. * * Can I just generate the schema components on-demand? That would mean a first * pass to generate these details, and a second pass which actually triggered * the generation process. But then I might also need a third pass, etc. I * suppose the best is to do a sort of modified on-demand, where I generate the * default equivalent directly */public class SchemaMappingDetail{ /** Mapping to be generated. */ private final MappingElement m_mapping; /** Schema type extension base mapping. */ private final MappingElement m_extensionBase; /** Has child element(s) flag. */ private final boolean m_hasChild; /** Has child text(s) flag. */ private final boolean m_hasText; /** Has attribute(s) flag. */ private final boolean m_hasAttribute; /** Type name (ignored if not generated as complex type). */ private final QName m_typeName; /** Element/group/attributeGroup name (ignored if not generated as any of these). */ private final QName m_otherName; /** Substitution group base name. */ private QName m_substitutionName; /** Generate as complex type flag. */ private boolean m_isType; /** Generate as element flag. */ private boolean m_isElement; /** Generate as group/attributeGroup flag. If set, will be generated as either a group (if elements defined), an attributeGroup (if attributes defined), or both. */ private boolean m_isGroup; /** * Constructor. * * @param map mapping definition * @param haschild has child element(s) flag * @param hastext has child text(s) flag * @param base base mapping for schema type extension * @param tname name as type * @param oname name as element/group/attributeGroup */ public SchemaMappingDetail(MappingElement map, boolean haschild, boolean hastext, MappingElement base, QName tname, QName oname) { m_mapping = map; m_extensionBase = base; m_hasChild = haschild; m_hasText = hastext; m_hasAttribute = map.getAttributeComponents().size() > 0; m_typeName = tname; m_otherName = oname; if (map.isAbstract() && map.getTypeName() != null) { m_isType = true; } else if (!map.isAbstract()) { m_isElement = true; } } /** * Check if generating as an element. * * @return flag */ public boolean isElement() { return m_isElement; } /** * Set generating as an element. * * @param gen */ public void setElement(boolean gen) { m_isElement = gen; } /** * Check if generating as a group. * * @return flag */ public boolean isGroup() { return m_isGroup; } /** * Set generating as a group. * * @param gen */ public void setGroup(boolean gen) { m_isGroup = gen; } /** * Check if generating as a group. * * @return flag */ public boolean isType() { return m_isType; } /** * Set generating as a type. * * @param gen */ public void setType(boolean gen) { m_isType = gen; } /** * Get base mapping for schema type extension. * * @return extension base */ public MappingElement getExtensionBase() { return m_extensionBase; } /** * Check if attribute component present. * * @return flag */ public boolean hasAttribute() { return m_hasAttribute; } /** * Check if child element component present. * * @return flag */ public boolean hasChild() { return m_hasChild; } /** * Check if text component present. * * @return flag */ public boolean hasText() { return m_hasText; } /** * Get mapping. * * @return mapping */ public MappingElement getMapping() { return m_mapping; } /** * Get name for type. * * @return name */ public QName getTypeName() { return m_typeName; } /** * Get element name. * * @return element name for concrete mapping (<code>null</code> if abstract) */ public QName getOtherName() { return m_otherName; } /** * Get substitution group base name. * * @return substitution group base name */ public QName getSubstitution() { return m_substitutionName; } /** * Set substitution group base name. * * @param qname */ public void setSubstitution(QName qname) { m_substitutionName = qname; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -