1 /* Copyright 2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package org.apache.xmlbeans;
17
18 import javax.xml.namespace.QName;
19
20 /**
21 * Represents a global Schema Component. That is, a type, element, attribute,
22 * model group, attribute group, or identity constraint.
23 * <p>
24 * Note that not all types, elements, and attributes are global; local
25 * types, element, and attributes do not appear in the global lookup table.
26 * Also note that other information items such as particles, facets, and
27 * so on are not globally indexed, so are not SchemaComponents.
28 *
29 * @see SchemaType
30 * @see SchemaGlobalElement
31 * @see SchemaGlobalAttribute
32 * @see SchemaAttributeGroup
33 * @see SchemaModelGroup
34 * @see SchemaIdentityConstraint
35 */
36 public interface SchemaComponent
37 {
38 /** A type definition. See {@link #getComponentType} */
39 static final int TYPE = 0;
40 /** An element definition. See {@link #getComponentType} */
41 static final int ELEMENT = 1;
42 /** An attribute definition. See {@link #getComponentType} */
43 static final int ATTRIBUTE = 3;
44 /** An attribute group definition. See {@link #getComponentType} */
45 static final int ATTRIBUTE_GROUP = 4;
46 /** An identity constraint definition. See {@link #getComponentType} */
47 static final int IDENTITY_CONSTRAINT = 5;
48 /** A model group definition. See {@link #getComponentType} */
49 static final int MODEL_GROUP = 6;
50 /** A notation definition. See {@link #getComponentType} */
51 static final int NOTATION = 7;
52 /** An annotation. See {@link #getComponentType} */
53 static final int ANNOTATION = 8;
54
55 /**
56 * Returns the type code for the schema object, either {@link #TYPE},
57 * {@link #ELEMENT}, {@link #ATTRIBUTE}, {@link #ATTRIBUTE_GROUP},
58 * {@link #MODEL_GROUP}, {@link #IDENTITY_CONSTRAINT}, or {@link #NOTATION}.
59 */
60 int getComponentType();
61
62 /**
63 * Returns the typesystem within which this component definition resides
64 */
65 SchemaTypeSystem getTypeSystem();
66
67 /**
68 * The name of the schema component
69 */
70 QName getName();
71
72 /**
73 * The name of resource that represends the source .xsd in which this component was defined (if known)
74 * <br/>See: {@link org.apache.xmlbeans.SchemaTypeLoader#getSourceAsStream(String)}
75 * <br/><br/>Example:<pre>
76 * SchemaType schemaType = ..;
77 * InputStream is = schemaType.getTypeSystem().getSourceAsStream(schemaType.getSourceName());
78 * </pre>
79 */
80 String getSourceName();
81
82 /**
83 * A lazy reference to a component. Used by SchemaTypeLoaders to
84 * avoid loading components until they are actually needed.
85 *
86 * @exclude
87 */
88 public static abstract class Ref
89 {
90 protected Ref(SchemaComponent schemaComponent)
91 { _schemaComponent = schemaComponent; }
92
93 protected Ref(SchemaTypeSystem schemaTypeSystem, String handle)
94 { assert(handle != null); _schemaTypeSystem = schemaTypeSystem; _handle = handle; }
95
96 private SchemaComponent _schemaComponent;
97 private SchemaTypeSystem _schemaTypeSystem;
98 public String _handle;
99
100 public abstract int getComponentType();
101
102 public final SchemaTypeSystem getTypeSystem()
103 { return _schemaTypeSystem; }
104
105 public final synchronized SchemaComponent getComponent()
106 {
107 if (_schemaComponent == null && _handle != null)
108 {
109 _schemaComponent = _schemaTypeSystem.resolveHandle(_handle);
110 _schemaTypeSystem = null;
111 }
112
113 return _schemaComponent;
114 }
115 }
116
117 /**
118 * Used for on-demand loading of schema components.
119 */
120 public Ref getComponentRef();
121 }