1 16 17 package org.apache.commons.betwixt.schema; 18 19 import java.beans.IntrospectionException ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.apache.commons.betwixt.AttributeDescriptor; 24 import org.apache.commons.betwixt.ElementDescriptor; 25 import org.apache.commons.betwixt.XMLBeanInfo; 26 27 31 public abstract class ComplexType { 32 33 protected List elements = new ArrayList (); 34 35 protected List attributes = new ArrayList (); 36 37 public ComplexType() {} 38 39 public ComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { 40 if (elementDescriptor.isHollow()) { 41 Class type = elementDescriptor.getSingularPropertyType(); 43 if (type == null) { 44 type = elementDescriptor.getPropertyType(); 45 } 46 XMLBeanInfo filledBeanInfo = schema.introspect(type); 47 elementDescriptor = filledBeanInfo.getElementDescriptor(); 48 } 49 init(configuration, elementDescriptor, schema); 50 } 51 52 protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { 53 54 AttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributeDescriptors(); 55 for (int i=0,length=attributeDescriptors.length; i<length ; i++) { 56 String uri = attributeDescriptors[i].getURI(); 59 if (! SchemaTranscriber.W3C_SCHEMA_INSTANCE_URI.equals(uri)) { 60 attributes.add(new Attribute(attributeDescriptors[i])); 61 } 62 } 63 64 ElementDescriptor[] elementDescriptors = elementDescriptor.getElementDescriptors(); 66 for (int i=0,length=elementDescriptors.length; i<length ; i++) { 67 if (elementDescriptors[i].isHollow()) { 68 elements.add(new ElementReference(configuration, elementDescriptors[i], schema)); 69 } else if (elementDescriptors[i].isSimple()){ 70 elements.add(new SimpleLocalElement(configuration, elementDescriptors[i], schema)); 71 } else { 72 elements.add(new ComplexLocalElement(configuration, elementDescriptors[i], schema)); 73 } 74 } 75 } 76 77 81 public List getElements() { 82 return elements; 83 } 84 85 89 public void addElement(ElementReference element) { 90 elements.add(element); 91 } 92 93 97 public void addElement(LocalElement element) { 98 elements.add(element); 99 } 100 101 102 106 public List getAttributes() { 107 return attributes; 108 } 109 110 114 public void addAttribute(Attribute attribute) { 115 attributes.add(attribute); 116 } 117 118 } 119 | Popular Tags |