1 28 29 package org.jibx.binding.model; 30 31 import java.util.ArrayList ; 32 33 import org.jibx.binding.util.StringArray; 34 35 44 45 public abstract class ContainerElementBase extends NestingElementBase 46 { 47 48 public static final StringArray s_allowedAttributes = 49 new StringArray(NestingElementBase.s_allowedAttributes, 50 new StringArray(ObjectAttributes.s_allowedAttributes, 51 StructureAttributes.s_allowedAttributes)); 52 53 54 private ObjectAttributes m_objectAttrs; 55 56 57 private StructureAttributes m_structureAttrs; 58 59 60 private IComponent m_idChild; 61 62 64 private ArrayList m_contentComponents; 65 66 68 private ArrayList m_attributeComponents; 69 70 75 protected ContainerElementBase(int type) { 76 super(type); 77 m_objectAttrs = new ObjectAttributes(); 78 m_structureAttrs = new StructureAttributes(); 79 } 80 81 87 public ArrayList getContentComponents() { 88 return m_contentComponents == null ? 89 EmptyList.INSTANCE : m_contentComponents; 90 } 91 92 98 public ArrayList getAttributeComponents() { 99 return m_attributeComponents == null ? 100 EmptyList.INSTANCE : m_attributeComponents; 101 } 102 103 109 public abstract IClass getEffectiveType(); 110 111 117 public abstract IClass getActualType(); 118 119 128 public final void setIdChild(IComponent child, ValidationContext vctx) { 129 if (m_idChild == null) { 130 m_idChild = child; 131 vctx.getBindingRoot().addIdClass(getActualType()); 132 } else { 133 vctx.addError("Only one child ID property allowed for an object " + 134 "- " + ValidationProblem.componentDescription(m_idChild) + 135 " and " + ValidationProblem.componentDescription(child) + 136 " refer to the same object"); 137 } 138 } 139 140 143 public IComponent getId() { 144 return m_idChild; 145 } 146 147 150 156 public String getFactoryName() { 157 return m_objectAttrs.getFactoryName(); 158 } 159 160 166 public IClassItem getFactory() { 167 return m_objectAttrs.getFactory(); 168 } 169 170 175 public void setFactoryName(String name) { 176 m_objectAttrs.setFactoryName(name); 177 } 178 179 184 public String getPresetName() { 185 return m_objectAttrs.getPresetName(); 186 } 187 188 194 public IClassItem getPreset() { 195 return m_objectAttrs.getPreset(); 196 } 197 198 203 public void setPresetName(String name) { 204 m_objectAttrs.setPresetName(name); 205 } 206 207 212 public String getPostsetName() { 213 return m_objectAttrs.getPostsetName(); 214 } 215 216 222 public IClassItem getPostset() { 223 return m_objectAttrs.getPostset(); 224 } 225 226 231 public void setPostsetName(String name) { 232 m_objectAttrs.setPostsetName(name); 233 } 234 235 240 public String getPregetName() { 241 return m_objectAttrs.getPregetName(); 242 } 243 244 250 public IClassItem getPreget() { 251 return m_objectAttrs.getPreget(); 252 } 253 254 259 public void setPreget(String name) { 260 m_objectAttrs.setPreget(name); 261 } 262 263 268 public String getMarshallerName() { 269 return m_objectAttrs.getMarshallerName(); 270 } 271 272 278 public IClass getMarshaller() { 279 return m_objectAttrs.getMarshaller(); 280 } 281 282 287 public void setMarshallerName(String name) { 288 m_objectAttrs.setMarshallerName(name); 289 } 290 291 296 public String getUnmarshallerName() { 297 return m_objectAttrs.getUnmarshallerName(); 298 } 299 300 306 public IClass getUnmarshaller() { 307 return m_objectAttrs.getUnmarshaller(); 308 } 309 310 315 public void setUnmarshallerName(String name) { 316 m_objectAttrs.setUnmarshallerName(name); 317 } 318 319 322 327 public boolean isOrdered() { 328 return m_structureAttrs.isOrdered(); 329 } 330 331 336 public void setOrdered(boolean ordered) { 337 m_structureAttrs.setOrdered(ordered); 338 } 339 340 343 346 public void prevalidate(ValidationContext vctx) { 347 m_objectAttrs.prevalidate(vctx); 348 m_structureAttrs.prevalidate(vctx); 349 super.prevalidate(vctx); 350 } 351 352 355 public void validate(ValidationContext vctx) { 356 super.validate(vctx); 357 m_objectAttrs.validate(vctx); 358 m_structureAttrs.validate(vctx); 359 ArrayList childs = children(); 360 if (childs == null || childs.size() == 0) { 361 m_attributeComponents = EmptyList.INSTANCE; 362 m_contentComponents = EmptyList.INSTANCE; 363 } else { 364 m_attributeComponents = new ArrayList (); 365 m_contentComponents = new ArrayList (); 366 for (int i = 0; i < childs.size(); i++) { 367 Object child = childs.get(i); 368 if (child instanceof IComponent) { 369 IComponent comp = (IComponent)child; 370 if (comp.hasAttribute()) { 371 m_attributeComponents.add(child); 372 } 373 if (comp.hasContent()) { 374 m_contentComponents.add(child); 375 } 376 } 377 } 378 } 379 } 380 } | Popular Tags |