1 17 package org.apache.ws.jaxme.xs.xml.impl; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.ws.jaxme.xs.xml.*; 24 25 26 42 public class XsGAttrDeclsImpl implements XsGAttrDecls { 43 private final XsObject owner; 44 private List childs; 45 private XsTWildcard anyAttribute; 46 47 protected XsGAttrDeclsImpl(XsObject pOwner) { 48 owner = pOwner; 49 } 50 51 protected void addChild(Object o) { 52 if (o instanceof XsTWildcard) { 53 if (anyAttribute != null) { 54 throw new IllegalStateException ("Multiple 'anyAttribute' child elements are forbidden."); 55 } 56 anyAttribute = (XsTWildcard) o; 57 } else { 58 if (anyAttribute != null) { 59 throw new IllegalStateException ("An 'attribute' or 'attributeGroup' child element is invalid after an 'anyAttribute' child element."); 60 } 61 } 62 if (childs == null) { 63 childs = new ArrayList (); 64 } 65 childs.add(o); 66 } 67 68 public XsTAttribute createAttribute() { 69 XsTAttribute attribute = owner.getObjectFactory().newXsTAttribute(owner); 70 addChild(attribute); 71 return attribute; 72 } 73 74 public XsTAttribute[] getAttributes() { 75 if (childs == null || childs.size() == 0) { 76 return new XsTAttribute[0]; 77 } 78 List result = new ArrayList (); 79 for (Iterator iter = childs.iterator(); iter.hasNext(); ) { 80 Object o = iter.next(); 81 if (o instanceof XsTAttribute) { 82 result.add(o); 83 } 84 } 85 return (XsTAttribute[]) result.toArray(new XsTAttribute[result.size()]); 86 } 87 88 public XsTAttributeGroupRef createAttributeGroup() { 89 XsTAttributeGroupRef attributeGroupRef = owner.getObjectFactory().newXsTAttributeGroupRef(owner); 90 addChild(attributeGroupRef); 91 return attributeGroupRef; 92 } 93 94 public XsTAttributeGroupRef[] getAttributeGroups() { 95 if (childs == null || childs.size() == 0) { 96 return new XsTAttributeGroupRefImpl[0]; 97 } 98 List result = new ArrayList (); 99 for (Iterator iter = childs.iterator(); iter.hasNext(); ) { 100 Object o = iter.next(); 101 if (o instanceof XsTAttributeGroupRef) { 102 result.add(o); 103 } 104 } 105 return (XsTAttributeGroupRef[]) result.toArray(new XsTAttributeGroupRef[result.size()]); 106 } 107 108 public XsTWildcard createAnyAttribute() { 109 XsTWildcard myAnyAttribute = owner.getObjectFactory().newXsTWildcard(owner); 110 addChild(myAnyAttribute); 111 return myAnyAttribute; 112 } 113 114 public XsTWildcard getAnyAttribute() { 115 return anyAttribute; 116 } 117 118 public Object [] getAllAttributes() { 119 if (childs == null) { 120 return new Object [0]; 121 } else { 122 return childs.toArray(); 123 } 124 } 125 } 126 | Popular Tags |