下面列出了javax.xml.bind.annotation.XmlEnum#com.sun.xml.internal.bind.v2.model.annotation.Locatable 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Have the builder recognize the type (if it hasn't done so yet),
* and returns a {@link NonElement} that represents it.
*
* @return
* always non-null.
*/
public NonElement<T,C> getTypeInfo(T t,Locatable upstream) {
NonElement<T,C> r = typeInfoSet.getTypeInfo(t);
if(r!=null) return r;
if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null
ArrayInfoImpl<T,C,F,M> ai =
createArrayInfo(upstream, t);
addTypeName(ai);
typeInfoSet.add(ai);
return ai;
}
C c = nav.asDecl(t);
assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it.";
return getClassInfo(c,upstream);
}
/**
* Have the builder recognize the type (if it hasn't done so yet),
* and returns a {@link NonElement} that represents it.
*
* @return
* always non-null.
*/
public NonElement<T,C> getTypeInfo(T t,Locatable upstream) {
NonElement<T,C> r = typeInfoSet.getTypeInfo(t);
if(r!=null) return r;
if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null
ArrayInfoImpl<T,C,F,M> ai =
createArrayInfo(upstream, t);
addTypeName(ai);
typeInfoSet.add(ai);
return ai;
}
C c = nav.asDecl(t);
assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it.";
return getClassInfo(c,upstream);
}
/**
* Have the builder recognize the type (if it hasn't done so yet),
* and returns a {@link NonElement} that represents it.
*
* @return
* always non-null.
*/
public NonElement<T,C> getTypeInfo(T t,Locatable upstream) {
NonElement<T,C> r = typeInfoSet.getTypeInfo(t);
if(r!=null) return r;
if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null
ArrayInfoImpl<T,C,F,M> ai =
createArrayInfo(upstream, t);
addTypeName(ai);
typeInfoSet.add(ai);
return ai;
}
C c = nav.asDecl(t);
assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it.";
return getClassInfo(c,upstream);
}
/**
* Have the builder recognize the type (if it hasn't done so yet),
* and returns a {@link NonElement} that represents it.
*
* @return
* always non-null.
*/
public NonElement<T,C> getTypeInfo(T t,Locatable upstream) {
NonElement<T,C> r = typeInfoSet.getTypeInfo(t);
if(r!=null) return r;
if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null
ArrayInfoImpl<T,C,F,M> ai =
createArrayInfo(upstream, t);
addTypeName(ai);
typeInfoSet.add(ai);
return ai;
}
C c = nav.asDecl(t);
assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it.";
return getClassInfo(c,upstream);
}
/**
* @param clazz
* @param type
* clazz and type should both point to the enum class
* that this {@link EnumLeafInfo} represents.
* Because of the type parameterization we have to take them separately.
*/
public EnumLeafInfoImpl(ModelBuilder<T,C,F,M> builder,
Locatable upstream, C clazz, T type ) {
super(builder,upstream);
this.clazz = clazz;
this.type = type;
elementName = parseElementName(clazz);
// compute the type name
// TODO: I guess it must be allowed for enums to have @XmlElement
typeName = parseTypeName(clazz);
// locate the base type.
// this can be done eagerly because there shouldn't be no cycle.
XmlEnum xe = builder.reader.getClassAnnotation(XmlEnum.class, clazz, this);
if(xe!=null) {
T base = builder.reader.getClassValue(xe, "value");
baseType = builder.getTypeInfo(base,this);
} else {
baseType = builder.getTypeInfo(builder.nav.ref(String.class),this);
}
}
/**
* @param clazz
* @param type
* clazz and type should both point to the enum class
* that this {@link EnumLeafInfo} represents.
* Because of the type parameterization we have to take them separately.
*/
public EnumLeafInfoImpl(ModelBuilder<T,C,F,M> builder,
Locatable upstream, C clazz, T type ) {
super(builder,upstream);
this.clazz = clazz;
this.type = type;
elementName = parseElementName(clazz);
// compute the type name
// TODO: I guess it must be allowed for enums to have @XmlElement
typeName = parseTypeName(clazz);
// locate the base type.
// this can be done eagerly because there shouldn't be no cycle.
XmlEnum xe = builder.reader.getClassAnnotation(XmlEnum.class, clazz, this);
if(xe!=null) {
T base = builder.reader.getClassValue(xe, "value");
baseType = builder.getTypeInfo(base,this);
} else {
baseType = builder.getTypeInfo(builder.nav.ref(String.class),this);
}
}
private List<List<Location>> build(Locatable... srcs) {
List<List<Location>> r = new ArrayList<List<Location>>();
for( Locatable l : srcs ) {
if(l!=null) {
List<Location> ll = convert(l);
if(ll!=null && !ll.isEmpty())
r.add(ll);
}
}
return Collections.unmodifiableList(r);
}
static <T,C,F,M> QName calcSchemaType(
AnnotationReader<T,C,F,M> reader,
AnnotationSource primarySource, C enclosingClass, T individualType, Locatable src ) {
XmlSchemaType xst = primarySource.readAnnotation(XmlSchemaType.class);
if(xst!=null) {
return new QName(xst.namespace(),xst.name());
}
// check the defaulted annotation
XmlSchemaTypes xsts = reader.getPackageAnnotation(XmlSchemaTypes.class,enclosingClass,src);
XmlSchemaType[] values = null;
if(xsts!=null)
values = xsts.value();
else {
xst = reader.getPackageAnnotation(XmlSchemaType.class,enclosingClass,src);
if(xst!=null) {
values = new XmlSchemaType[1];
values[0] = xst;
}
}
if(values!=null) {
for( XmlSchemaType item : values ) {
if(reader.getClassValue(item,"type").equals(individualType)) {
return new QName(item.namespace(),item.name());
}
}
}
return null;
}
static <T,C,F,M> QName calcSchemaType(
AnnotationReader<T,C,F,M> reader,
AnnotationSource primarySource, C enclosingClass, T individualType, Locatable src ) {
XmlSchemaType xst = primarySource.readAnnotation(XmlSchemaType.class);
if(xst!=null) {
return new QName(xst.namespace(),xst.name());
}
// check the defaulted annotation
XmlSchemaTypes xsts = reader.getPackageAnnotation(XmlSchemaTypes.class,enclosingClass,src);
XmlSchemaType[] values = null;
if(xsts!=null)
values = xsts.value();
else {
xst = reader.getPackageAnnotation(XmlSchemaType.class,enclosingClass,src);
if(xst!=null) {
values = new XmlSchemaType[1];
values[0] = xst;
}
}
if(values!=null) {
for( XmlSchemaType item : values ) {
if(reader.getClassValue(item,"type").equals(individualType)) {
return new QName(item.namespace(),item.name());
}
}
}
return null;
}
private List<List<Location>> build(Locatable... srcs) {
List<List<Location>> r = new ArrayList<List<Location>>();
for( Locatable l : srcs ) {
if(l!=null) {
List<Location> ll = convert(l);
if(ll!=null && !ll.isEmpty())
r.add(ll);
}
}
return Collections.unmodifiableList(r);
}
private List<List<Location>> build(Locatable... srcs) {
List<List<Location>> r = new ArrayList<List<Location>>();
for( Locatable l : srcs ) {
if(l!=null) {
List<Location> ll = convert(l);
if(ll!=null && !ll.isEmpty())
r.add(ll);
}
}
return Collections.unmodifiableList(r);
}
protected TypeInfoImpl(
ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
Locatable upstream) {
this.builder = builder;
this.owner = builder.typeInfoSet;
this.upstream = upstream;
}
static <T,C,F,M> QName calcSchemaType(
AnnotationReader<T,C,F,M> reader,
AnnotationSource primarySource, C enclosingClass, T individualType, Locatable src ) {
XmlSchemaType xst = primarySource.readAnnotation(XmlSchemaType.class);
if(xst!=null) {
return new QName(xst.namespace(),xst.name());
}
// check the defaulted annotation
XmlSchemaTypes xsts = reader.getPackageAnnotation(XmlSchemaTypes.class,enclosingClass,src);
XmlSchemaType[] values = null;
if(xsts!=null)
values = xsts.value();
else {
xst = reader.getPackageAnnotation(XmlSchemaType.class,enclosingClass,src);
if(xst!=null) {
values = new XmlSchemaType[1];
values[0] = xst;
}
}
if(values!=null) {
for( XmlSchemaType item : values ) {
if(reader.getClassValue(item,"type").equals(individualType)) {
return new QName(item.namespace(),item.name());
}
}
}
return null;
}
private List<List<Location>> build(Locatable... srcs) {
List<List<Location>> r = new ArrayList<List<Location>>();
for( Locatable l : srcs ) {
if(l!=null) {
List<Location> ll = convert(l);
if(ll!=null && !ll.isEmpty())
r.add(ll);
}
}
return Collections.unmodifiableList(r);
}
static <T,C,F,M> QName calcSchemaType(
AnnotationReader<T,C,F,M> reader,
AnnotationSource primarySource, C enclosingClass, T individualType, Locatable src ) {
XmlSchemaType xst = primarySource.readAnnotation(XmlSchemaType.class);
if(xst!=null) {
return new QName(xst.namespace(),xst.name());
}
// check the defaulted annotation
XmlSchemaTypes xsts = reader.getPackageAnnotation(XmlSchemaTypes.class,enclosingClass,src);
XmlSchemaType[] values = null;
if(xsts!=null)
values = xsts.value();
else {
xst = reader.getPackageAnnotation(XmlSchemaType.class,enclosingClass,src);
if(xst!=null) {
values = new XmlSchemaType[1];
values[0] = xst;
}
}
if(values!=null) {
for( XmlSchemaType item : values ) {
if(reader.getClassValue(item,"type").equals(individualType)) {
return new QName(item.namespace(),item.name());
}
}
}
return null;
}
protected TypeInfoImpl(
ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
Locatable upstream) {
this.builder = builder;
this.owner = builder.typeInfoSet;
this.upstream = upstream;
}
public Locatable getUpstream() {
return null;
}
@Override
public RuntimeNonElement getClassInfo( Class clazz, Locatable upstream ) {
return (RuntimeNonElement)super.getClassInfo(clazz,upstream);
}
public IllegalAnnotationException(String message, Annotation src1, Locatable src2) {
this(message,cast(src1),src2);
}
public final Locatable getUpstream() {
throw new UnsupportedOperationException();
}
public Locatable getUpstream() {
return null;
}
public Locatable getUpstream() {
return null;
}
@Override
public RuntimeNonElement getClassInfo( Class clazz, Locatable upstream ) {
return (RuntimeNonElement)super.getClassInfo(clazz,upstream);
}
/**
* Use the enclosing class as the upsream {@link Location}.
*/
public Locatable getUpstream() {
return parent;
}
public IllegalAnnotationException(String message, Locatable src1, Locatable src2) {
super(message);
pos = build(src1,src2);
}
/**
* Picks up references in this registry to other types.
*/
RegistryInfoImpl(ModelBuilder<T,C,F,M> builder, Locatable upstream, C registryClass) {
this.nav = builder.nav;
this.registryClass = registryClass;
this.upstream = upstream;
builder.registries.put(getPackageName(),this);
if(nav.getDeclaredField(registryClass,ContextFactory.USE_JAXB_PROPERTIES)!=null) {
// the user is trying to use ObjectFactory that we generate for interfaces,
// that means he's missing jaxb.properties
builder.reportError(new IllegalAnnotationException(
Messages.MISSING_JAXB_PROPERTIES.format(getPackageName()),
this
));
// looking at members will only add more errors, so just abort now
return;
}
for( M m : nav.getDeclaredMethods(registryClass) ) {
XmlElementDecl em = builder.reader.getMethodAnnotation(
XmlElementDecl.class, m, this );
if(em==null) {
if(nav.getMethodName(m).startsWith("create")) {
// this is a factory method. visit this class
references.add(
builder.getTypeInfo(nav.getReturnType(m),
new MethodLocatable<M>(this,m,nav)));
}
continue;
}
ElementInfoImpl<T,C,F,M> ei;
try {
ei = builder.createElementInfo(this,m);
} catch (IllegalAnnotationException e) {
builder.reportError(e);
continue; // recover by ignoring this element
}
// register this mapping
// TODO: any chance this could cause a stack overflow (by recursively visiting classes)?
builder.typeInfoSet.add(ei,builder);
references.add(ei);
}
}
protected EnumLeafInfoImpl<T,C,F,M> createEnumLeafInfo(C clazz,Locatable upstream) {
return new EnumLeafInfoImpl<T,C,F,M>(this,upstream,clazz,nav.use(clazz));
}
/**
* For limited cases where the caller needs to search for a super class.
* This is necessary because we don't want {@link #subclassReplacements}
* to kick in for the super class search, which will cause infinite recursion.
*/
public NonElement<T,C> getClassInfo( C clazz, boolean searchForSuperClass, Locatable upstream ) {
assert clazz!=null;
NonElement<T,C> r = typeInfoSet.getClassInfo(clazz);
if(r!=null)
return r;
if(nav.isEnum(clazz)) {
EnumLeafInfoImpl<T,C,F,M> li = createEnumLeafInfo(clazz,upstream);
typeInfoSet.add(li);
r = li;
addTypeName(r);
} else {
boolean isReplaced = subclassReplacements.containsKey(clazz);
if(isReplaced && !searchForSuperClass) {
// handle it as if the replacement was specified
r = getClassInfo(subclassReplacements.get(clazz),upstream);
} else
if(reader.hasClassAnnotation(clazz,XmlTransient.class) || isReplaced) {
// handle it as if the base class was specified
r = getClassInfo( nav.getSuperClass(clazz), searchForSuperClass,
new ClassLocatable<C>(upstream,clazz,nav) );
} else {
ClassInfoImpl<T,C,F,M> ci = createClassInfo(clazz,upstream);
typeInfoSet.add(ci);
// compute the closure by eagerly expanding references
for( PropertyInfo<T,C> p : ci.getProperties() ) {
if(p.kind()== PropertyKind.REFERENCE) {
// make sure that we have a registry for this package
addToRegistry(clazz, (Locatable) p);
Class[] prmzdClasses = getParametrizedTypes(p);
if (prmzdClasses != null) {
for (Class prmzdClass : prmzdClasses) {
if (prmzdClass != clazz) {
addToRegistry((C) prmzdClass, (Locatable) p);
}
}
}
}
for( TypeInfo<T,C> t : p.ref() )
; // just compute a reference should be suffice
}
ci.getBaseClass(); // same as above.
r = ci;
addTypeName(r);
}
}
// more reference closure expansion. @XmlSeeAlso
XmlSeeAlso sa = reader.getClassAnnotation(XmlSeeAlso.class, clazz, upstream);
if(sa!=null) {
for( T t : reader.getClassArrayValue(sa,"value") ) {
getTypeInfo(t,(Locatable)sa);
}
}
return r;
}
public Locatable getUpstream() {
return null;
}
public Locatable getUpstream() {
return null;
}