1 28 29 package org.jibx.binding.model; 30 31 import org.jibx.binding.util.StringArray; 32 import org.jibx.runtime.IUnmarshallingContext; 33 import org.jibx.runtime.JiBXException; 34 35 42 43 public class FormatElement extends ElementBase 44 { 45 46 public static final StringArray s_allowedAttributes = 47 new StringArray(new String [] { "label", "type" }, 48 StringAttributes.s_allowedAttributes); 49 50 51 private String m_label; 52 53 54 private boolean m_isDefault; 55 56 57 private String m_typeName; 58 59 60 private IClass m_type; 61 62 63 private StringAttributes m_stringAttrs; 64 65 68 public FormatElement() { 69 super(FORMAT_ELEMENT); 70 m_stringAttrs = new StringAttributes(); 71 } 72 73 78 public String getLabel() { 79 return m_label; 80 } 81 82 87 public void setLabel(String label) { 88 m_label = label; 89 } 90 91 96 public boolean isDefaultFormat() { 97 return m_isDefault; 98 } 99 100 106 public void setDefaultFormat(boolean dflt) { 107 m_isDefault = dflt; 108 } 109 110 116 public IClass getType() { 117 return m_type; 118 } 119 120 125 public String getTypeName() { 126 return m_typeName; 127 } 128 129 134 public void setTypeName(String value) { 135 m_typeName = value; 136 } 137 138 141 146 public String getDefaultText() { 147 return m_stringAttrs.getDefaultText(); 148 } 149 150 155 public Object getDefault() { 156 return m_stringAttrs.getDefault(); 157 } 158 159 164 public void setDefaultText(String value) { 165 m_stringAttrs.setDefaultText(value); 166 } 167 168 174 public String getSerializerName() { 175 return m_stringAttrs.getSerializerName(); 176 } 177 178 184 public IClassItem getSerializer() { 185 return m_stringAttrs.getSerializer(); 186 } 187 188 193 public void setSerializerName(String name) { 194 m_stringAttrs.setSerializerName(name); 195 } 196 197 203 public String getDeserializerName() { 204 return m_stringAttrs.getDeserializerName(); 205 } 206 207 213 public IClassItem getDeserializer() { 214 return m_stringAttrs.getDeserializer(); 215 } 216 217 222 public void setDeserializerName(String name) { 223 m_stringAttrs.setDeserializerName(name); 224 } 225 226 232 public FormatElement getBaseFormat() { 233 return m_stringAttrs.getBaseFormat(); 234 } 235 236 239 245 private void preSet(IUnmarshallingContext uctx) throws JiBXException { 246 validateAttributes(uctx, s_allowedAttributes); 247 } 248 249 258 public void prevalidate(ValidationContext vctx) { 259 260 if (m_typeName != null) { 262 m_type = vctx.getClassInfo(m_typeName); 263 if (m_type != null) { 264 m_stringAttrs.setType(m_type); 265 m_stringAttrs.prevalidate(vctx); 266 } else { 267 vctx.addFatal("Unable to find type " + m_typeName); 268 } 269 } else { 270 vctx.addFatal("Missing required type name"); 271 } 272 273 if (vctx.getParentElement() != null) { 275 vctx.getFormatDefinitions().addFormat(this, vctx); 276 } 277 super.prevalidate(vctx); 278 } 279 280 283 public void validate(ValidationContext vctx) { 284 m_stringAttrs.validate(vctx); 285 super.validate(vctx); 286 } 287 } | Popular Tags |