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 import org.jibx.runtime.impl.UnmarshallingContext; 35 36 44 45 public abstract class ElementBase 46 { 47 50 public static final int BINDING_ELEMENT = 0; 51 public static final int COLLECTION_ELEMENT = 1; 52 public static final int FORMAT_ELEMENT = 2; 53 public static final int MAPPING_ELEMENT = 3; 54 public static final int NAMESPACE_ELEMENT = 4; 55 public static final int STRUCTURE_ELEMENT = 5; 56 public static final int TEMPLATE_ELEMENT = 6; 57 public static final int VALUE_ELEMENT = 7; 58 public static final int INCLUDE_ELEMENT = 8; 60 public static final int SPLIT_ELEMENT = 9; 61 public static final int INPUT_ELEMENT = 10; 62 public static final int OUTPUT_ELEMENT = 11; 63 64 public static final String [] ELEMENT_NAMES = 65 { 66 "binding", "collection", "format", "mapping", "namespace", "structure", 67 "template", "value", "include", "split", "input", "output" 68 }; 69 70 73 74 private final int m_type; 75 76 77 private String m_comment; 78 79 84 protected ElementBase(int type) { 85 m_type = type; 86 } 87 88 93 public final int type() { 94 return m_type; 95 } 96 97 102 public final String name() { 103 return ELEMENT_NAMES[m_type]; 104 } 105 106 111 public final String getComment() { 112 return m_comment; 113 } 114 115 120 public final void setComment(String text) { 121 m_comment = text; 122 } 123 124 133 protected void validateAttributes(IUnmarshallingContext ictx, 134 StringArray attrs) throws JiBXException { 135 136 int count = ictx.getStackDepth(); 138 BindingElement.UnmarshalWrapper wrapper = 139 (BindingElement.UnmarshalWrapper)ictx.getStackObject(count-1); 140 ValidationContext vctx = wrapper.getValidation(); 141 UnmarshallingContext uctx = (UnmarshallingContext)ictx; 142 try { 143 144 for (int i = 0; i < uctx.getAttributeCount(); i++) { 146 147 String name = uctx.getAttributeName(i); 149 if (uctx.getAttributeNamespace(i).length() == 0) { 150 if (attrs.indexOf(name) < 0) { 151 vctx.addWarning("Undefined attribute " + name, this); 152 } 153 } 154 } 155 } catch (JiBXException e) { 156 } 157 } 158 159 168 public void prevalidate(ValidationContext vctx) {} 169 170 180 public void validate(ValidationContext vctx) {} 181 } | Popular Tags |