1 28 29 package org.jibx.binding.def; 30 31 import java.util.ArrayList ; 32 33 import org.jibx.binding.classes.*; 34 import org.jibx.runtime.JiBXException; 35 36 43 44 public abstract class NestedBase extends BindingBuilder.ContainerBase 45 implements IComponent, IContainer 46 { 47 48 private final IContextObj m_contextObject; 49 50 51 private final boolean m_hasContext; 52 53 54 protected final boolean m_isOrdered; 55 56 57 private final DefinitionContext m_defContext; 58 59 60 protected ArrayList m_attributes; 61 62 63 protected ArrayList m_contents; 64 65 73 74 public NestedBase(IContainer contain, IContextObj objc, 75 boolean ord, boolean defc) { 76 77 super(contain); 79 m_styleDefault = m_autoLink = m_accessLevel = m_nameStyle = -1; 80 81 m_contextObject = objc; 83 m_contents = new ArrayList (); 84 m_isOrdered = ord; 85 m_hasContext = defc; 86 if (defc) { 87 m_defContext = new DefinitionContext(contain); 88 } else { 89 m_defContext = contain.getDefinitionContext(); 90 } 91 } 92 93 99 100 public ArrayList getAttributes() { 101 return m_attributes; 102 } 103 104 109 110 public ArrayList getContents() { 111 return m_contents; 112 } 113 114 122 123 public void addComponent(IComponent comp) { 124 m_contents.add(comp); 125 } 126 127 130 public boolean isContentOrdered() { 131 return m_isOrdered; 132 } 133 134 public boolean hasNamespaces() { 135 return m_hasContext && m_defContext.hasNamespace(); 136 } 137 138 public BindingDefinition getBindingRoot() { 139 return m_container.getBindingRoot(); 140 } 141 142 public DefinitionContext getDefinitionContext() { 143 return m_defContext; 144 } 145 146 149 public boolean isOptional() { 150 151 if (m_attributes != null) { 153 for (int i = 0; i < m_attributes.size(); i++) { 154 if (!((IComponent)m_attributes.get(i)).isOptional()) { 155 return false; 156 } 157 } 158 } 159 for (int i = 0; i < m_contents.size(); i++) { 160 if (!((IComponent)m_contents.get(i)).isOptional()) { 161 return false; 162 } 163 } 164 return true; 165 } 166 167 public boolean hasContent() { 168 return m_contents.size() > 0; 169 } 170 171 public void genContentPresentTest(ContextMethodBuilder mb) 172 throws JiBXException { 173 if (m_contents.size() > 0) { 174 175 int count = m_contents.size(); 177 if (count == 1) { 178 ((IComponent)m_contents.get(0)).genContentPresentTest(mb); 179 } else { 180 181 BranchWrapper[] tofound = new BranchWrapper[count]; 183 for (int i = 0; i < count; i++) { 184 IComponent comp = (IComponent)m_contents.get(i); 185 comp.genContentPresentTest(mb); 186 tofound[i] = mb.appendIFNE(this); 187 } 188 189 mb.appendICONST_0(); 191 BranchWrapper toend = mb.appendUnconditionalBranch(this); 192 193 for (int i = 0; i < count; i++) { 195 mb.targetNext(tofound[i]); 196 } 197 mb.appendICONST_1(); 198 mb.targetNext(toend); 199 200 } 201 } else { 202 throw new IllegalStateException 203 ("Internal error - no content present"); 204 } 205 } 206 207 public void genNewInstance(ContextMethodBuilder mb) { 208 throw new IllegalStateException 209 ("Internal error - no instance creation"); 210 } 211 212 public String getType() { 213 return m_contextObject.getBoundClass().getClassName(); 214 } 215 } | Popular Tags |