1 28 29 package org.jibx.binding.def; 30 31 import org.jibx.runtime.JiBXException; 32 33 39 40 public class NamespaceDefinition 41 { 42 45 static final int NODEFAULT_USAGE = 0; 46 static final int ELEMENTS_USAGE = 1; 47 static final int ATTRIBUTES_USAGE = 2; 48 static final int ALLDEFAULT_USAGE = 3; 49 50 53 54 private String m_uri; 55 56 57 private String m_prefix; 58 59 60 private int m_index; 61 62 63 private boolean m_elementDefault; 64 65 66 private boolean m_attributeDefault; 67 68 77 78 public NamespaceDefinition(String uri, String prefix, int usage) 79 throws JiBXException { 80 m_uri = uri; 81 m_prefix = prefix; 82 m_elementDefault = 83 (usage == ALLDEFAULT_USAGE) || (usage == ELEMENTS_USAGE); 84 m_attributeDefault = 85 (usage == ALLDEFAULT_USAGE) || (usage == ATTRIBUTES_USAGE); 86 if (usage != ELEMENTS_USAGE && prefix == null) { 87 throw new JiBXException 88 ("Prefix required for namespace unless element default"); 89 } 90 if (m_attributeDefault && m_prefix == null) { 91 throw new JiBXException("Prefix required for attribute namespace"); 92 } 93 } 94 95 101 102 public boolean isAttributeDefault() { 103 return m_attributeDefault; 104 } 105 106 112 113 public boolean isElementDefault() { 114 return m_elementDefault; 115 } 116 117 122 123 public String getPrefix() { 124 return m_prefix; 125 } 126 127 132 133 public String getUri() { 134 return m_uri; 135 } 136 137 142 143 public void setIndex(int index) { 144 m_index = index; 145 } 146 147 152 153 public int getIndex() { 154 return m_index; 155 } 156 157 164 165 public static NamespaceDefinition buildNamespace(String uri, 166 String prefix) throws JiBXException { 167 return new NamespaceDefinition(uri, prefix, NODEFAULT_USAGE); 168 } 169 170 public void print(int depth) { 172 BindingDefinition.indent(depth); 173 System.out.print("namespace " + m_uri); 174 if (m_prefix != null) { 175 System.out.print(" (prefix " + m_prefix + ")"); 176 } 177 System.out.println(); 178 } 179 } 180 | Popular Tags |