001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.xml.xsom;
021:
022: import com.sun.xml.xsom.parser.SchemaDocument;
023: import com.sun.xml.xsom.visitor.XSFunction;
024: import com.sun.xml.xsom.visitor.XSVisitor;
025: import org.xml.sax.Locator;
026:
027: import javax.xml.namespace.NamespaceContext;
028: import java.util.List;
029: import java.util.Collection;
030:
031: /**
032: * Base interface for all the schema components.
033: *
034: * @author
035: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
036: */
037: public interface XSComponent {
038: /** Gets the annotation associated to this component, if any. */
039: XSAnnotation getAnnotation();
040:
041: /**
042: * Works like {@link #getAnnotation()}, but allow a new empty {@link XSAnnotation} to be created
043: * if not exist.
044: *
045: * @param createIfNotExist
046: * true to create a new {@link XSAnnotation} if it doesn't exist already.
047: * false to make this method behavel like {@link #getAnnotation()}.
048: *
049: * @return
050: * null if <tt>createIfNotExist==false</tt> and annotation didn't exist.
051: * Otherwise non-null.
052: */
053: XSAnnotation getAnnotation(boolean createIfNotExist);
054:
055: /**
056: * Gets the foreign attributes on this schema component.
057: *
058: * <p>
059: * In general, a schema component may match multiple elements
060: * in a schema document, and those elements can individually
061: * carry foreign attributes.
062: *
063: * <p>
064: * This method returns a list of {@link ForeignAttributes}, where
065: * each {@link ForeignAttributes} object represent foreign attributes
066: * on one element.
067: *
068: * @return
069: * can be an empty list but never be null.
070: */
071: List<? extends ForeignAttributes> getForeignAttributes();
072:
073: /**
074: * Gets the foreign attribute of the given name, or null if not found.
075: *
076: * <p>
077: * If multiple occurences of the same attribute is found,
078: * this method returns the first one.
079: *
080: * @see #getForeignAttributes()
081: */
082: String getForeignAttribute(String nsUri, String localName);
083:
084: /**
085: * Gets the locator that indicates the source location where
086: * this component is created from, or null if no information is
087: * available.
088: */
089: Locator getLocator();
090:
091: /**
092: * Gets a reference to the {@link XSSchema} object to which this component
093: * belongs.
094: * <p>
095: * In case of <code>XSEmpty</code> component, this method
096: * returns null since there is no owner component.
097: */
098: XSSchema getOwnerSchema();
099:
100: /**
101: * Gets the root schema set that includes this component.
102: *
103: * <p>
104: * In case of <code>XSEmpty</code> component, this method
105: * returns null since there is no owner component.
106: */
107: XSSchemaSet getRoot();
108:
109: /**
110: * Gets the {@link SchemaDocument} that indicates which document this component
111: * was defined in.
112: *
113: * @return
114: * null for components that are built-in to XML Schema, such
115: * as anyType, or "empty" {@link XSContentType}. This method also
116: * returns null for {@link XSSchema}.
117: * For all other user-defined
118: * components this method returns non-null, even if they are local.
119: */
120: SchemaDocument getSourceDocument();
121:
122: /**
123: * Evaluates a schema component designator against this schema component
124: * and returns the resulting schema components.
125: *
126: * @throws IllegalArgumentException
127: * if SCD is syntactically incorrect.
128: *
129: * @param scd
130: * Schema component designator. See {@link SCD} for more details.
131: * @param nsContext
132: * The namespace context in which SCD is evaluated. Cannot be null.
133: * @return
134: * Can be empty but never null.
135: */
136: Collection<XSComponent> select(String scd,
137: NamespaceContext nsContext);
138:
139: /**
140: * Evaluates a schema component designator against this schema component
141: * and returns the first resulting schema component.
142: *
143: * @throws IllegalArgumentException
144: * if SCD is syntactically incorrect.
145: *
146: * @param scd
147: * Schema component designator. See {@link SCD} for more details.
148: * @param nsContext
149: * The namespace context in which SCD is evaluated. Cannot be null.
150: * @return
151: * null if the SCD didn't match anything. If the SCD matched more than one node,
152: * the first one will be returned.
153: */
154: XSComponent selectSingle(String scd, NamespaceContext nsContext);
155:
156: /**
157: * Accepts a visitor.
158: */
159: void visit(XSVisitor visitor);
160:
161: /**
162: * Accepts a functor.
163: */
164: <T> T apply(XSFunction<T> function);
165: }
|