1 28 29 package org.jibx.binding.def; 30 31 import org.jibx.binding.classes.MethodBuilder; 32 import org.jibx.runtime.JiBXException; 33 34 41 42 public class NameDefinition 43 { 44 45 private final String m_name; 46 47 48 private String m_namespace; 49 50 51 private final boolean m_isAttribute; 52 53 54 private int m_namespaceIndex; 55 56 61 62 public NameDefinition(String name, String ns, boolean attr) { 63 m_name = name; 64 m_namespace = ns; 65 m_isAttribute = attr; 66 } 67 68 73 74 public boolean isNullUri() { 75 return m_namespace == null; 76 } 77 78 84 85 public void genPushUri(MethodBuilder mb) throws JiBXException { 86 if (m_namespace == null) { 87 mb.appendACONST_NULL(); 88 } else { 89 mb.appendLoadConstant(m_namespace); 90 } 91 } 92 93 99 100 public void genPushName(MethodBuilder mb) throws JiBXException { 101 mb.appendLoadConstant(m_name); 102 } 103 104 110 111 public void genPushUriPair(MethodBuilder mb) throws JiBXException { 112 genPushUri(mb); 113 genPushName(mb); 114 } 115 116 122 123 public void genPushIndexPair(MethodBuilder mb) throws JiBXException { 124 mb.appendLoadConstant(m_namespaceIndex); 125 genPushName(mb); 126 } 127 128 137 138 public void fixNamespace(DefinitionContext defc) throws JiBXException { 139 if (m_namespace == null) { 140 m_namespace = defc.getDefaultURI(m_isAttribute); 141 m_namespaceIndex = defc.getDefaultIndex(m_isAttribute); 142 } else { 143 try { 144 m_namespaceIndex = defc.getNamespaceIndex 145 (m_namespace, m_isAttribute); 146 } catch (JiBXException ex) { 147 throw new JiBXException("Undefined or unusable namespace \"" + 148 m_namespace + '"'); 149 } 150 } 151 } 152 153 public String toString() { 155 if (m_namespace == null) { 156 return m_name; 157 } else { 158 return "{" + m_namespace + "}:" + m_name; 159 } 160 } 161 } 162 | Popular Tags |