1 22 package org.jboss.xb.binding.sunday.unmarshalling; 23 24 import java.util.List ; 25 import java.util.Collections ; 26 import java.util.ArrayList ; 27 28 import javax.xml.namespace.QName ; 29 import org.jboss.xb.binding.metadata.AddMethodMetaData; 30 import org.jboss.xb.binding.metadata.ClassMetaData; 31 import org.jboss.xb.binding.metadata.MapEntryMetaData; 32 import org.jboss.xb.binding.metadata.PutMethodMetaData; 33 import org.jboss.xb.binding.metadata.ValueMetaData; 34 import org.jboss.xb.binding.JBossXBRuntimeException; 35 import org.jboss.xb.binding.sunday.marshalling.TermBeforeMarshallingCallback; 36 import org.jboss.xb.binding.sunday.xop.XOPUnmarshaller; 37 38 42 public class ElementBinding 43 extends TermBinding 44 { 45 protected List interceptors = Collections.EMPTY_LIST; 46 47 protected QName qName; 48 protected TypeBinding typeBinding; 49 protected boolean nillable; 50 51 protected XOPUnmarshaller xopUnmarshaller; 52 53 public ElementBinding(SchemaBinding schema, QName qName, TypeBinding typeBinding) 54 { 55 super(schema); 56 this.qName = qName; 57 this.typeBinding = typeBinding; 58 59 if(qName == null) 60 { 61 throw new JBossXBRuntimeException("Each element must have a non-null QName!"); 62 } 63 } 64 65 protected ElementBinding() 66 { 67 } 68 69 public QName getQName() 70 { 71 return qName; 72 } 73 74 public List getInterceptors() 75 { 76 return interceptors; 77 } 78 79 public TypeBinding getType() 80 { 81 return typeBinding; 82 } 83 84 public void pushInterceptor(ElementInterceptor interceptor) 85 { 86 switch(interceptors.size()) 87 { 88 case 0: 89 interceptors = Collections.singletonList(interceptor); 90 break; 91 case 1: 92 interceptors = new ArrayList (interceptors); 93 default: 94 interceptors.add(interceptor); 95 96 } 97 } 98 99 public ClassMetaData getClassMetaData() 100 { 101 ClassMetaData result = classMetaData; 102 if(result == null && mapEntryMetaData == null) 103 { 104 result = typeBinding.getClassMetaData(); 105 } 106 return result; 107 } 108 109 public MapEntryMetaData getMapEntryMetaData() 110 { 111 MapEntryMetaData result = mapEntryMetaData; 112 if(result == null && classMetaData == null) 113 { 114 result = typeBinding.getMapEntryMetaData(); 115 } 116 return result; 117 } 118 119 public ValueMetaData getValueMetaData() 120 { 121 return valueMetaData != null ? valueMetaData : typeBinding.getValueMetaData(); 122 } 123 124 public PutMethodMetaData getPutMethodMetaData() 125 { 126 return putMethodMetaData; 128 } 129 130 public AddMethodMetaData getAddMethodMetaData() 131 { 132 AddMethodMetaData result = addMethodMetaData; 133 if(result == null && putMethodMetaData == null && propertyMetaData == null) 134 { 135 result = typeBinding.getAddMethodMetaData(); 136 } 137 return result; 138 } 139 140 public boolean isSkip() 141 { 142 return skip == null ? typeBinding.isSkip() : skip.booleanValue(); 143 } 144 145 public ValueAdapter getValueAdapter() 146 { 147 return valueAdapter == null ? typeBinding.getValueAdapter() : valueAdapter; 148 } 149 150 public TermBeforeMarshallingCallback getBeforeMarshallingCallback() 151 { 152 return beforeMarshallingCallback == null ? typeBinding.getBeforeMarshallingCallback() : beforeMarshallingCallback; 153 } 154 155 public TermBeforeSetParentCallback getBeforeSetParentCallback() 156 { 157 return beforeSetParentCallback == null ? typeBinding.getBeforeSetParentCallback() : beforeSetParentCallback; 158 } 159 160 public boolean isNillable() 161 { 162 return nillable; 163 } 164 165 public void setNillable(boolean nillable) 166 { 167 this.nillable = nillable; 168 } 169 170 public boolean isModelGroup() 171 { 172 return false; 173 } 174 175 public boolean isWildcard() 176 { 177 return false; 178 } 179 180 public boolean isElement() 181 { 182 return true; 183 } 184 185 public XOPUnmarshaller getXopUnmarshaller() 186 { 187 return xopUnmarshaller == null ? typeBinding.getXopUnmarshaller() : xopUnmarshaller; 188 } 189 190 public void setXopUnmarshaller(XOPUnmarshaller xopUnmarshaller) 191 { 192 this.xopUnmarshaller = xopUnmarshaller; 193 } 194 195 public String toString() 196 { 197 return super.toString() + "(" + qName + ", type=" + typeBinding.getQName() + ")"; 198 } 199 } 200 | Popular Tags |