1 28 29 package org.jibx.binding.def; 30 31 import org.jibx.runtime.JiBXException; 32 33 44 45 public class MappingReference extends PassThroughComponent 46 { 47 48 private final IContainer m_container; 49 50 51 private final PropertyDefinition m_property; 52 53 54 private final String m_type; 55 56 57 private final IContextObj m_contextObject; 58 59 60 private final NameDefinition m_name; 61 62 72 73 public MappingReference(IContainer contain, PropertyDefinition prop, 74 String type, IContextObj objc, NameDefinition name) { 75 super(); 76 m_container = contain; 77 m_property = prop; 78 m_type = type; 79 m_contextObject = objc; 80 m_name = name; 81 } 82 83 89 90 public MappingReference(IContainer parent, String type) { 91 this(parent, null, type, null, null); 92 } 93 94 97 public String getType() { 98 return m_type; 99 } 100 101 public void setLinkages() throws JiBXException { 102 103 DefinitionContext defc = m_container.getDefinitionContext(); 105 IMapping mdef = defc.getClassMapping(m_type); 106 IComponent wrap; 107 if (mdef == null) { 108 109 if (m_name != null) { 111 throw new JiBXException 112 ("Name not allowed for generic mapping of type " + m_type); 113 } 114 wrap = new DirectGeneric(m_container, m_type, m_property); 115 116 } else { 117 118 wrap = mdef.buildRef(m_container, m_contextObject, m_type, 120 m_property); 121 if (m_name != null) { 122 if (mdef.getName() == null) { 123 wrap = new ElementWrapper(defc, m_name, wrap); 124 if (m_property.isOptional()) { 125 ((ElementWrapper)wrap).setOptionalNormal(true); 126 ((ElementWrapper)wrap).setStructureObject(true); 127 wrap = new OptionalStructureWrapper(wrap, m_property, 128 true); 129 m_property.setOptional(false); 130 } 131 } else { 132 throw new JiBXException 133 ("Name not allowed for reference to mapping of type " + 134 m_type + ", which already defines a name"); 135 } 136 } 137 } 138 139 setWrappedComponent(wrap); 141 super.setLinkages(); 142 } 143 144 public void print(int depth) { 146 BindingDefinition.indent(depth); 147 System.out.print("mapping reference to " + m_type); 148 if (m_property != null) { 149 System.out.print(" using " + m_property.toString()); 150 } 151 System.out.println(); 152 } 153 } | Popular Tags |