KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > schema > ComplexType


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.betwixt.schema;
18
19 import java.beans.IntrospectionException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.commons.betwixt.AttributeDescriptor;
24 import org.apache.commons.betwixt.ElementDescriptor;
25 import org.apache.commons.betwixt.XMLBeanInfo;
26
27 /**
28  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29  * @version $Revision: 1.2 $
30  */

31 public abstract class ComplexType {
32
33     protected List JavaDoc elements = new ArrayList JavaDoc();
34
35     protected List JavaDoc attributes = new ArrayList JavaDoc();
36
37     public ComplexType() {}
38
39     public ComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException JavaDoc {
40         if (elementDescriptor.isHollow()) {
41             // need to introspector for filled descriptor
42
Class JavaDoc 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 JavaDoc {
53         
54         AttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributeDescriptors();
55         for (int i=0,length=attributeDescriptors.length; i<length ; i++) {
56             //TODO: need to think about computing schema types from descriptors
57
// this will probably depend on the class mapped to
58
String JavaDoc uri = attributeDescriptors[i].getURI();
59             if (! SchemaTranscriber.W3C_SCHEMA_INSTANCE_URI.equals(uri)) {
60                 attributes.add(new Attribute(attributeDescriptors[i]));
61             }
62         }
63         
64         //TODO: add support for spacing elements
65
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     /**
78          * Gets the elements contained by this type
79          * @return
80          */

81     public List JavaDoc getElements() {
82         return elements;
83     }
84
85     /**
86          * Adds an element to those contained by this type
87          * @param element
88          */

89     public void addElement(ElementReference element) {
90         elements.add(element);
91     }
92     
93     /**
94           * Adds an element to those contained by this type
95           * @param element
96           */

97      public void addElement(LocalElement element) {
98          elements.add(element);
99      }
100
101
102     /**
103          * Gets the attributes contained by this type.
104          * @return
105          */

106     public List JavaDoc getAttributes() {
107         return attributes;
108     }
109
110     /**
111          * Adds an attribute to those contained by this type
112          * @param attribute
113          */

114     public void addAttribute(Attribute attribute) {
115         attributes.add(attribute);
116     }
117
118 }
119
Popular Tags