001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.bind.v2.model.core;
038:
039: import java.util.Map;
040:
041: import javax.xml.bind.JAXBException;
042: import javax.xml.bind.annotation.XmlSchema;
043: import javax.xml.bind.annotation.XmlNsForm;
044: import javax.xml.namespace.QName;
045: import javax.xml.transform.Result;
046:
047: import com.sun.xml.bind.v2.model.nav.Navigator;
048:
049: /**
050: * Root of models. Set of {@link TypeInfo}s.
051: *
052: * @author Kohsuke Kawaguchi
053: */
054: public interface TypeInfoSet<T, C, F, M> {
055:
056: /**
057: * {@link Navigator} for this model.
058: */
059: Navigator<T, C, F, M> getNavigator();
060:
061: // turns out we can't have AnnotationReader in XJC, so it's impossible to have this here.
062: // perhaps we should revisit this in the future.
063: // /**
064: // * {@link AnnotationReader} for this model.
065: // */
066: // AnnotationReader<T,C,F,M> getReader();
067:
068: /**
069: * Returns a {@link TypeInfo} for the given type.
070: *
071: * @return
072: * null if the specified type cannot be bound by JAXB, or
073: * not known to this set.
074: */
075: NonElement<T, C> getTypeInfo(T type);
076:
077: /**
078: * Gets the {@link TypeInfo} for the any type.
079: */
080: NonElement<T, C> getAnyTypeInfo();
081:
082: /**
083: * Returns a {@link ClassInfo}, {@link ArrayInfo}, or {@link LeafInfo}
084: * for the given bean.
085: *
086: * <p>
087: * This method is almost like refinement of {@link #getTypeInfo(Object)} except
088: * our C cannot derive from T.
089: *
090: * @return
091: * null if the specified type is not bound by JAXB or otherwise
092: * unknown to this set.
093: */
094: NonElement<T, C> getClassInfo(C type);
095:
096: /**
097: * Returns all the {@link ArrayInfo}s known to this set.
098: */
099: Map<? extends T, ? extends ArrayInfo<T, C>> arrays();
100:
101: /**
102: * Returns all the {@link ClassInfo}s known to this set.
103: */
104: Map<C, ? extends ClassInfo<T, C>> beans();
105:
106: /**
107: * Returns all the {@link BuiltinLeafInfo}s known to this set.
108: */
109: Map<T, ? extends BuiltinLeafInfo<T, C>> builtins();
110:
111: /**
112: * Returns all the {@link EnumLeafInfo}s known to this set.
113: */
114: Map<C, ? extends EnumLeafInfo<T, C>> enums();
115:
116: /**
117: * Returns a {@link ElementInfo} for the given element.
118: *
119: * @param scope
120: * if null, return the info about a global element.
121: * Otherwise return a local element in the given scope if available,
122: * then look for a global element next.
123: */
124: ElementInfo<T, C> getElementInfo(C scope, QName name);
125:
126: /**
127: * Returns a type information for the given reference.
128: */
129: NonElement<T, C> getTypeInfo(Ref<T, C> ref);
130:
131: /**
132: * Returns all {@link ElementInfo}s in the given scope.
133: *
134: * @param scope
135: * if non-null, this method only returns the local element mapping.
136: */
137: Map<QName, ? extends ElementInfo<T, C>> getElementMappings(C scope);
138:
139: /**
140: * Returns all the {@link ElementInfo} known to this set.
141: */
142: Iterable<? extends ElementInfo<T, C>> getAllElements();
143:
144: /**
145: * Gets all {@link XmlSchema#xmlns()} found in this context for the given namespace URI.
146: *
147: * <p>
148: * This operation is expected to be only used in schema generator, so it can be slow.
149: *
150: * @return
151: * A map from prefixes to namespace URIs, which should be declared when generating a schema.
152: * Could be empty but never null.
153: */
154: Map<String, String> getXmlNs(String namespaceUri);
155:
156: /**
157: * Gets {@link XmlSchema#location()} found in this context.
158: *
159: * <p>
160: * This operation is expected to be only used in schema generator, so it can be slow.
161: *
162: * @return
163: * A map from namespace URI to the value of the location.
164: * If the entry is missing, that means a schema should be generated for that namespace.
165: * If the value is "", that means the schema location is implied
166: * (<xs:schema namespace="..."/> w/o schemaLocation.)
167: */
168: Map<String, String> getSchemaLocations();
169:
170: /**
171: * Gets the reasonable {@link XmlNsForm} for the given namespace URI.
172: *
173: * <p>
174: * The spec doesn't define very precisely what the {@link XmlNsForm} value
175: * for the given namespace would be, so this method is implemented in rather
176: * ad-hoc way. It should work as what most people expect for simple cases.
177: *
178: * @return never null.
179: */
180: XmlNsForm getElementFormDefault(String nsUri);
181:
182: /**
183: * Gets the reasonable {@link XmlNsForm} for the given namespace URI.
184: *
185: * <p>
186: * The spec doesn't define very precisely what the {@link XmlNsForm} value
187: * for the given namespace would be, so this method is implemented in rather
188: * ad-hoc way. It should work as what most people expect for simple cases.
189: *
190: * @return never null.
191: */
192: XmlNsForm getAttributeFormDefault(String nsUri);
193:
194: /**
195: * Dumps this model into XML.
196: *
197: * For debug only.
198: *
199: * TODO: not sure if this actually works. We don't really know what are T,C.
200: */
201: public void dump(Result out) throws JAXBException;
202: }
|