1 28 29 package org.jibx.binding.model; 30 31 import org.jibx.binding.util.StringArray; 32 import org.jibx.runtime.EnumSet; 33 import org.jibx.runtime.IUnmarshallingContext; 34 import org.jibx.runtime.JiBXException; 35 36 42 43 public class NamespaceElement extends ElementBase 44 { 45 46 public static final StringArray s_allowedAttributes = 47 new StringArray(new String [] { "default", "prefix", "uri" }); 48 49 52 public static final int NODEFAULT_USAGE = 0; 53 public static final int ELEMENTS_USAGE = 1; 54 public static final int ATTRIBUTES_USAGE = 2; 55 public static final int ALLDEFAULT_USAGE = 3; 56 57 public static final EnumSet s_defaultEnum = 58 new EnumSet(NODEFAULT_USAGE, 59 new String [] { "none", "elements", "attributes", "all" }); 60 61 64 65 private String m_defaultName = s_defaultEnum.getName(NODEFAULT_USAGE); 66 67 68 private int m_defaultIndex; 69 70 71 private String m_uri; 72 73 74 private String m_prefix; 75 76 79 public NamespaceElement() { 80 super(NAMESPACE_ELEMENT); 81 } 82 83 88 public String getPrefix() { 89 return m_prefix; 90 } 91 92 97 public void setPrefix(String text) { 98 m_prefix = text; 99 } 100 101 106 public String getUri() { 107 return m_uri; 108 } 109 110 115 public void setUri(String uri) { 116 m_uri = uri; 117 } 118 119 124 public void setDefaultName(String name) { 125 m_defaultName = name; 126 } 127 128 135 public boolean isAttributeDefault() { 136 return m_defaultIndex == ATTRIBUTES_USAGE || 137 m_defaultIndex == ALLDEFAULT_USAGE; 138 } 139 140 147 public boolean isElementDefault() { 148 return m_defaultIndex == ELEMENTS_USAGE || 149 m_defaultIndex == ALLDEFAULT_USAGE; 150 } 151 152 155 161 private void preSet(IUnmarshallingContext uctx) throws JiBXException { 162 validateAttributes(uctx, s_allowedAttributes); 163 } 164 165 170 public void prevalidate(ValidationContext vctx) { 171 m_defaultIndex = s_defaultEnum.getValue(m_defaultName); 172 if (m_defaultIndex < 0) { 173 vctx.addError("Value \"" + m_defaultName + 174 "\" is not a valid choice for namespace default usage"); 175 } 176 } 177 } | Popular Tags |