feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
* {@link AnnotationReader} that reads annotation from classes,
* not from external binding files.
*
* This is meant to be used as a convenient partial implementation.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public abstract class AbstractInlineAnnotationReaderImpl<T,C,F,M>
implements AnnotationReader<T,C,F,M> {
private ErrorHandler errorHandler;
public void setErrorHandler(ErrorHandler errorHandler) {
if(errorHandler==null)
throw new IllegalArgumentException();
this.errorHandler = errorHandler;
}
/**
* Always return a non-null valid {@link ErrorHandler}
*/
public final ErrorHandler getErrorHandler() {
assert errorHandler!=null : "error handler must be set before use";
return errorHandler;
}
public final <A extends Annotation> A getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcPos) {
A a1 = getter==null?null:getMethodAnnotation(annotation,getter,srcPos);
A a2 = setter==null?null:getMethodAnnotation(annotation,setter,srcPos);
if(a1==null) {
if(a2==null)
return null;
else
return a2;
} else {
if(a2==null)
return a1;
else {
// both are present
getErrorHandler().error(new IllegalAnnotationException(
Messages.DUPLICATE_ANNOTATIONS.format(
annotation.getName(), fullName(getter),fullName(setter)),
a1, a2 ));
// recover by ignoring one of them
return a1;
}
}
}
public boolean hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos) {
boolean x = ( getter != null && hasMethodAnnotation(annotation, getter) );
boolean y = ( setter != null && hasMethodAnnotation(annotation, setter) );
if(x && y) {
// both are present. have getMethodAnnotation report an error
getMethodAnnotation(annotation,getter,setter,srcPos);
}
return x||y;
}
/**
* Gets the fully-qualified name of the method.
*
* Used for error messages.
*/
protected abstract String fullName(M m);
}

View File

@@ -0,0 +1,162 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
/**
* Reads annotations for the given property.
*
* <p>
* This is the lowest abstraction that encapsulates the difference
* between reading inline annotations and external binding files.
*
* <p>
* Because the former operates on a {@link Field} and {@link Method}
* while the latter operates on a "property", the methods defined
* on this interface takes both, and the callee gets to choose which
* to use.
*
* <p>
* Most of the get method takes {@link Locatable}, which points to
* the place/context in which the annotation is read. The returned
* annotation also implements {@link Locatable} (so that it can
* point to the place where the annotation is placed), and its
* {@link Locatable#getUpstream()} will return the given
* {@link Locatable}.
*
*
* <p>
* Errors found during reading annotations are reported through the error handler.
* A valid {@link ErrorHandler} must be registered before the {@link AnnotationReader}
* is used.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public interface AnnotationReader<T,C,F,M> {
/**
* Sets the error handler that receives errors found
* during reading annotations.
*
* @param errorHandler
* must not be null.
*/
void setErrorHandler(ErrorHandler errorHandler);
/**
* Reads an annotation on a property that consists of a field.
*/
<A extends Annotation> A getFieldAnnotation(Class<A> annotation,
F field, Locatable srcpos);
/**
* Checks if the given field has an annotation.
*/
boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, F field);
/**
* Checks if a class has the annotation.
*/
boolean hasClassAnnotation(C clazz, Class<? extends Annotation> annotationType);
/**
* Gets all the annotations on a field.
*/
Annotation[] getAllFieldAnnotations(F field, Locatable srcPos);
/**
* Reads an annotation on a property that consists of a getter and a setter.
*
*/
<A extends Annotation> A getMethodAnnotation(Class<A> annotation,
M getter, M setter, Locatable srcpos);
/**
* Checks if the given method has an annotation.
*/
boolean hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos);
/**
* Gets all the annotations on a method.
*
* @param srcPos
* the location from which this annotation is read.
*/
Annotation[] getAllMethodAnnotations(M method, Locatable srcPos);
// TODO: we do need this to read certain annotations,
// but that shows inconsistency wrt the spec. consult the spec team about the abstraction.
<A extends Annotation> A getMethodAnnotation(Class<A> annotation, M method, Locatable srcpos );
boolean hasMethodAnnotation(Class<? extends Annotation> annotation, M method );
/**
* Reads an annotation on a parameter of the method.
*
* @return null
* if the annotation was not found.
*/
@Nullable
<A extends Annotation> A getMethodParameterAnnotation(
Class<A> annotation, M method, int paramIndex, Locatable srcPos );
/**
* Reads an annotation on a class.
*/
@Nullable
<A extends Annotation> A getClassAnnotation(Class<A> annotation, C clazz, Locatable srcpos) ;
/**
* Reads an annotation on the package that the given class belongs to.
*/
@Nullable
<A extends Annotation> A getPackageAnnotation(Class<A> annotation, C clazz, Locatable srcpos);
/**
* Reads a value of an annotation that returns a Class object.
*
* <p>
* Depending on the underlying reflection library, you can't always
* obtain the {@link Class} object directly (see the Annotation Processing MirrorTypeException
* for example), so use this method to avoid that.
*
* @param name
* The name of the annotation parameter to be read.
*/
T getClassValue( Annotation a, String name );
/**
* Similar to {@link #getClassValue(Annotation, String)} method but
* obtains an array parameter.
*/
T[] getClassArrayValue( Annotation a, String name );
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
/**
* Implemented by objects that can have annotations.
*
* @author Kohsuke Kawaguchi
*/
public interface AnnotationSource {
/**
* Gets the value of the specified annotation from the given property.
*
* <p>
* When this method is used for a property that consists of a getter and setter,
* it returns the annotation on either of those methods. If both methods have
* the same annotation, it is an error.
*
* @return
* null if the annotation is not present.
*/
<A extends Annotation> A readAnnotation(Class<A> annotationType);
/**
* Returns true if the property has the specified annotation.
* <p>
* Short for <code>readAnnotation(annotationType)!=null</code>,
* but this method is typically faster.
*/
boolean hasAnnotation(Class<? extends Annotation> annotationType);
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Locatable} implementation for a class.
*
* @author Kohsuke Kawaguchi
*/
public class ClassLocatable<C> implements Locatable {
private final Locatable upstream;
private final C clazz;
private final Navigator<?,C,?,?> nav;
public ClassLocatable(Locatable upstream, C clazz, Navigator<?,C,?,?> nav) {
this.upstream = upstream;
this.clazz = clazz;
this.nav = nav;
}
public Locatable getUpstream() {
return upstream;
}
public Location getLocation() {
return nav.getClassLocation(clazz);
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Locatable} implementation for a field.
*
* @author Kohsuke Kawaguchi
*/
public class FieldLocatable<F> implements Locatable {
private final Locatable upstream;
private final F field;
private final Navigator<?,?,F,?> nav;
public FieldLocatable(Locatable upstream, F field, Navigator<?,?,F,?> nav) {
this.upstream = upstream;
this.field = field;
this.nav = nav;
}
public Locatable getUpstream() {
return upstream;
}
public Location getLocation() {
return nav.getFieldLocation(field);
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
class Init {
static Quick[] getAll() {
return new Quick[] {new XmlAttributeQuick(null, null), new XmlElementQuick(null, null), new XmlElementDeclQuick(null, null), new XmlElementRefQuick(null, null), new XmlElementRefsQuick(null, null), new XmlEnumQuick(null, null), new XmlRootElementQuick(null, null), new XmlSchemaQuick(null, null), new XmlSchemaTypeQuick(null, null), new XmlTransientQuick(null, null), new XmlTypeQuick(null, null), new XmlValueQuick(null, null)};
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Location} that is chained.
*
* <p>
* {@link Locatable} forms a tree structure, where each {@link Locatable}
* points back to the upstream {@link Locatable}.
* For example, imagine {@link Locatable} X that points to a particular annotation,
* whose upstream is {@link Locatable} Y, which points to a particular method
* (on which the annotation is put), whose upstream is {@link Locatable} Z,
* which points to a particular class (in which the method is defined),
* whose upstream is {@link Locatable} W,
* which points to another class (which refers to the class Z), and so on.
*
* <p>
* This chain will be turned into a list when we report the error to users.
* This allows them to know where the error happened
* and why that place became relevant.
*
* @author Kohsuke Kawaguchi
*/
public interface Locatable {
/**
* Gets the upstream {@link Location} information.
*
* @return
* can be null.
*/
Locatable getUpstream();
/**
* Gets the location object that this object points to.
*
* This operation could be inefficient and costly.
*/
Location getLocation();
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Annotation} that also implements {@link Locatable}.
*
* @author Kohsuke Kawaguchi
*/
public class LocatableAnnotation implements InvocationHandler, Locatable, Location {
private final Annotation core;
private final Locatable upstream;
/**
* Wraps the annotation into a proxy so that the returned object will also implement
* {@link Locatable}.
*/
public static <A extends Annotation> A create( A annotation, Locatable parentSourcePos ) {
if(annotation==null) return null;
Class<? extends Annotation> type = annotation.annotationType();
if(quicks.containsKey(type)) {
// use the existing proxy implementation if available
return (A)quicks.get(type).newInstance(parentSourcePos,annotation);
}
// otherwise take the slow route
ClassLoader cl = SecureLoader.getClassClassLoader(LocatableAnnotation.class);
try {
Class loadableT = Class.forName(type.getName(), false, cl);
if(loadableT !=type)
return annotation; // annotation type not loadable from this class loader
return (A)Proxy.newProxyInstance(cl,
new Class[]{ type, Locatable.class },
new LocatableAnnotation(annotation,parentSourcePos));
} catch (ClassNotFoundException e) {
// annotation not loadable
return annotation;
} catch (IllegalArgumentException e) {
// Proxy.newProxyInstance throws this if it cannot resolve this annotation
// in this classloader
return annotation;
}
}
LocatableAnnotation(Annotation core, Locatable upstream) {
this.core = core;
this.upstream = upstream;
}
public Locatable getUpstream() {
return upstream;
}
public Location getLocation() {
return this;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if(method.getDeclaringClass()==Locatable.class)
return method.invoke(this,args);
if(Modifier.isStatic(method.getModifiers()))
// malicious code can pass in a static Method object.
// doing method.invoke() would end up executing it,
// so we need to protect against it.
throw new IllegalArgumentException();
return method.invoke(core,args);
} catch (InvocationTargetException e) {
if(e.getTargetException()!=null)
throw e.getTargetException();
throw e;
}
}
public String toString() {
return core.toString();
}
/**
* List of {@link Quick} implementations keyed by their annotation type.
*/
private static final Map<Class,Quick> quicks = new HashMap<Class, Quick>();
static {
for( Quick q : Init.getAll() ) {
quicks.put(q.annotationType(),q);
}
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/**
* Message resources
*/
enum Messages {
// AnnotationParser
DUPLICATE_ANNOTATIONS,
CLASS_NOT_FOUND
;
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getName());
public String toString() {
return format();
}
public String format( Object... args ) {
return MessageFormat.format( rb.getString(name()), args );
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Locatable} implementation for a method.
*
* @author Kohsuke Kawaguchi
*/
public class MethodLocatable<M> implements Locatable {
private final Locatable upstream;
private final M method;
private final Navigator<?,?,?,M> nav;
public MethodLocatable(Locatable upstream, M method, Navigator<?,?,?,M> nav) {
this.upstream = upstream;
this.method = method;
this.nav = nav;
}
public Locatable getUpstream() {
return upstream;
}
public Location getLocation() {
return nav.getMethodLocation(method);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* Base implementation of {@link Locatable} {@link Annotation}.
*
* <p>
* Derived classes of this class is provided for annotations that are commonly
* used in JAXB, to improve the performance of {@link LocatableAnnotation#create}.
*
* @author Kohsuke Kawaguchi
*/
public /*so that our code generator can refer to this class*/ abstract class Quick implements Annotation, Locatable, Location {
private final Locatable upstream;
protected Quick(Locatable upstream) {
this.upstream = upstream;
}
/**
* Gets the annotation object that this object is wrapping.
*/
protected abstract Annotation getAnnotation();
/**
* Factory method to create a new instance of the same kind.
* A {@link Quick} object also works as a factory of itself
*/
protected abstract Quick newInstance( Locatable upstream, Annotation core );
public final Location getLocation() {
return this;
}
public final Locatable getUpstream() {
return upstream;
}
public final String toString() {
return getAnnotation().toString();
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
/**
* @author Kohsuke Kawaguchi
*/
public interface RuntimeAnnotationReader extends AnnotationReader<Type,Class,Field,Method> {
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
/**
* {@link AnnotationReader} that uses {@code java.lang.reflect} to
* read annotations from class files.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public final class RuntimeInlineAnnotationReader extends AbstractInlineAnnotationReaderImpl<Type,Class,Field,Method>
implements RuntimeAnnotationReader {
public <A extends Annotation> A getFieldAnnotation(Class<A> annotation, Field field, Locatable srcPos) {
return LocatableAnnotation.create(field.getAnnotation(annotation),srcPos);
}
public boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, Field field) {
return field.isAnnotationPresent(annotationType);
}
public boolean hasClassAnnotation(Class clazz, Class<? extends Annotation> annotationType) {
return clazz.isAnnotationPresent(annotationType);
}
public Annotation[] getAllFieldAnnotations(Field field, Locatable srcPos) {
Annotation[] r = field.getAnnotations();
for( int i=0; i<r.length; i++ ) {
r[i] = LocatableAnnotation.create(r[i],srcPos);
}
return r;
}
public <A extends Annotation> A getMethodAnnotation(Class<A> annotation, Method method, Locatable srcPos) {
return LocatableAnnotation.create(method.getAnnotation(annotation),srcPos);
}
public boolean hasMethodAnnotation(Class<? extends Annotation> annotation, Method method) {
return method.isAnnotationPresent(annotation);
}
public Annotation[] getAllMethodAnnotations(Method method, Locatable srcPos) {
Annotation[] r = method.getAnnotations();
for( int i=0; i<r.length; i++ ) {
r[i] = LocatableAnnotation.create(r[i],srcPos);
}
return r;
}
public <A extends Annotation> A getMethodParameterAnnotation(Class<A> annotation, Method method, int paramIndex, Locatable srcPos) {
Annotation[] pa = method.getParameterAnnotations()[paramIndex];
for( Annotation a : pa ) {
if(a.annotationType()==annotation)
return LocatableAnnotation.create((A)a,srcPos);
}
return null;
}
public <A extends Annotation> A getClassAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
return LocatableAnnotation.create(((Class<?>)clazz).getAnnotation(a),srcPos);
}
/**
* Cache for package-level annotations.
*/
private final Map<Class<? extends Annotation>,Map<Package,Annotation>> packageCache =
new HashMap<Class<? extends Annotation>,Map<Package,Annotation>>();
public <A extends Annotation> A getPackageAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
Package p = clazz.getPackage();
if(p==null) return null;
Map<Package,Annotation> cache = packageCache.get(a);
if(cache==null) {
cache = new HashMap<Package,Annotation>();
packageCache.put(a,cache);
}
if(cache.containsKey(p))
return (A)cache.get(p);
else {
A ann = LocatableAnnotation.create(p.getAnnotation(a),srcPos);
cache.put(p,ann);
return ann;
}
}
public Class getClassValue(Annotation a, String name) {
try {
return (Class)a.annotationType().getMethod(name).invoke(a);
} catch (IllegalAccessException e) {
// impossible
throw new IllegalAccessError(e.getMessage());
} catch (InvocationTargetException e) {
// impossible
throw new InternalError(Messages.CLASS_NOT_FOUND.format(a.annotationType(), e.getMessage()));
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage());
}
}
public Class[] getClassArrayValue(Annotation a, String name) {
try {
return (Class[])a.annotationType().getMethod(name).invoke(a);
} catch (IllegalAccessException e) {
// impossible
throw new IllegalAccessError(e.getMessage());
} catch (InvocationTargetException e) {
// impossible
throw new InternalError(e.getMessage());
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage());
}
}
protected String fullName(Method m) {
return m.getDeclaringClass().getName()+'#'+m.getName();
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
/**
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
* classloader. This MUST be package private and defined in every package which
* uses such invocations.
* @author snajper
*/
class SecureLoader {
static ClassLoader getContextClassLoader() {
if (System.getSecurityManager() == null) {
return Thread.currentThread().getContextClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
}
}
static ClassLoader getClassClassLoader(final Class c) {
if (System.getSecurityManager() == null) {
return c.getClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return c.getClassLoader();
}
});
}
}
static ClassLoader getSystemClassLoader() {
if (System.getSecurityManager() == null) {
return ClassLoader.getSystemClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return ClassLoader.getSystemClassLoader();
}
});
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlAttribute;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlAttributeQuick
extends Quick
implements XmlAttribute
{
private final XmlAttribute core;
public XmlAttributeQuick(Locatable upstream, XmlAttribute core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlAttributeQuick(upstream, ((XmlAttribute) core));
}
public Class<XmlAttribute> annotationType() {
return XmlAttribute.class;
}
public String name() {
return core.name();
}
public String namespace() {
return core.namespace();
}
public boolean required() {
return core.required();
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlElementDecl;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlElementDeclQuick
extends Quick
implements XmlElementDecl
{
private final XmlElementDecl core;
public XmlElementDeclQuick(Locatable upstream, XmlElementDecl core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlElementDeclQuick(upstream, ((XmlElementDecl) core));
}
public Class<XmlElementDecl> annotationType() {
return XmlElementDecl.class;
}
public String name() {
return core.name();
}
public Class scope() {
return core.scope();
}
public String namespace() {
return core.namespace();
}
public String defaultValue() {
return core.defaultValue();
}
public String substitutionHeadNamespace() {
return core.substitutionHeadNamespace();
}
public String substitutionHeadName() {
return core.substitutionHeadName();
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlElement;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlElementQuick
extends Quick
implements XmlElement
{
private final XmlElement core;
public XmlElementQuick(Locatable upstream, XmlElement core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlElementQuick(upstream, ((XmlElement) core));
}
public Class<XmlElement> annotationType() {
return XmlElement.class;
}
public String name() {
return core.name();
}
public Class type() {
return core.type();
}
public String namespace() {
return core.namespace();
}
public String defaultValue() {
return core.defaultValue();
}
public boolean required() {
return core.required();
}
public boolean nillable() {
return core.nillable();
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlElementRef;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlElementRefQuick
extends Quick
implements XmlElementRef
{
private final XmlElementRef core;
public XmlElementRefQuick(Locatable upstream, XmlElementRef core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlElementRefQuick(upstream, ((XmlElementRef) core));
}
public Class<XmlElementRef> annotationType() {
return XmlElementRef.class;
}
public String name() {
return core.name();
}
public Class type() {
return core.type();
}
public String namespace() {
return core.namespace();
}
public boolean required() {
return core.required();
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlElementRefsQuick
extends Quick
implements XmlElementRefs
{
private final XmlElementRefs core;
public XmlElementRefsQuick(Locatable upstream, XmlElementRefs core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlElementRefsQuick(upstream, ((XmlElementRefs) core));
}
public Class<XmlElementRefs> annotationType() {
return XmlElementRefs.class;
}
public XmlElementRef[] value() {
return core.value();
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlEnum;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlEnumQuick
extends Quick
implements XmlEnum
{
private final XmlEnum core;
public XmlEnumQuick(Locatable upstream, XmlEnum core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlEnumQuick(upstream, ((XmlEnum) core));
}
public Class<XmlEnum> annotationType() {
return XmlEnum.class;
}
public Class value() {
return core.value();
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlRootElement;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlRootElementQuick
extends Quick
implements XmlRootElement
{
private final XmlRootElement core;
public XmlRootElementQuick(Locatable upstream, XmlRootElement core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlRootElementQuick(upstream, ((XmlRootElement) core));
}
public Class<XmlRootElement> annotationType() {
return XmlRootElement.class;
}
public String name() {
return core.name();
}
public String namespace() {
return core.namespace();
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlSchemaQuick
extends Quick
implements XmlSchema
{
private final XmlSchema core;
public XmlSchemaQuick(Locatable upstream, XmlSchema core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlSchemaQuick(upstream, ((XmlSchema) core));
}
public Class<XmlSchema> annotationType() {
return XmlSchema.class;
}
public String location() {
return core.location();
}
public String namespace() {
return core.namespace();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNsForm elementFormDefault() {
return core.elementFormDefault();
}
public XmlNsForm attributeFormDefault() {
return core.attributeFormDefault();
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlSchemaType;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlSchemaTypeQuick
extends Quick
implements XmlSchemaType
{
private final XmlSchemaType core;
public XmlSchemaTypeQuick(Locatable upstream, XmlSchemaType core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlSchemaTypeQuick(upstream, ((XmlSchemaType) core));
}
public Class<XmlSchemaType> annotationType() {
return XmlSchemaType.class;
}
public String name() {
return core.name();
}
public Class type() {
return core.type();
}
public String namespace() {
return core.namespace();
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlTransient;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlTransientQuick
extends Quick
implements XmlTransient
{
private final XmlTransient core;
public XmlTransientQuick(Locatable upstream, XmlTransient core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlTransientQuick(upstream, ((XmlTransient) core));
}
public Class<XmlTransient> annotationType() {
return XmlTransient.class;
}
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlType;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlTypeQuick
extends Quick
implements XmlType
{
private final XmlType core;
public XmlTypeQuick(Locatable upstream, XmlType core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlTypeQuick(upstream, ((XmlType) core));
}
public Class<XmlType> annotationType() {
return XmlType.class;
}
public String name() {
return core.name();
}
public String namespace() {
return core.namespace();
}
public String[] propOrder() {
return core.propOrder();
}
public Class factoryClass() {
return core.factoryClass();
}
public String factoryMethod() {
return core.factoryMethod();
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.annotation;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.XmlValue;
/**
* <p><b>Auto-generated, do not edit.</b></p>
*
*/
final class XmlValueQuick
extends Quick
implements XmlValue
{
private final XmlValue core;
public XmlValueQuick(Locatable upstream, XmlValue core) {
super(upstream);
this.core = core;
}
protected Annotation getAnnotation() {
return core;
}
protected Quick newInstance(Locatable upstream, Annotation core) {
return new XmlValueQuick(upstream, ((XmlValue) core));
}
public Class<XmlValue> annotationType() {
return XmlValue.class;
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* {@link Adapter} that wraps {@link XmlJavaTypeAdapter}.
*
* @author Kohsuke Kawaguchi
*/
public class Adapter<TypeT,ClassDeclT> {
/**
* The adapter class. Always non-null.
*
* A class that derives from {@link javax.xml.bind.annotation.adapters.XmlAdapter}.
*/
public final ClassDeclT adapterType;
/**
* The type that the JAXB can handle natively.
* The <tt>Default</tt> parameter of <tt>XmlAdapter&lt;Default,Custom></tt>.
*
* Always non-null.
*/
public final TypeT defaultType;
/**
* The type that is stored in memory.
* The <tt>Custom</tt> parameter of <tt>XmlAdapter&lt;Default,Custom></tt>.
*/
public final TypeT customType;
public Adapter(
XmlJavaTypeAdapter spec,
AnnotationReader<TypeT,ClassDeclT,?,?> reader,
Navigator<TypeT,ClassDeclT,?,?> nav) {
this( nav.asDecl(reader.getClassValue(spec,"value")), nav );
}
public Adapter(ClassDeclT adapterType,Navigator<TypeT,ClassDeclT,?,?> nav) {
this.adapterType = adapterType;
TypeT baseClass = nav.getBaseClass(nav.use(adapterType), nav.asDecl(XmlAdapter.class));
// because the parameterization of XmlJavaTypeAdapter requires that the class derives from XmlAdapter.
assert baseClass!=null;
if(nav.isParameterizedType(baseClass))
defaultType = nav.getTypeArgument(baseClass,0);
else
defaultType = nav.ref(Object.class);
if(nav.isParameterizedType(baseClass))
customType = nav.getTypeArgument(baseClass,1);
else
customType = nav.ref(Object.class);
}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Stand-alone array that can be marshalled/unmarshalled on its own
* (without being part of any encloding {@link ClassInfo}.)
*
* <p>
* Most of the times arrays are treated as properties of their enclosing classes,
* but sometimes we do need to map an array class to its own XML type.
* This object is used for that purpose.
*
* @author Kohsuke Kawaguchi
*/
public interface ArrayInfo<T,C> extends NonElement<T,C> {
/**
* T of T[]. The type of the items of the array.
*
* @return never null
*/
NonElement<T,C> getItemType();
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.namespace.QName;
/**
* Attribute {@link PropertyInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface AttributePropertyInfo<T,C> extends PropertyInfo<T,C>, NonElementRef<T,C> {
/**
* Gets the type of the attribute.
*
* <p>
* Note that when this property is a collection, this method returns
* the type of each item in the collection.
*
* @return
* always non-null.
*/
NonElement<T,C> getTarget();
/**
* Returns true if this attribute is mandatory.
*/
boolean isRequired();
/**
* Gets the attribute name.
*
* @return
* must be non-null.
*/
QName getXmlName();
Adapter<T,C> getAdapter();
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.namespace.QName;
/**
* JAXB spec designates a few Java classes to be mapped to leaves in XML.
*
* <p>
* Built-in leaves also have another priviledge; specifically, they often
* have more than one XML type names associated with it.
*
* @author Kohsuke Kawaguchi
*/
public interface BuiltinLeafInfo<T,C> extends LeafInfo<T,C> {
/**
* {@inheritDoc}
*
* <p>
* This method returns the 'primary' type name of this built-in leaf,
* which should be used when values of this type are marshalled.
*
* @return
* never null.
*/
public QName getTypeName();
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.List;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlValue;
/**
* Information about JAXB-bound class.
*
* <p>
* All the JAXB annotations are already reflected to the model so that
* the caller doesn't have to worry about them. For this reason, you
* cannot access annotations on properties.
*
* <h2>XML representation</h2>
* <p>
* A JAXB-bound class always have at least one representation
* (called "type representation"),but it can optionally have another
* representation ("element representation").
*
* <p>
* In the type representaion, a class
* is represented as a set of attributes and (elements or values).
* You can inspect the details of those attributes/elements/values by {@link #getProperties()}.
* This representation corresponds to a complex/simple type in XML Schema.
* You can obtain the schema type name by {@link #getTypeName()}.
*
* <p>
* If a class has an element representation, {@link #isElement()} returns true.
* This representation is mostly similar to the type representation
* except that the whoe attributes/elements/values are wrapped into
* one element. You can obtain the name of this element through {@link #asElement()}.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public interface ClassInfo<T,C> extends MaybeElement<T,C> {
/**
* Obtains the information about the base class.
*
* @return null
* if this info extends from {@link Object}.
*/
ClassInfo<T,C> getBaseClass();
/**
* Gets the declaration this object is wrapping.
*/
C getClazz();
/**
* Gets the fully-qualified name of the class.
*/
String getName();
/**
* Returns all the properties newly declared in this class.
*
* <p>
* This excludes properties defined in the super class.
*
* <p>
* If the properties are {@link #isOrdered() ordered},
* it will be returned in the order that appear in XML.
* Otherwise it will be returned in no particular order.
*
* <p>
* Properties marked with {@link XmlTransient} will not show up
* in this list. As far as JAXB is concerned, they are considered
* non-existent.
*
* @return
* always non-null, but can be empty.
*/
List<? extends PropertyInfo<T,C>> getProperties();
/**
* Returns true if this class or its ancestor has {@link XmlValue}
* property.
*/
boolean hasValueProperty();
/**
* Gets the property that has the specified name.
*
* <p>
* This is just a convenience method for:
* <pre>
* for( PropertyInfo p : getProperties() ) {
* if(p.getName().equals(name))
* return p;
* }
* return null;
* </pre>
*
* @return null
* if the property was not found.
*
* @see PropertyInfo#getName()
*/
PropertyInfo<T,C> getProperty(String name);
/**
* If the class has properties, return true. This is only
* true if the Collection object returned by {@link #getProperties()}
* is not empty.
*/
boolean hasProperties();
/**
* If this class is abstract and thus shall never be directly instanciated.
*/
boolean isAbstract();
/**
* Returns true if the properties of this class is ordered in XML.
* False if it't not.
*
* <p>
* In RELAX NG context, ordered properties mean &lt;group> and
* unordered properties mean &lt;interleave>.
*/
boolean isOrdered();
/**
* If this class is marked as final and no further extension/restriction is allowed.
*/
boolean isFinal();
/**
* True if there's a known sub-type of this class in {@link TypeInfoSet}.
*/
boolean hasSubClasses();
/**
* Returns true if this bean class has an attribute wildcard.
*
* <p>
* This is true if the class declares an attribute wildcard,
* or it is inherited from its super classes.
*
* @see #inheritsAttributeWildcard()
*/
boolean hasAttributeWildcard();
/**
* Returns true iff this class inherits a wildcard attribute
* from its ancestor classes.
*/
boolean inheritsAttributeWildcard();
/**
* Returns true iff this class declares a wildcard attribute.
*/
boolean declaresAttributeWildcard();
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.namespace.QName;
/**
* {@link TypeInfo} that maps to an element.
*
* Either {@link ElementInfo} or {@link ClassInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface Element<T,C> extends TypeInfo<T,C> {
/**
* Gets the element name of the class.
*
* @return
* Always non-null.
*/
QName getElementName();
/**
* If this element can substitute another element, return that element.
*
* <p>
* Substitutability of elements are transitive.
*
* @return
* null if no such element exists.
*/
Element<T,C> getSubstitutionHead();
/**
* If non-null, this element is only active inside the given scope.
*/
ClassInfo<T,C> getScope();
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Collection;
import javax.xml.bind.JAXBElement;
/**
* A particular use (specialization) of {@link JAXBElement}.
*
* TODO: is ElementInfo adaptable?
*
* @author Kohsuke Kawaguchi
*/
public interface ElementInfo<T,C> extends Element<T,C> {
/**
* Gets the object that represents the value property.
*
* @return
* non-null.
*/
ElementPropertyInfo<T,C> getProperty();
/**
* Short for <code>getProperty().ref().get(0)</code>.
*
* The type of the value this element holds.
*
* Normally, this is the T of {@code JAXBElement<T>}.
* But if the property is adapted, this is the on-the-wire type.
*
* Or if the element has a list of values, then this field
* represents the type of the individual item.
*
* @see #getContentInMemoryType()
*/
NonElement<T,C> getContentType();
/**
* T of {@code JAXBElement<T>}.
*
* <p>
* This is tied to the in-memory representation.
*
* @see #getContentType()
*/
T getContentInMemoryType();
/**
* Returns the representation for {@link JAXBElement}&lt;<i>contentInMemoryType</i>&gt;.
*
* <p>
* This returns the signature in Java and thus isn't affected by the adapter.
*/
T getType();
/**
* @inheritDoc
*
* {@link ElementInfo} can only substitute {@link ElementInfo}.
*/
ElementInfo<T,C> getSubstitutionHead();
/**
* All the {@link ElementInfo}s whose {@link #getSubstitutionHead()} points
* to this object.
*
* @return
* can be empty but never null.
*/
Collection<? extends ElementInfo<T,C>> getSubstitutionMembers();
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.List;
import javax.xml.namespace.QName;
/**
* Property that maps to an element.
*
* @author Kohsuke Kawaguchi
*/
// TODO: there seems to be too much interactions between switches, and that's no good.
public interface ElementPropertyInfo<T,C> extends PropertyInfo<T,C> {
/**
* Returns the information about the types allowed in this property.
*
* <p>
* In a simple case like the following, an element property only has
* one {@link TypeRef} that points to {@link String} and tag name "foo".
* <pre>
* &#64;XmlElement
* String abc;
* </pre>
*
* <p>
* However, in a general case an element property can be heterogeneous,
* meaning you can put different types in it, each with a different tag name
* (and a few other settings.)
* <pre>
* // list can contain String or Integer.
* &#64;XmlElements({
* &#64;XmlElement(name="a",type=String.class),
* &#64;XmlElement(name="b",type=Integer.class),
* })
* List&lt;Object> abc;
* </pre>
* <p>
* In this case this method returns a list of two {@link TypeRef}s.
*
*
* @return
* Always non-null. Contains at least one entry.
* If {@link #isValueList()}==true, there's always exactly one type.
*/
List<? extends TypeRef<T,C>> getTypes();
/**
* Gets the wrapper element name.
*
* @return
* must be null if {@link #isCollection()}==false or
* if {@link #isValueList()}==true.
*
* Otherwise,
* this can be null (in which case there'll be no wrapper),
* or it can be non-null (in which case there'll be a wrapper)
*/
QName getXmlName();
/**
* Checks if the wrapper element is required.
*
* @return
* Always false if {@link #getXmlName()}==null.
*/
boolean isCollectionRequired();
/**
* Returns true if this property is nillable
* (meaning the absence of the value is treated as nil='true')
*
* <p>
* This method is only used when this property is a collection.
*/
boolean isCollectionNillable();
/**
* Returns true if this property is a collection but its XML
* representation is a list of values, not repeated elements.
*
* <p>
* If {@link #isCollection()}==false, this property is always false.
*
* <p>
* When this flag is true, <tt>getTypes().size()==1</tt> always holds.
*/
boolean isValueList();
/**
* Returns true if this element is mandatory.
*
* For collections, this property isn't used.
* TODO: define the semantics when this is a collection
*/
boolean isRequired();
Adapter<T,C> getAdapter();
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.XmlEnumValue;
/**
* Individual constant of an enumeration.
*
* <p>
* Javadoc in this class uses the following sample to explain the semantics:
* <pre>
* &#64;XmlEnum(Integer.class)
* enum Foo {
* &#64;XmlEnumValue("1")
* ONE,
* &#64;XmlEnumValue("2")
* TWO
* }
* </pre>
*
* @see EnumLeafInfo
* @author Kohsuke Kawaguchi
*/
public interface EnumConstant<T,C> {
/**
* Gets the {@link EnumLeafInfo} to which this constant belongs to.
*
* @return never null.
*/
EnumLeafInfo<T,C> getEnclosingClass();
/**
* Lexical value of this constant.
*
* <p>
* This value should be evaluated against
* {@link EnumLeafInfo#getBaseType()} to obtain the typed value.
*
* <p>
* This is the same value as written in the {@link XmlEnumValue} annotation.
* In the above example, this method returns "1" and "2".
*
* @return
* never null.
*/
String getLexicalValue();
/**
* Gets the constant name.
*
* <p>
* In the above example this method return "ONE" and "TWO".
*
* @return
* never null. A valid Java identifier.
*/
String getName();
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* {@link NonElement} that represents an {@link Enum} class.
*
* @author Kohsuke Kawaguchi
*/
public interface EnumLeafInfo<T,C> extends LeafInfo<T,C> {
/**
* The same as {@link #getType()} but an {@link EnumLeafInfo}
* is guaranteed to represent an enum declaration, which is a
* kind of a class declaration.
*
* @return
* always non-null.
*/
C getClazz();
/**
* Returns the base type of the enumeration.
*
* <p>
* For example, with the following enum class, this method
* returns {@link BuiltinLeafInfo} for {@link Integer}.
*
* <pre>
* &amp;XmlEnum(Integer.class)
* enum Foo {
* &amp;XmlEnumValue("1")
* ONE,
* &amp;XmlEnumValue("2")
* TWO
* }
* </pre>
*
* @return
* never null.
*/
NonElement<T,C> getBaseType();
/**
* Returns the read-only list of enumeration constants.
*
* @return
* never null. Can be empty (really?).
*/
Iterable<? extends EnumConstant> getConstants();
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
* listen to static errors found during building a JAXB model from a set of classes.
* Implemented by the client of {@link com.sun.xml.internal.bind.v2.model.impl.ModelBuilder}.
*
* <p>
* All the static errors have to be reported while constructing a
* model, not when a model is used (IOW, until the {@link com.sun.xml.internal.bind.v2.model.impl.ModelBuilder#link} completes.
* Internally, {@link com.sun.xml.internal.bind.v2.model.impl.ModelBuilder} wraps an {@link ErrorHandler} and all the model
* components should report errors through it.
*
* <p>
* {@link IllegalAnnotationException} is a checked exception to remind
* the model classes to report it rather than to throw it.
*
* @see com.sun.xml.internal.bind.v2.model.impl.ModelBuilder
* @author Kohsuke Kawaguchi
*/
public interface ErrorHandler {
/**
* Receives a notification for an error in the annotated code.
*/
void error( IllegalAnnotationException e );
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* @author Kohsuke Kawaguchi
*/
public enum ID {
ID,IDREF,NONE
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Either {@link BuiltinLeafInfo} or {@link EnumLeafInfo}.
*
* <p>
* Those Java types are all mapped to a chunk of text, so we call
* them "leaves".
* This interface represents the mapping information for those
* special Java types.
*
* @author Kohsuke Kawaguchi
*/
public interface LeafInfo<T,C> extends MaybeElement<T,C> {
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Map;
import javax.xml.namespace.QName;
/**
* Property that maps to the following schema fragment.
*
* <pre><xmp>
* <xs:complexType>
* <xs:sequence>
* <xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
* <xs:complexType>
* <xs:sequence>
* <xs:element name="key" type="XXXX"/>
* <xs:element name="value" type="YYYY"/>
* </xs:sequence>
* </xs:complexType>
* </xs:element>
* </xs:sequence>
* </xs:complexType>
* </xmp></pre>
*
* <p>
* This property is used to represent a default binding of a {@link Map} property.
* ({@link Map} properties with adapters will be represented by {@link ElementPropertyInfo}.)
*
*
* <h2>Design Thinking Led to This</h2>
* <p>
* I didn't like the idea of adding such a special-purpose {@link PropertyInfo} to a model.
* The alternative was to implicitly assume an adapter, and have internal representation of
* the Entry class ready.
* But the fact that the key type and the value type changes with the parameterization makes
* it very difficult to have such a class (especially inside Annotation Processing, where we can't even generate
* classes.)
*
* @author Kohsuke Kawaguchi
*/
public interface MapPropertyInfo<T,C> extends PropertyInfo<T,C> {
/**
* Gets the wrapper element name.
*
* @return
* always non-null.
*/
QName getXmlName();
/**
* Returns true if this property is nillable
* (meaning the absence of the value is treated as nil='true')
*
* <p>
* This method is only used when this property is a collection.
*/
boolean isCollectionNillable();
/**
* Type of the key of the map. K of {@code HashMap<K,V>}
*
* @return never null.
*/
NonElement<T,C> getKeyType();
/**
* Type of the value of the map. V of {@code HashMap<K,V>}
*
* @return never null.
*/
NonElement<T,C> getValueType();
// TODO
// Adapter<T,C> getKeyAdapter();
// Adapter<T,C> getValueAdapter();
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.namespace.QName;
/**
* Some {@link NonElement} can optionally be an {@link Element}.
*
* This interface captures such characteristics.
*
* @author Kohsuke Kawaguchi
*/
public interface MaybeElement<T,C> extends NonElement<T,C> {
/**
* If the class is bound to an element, return true.
*
* <p>
* Note that when this is true, the class is bound to both an element
* and a type.
*/
boolean isElement();
/**
* Gets the element name of the class, if the class is bound
* to an element.
*
* @return
* non-null iff {@link #isElement()}.
*/
QName getElementName();
/**
* Returns the {@link Element} aspect of this {@link ClassInfo}.
*
* @return
* null if {@link #isElement()}==false, non-null if {@link #isElement()}==true.
*/
Element<T,C> asElement();
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import javax.xml.namespace.QName;
/**
* {@link TypeInfo} that maps to an element.
*
* Either {@link LeafInfo} or {@link ClassInfo}.
*
* TODO: better ANYTYPE_NAME.
*
* @author Kohsuke Kawaguchi
*/
public interface NonElement<T,C> extends TypeInfo<T,C> {
public static final QName ANYTYPE_NAME = new QName(WellKnownNamespace.XML_SCHEMA, "anyType");
/**
* Gets the primary XML type ANYTYPE_NAME of the class.
*
* <p>
* A Java type can be mapped to multiple XML types, but one of them is
* considered "primary" and used when we generate a schema.
*
* @return
* null if the object doesn't have an explicit type ANYTYPE_NAME (AKA anonymous.)
*/
QName getTypeName();
/**
* Returns true if this {@link NonElement} maps to text in XML,
* without any attribute nor child elements.
*/
boolean isSimpleType();
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Reference to a {@link NonElement}.
*
* This interface defines properties of a reference.
*
* @author Kohsuke Kawaguchi
*/
public interface NonElementRef<T,C> {
/**
* Target of the reference.
*
* @return never null
*/
NonElement<T,C> getTarget();
/**
* Gets the property which is the source of this reference.
*
* @return never null
*/
PropertyInfo<T,C> getSource();
}

View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Collection;
import javax.activation.MimeType;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.namespace.QName;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationSource;
/**
* Information about a JAXB-bound property.
*
* <p>
* All the JAXB annotations are already incorporated into the model so that
* the caller doesn't have to worry about reading them. For this reason, you
* cannot access annotations on properties directly.
*
* TODO: don't we need a visitor?
*
* @author Kohsuke Kawaguchi
*/
public interface PropertyInfo<T,C> extends AnnotationSource {
/**
* Gets the {@link ClassInfo} or {@link ElementInfo} to which this property belongs.
*/
TypeInfo<T,C> parent();
/**
* Gets the name of the property.
*
* <p>
* For example, "foo" or "bar".
* Generally, a property name is different from XML,
* (although they are often related, as a property name is often
* computed from tag names / attribute names.)
* In fact, <b>property names do not directly affect XML</b>.
* The property name uniquely identifies a property within a class.
*
* @see XmlType#propOrder()
*/
String getName();
/**
* Gets the display name of the property.
*
* <p>
* This is a convenience method for
* {@code parent().getName()+'#'+getName()}.
*/
String displayName();
/**
* Returns true if this is a multi-valued collection property.
* Otherwise false, in which case the property is a single value.
*/
boolean isCollection();
/**
* List of {@link TypeInfo}s that this property references.
*
* This allows the caller to traverse the reference graph without
* getting into the details of each different property type.
*
* @return
* non-null read-only collection.
*/
Collection<? extends TypeInfo<T,C>> ref();
/**
* Gets the kind of this property.
*
* @return
* always non-null.
*/
PropertyKind kind();
/**
* @return
* null if the property is not adapted.
*/
Adapter<T,C> getAdapter();
/**
* Returns the IDness of the value of this element.
*
* @see XmlID
* @see XmlIDREF
*
* @return
* always non-null
*/
ID id();
/**
* Expected MIME type, if any.
*/
MimeType getExpectedMimeType();
/**
* If this is true and this property indeed represents a binary data,
* it should be always inlined.
*/
boolean inlineBinaryData();
/**
* The effective value of {@link XmlSchemaType} annotation, if any.
*
* <p>
* If the property doesn't have {@link XmlSchemaType} annotation,
* this method returns null.
*
* <p>
* Since a type name is a property of a Java type, not a Java property,
* A schema type name of a Java type should be primarily obtained
* by using {@link NonElement#getTypeName()}. This method is to correctly
* implement the ugly semantics of {@link XmlSchemaType} (namely
* when this returns non-null, it overrides the type names of all types
* that are in this property.)
*/
@Nullable QName getSchemaType();
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlInlineBinaryData;
/**
* An Enum that indicates if the property is
* Element, ElementRef, Value, or Attribute.
*
* <p>
* Corresponds to the four different kind of {@link PropertyInfo}.
* @author Bhakti Mehta (bhakti.mehta@sun.com)
*/
public enum PropertyKind {
VALUE(true,false,Integer.MAX_VALUE),
ATTRIBUTE(false,false,Integer.MAX_VALUE),
ELEMENT(true,true,0),
REFERENCE(false,true,1),
MAP(false,true,2),
;
/**
* This kind of property can have {@link XmlMimeType} and {@link XmlInlineBinaryData}
* annotation with it.
*/
public final boolean canHaveXmlMimeType;
/**
* This kind of properties need to show up in {@link XmlType#propOrder()}.
*/
public final boolean isOrdered;
/**
* {@link com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory} benefits from having index numbers assigned to
* {@link #ELEMENT}, {@link #REFERENCE}, and {@link #MAP} in this order.
*/
public final int propertyIndex;
PropertyKind(boolean canHaveExpectedContentType, boolean isOrdered, int propertyIndex) {
this.canHaveXmlMimeType = canHaveExpectedContentType;
this.isOrdered = isOrdered;
this.propertyIndex = propertyIndex;
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.impl.ModelBuilderI;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* Reference to a type in a model.
*
* TODO: isn't there a similarity between this and TypeUse in XJC?
*
* @author Kohsuke Kawaguchi
*/
public final class Ref<T,C> {
/**
* The type being referenced.
* <p>
* If the type is adapted, this field is the same as the adapter's default type.
*/
public final T type;
/**
* If the reference has an adapter, non-null.
*/
public final Adapter<T,C> adapter;
/**
* If the {@link #type} is an array and it is a value list,
* true.
*/
public final boolean valueList;
public Ref(T type) {
this(type,null,false);
}
public Ref(T type, Adapter<T, C> adapter, boolean valueList) {
this.adapter = adapter;
if(adapter!=null)
type=adapter.defaultType;
this.type = type;
this.valueList = valueList;
}
public Ref(ModelBuilderI<T,C,?,?> builder, T type, XmlJavaTypeAdapter xjta, XmlList xl ) {
this(builder.getReader(),builder.getNavigator(),type,xjta,xl);
}
public Ref(AnnotationReader<T,C,?,?> reader,
Navigator<T,C,?,?> nav,
T type, XmlJavaTypeAdapter xjta, XmlList xl ) {
Adapter<T,C> adapter=null;
if(xjta!=null) {
adapter = new Adapter<T,C>(xjta,reader,nav);
type = adapter.defaultType;
}
this.type = type;
this.adapter = adapter;
this.valueList = xl!=null;
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Collection;
import java.util.Set;
import javax.xml.namespace.QName;
/**
* {@link PropertyInfo} that holds references to other {@link Element}s.
*
* @author Kohsuke Kawaguchi
*/
public interface ReferencePropertyInfo<T,C> extends PropertyInfo<T,C> {
/**
* Returns the information about the possible elements in this property.
*
* <p>
* As of 2004/08/17, the spec only allows you to use different element names
* when a property is a collection, but I think there's really no reason
* to limit it there --- if the user wants to use a different tag name
* for different objects, I don't see why this can be limited to collections.
*
* <p>
* So this is a generalization of the spec. We always allow a property to have
* multiple types and use different tag names for it, depending on the actual type.
*
* <p>
* In most of the cases, this collection only contains 1 item. So the runtime system
* is encouraged to provide a faster code-path that is optimized toward such cases.
*
* @return
* Always non-null. Contains at least one entry.
*/
Set<? extends Element<T,C>> getElements();
/**
* {@inheritDoc}.
*
* If this {@link ReferencePropertyInfo} has a wildcard in it,
* then the returned list will contain {@link WildcardTypeInfo}.
*/
Collection<? extends TypeInfo<T,C>> ref();
/**
* Gets the wrapper element name.
*
* @return
* must be null if not collection. If the property is a collection,
* this can be null (in which case there'll be no wrapper),
* or it can be non-null (in which case there'll be a wrapper)
*/
QName getXmlName();
/**
* Returns true if this property is nillable
* (meaning the absence of the value is treated as nil='true')
*
* <p>
* This method is only used when this property is a collection.
*/
boolean isCollectionNillable();
/**
* Checks if the wrapper element is required.
*
* @return
* Always false if {@link #getXmlName()}==null.
*/
boolean isCollectionRequired();
/**
* Returns true if this property can hold {@link String}s to represent
* mixed content model.
*/
boolean isMixed();
/**
* If this property supports the wildcard, returns its mode.
*
* @return null
* if the wildcard is not allowed on this element.
*/
WildcardMode getWildcard();
/**
* If this property supports the wildcard, returns its DOM handler.
*
* @return null
* if the wildcard is not allowed on this element.
*/
C getDOMHandler();
/**
* Returns true if this element is mandatory.
*/
boolean isRequired();
Adapter<T,C> getAdapter();
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Set;
import javax.xml.bind.annotation.XmlRegistry;
/**
* Represents the information in a class with {@link XmlRegistry} annotaion.
*
* <p>
* This interface is only meant to be used as a return type from {@link com.sun.xml.internal.bind.v2.model.impl.ModelBuilder}.
*
* @author Kohsuke Kawaguchi
*/
public interface RegistryInfo<T,C> {
/**
* Returns all the references to other types in this registry.
*/
Set<TypeInfo<T,C>> getReferences();
/**
* Returns the class with {@link XmlRegistry}.
*/
C getClazz();
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.XmlIDREF;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
/**
* Either {@link ClassInfo}, {@link ElementInfo}, or {@link LeafInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface TypeInfo<T,C> extends Locatable {
/**
* Gets the underlying Java type that object represents.
*
* @return
* always non-null.
*/
T getType();
/**
* True if this type is a valid target from a property annotated with {@link XmlIDREF}.
*/
boolean canBeReferencedByIDREF();
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import java.util.Map;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* Root of models.&nbsp;Set of {@link TypeInfo}s.
*
* @author Kohsuke Kawaguchi
*/
public interface TypeInfoSet<T,C,F,M> {
/**
* {@link Navigator} for this model.
*/
Navigator<T,C,F,M> getNavigator();
// turns out we can't have AnnotationReader in XJC, so it's impossible to have this here.
// perhaps we should revisit this in the future.
// /**
// * {@link AnnotationReader} for this model.
// */
// AnnotationReader<T,C,F,M> getReader();
/**
* Returns a {@link TypeInfo} for the given type.
*
* @return
* null if the specified type cannot be bound by JAXB, or
* not known to this set.
*/
NonElement<T,C> getTypeInfo( T type );
/**
* Gets the {@link TypeInfo} for the any type.
*/
NonElement<T,C> getAnyTypeInfo();
/**
* Returns a {@link ClassInfo}, {@link ArrayInfo}, or {@link LeafInfo}
* for the given bean.
*
* <p>
* This method is almost like refinement of {@link #getTypeInfo(Object)} except
* our C cannot derive from T.
*
* @return
* null if the specified type is not bound by JAXB or otherwise
* unknown to this set.
*/
NonElement<T,C> getClassInfo( C type );
/**
* Returns all the {@link ArrayInfo}s known to this set.
*/
Map<? extends T,? extends ArrayInfo<T,C>> arrays();
/**
* Returns all the {@link ClassInfo}s known to this set.
*/
Map<C,? extends ClassInfo<T,C>> beans();
/**
* Returns all the {@link BuiltinLeafInfo}s known to this set.
*/
Map<T,? extends BuiltinLeafInfo<T,C>> builtins();
/**
* Returns all the {@link EnumLeafInfo}s known to this set.
*/
Map<C,? extends EnumLeafInfo<T,C>> enums();
/**
* Returns a {@link ElementInfo} for the given element.
*
* @param scope
* if null, return the info about a global element.
* Otherwise return a local element in the given scope if available,
* then look for a global element next.
*/
ElementInfo<T,C> getElementInfo( C scope, QName name );
/**
* Returns a type information for the given reference.
*/
NonElement<T,C> getTypeInfo(Ref<T,C> ref);
/**
* Returns all {@link ElementInfo}s in the given scope.
*
* @param scope
* if non-null, this method only returns the local element mapping.
*/
Map<QName,? extends ElementInfo<T,C>> getElementMappings( C scope );
/**
* Returns all the {@link ElementInfo} known to this set.
*/
Iterable<? extends ElementInfo<T,C>> getAllElements();
/**
* Gets all {@link XmlSchema#xmlns()} found in this context for the given namespace URI.
*
* <p>
* This operation is expected to be only used in schema generator, so it can be slow.
*
* @return
* A map from prefixes to namespace URIs, which should be declared when generating a schema.
* Could be empty but never null.
*/
Map<String,String> getXmlNs(String namespaceUri);
/**
* Gets {@link XmlSchema#location()} found in this context.
*
* <p>
* This operation is expected to be only used in schema generator, so it can be slow.
*
* @return
* A map from namespace URI to the value of the location.
* If the entry is missing, that means a schema should be generated for that namespace.
* If the value is "", that means the schema location is implied
* (&lt;xs:schema namespace="..."/> w/o schemaLocation.)
*/
Map<String,String> getSchemaLocations();
/**
* Gets the reasonable {@link XmlNsForm} for the given namespace URI.
*
* <p>
* The spec doesn't define very precisely what the {@link XmlNsForm} value
* for the given namespace would be, so this method is implemented in rather
* ad-hoc way. It should work as what most people expect for simple cases.
*
* @return never null.
*/
XmlNsForm getElementFormDefault(String nsUri);
/**
* Gets the reasonable {@link XmlNsForm} for the given namespace URI.
*
* <p>
* The spec doesn't define very precisely what the {@link XmlNsForm} value
* for the given namespace would be, so this method is implemented in rather
* ad-hoc way. It should work as what most people expect for simple cases.
*
* @return never null.
*/
XmlNsForm getAttributeFormDefault(String nsUri);
/**
* Dumps this model into XML.
*
* For debug only.
*
* TODO: not sure if this actually works. We don't really know what are T,C.
*/
public void dump( Result out ) throws JAXBException;
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.namespace.QName;
/**
* Information about a type referenced from {@link ElementPropertyInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface TypeRef<T,C> extends NonElementRef<T,C> {
/**
* The associated element name.
*
* @return
* never null.
*/
QName getTagName();
/**
* Returns true if this element is nillable.
*/
boolean isNillable();
/**
* The default value for this element if any.
* Otherwise null.
*/
String getDefaultValue();
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Value {@link PropertyInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface ValuePropertyInfo<T,C> extends PropertyInfo<T,C>, NonElementRef<T,C> {
Adapter<T,C> getAdapter();
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Mode of the wildcard.
*
* @author Kohsuke Kawaguchi
*/
public enum WildcardMode {
STRICT(false,true), SKIP(true,false), LAX(true,true);
public final boolean allowDom;
public final boolean allowTypedObject;
WildcardMode(boolean allowDom, boolean allowTypedObject) {
this.allowDom = allowDom;
this.allowTypedObject = allowTypedObject;
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.core;
/**
* Type referenced as a result of having the wildcard.
*
* TODO: think about how to gracefully handle the difference between LAX,SKIP, and STRICT.
*
* @author Kohsuke Kawaguchi
*/
public interface WildcardTypeInfo<T,C> extends TypeInfo<T,C> {
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The in-memory model of the JAXB-bound beans.
*
* <h2>Parameterizations</h2>
* <p>
* Interfaces in this package are parameterized to work with arbitrary Java reflection library.
* This is necessary because the RI needs to work with both the runtime reflection library
* ({@link java.lang.reflect}) and the Annotation Processing.
*
* <p>
* The meaning of parameterizations are as follows:
*
* <dl>
* <dt><b>T</b>
* <dd>Represents an use of type, such as {@code int}, {@code Foo[]}, or {@code List<Foo>}.
* Corresponds to {@link Type}.
*
* <dt><b>C</b>
* <dd>Represents a declaration of a type (that is, class, interface, enum, or annotation.)
* This doesn't include {@code int}, {@code Foo[]}, or {@code List<Foo>}, because
* they don't have corresponding declarations.
* Corresponds to {@link Class} (roughly).
*
* <dt><b>F</b>
* <dd>Represents a field.
* Corresponds to {@link Field}.
*
* <dt><b>M</b>
* <dd>Represents a method.
* Corresponds to {@link Method}.
*
* <dt>
*/
@XmlSchema(namespace="http://jaxb.dev.java.net/xjc/model",elementFormDefault=QUALIFIED)
package com.sun.xml.internal.bind.v2.model.core;
import javax.xml.bind.annotation.XmlSchema;
import static javax.xml.bind.annotation.XmlNsForm.QUALIFIED;

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.namespace.QName;
import javax.xml.bind.annotation.XmlIDREF;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
/**
* {@link TypeInfo} implementation for <tt>xs:anyType</tt>.
*
* @author Kohsuke Kawaguchi
*/
class AnyTypeImpl<T,C> implements NonElement<T,C> {
private final T type;
private final Navigator<T,C,?,?> nav;
public AnyTypeImpl(Navigator<T,C,?,?> nav) {
this.type = nav.ref(Object.class);
this.nav = nav;
}
public QName getTypeName() {
return ANYTYPE_NAME;
}
public T getType() {
return type;
}
public Locatable getUpstream() {
return null;
}
public boolean isSimpleType() {
return false;
}
public Location getLocation() {
return nav.getClassLocation(nav.asDecl(Object.class));
}
/**
* xs:anyType can be referenced from {@link XmlIDREF}.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return true;
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.ArrayInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.util.ArrayInfoUtil;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
*
* <p>
* Public because XJC needs to access it
*
* @author Kohsuke Kawaguchi
*/
public class ArrayInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
extends TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
implements ArrayInfo<TypeT,ClassDeclT>, Location {
private final NonElement<TypeT,ClassDeclT> itemType;
private final QName typeName;
/**
* The representation of T[] in the underlying reflection library.
*/
private final TypeT arrayType;
public ArrayInfoImpl(ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
Locatable upstream, TypeT arrayType) {
super(builder, upstream);
this.arrayType = arrayType;
TypeT componentType = nav().getComponentType(arrayType);
this.itemType = builder.getTypeInfo(componentType, this);
QName n = itemType.getTypeName();
if(n==null) {
builder.reportError(new IllegalAnnotationException(Messages.ANONYMOUS_ARRAY_ITEM.format(
nav().getTypeName(componentType)),this));
n = new QName("#dummy"); // for error recovery
}
this.typeName = ArrayInfoUtil.calcArrayTypeName(n);
}
public NonElement<TypeT, ClassDeclT> getItemType() {
return itemType;
}
public QName getTypeName() {
return typeName;
}
public boolean isSimpleType() {
return false;
}
public TypeT getType() {
return arrayType;
}
/**
* Leaf-type cannot be referenced from IDREF.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return false;
}
public Location getLocation() {
return this;
}
public String toString() {
return nav().getTypeName(arrayType);
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.api.impl.NameConverter;
import com.sun.xml.internal.bind.v2.model.core.AttributePropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
/**
* @author Kohsuke Kawaguchi
*/
class AttributePropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
extends SingleTypePropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
implements AttributePropertyInfo<TypeT,ClassDeclT> {
private final QName xmlName;
private final boolean isRequired;
AttributePropertyInfoImpl(ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent, PropertySeed<TypeT,ClassDeclT,FieldT,MethodT> seed ) {
super(parent,seed);
XmlAttribute att = seed.readAnnotation(XmlAttribute.class);
assert att!=null;
if(att.required())
isRequired = true;
else isRequired = nav().isPrimitive(getIndividualType());
this.xmlName = calcXmlName(att);
}
private QName calcXmlName(XmlAttribute att) {
String uri;
String local;
uri = att.namespace();
local = att.name();
// compute the default
if(local.equals("##default"))
local = NameConverter.standard.toVariableName(getName());
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.attributeFormDefault()) {
case QUALIFIED:
uri = parent.getTypeName().getNamespaceURI();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else
uri = "";
}
return new QName(uri.intern(),local.intern());
}
public boolean isRequired() {
return isRequired;
}
public final QName getXmlName() {
return xmlName;
}
public final PropertyKind kind() {
return PropertyKind.ATTRIBUTE;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.core.BuiltinLeafInfo;
import com.sun.xml.internal.bind.v2.model.core.LeafInfo;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* JAXB spec designates a few Java classes to be mapped to XML types
* in a way that ignores restrictions placed on user-defined beans.
*
* @author Kohsuke Kawaguchi
*/
public class BuiltinLeafInfoImpl<TypeT,ClassDeclT> extends LeafInfoImpl<TypeT,ClassDeclT> implements BuiltinLeafInfo<TypeT,ClassDeclT> {
private final QName[] typeNames;
protected BuiltinLeafInfoImpl(TypeT type, QName... typeNames) {
super(type, typeNames.length>0?typeNames[0]:null);
this.typeNames = typeNames;
}
/**
* Returns all the type names recognized by this bean info.
*
* @return
* do not modify the returned array.
*/
public final QName[] getTypeNames() {
return typeNames;
}
/**
* @deprecated always return false at this level.
*/
public final boolean isElement() {
return false;
}
/**
* @deprecated always return null at this level.
*/
public final QName getElementName() {
return null;
}
/**
* @deprecated always return null at this level.
*/
public final Element<TypeT,ClassDeclT> asElement() {
return null;
}
/**
* Creates all the {@link BuiltinLeafInfoImpl}s as specified in the spec.
*
* {@link LeafInfo}s are all defined by the spec.
*/
public static <TypeT,ClassDeclT>
Map<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>> createLeaves( Navigator<TypeT,ClassDeclT,?,?> nav ) {
Map<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>> leaves = new HashMap<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>>();
for( RuntimeBuiltinLeafInfoImpl<?> leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) {
TypeT t = nav.ref(leaf.getClazz());
leaves.put( t, new BuiltinLeafInfoImpl<TypeT,ClassDeclT>(t,leaf.getTypeNames()) );
}
return leaves;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
/**
* {@link PropertyInfo} that allows to add additional elements to the collection.
*
* @author Martin Grebac
*/
public interface DummyPropertyInfo<T, C, F, M> {
void addType(PropertyInfoImpl<T, C, F, M> info);
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
* Common part of {@link ElementPropertyInfoImpl} and {@link ReferencePropertyInfoImpl}.
*
* @author Kohsuke Kawaguchi
*/
abstract class ERPropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
extends PropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> {
public ERPropertyInfoImpl(ClassInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> classInfo, PropertySeed<TypeT, ClassDeclT, FieldT, MethodT> propertySeed) {
super(classInfo, propertySeed);
XmlElementWrapper e = seed.readAnnotation(XmlElementWrapper.class);
boolean nil = false;
boolean required = false;
if(!isCollection()) {
xmlName = null;
if(e!=null)
classInfo.builder.reportError(new IllegalAnnotationException(
Messages.XML_ELEMENT_WRAPPER_ON_NON_COLLECTION.format(
nav().getClassName(parent.getClazz())+'.'+seed.getName()),
e
));
} else {
if(e!=null) {
xmlName = calcXmlName(e);
nil = e.nillable();
required = e.required();
} else
xmlName = null;
}
wrapperNillable = nil;
wrapperRequired = required;
}
private final QName xmlName;
/**
* True if the wrapper tag name is nillable.
*/
private final boolean wrapperNillable;
/**
* True if the wrapper tag is required.
*/
private final boolean wrapperRequired;
/**
* Gets the wrapper element name.
*/
public final QName getXmlName() {
return xmlName;
}
public final boolean isCollectionNillable() {
return wrapperNillable;
}
public final boolean isCollectionRequired() {
return wrapperRequired;
}
}

View File

@@ -0,0 +1,430 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.activation.MimeType;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAttachmentRef;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlInlineBinaryData;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import com.sun.istack.internal.FinalArrayList;
import com.sun.xml.internal.bind.v2.TODO;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationSource;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.model.core.ElementInfo;
import com.sun.xml.internal.bind.v2.model.core.ElementPropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeRef;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.runtime.SwaRefAdapter;
/**
* {@link ElementInfo} implementation.
*
* @author Kohsuke Kawaguchi
*/
class ElementInfoImpl<T,C,F,M> extends TypeInfoImpl<T,C,F,M> implements ElementInfo<T,C> {
private final QName tagName;
private final NonElement<T,C> contentType;
private final T tOfJAXBElementT;
private final T elementType;
private final ClassInfo<T,C> scope;
/**
* Annotation that controls the binding.
*/
private final XmlElementDecl anno;
/**
* If this element can substitute another element, the element name.
* @see #link()
*/
private ElementInfoImpl<T,C,F,M> substitutionHead;
/**
* Lazily constructed list of {@link ElementInfo}s that can substitute this element.
* This could be null.
* @see #link()
*/
private FinalArrayList<ElementInfoImpl<T,C,F,M>> substitutionMembers;
/**
* The factory method from which this mapping was created.
*/
private final M method;
/**
* If the content type is adapter, return that adapter.
*/
private final Adapter<T,C> adapter;
private final boolean isCollection;
private final ID id;
private final PropertyImpl property;
private final MimeType expectedMimeType;
private final boolean inlineBinary;
private final QName schemaType;
/**
* Singleton instance of {@link ElementPropertyInfo} for this element.
*/
protected class PropertyImpl implements
ElementPropertyInfo<T,C>,
TypeRef<T,C>,
AnnotationSource {
//
// TypeRef impl
//
public NonElement<T,C> getTarget() {
return contentType;
}
public QName getTagName() {
return tagName;
}
public List<? extends TypeRef<T,C>> getTypes() {
return Collections.singletonList(this);
}
public List<? extends NonElement<T,C>> ref() {
return Collections.singletonList(contentType);
}
public QName getXmlName() {
return tagName;
}
public boolean isCollectionRequired() {
return false;
}
public boolean isCollectionNillable() {
return true;
}
public boolean isNillable() {
return true;
}
public String getDefaultValue() {
String v = anno.defaultValue();
if(v.equals("\u0000"))
return null;
else
return v;
}
public ElementInfoImpl<T,C,F,M> parent() {
return ElementInfoImpl.this;
}
public String getName() {
return "value";
}
public String displayName() {
return "JAXBElement#value";
}
public boolean isCollection() {
return isCollection;
}
/**
* For {@link ElementInfo}s, a collection always means a list of values.
*/
public boolean isValueList() {
return isCollection;
}
public boolean isRequired() {
return true;
}
public PropertyKind kind() {
return PropertyKind.ELEMENT;
}
public Adapter<T,C> getAdapter() {
return adapter;
}
public ID id() {
return id;
}
public MimeType getExpectedMimeType() {
return expectedMimeType;
}
public QName getSchemaType() {
return schemaType;
}
public boolean inlineBinaryData() {
return inlineBinary;
}
public PropertyInfo<T,C> getSource() {
return this;
}
//
//
// AnnotationSource impl
//
//
public <A extends Annotation> A readAnnotation(Class<A> annotationType) {
return reader().getMethodAnnotation(annotationType,method,ElementInfoImpl.this);
}
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return reader().hasMethodAnnotation(annotationType,method);
}
}
/**
* @param m
* The factory method on ObjectFactory that comes with {@link XmlElementDecl}.
*/
public ElementInfoImpl(ModelBuilder<T,C,F,M> builder,
RegistryInfoImpl<T,C,F,M> registry, M m ) throws IllegalAnnotationException {
super(builder,registry);
this.method = m;
anno = reader().getMethodAnnotation( XmlElementDecl.class, m, this );
assert anno!=null; // the caller should check this
assert anno instanceof Locatable;
elementType = nav().getReturnType(m);
T baseClass = nav().getBaseClass(elementType,nav().asDecl(JAXBElement.class));
if(baseClass==null)
throw new IllegalAnnotationException(
Messages.XML_ELEMENT_MAPPING_ON_NON_IXMLELEMENT_METHOD.format(nav().getMethodName(m)),
anno );
tagName = parseElementName(anno);
T[] methodParams = nav().getMethodParameters(m);
// adapter
Adapter<T,C> a = null;
if(methodParams.length>0) {
XmlJavaTypeAdapter adapter = reader().getMethodAnnotation(XmlJavaTypeAdapter.class,m,this);
if(adapter!=null)
a = new Adapter<T,C>(adapter,reader(),nav());
else {
XmlAttachmentRef xsa = reader().getMethodAnnotation(XmlAttachmentRef.class,m,this);
if(xsa!=null) {
TODO.prototype("in Annotation Processing swaRefAdapter isn't avaialble, so this returns null");
a = new Adapter<T,C>(owner.nav.asDecl(SwaRefAdapter.class),owner.nav);
}
}
}
this.adapter = a;
// T of JAXBElement<T>
tOfJAXBElementT =
methodParams.length>0 ? methodParams[0] // this is more reliable, as it works even for ObjectFactory that sometimes have to return public types
: nav().getTypeArgument(baseClass,0); // fall back to infer from the return type if no parameter.
if(adapter==null) {
T list = nav().getBaseClass(tOfJAXBElementT,nav().asDecl(List.class));
if(list==null) {
isCollection = false;
contentType = builder.getTypeInfo(tOfJAXBElementT,this); // suck this type into the current set.
} else {
isCollection = true;
contentType = builder.getTypeInfo(nav().getTypeArgument(list,0),this);
}
} else {
// but if adapted, use the adapted type
contentType = builder.getTypeInfo(this.adapter.defaultType,this);
isCollection = false;
}
// scope
T s = reader().getClassValue(anno,"scope");
if(nav().isSameType(s, nav().ref(XmlElementDecl.GLOBAL.class)))
scope = null;
else {
// TODO: what happens if there's an error?
NonElement<T,C> scp = builder.getClassInfo(nav().asDecl(s),this);
if(!(scp instanceof ClassInfo)) {
throw new IllegalAnnotationException(
Messages.SCOPE_IS_NOT_COMPLEXTYPE.format(nav().getTypeName(s)),
anno );
}
scope = (ClassInfo<T,C>)scp;
}
id = calcId();
property = createPropertyImpl();
this.expectedMimeType = Util.calcExpectedMediaType(property,builder);
this.inlineBinary = reader().hasMethodAnnotation(XmlInlineBinaryData.class,method);
this.schemaType = Util.calcSchemaType(reader(),property,registry.registryClass,
getContentInMemoryType(),this);
}
final QName parseElementName(XmlElementDecl e) {
String local = e.name();
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
nav().getDeclaringClassForMethod(method),this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
protected PropertyImpl createPropertyImpl() {
return new PropertyImpl();
}
public ElementPropertyInfo<T,C> getProperty() {
return property;
}
public NonElement<T,C> getContentType() {
return contentType;
}
public T getContentInMemoryType() {
if(adapter==null) {
return tOfJAXBElementT;
} else {
return adapter.customType;
}
}
public QName getElementName() {
return tagName;
}
public T getType() {
return elementType;
}
/**
* Leaf-type cannot be referenced from IDREF.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return false;
}
private ID calcId() {
// TODO: share code with PropertyInfoImpl
if(reader().hasMethodAnnotation(XmlID.class,method)) {
return ID.ID;
} else
if(reader().hasMethodAnnotation(XmlIDREF.class,method)) {
return ID.IDREF;
} else {
return ID.NONE;
}
}
public ClassInfo<T, C> getScope() {
return scope;
}
public ElementInfo<T,C> getSubstitutionHead() {
return substitutionHead;
}
public Collection<? extends ElementInfoImpl<T,C,F,M>> getSubstitutionMembers() {
if(substitutionMembers==null)
return Collections.emptyList();
else
return substitutionMembers;
}
/**
* Called after all the {@link TypeInfo}s are collected into the {@link #owner}.
*/
/*package*/ void link() {
// substitution head
if(anno.substitutionHeadName().length()!=0) {
QName name = new QName(
anno.substitutionHeadNamespace(), anno.substitutionHeadName() );
substitutionHead = owner.getElementInfo(null,name);
if(substitutionHead==null) {
builder.reportError(
new IllegalAnnotationException(Messages.NON_EXISTENT_ELEMENT_MAPPING.format(
name.getNamespaceURI(),name.getLocalPart()), anno));
// recover by ignoring this substitution declaration
} else
substitutionHead.addSubstitutionMember(this);
} else
substitutionHead = null;
super.link();
}
private void addSubstitutionMember(ElementInfoImpl<T,C,F,M> child) {
if(substitutionMembers==null)
substitutionMembers = new FinalArrayList<ElementInfoImpl<T,C,F,M>>();
substitutionMembers.add(child);
}
public Location getLocation() {
return nav().getMethodLocation(method);
}
}

View File

@@ -0,0 +1,201 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlList;
import javax.xml.namespace.QName;
import com.sun.istack.internal.FinalArrayList;
import com.sun.xml.internal.bind.v2.model.core.ElementPropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeRef;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
* Common {@link ElementPropertyInfo} implementation used for both
* Annotation Processing and runtime.
*
* @author Kohsuke Kawaguchi
*/
class ElementPropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
extends ERPropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
implements ElementPropertyInfo<TypeT,ClassDeclT>
{
/**
* Lazily computed.
* @see #getTypes()
*/
private List<TypeRefImpl<TypeT,ClassDeclT>> types;
private final List<TypeInfo<TypeT,ClassDeclT>> ref = new AbstractList<TypeInfo<TypeT,ClassDeclT>>() {
public TypeInfo<TypeT,ClassDeclT> get(int index) {
return getTypes().get(index).getTarget();
}
public int size() {
return getTypes().size();
}
};
/**
* Lazily computed.
* @see #isRequired()
*/
private Boolean isRequired;
/**
* @see #isValueList()
*/
private final boolean isValueList;
ElementPropertyInfoImpl(
ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent,
PropertySeed<TypeT,ClassDeclT,FieldT,MethodT> propertySeed) {
super(parent, propertySeed);
isValueList = seed.hasAnnotation(XmlList.class);
}
public List<? extends TypeRefImpl<TypeT,ClassDeclT>> getTypes() {
if(types==null) {
types = new FinalArrayList<TypeRefImpl<TypeT,ClassDeclT>>();
XmlElement[] ann=null;
XmlElement xe = seed.readAnnotation(XmlElement.class);
XmlElements xes = seed.readAnnotation(XmlElements.class);
if(xe!=null && xes!=null) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format(
nav().getClassName(parent.getClazz())+'#'+seed.getName(),
xe.annotationType().getName(), xes.annotationType().getName()),
xe, xes ));
}
isRequired = true;
if(xe!=null)
ann = new XmlElement[]{xe};
else
if(xes!=null)
ann = xes.value();
if(ann==null) {
// default
TypeT t = getIndividualType();
if(!nav().isPrimitive(t) || isCollection())
isRequired = false;
// nillableness defaults to true if it's collection
types.add(createTypeRef(calcXmlName((XmlElement)null),t,isCollection(),null));
} else {
for( XmlElement item : ann ) {
// TODO: handle defaulting in names.
QName name = calcXmlName(item);
TypeT type = reader().getClassValue(item, "type");
if (nav().isSameType(type, nav().ref(XmlElement.DEFAULT.class)))
type = getIndividualType();
if((!nav().isPrimitive(type) || isCollection()) && !item.required())
isRequired = false;
types.add(createTypeRef(name, type, item.nillable(), getDefaultValue(item.defaultValue()) ));
}
}
types = Collections.unmodifiableList(types);
assert !types.contains(null);
}
return types;
}
private String getDefaultValue(String value) {
if(value.equals("\u0000"))
return null;
else
return value;
}
/**
* Used by {@link PropertyInfoImpl} to create new instances of {@link TypeRef}
*/
protected TypeRefImpl<TypeT,ClassDeclT> createTypeRef(QName name,TypeT type,boolean isNillable,String defaultValue) {
return new TypeRefImpl<TypeT,ClassDeclT>(this,name,type,isNillable,defaultValue);
}
public boolean isValueList() {
return isValueList;
}
public boolean isRequired() {
if(isRequired==null)
getTypes(); // compute the value
return isRequired;
}
public List<? extends TypeInfo<TypeT,ClassDeclT>> ref() {
return ref;
}
public final PropertyKind kind() {
return PropertyKind.ELEMENT;
}
protected void link() {
super.link();
for (TypeRefImpl<TypeT, ClassDeclT> ref : getTypes() ) {
ref.link();
}
if(isValueList()) {
// ugly test, because IDREF's are represented as text on the wire,
// it's OK to be a value list in that case.
if(id()!= ID.IDREF) {
// check if all the item types are simple types
// this can't be done when we compute types because
// not all TypeInfos are available yet
for (TypeRefImpl<TypeT,ClassDeclT> ref : types) {
if(!ref.getTarget().isSimpleType()) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.XMLLIST_NEEDS_SIMPLETYPE.format(
nav().getTypeName(ref.getTarget().getType())), this ));
break;
}
}
}
if(!isCollection())
parent.builder.reportError(new IllegalAnnotationException(
Messages.XMLLIST_ON_SINGLE_PROPERTY.format(), this
));
}
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import com.sun.xml.internal.bind.v2.model.core.EnumConstant;
import com.sun.xml.internal.bind.v2.model.core.EnumLeafInfo;
/**
* @author Kohsuke Kawaguchi
*/
class EnumConstantImpl<T,C,F,M> implements EnumConstant<T,C> {
protected final String lexical;
protected final EnumLeafInfoImpl<T,C,F,M> owner;
protected final String name;
/**
* All the constants of the {@link EnumConstantImpl} is linked in one list.
*/
protected final EnumConstantImpl<T,C,F,M> next;
public EnumConstantImpl(EnumLeafInfoImpl<T,C,F,M> owner, String name, String lexical, EnumConstantImpl<T,C,F,M> next) {
this.lexical = lexical;
this.owner = owner;
this.name = name;
this.next = next;
}
public EnumLeafInfo<T,C> getEnclosingClass() {
return owner;
}
public final String getLexicalValue() {
return lexical;
}
public final String getName() {
return name;
}
}

View File

@@ -0,0 +1,260 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Iterator;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.EnumConstant;
import com.sun.xml.internal.bind.v2.model.core.EnumLeafInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.runtime.Location;
import java.util.Collection;
import javax.xml.bind.annotation.XmlSchemaType;
/**
* {@link EnumLeafInfo} implementation.
*
* @author Kohsuke Kawaguchi
*/
class EnumLeafInfoImpl<T,C,F,M> extends TypeInfoImpl<T,C,F,M>
implements EnumLeafInfo<T,C>, Element<T,C>, Iterable<EnumConstantImpl<T,C,F,M>> {
/**
* The enum class whose information this object represents.
*/
/*package*/ final C clazz;
NonElement<T,C> baseType;
private final T type;
/**
* Can be null for anonymous types.
*/
private final QName typeName;
/**
* All the {@link EnumConstantImpl}s are linked in this list.
*/
private EnumConstantImpl<T,C,F,M> firstConstant;
/**
* If this enum is also bound to an element, that tag name.
* Or else null.
*/
private QName elementName;
/**
* Used to recognize token vs string.
*/
protected boolean tokenStringType;
/**
* @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);
}
}
/**
* Build {@link EnumConstant}s and discover/report any error in it.
*/
protected void calcConstants() {
EnumConstantImpl<T,C,F,M> last = null;
// first check if we represent xs:token derived type
Collection<? extends F> fields = nav().getDeclaredFields(clazz);
for (F f : fields) {
if (nav().isSameType(nav().getFieldType(f), nav().ref(String.class))) {
XmlSchemaType schemaTypeAnnotation = builder.reader.getFieldAnnotation(XmlSchemaType.class, f, this);
if (schemaTypeAnnotation != null) {
if ("token".equals(schemaTypeAnnotation.name())) {
tokenStringType = true;
break;
}
};
}
}
F[] constants = nav().getEnumConstants(clazz);
for( int i=constants.length-1; i>=0; i-- ) {
F constant = constants[i];
String name = nav().getFieldName(constant);
XmlEnumValue xev = builder.reader.getFieldAnnotation(XmlEnumValue.class, constant, this);
String literal;
if(xev==null) literal = name;
else literal = xev.value();
last = createEnumConstant(name,literal,constant,last);
}
this.firstConstant = last;
}
protected EnumConstantImpl<T,C,F,M> createEnumConstant(String name, String literal, F constant, EnumConstantImpl<T,C,F,M> last) {
return new EnumConstantImpl<T,C,F,M>(this, name, literal, last);
}
public T getType() {
return type;
}
/**
*
* @return true if enum is restriction/extension from xs:token type, otherwise false
*/
public boolean isToken() {
return tokenStringType;
}
/**
* Leaf-type cannot be referenced from IDREF.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return false;
}
public QName getTypeName() {
return typeName;
}
public C getClazz() {
return clazz;
}
public NonElement<T,C> getBaseType() {
return baseType;
}
public boolean isSimpleType() {
return true;
}
public Location getLocation() {
return nav().getClassLocation(clazz);
}
public Iterable<? extends EnumConstantImpl<T,C,F,M>> getConstants() {
if(firstConstant==null)
calcConstants();
return this;
}
@Override
public void link() {
// make sure we've computed constants
getConstants();
super.link();
}
/**
* No substitution.
*
* @deprecated if you are invoking this method directly, there's something wrong.
*/
public Element<T, C> getSubstitutionHead() {
return null;
}
public QName getElementName() {
return elementName;
}
public boolean isElement() {
return elementName!=null;
}
public Element<T,C> asElement() {
if(isElement())
return this;
else
return null;
}
/**
* When a bean binds to an element, it's always through {@link XmlRootElement},
* so this method always return null.
*
* @deprecated
* you shouldn't be invoking this method on {@link ClassInfoImpl}.
*/
public ClassInfo<T,C> getScope() {
return null;
}
public Iterator<EnumConstantImpl<T,C,F,M>> iterator() {
return new Iterator<EnumConstantImpl<T,C,F,M>>() {
private EnumConstantImpl<T,C,F,M> next = firstConstant;
public boolean hasNext() {
return next!=null;
}
public EnumConstantImpl<T,C,F,M> next() {
EnumConstantImpl<T,C,F,M> r = next;
next = next.next;
return r;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.annotation.Annotation;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link PropertyInfo} implementation backed by a field.
*/
class FieldPropertySeed<TypeT,ClassDeclT,FieldT,MethodT> implements
PropertySeed<TypeT,ClassDeclT,FieldT,MethodT> {
protected final FieldT field;
private ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent;
FieldPropertySeed(ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> classInfo, FieldT field) {
this.parent = classInfo;
this.field = field;
}
public <A extends Annotation> A readAnnotation(Class<A> a) {
return parent.reader().getFieldAnnotation(a, field,this);
}
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return parent.reader().hasFieldAnnotation(annotationType,field);
}
public String getName() {
// according to the spec team, the BeanIntrospector.decapitalize does not apply
// to the fields. Don't call Introspector.decapitalize
return parent.nav().getFieldName(field);
}
public TypeT getRawType() {
return parent.nav().getFieldType(field);
}
/**
* Use the enclosing class as the upsream {@link Location}.
*/
public Locatable getUpstream() {
return parent;
}
public Location getLocation() {
return parent.nav().getFieldLocation(field);
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.annotation.Annotation;
import java.beans.Introspector;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link PropertyInfo} implementation backed by a getter and a setter.
*
* We allow the getter or setter to be null, in which case the bean
* can only participate in unmarshalling (or marshalling)
*/
class GetterSetterPropertySeed<TypeT,ClassDeclT,FieldT,MethodT> implements
PropertySeed<TypeT,ClassDeclT,FieldT,MethodT> {
protected final MethodT getter;
protected final MethodT setter;
private ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent;
GetterSetterPropertySeed(ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent, MethodT getter, MethodT setter) {
this.parent = parent;
this.getter = getter;
this.setter = setter;
if(getter==null && setter==null)
throw new IllegalArgumentException();
}
public TypeT getRawType() {
if(getter!=null)
return parent.nav().getReturnType(getter);
else
return parent.nav().getMethodParameters(setter)[0];
}
public <A extends Annotation> A readAnnotation(Class<A> annotation) {
return parent.reader().getMethodAnnotation(annotation, getter,setter,this);
}
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return parent.reader().hasMethodAnnotation(annotationType,getName(),getter,setter,this);
}
public String getName() {
if(getter!=null)
return getName(getter);
else
return getName(setter);
}
private String getName(MethodT m) {
String seed = parent.nav().getMethodName(m);
String lseed = seed.toLowerCase();
if(lseed.startsWith("get") || lseed.startsWith("set"))
return camelize(seed.substring(3));
if(lseed.startsWith("is"))
return camelize(seed.substring(2));
return seed;
}
private static String camelize(String s) {
return Introspector.decapitalize(s);
}
/**
* Use the enclosing class as the upsream {@link Location}.
*/
public Locatable getUpstream() {
return parent;
}
public Location getLocation() {
if(getter!=null)
return parent.nav().getMethodLocation(getter);
else
return parent.nav().getMethodLocation(setter);
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.LeafInfo;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* @author Kohsuke Kawaguchi
*/
abstract class LeafInfoImpl<TypeT,ClassDeclT> implements LeafInfo<TypeT,ClassDeclT>, Location {
private final TypeT type;
/**
* Can be null for anonymous types.
*/
private final QName typeName;
protected LeafInfoImpl(TypeT type,QName typeName) {
assert type!=null;
this.type = type;
this.typeName = typeName;
}
/**
* A reference to the representation of the type.
*/
public TypeT getType() {
return type;
}
/**
* Leaf-type cannot be referenced from IDREF.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return false;
}
public QName getTypeName() {
return typeName;
}
public Locatable getUpstream() {
return null;
}
public Location getLocation() {
// this isn't very accurate, but it's not too bad
// doing it correctly need leaves to hold navigator.
// otherwise revisit the design so that we take navigator as a parameter
return this;
}
public boolean isSimpleType() {
return true;
}
public String toString() {
return type.toString();
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.core.MapPropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
/**
* @author Kohsuke Kawaguchi
*/
class MapPropertyInfoImpl<T,C,F,M> extends PropertyInfoImpl<T,C,F,M> implements MapPropertyInfo<T,C> {
private final QName xmlName;
private boolean nil;
private final T keyType;
private final T valueType;
// laziy computed to handle cyclic references
private NonElement<T,C> keyTypeInfo;
private NonElement<T,C> valueTypeInfo;
public MapPropertyInfoImpl(ClassInfoImpl<T,C,F,M> ci, PropertySeed<T,C,F,M> seed) {
super(ci, seed);
XmlElementWrapper xe = seed.readAnnotation(XmlElementWrapper.class);
xmlName = calcXmlName(xe);
nil = xe!=null && xe.nillable();
T raw = getRawType();
T bt = nav().getBaseClass(raw, nav().asDecl(Map.class) );
assert bt!=null; // Map property is only for Maps
if(nav().isParameterizedType(bt)) {
keyType = nav().getTypeArgument(bt,0);
valueType = nav().getTypeArgument(bt,1);
} else {
keyType = valueType = nav().ref(Object.class);
}
}
public Collection<? extends TypeInfo<T,C>> ref() {
return Arrays.asList(getKeyType(),getValueType());
}
public final PropertyKind kind() {
return PropertyKind.MAP;
}
public QName getXmlName() {
return xmlName;
}
public boolean isCollectionNillable() {
return nil;
}
public NonElement<T,C> getKeyType() {
if(keyTypeInfo==null)
keyTypeInfo = getTarget(keyType);
return keyTypeInfo;
}
public NonElement<T,C> getValueType() {
if(valueTypeInfo==null)
valueTypeInfo = getTarget(valueType);
return valueTypeInfo;
}
public NonElement<T,C> getTarget(T type) {
assert parent.builder!=null : "this method must be called during the build stage";
return parent.builder.getTypeInfo(type,this);
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/**
* Message resources
*/
enum Messages {
// ClassInfoImpl
ID_MUST_BE_STRING, // 1 arg
MUTUALLY_EXCLUSIVE_ANNOTATIONS, // 2 args
DUPLICATE_ANNOTATIONS, // 1 arg
NO_DEFAULT_CONSTRUCTOR, // 1 arg
CANT_HANDLE_INTERFACE, // 1 arg
CANT_HANDLE_INNER_CLASS, // 1 arg
ANNOTATION_ON_WRONG_METHOD, // 0 args
GETTER_SETTER_INCOMPATIBLE_TYPE, // 2 args
DUPLICATE_ENTRY_IN_PROP_ORDER, // 1 arg
DUPLICATE_PROPERTIES, // 1 arg
XML_ELEMENT_MAPPING_ON_NON_IXMLELEMENT_METHOD, // 1 arg
SCOPE_IS_NOT_COMPLEXTYPE, // 1 arg
CONFLICTING_XML_ELEMENT_MAPPING, // 2 args
REFERENCE_TO_NON_ELEMENT, // 1 arg
NON_EXISTENT_ELEMENT_MAPPING, // 2 args
TWO_ATTRIBUTE_WILDCARDS, // 1 arg
SUPER_CLASS_HAS_WILDCARD, // 0 args
INVALID_ATTRIBUTE_WILDCARD_TYPE, // 1 arg
PROPERTY_MISSING_FROM_ORDER, // 1 arg
PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY, // 2 args
INVALID_XML_ENUM_VALUE, // 2 arg
NO_IMAGE_WRITER, // 1 arg
ILLEGAL_MIME_TYPE, // 2 args
ILLEGAL_ANNOTATION, // 1 arg
MULTIPLE_VALUE_PROPERTY, // 0 args
ELEMENT_AND_VALUE_PROPERTY, // 0 args
CONFLICTING_XML_TYPE_MAPPING, // 1 arg
XMLVALUE_IN_DERIVED_TYPE, // 0 args
SIMPLE_TYPE_IS_REQUIRED, // 1 arg
PROPERTY_COLLISION, // 1 arg
INVALID_IDREF, // 1 arg
INVALID_XML_ELEMENT_REF, // 1 arg
NO_XML_ELEMENT_DECL, // 2 args
XML_ELEMENT_WRAPPER_ON_NON_COLLECTION, // 1 arg
ANNOTATION_NOT_ALLOWED, // 1 arg
XMLLIST_NEEDS_SIMPLETYPE, // 1 arg
XMLLIST_ON_SINGLE_PROPERTY, // 0 arg
NO_FACTORY_METHOD, // 2 args
FACTORY_CLASS_NEEDS_FACTORY_METHOD, // 1 arg
INCOMPATIBLE_API_VERSION, // 2 args
INCOMPATIBLE_API_VERSION_MUSTANG, // 2 args
RUNNING_WITH_1_0_RUNTIME, // 2 args
MISSING_JAXB_PROPERTIES, // 1arg
TRANSIENT_FIELD_NOT_BINDABLE, // 1 arg
THERE_MUST_BE_VALUE_IN_XMLVALUE, // 1 arg
UNMATCHABLE_ADAPTER, // 2 args
ANONYMOUS_ARRAY_ITEM, // 1 arg
ACCESSORFACTORY_INSTANTIATION_EXCEPTION, // 2 arg
ACCESSORFACTORY_ACCESS_EXCEPTION, // 2 arg
CUSTOM_ACCESSORFACTORY_PROPERTY_ERROR, // 2 arg
CUSTOM_ACCESSORFACTORY_FIELD_ERROR, // 2 arg
XMLGREGORIANCALENDAR_INVALID, // 1 arg
XMLGREGORIANCALENDAR_SEC, // 0 arg
XMLGREGORIANCALENDAR_MIN, // 0 arg
XMLGREGORIANCALENDAR_HR, // 0 arg
XMLGREGORIANCALENDAR_DAY, // 0 arg
XMLGREGORIANCALENDAR_MONTH, // 0 arg
XMLGREGORIANCALENDAR_YEAR, // 0 arg
XMLGREGORIANCALENDAR_TIMEZONE, // 0 arg
;
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getName());
@Override
public String toString() {
return format();
}
public String format( Object... args ) {
return MessageFormat.format( rb.getString(name()), args );
}
}

View File

@@ -0,0 +1,485 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAttachmentRef;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.util.Which;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.annotation.ClassLocatable;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
import com.sun.xml.internal.bind.v2.model.core.LeafInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.Ref;
import com.sun.xml.internal.bind.v2.model.core.RegistryInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.WhiteSpaceProcessor;
/**
* Builds a {@link TypeInfoSet} (a set of JAXB properties)
* by using {@link ElementInfoImpl} and {@link ClassInfoImpl}.
* from annotated Java classes.
*
* <p>
* This class uses {@link Navigator} and {@link AnnotationReader} to
* work with arbitrary annotation source and arbitrary Java model.
* For this purpose this class is parameterized.
*
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class ModelBuilder<T,C,F,M> implements ModelBuilderI<T,C,F,M> {
private static final Logger logger;
/**
* {@link TypeInfo}s that are built will go into this set.
*/
final TypeInfoSetImpl<T,C,F,M> typeInfoSet;
public final AnnotationReader<T,C,F,M> reader;
public final Navigator<T,C,F,M> nav;
/**
* Used to detect collisions among global type names.
*/
private final Map<QName,TypeInfo> typeNames = new HashMap<QName,TypeInfo>();
/**
* JAXB doesn't want to use namespaces unless we are told to, but WS-I BP
* conformace requires JAX-RPC to always use a non-empty namespace URI.
* (see http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#WSDLTYPES R2105)
*
* <p>
* To work around this issue, we allow the use of the empty namespaces to be
* replaced by a particular designated namespace URI.
*
* <p>
* This field keeps the value of that replacing namespace URI.
* When there's no replacement, this field is set to "".
*/
public final String defaultNsUri;
/**
* Packages whose registries are already added.
*/
/*package*/ final Map<String,RegistryInfoImpl<T,C,F,M>> registries
= new HashMap<String,RegistryInfoImpl<T,C,F,M>>();
private final Map<C,C> subclassReplacements;
/**
* @see #setErrorHandler
*/
private ErrorHandler errorHandler;
private boolean hadError;
/**
* Set to true if the model includes {@link XmlAttachmentRef}. JAX-WS
* needs to know this information.
*/
public boolean hasSwaRef;
private final ErrorHandler proxyErrorHandler = new ErrorHandler() {
public void error(IllegalAnnotationException e) {
reportError(e);
}
};
public ModelBuilder(
AnnotationReader<T, C, F, M> reader,
Navigator<T, C, F, M> navigator,
Map<C, C> subclassReplacements,
String defaultNamespaceRemap
) {
this.reader = reader;
this.nav = navigator;
this.subclassReplacements = subclassReplacements;
if(defaultNamespaceRemap==null)
defaultNamespaceRemap = "";
this.defaultNsUri = defaultNamespaceRemap;
reader.setErrorHandler(proxyErrorHandler);
typeInfoSet = createTypeInfoSet();
}
/**
* Makes sure that we are running with 2.1 JAXB API,
* and report an error if not.
*/
static {
try {
XmlSchema s = null;
s.location();
} catch (NullPointerException e) {
// as epxected
} catch (NoSuchMethodError e) {
// this is not a 2.1 API. Where is it being loaded from?
Messages res;
if (SecureLoader.getClassClassLoader(XmlSchema.class) == null) {
res = Messages.INCOMPATIBLE_API_VERSION_MUSTANG;
} else {
res = Messages.INCOMPATIBLE_API_VERSION;
}
throw new LinkageError( res.format(
Which.which(XmlSchema.class),
Which.which(ModelBuilder.class)
));
}
}
/**
* Makes sure that we don't have conflicting 1.0 runtime,
* and report an error if we do.
*/
static {
try {
WhiteSpaceProcessor.isWhiteSpace("xyz");
} catch (NoSuchMethodError e) {
// we seem to be getting 1.0 runtime
throw new LinkageError( Messages.RUNNING_WITH_1_0_RUNTIME.format(
Which.which(WhiteSpaceProcessor.class),
Which.which(ModelBuilder.class)
));
}
}
/**
* Logger init
*/
static {
logger = Logger.getLogger(ModelBuilder.class.getName());
}
protected TypeInfoSetImpl<T,C,F,M> createTypeInfoSet() {
return new TypeInfoSetImpl<T,C,F,M>(nav,reader,BuiltinLeafInfoImpl.createLeaves(nav));
}
/**
* Builds a JAXB {@link ClassInfo} model from a given class declaration
* and adds that to this model owner.
*
* <p>
* Return type is either {@link ClassInfo} or {@link LeafInfo} (for types like
* {@link String} or {@link Enum}-derived ones)
*/
public NonElement<T,C> getClassInfo( C clazz, Locatable upstream ) {
return getClassInfo(clazz,false,upstream);
}
/**
* 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;
}
/**
* Adding package's ObjectFactory methods to registry
* @param clazz which package will be used
* @param p location
*/
private void addToRegistry(C clazz, Locatable p) {
String pkg = nav.getPackageName(clazz);
if (!registries.containsKey(pkg)) {
// insert the package's object factory
C c = nav.loadObjectFactory(clazz, pkg);
if (c != null)
addRegistry(c, p);
}
}
/**
* Getting parametrized classes of {@code JAXBElement<...>} property
* @param p property which parametrized types we will try to get
* @return null - if it's not JAXBElement property, or it's not parametrized, and array of parametrized classes in other case
*/
private Class[] getParametrizedTypes(PropertyInfo p) {
try {
Type pType = ((RuntimePropertyInfo) p).getIndividualType();
if (pType instanceof ParameterizedType) {
ParameterizedType prmzdType = (ParameterizedType) pType;
if (prmzdType.getRawType() == JAXBElement.class) {
Type[] actualTypes = prmzdType.getActualTypeArguments();
Class[] result = new Class[actualTypes.length];
for (int i = 0; i < actualTypes.length; i++) {
result[i] = (Class) actualTypes[i];
}
return result;
}
}
} catch (Exception e) {
logger.log(Level.FINE, "Error in ModelBuilder.getParametrizedTypes. " + e.getMessage());
}
return null;
}
/**
* Checks the uniqueness of the type name.
*/
private void addTypeName(NonElement<T, C> r) {
QName t = r.getTypeName();
if(t==null) return;
TypeInfo old = typeNames.put(t,r);
if(old!=null) {
// collision
reportError(new IllegalAnnotationException(
Messages.CONFLICTING_XML_TYPE_MAPPING.format(r.getTypeName()),
old, r ));
}
}
/**
* 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);
}
/**
* This method is used to add a root reference to a model.
*/
public NonElement<T,C> getTypeInfo(Ref<T,C> ref) {
// TODO: handle XmlValueList
assert !ref.valueList;
C c = nav.asDecl(ref.type);
if(c!=null && reader.getClassAnnotation(XmlRegistry.class,c,null/*TODO: is this right?*/)!=null) {
if(!registries.containsKey(nav.getPackageName(c)))
addRegistry(c,null);
return null; // TODO: is this correct?
} else
return getTypeInfo(ref.type,null);
}
protected EnumLeafInfoImpl<T,C,F,M> createEnumLeafInfo(C clazz,Locatable upstream) {
return new EnumLeafInfoImpl<T,C,F,M>(this,upstream,clazz,nav.use(clazz));
}
protected ClassInfoImpl<T,C,F,M> createClassInfo(C clazz, Locatable upstream ) {
return new ClassInfoImpl<T,C,F,M>(this,upstream,clazz);
}
protected ElementInfoImpl<T,C,F,M> createElementInfo(
RegistryInfoImpl<T,C,F,M> registryInfo, M m) throws IllegalAnnotationException {
return new ElementInfoImpl<T,C,F,M>(this,registryInfo,m);
}
protected ArrayInfoImpl<T,C,F,M> createArrayInfo(Locatable upstream, T arrayType) {
return new ArrayInfoImpl<T, C, F, M>(this,upstream,arrayType);
}
/**
* Visits a class with {@link XmlRegistry} and records all the element mappings
* in it.
*/
public RegistryInfo<T,C> addRegistry(C registryClass, Locatable upstream ) {
return new RegistryInfoImpl<T,C,F,M>(this,upstream,registryClass);
}
/**
* Gets a {@link RegistryInfo} for the given package.
*
* @return
* null if no registry exists for the package.
* unlike other getXXX methods on this class,
* this method is side-effect free.
*/
public RegistryInfo<T,C> getRegistry(String packageName) {
return registries.get(packageName);
}
private boolean linked;
/**
* Called after all the classes are added to the type set
* to "link" them together.
*
* <p>
* Don't expose implementation classes in the signature.
*
* @return
* fully built {@link TypeInfoSet} that represents the model,
* or null if there was an error.
*/
public TypeInfoSet<T,C,F,M> link() {
assert !linked;
linked = true;
for( ElementInfoImpl ei : typeInfoSet.getAllElements() )
ei.link();
for( ClassInfoImpl ci : typeInfoSet.beans().values() )
ci.link();
for( EnumLeafInfoImpl li : typeInfoSet.enums().values() )
li.link();
if(hadError)
return null;
else
return typeInfoSet;
}
//
//
// error handling
//
//
/**
* Sets the error handler that receives errors discovered during the model building.
*
* @param errorHandler
* can be null.
*/
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
public final void reportError(IllegalAnnotationException e) {
hadError = true;
if(errorHandler!=null)
errorHandler.error(e);
}
public boolean isReplaced(C sc) {
return subclassReplacements.containsKey(sc);
}
@Override
public Navigator<T, C, F, M> getNavigator() {
return nav;
}
@Override
public AnnotationReader<T, C, F, M> getReader() {
return reader;
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* User: Iaroslav Savytskyi
* Date: 24/05/12
*/
public interface ModelBuilderI<T,C,F,M> {
Navigator<T,C,F,M> getNavigator();
AnnotationReader<T,C,F,M> getReader();
}

View File

@@ -0,0 +1,386 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Collection;
import java.lang.annotation.Annotation;
import javax.activation.MimeType;
import javax.xml.bind.annotation.XmlAttachmentRef;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlInlineBinaryData;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.TODO;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.runtime.SwaRefAdapter;
/**
* Default partial implementation for {@link PropertyInfo}.
*
* @author Kohsuke Kawaguchi
*/
abstract class PropertyInfoImpl<T,C,F,M>
implements PropertyInfo<T,C>, Locatable, Comparable<PropertyInfoImpl> /*by their names*/ {
/**
* Object that reads annotations.
*/
protected final PropertySeed<T,C,F,M> seed;
private final boolean isCollection;
private final ID id;
private final MimeType expectedMimeType;
private final boolean inlineBinary;
private final QName schemaType;
protected final ClassInfoImpl<T,C,F,M> parent;
private final Adapter<T,C> adapter;
protected PropertyInfoImpl(ClassInfoImpl<T,C,F,M> parent, PropertySeed<T,C,F,M> spi) {
this.seed = spi;
this.parent = parent;
if(parent==null)
/*
Various people reported a bug where this parameter is somehow null.
In an attempt to catch the error better, let's do an explicit check here.
http://forums.java.net/jive/thread.jspa?threadID=18479
http://forums.java.net/jive/thread.jspa?messageID=165946
*/
throw new AssertionError();
MimeType mt = Util.calcExpectedMediaType(seed,parent.builder);
if(mt!=null && !kind().canHaveXmlMimeType) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.ILLEGAL_ANNOTATION.format(XmlMimeType.class.getName()),
seed.readAnnotation(XmlMimeType.class)
));
mt = null;
}
this.expectedMimeType = mt;
this.inlineBinary = seed.hasAnnotation(XmlInlineBinaryData.class);
T t = seed.getRawType();
// check if there's an adapter applicable to the whole property
XmlJavaTypeAdapter xjta = getApplicableAdapter(t);
if(xjta!=null) {
isCollection = false;
adapter = new Adapter<T,C>(xjta,reader(),nav());
} else {
// check if the adapter is applicable to the individual item in the property
this.isCollection = nav().isSubClassOf(t, nav().ref(Collection.class))
|| nav().isArrayButNotByteArray(t);
xjta = getApplicableAdapter(getIndividualType());
if(xjta==null) {
// ugly ugly hack, but we implement swaRef as adapter
XmlAttachmentRef xsa = seed.readAnnotation(XmlAttachmentRef.class);
if(xsa!=null) {
parent.builder.hasSwaRef = true;
adapter = new Adapter<T,C>(nav().asDecl(SwaRefAdapter.class),nav());
} else {
adapter = null;
// if this field has adapter annotation but not applicable,
// that must be an error of the user
xjta = seed.readAnnotation(XmlJavaTypeAdapter.class);
if(xjta!=null) {
T ad = reader().getClassValue(xjta,"value");
parent.builder.reportError(new IllegalAnnotationException(
Messages.UNMATCHABLE_ADAPTER.format(
nav().getTypeName(ad), nav().getTypeName(t)),
xjta
));
}
}
} else {
adapter = new Adapter<T,C>(xjta,reader(),nav());
}
}
this.id = calcId();
this.schemaType = Util.calcSchemaType(reader(),seed,parent.clazz,
getIndividualType(),this);
}
public ClassInfoImpl<T,C,F,M> parent() {
return parent;
}
protected final Navigator<T,C,F,M> nav() {
return parent.nav();
}
protected final AnnotationReader<T,C,F,M> reader() {
return parent.reader();
}
public T getRawType() {
return seed.getRawType();
}
public T getIndividualType() {
if(adapter!=null)
return adapter.defaultType;
T raw = getRawType();
if(!isCollection()) {
return raw;
} else {
if(nav().isArrayButNotByteArray(raw))
return nav().getComponentType(raw);
T bt = nav().getBaseClass(raw, nav().asDecl(Collection.class) );
if(nav().isParameterizedType(bt))
return nav().getTypeArgument(bt,0);
else
return nav().ref(Object.class);
}
}
public final String getName() {
return seed.getName();
}
/**
* Checks if the given adapter is applicable to the declared property type.
*/
private boolean isApplicable(XmlJavaTypeAdapter jta, T declaredType ) {
if(jta==null) return false;
T type = reader().getClassValue(jta,"type");
if(nav().isSameType(declaredType, type))
return true; // for types explicitly marked in XmlJavaTypeAdapter.type()
T ad = reader().getClassValue(jta,"value");
T ba = nav().getBaseClass(ad, nav().asDecl(XmlAdapter.class));
if(!nav().isParameterizedType(ba))
return true; // can't check type applicability. assume Object, which means applicable to any.
T inMemType = nav().getTypeArgument(ba, 1);
return nav().isSubClassOf(declaredType,inMemType);
}
private XmlJavaTypeAdapter getApplicableAdapter(T type) {
XmlJavaTypeAdapter jta = seed.readAnnotation(XmlJavaTypeAdapter.class);
if(jta!=null && isApplicable(jta,type))
return jta;
// check the applicable adapters on the package
XmlJavaTypeAdapters jtas = reader().getPackageAnnotation(XmlJavaTypeAdapters.class, parent.clazz, seed );
if(jtas!=null) {
for (XmlJavaTypeAdapter xjta : jtas.value()) {
if(isApplicable(xjta,type))
return xjta;
}
}
jta = reader().getPackageAnnotation(XmlJavaTypeAdapter.class, parent.clazz, seed );
if(isApplicable(jta,type))
return jta;
// then on the target class
C refType = nav().asDecl(type);
if(refType!=null) {
jta = reader().getClassAnnotation(XmlJavaTypeAdapter.class, refType, seed );
if(jta!=null && isApplicable(jta,type)) // the one on the type always apply.
return jta;
}
return null;
}
/**
* This is the default implementation of the getAdapter method
* defined on many of the {@link PropertyInfo}-derived classes.
*/
public Adapter<T,C> getAdapter() {
return adapter;
}
public final String displayName() {
return nav().getClassName(parent.getClazz())+'#'+getName();
}
public final ID id() {
return id;
}
private ID calcId() {
if(seed.hasAnnotation(XmlID.class)) {
// check the type
if(!nav().isSameType(getIndividualType(), nav().ref(String.class)))
parent.builder.reportError(new IllegalAnnotationException(
Messages.ID_MUST_BE_STRING.format(getName()), seed )
);
return ID.ID;
} else
if(seed.hasAnnotation(XmlIDREF.class)) {
return ID.IDREF;
} else {
return ID.NONE;
}
}
public final MimeType getExpectedMimeType() {
return expectedMimeType;
}
public final boolean inlineBinaryData() {
return inlineBinary;
}
public final QName getSchemaType() {
return schemaType;
}
public final boolean isCollection() {
return isCollection;
}
/**
* Called after all the {@link TypeInfo}s are collected into the governing {@link TypeInfoSet}.
*
* Derived class can do additional actions to complete the model.
*/
protected void link() {
if(id==ID.IDREF) {
// make sure that the refereced type has ID
for (TypeInfo<T,C> ti : ref()) {
if(!ti.canBeReferencedByIDREF())
parent.builder.reportError(new IllegalAnnotationException(
Messages.INVALID_IDREF.format(
parent.builder.nav.getTypeName(ti.getType())), this ));
}
}
}
/**
* A {@link PropertyInfoImpl} is always referenced by its enclosing class,
* so return that as the upstream.
*/
public Locatable getUpstream() {
return parent;
}
public Location getLocation() {
return seed.getLocation();
}
//
//
// convenience methods for derived classes
//
//
/**
* Computes the tag name from a {@link XmlElement} by taking the defaulting into account.
*/
protected final QName calcXmlName(XmlElement e) {
if(e!=null)
return calcXmlName(e.namespace(),e.name());
else
return calcXmlName("##default","##default");
}
/**
* Computes the tag name from a {@link XmlElementWrapper} by taking the defaulting into account.
*/
protected final QName calcXmlName(XmlElementWrapper e) {
if(e!=null)
return calcXmlName(e.namespace(),e.name());
else
return calcXmlName("##default","##default");
}
private QName calcXmlName(String uri,String local) {
// compute the default
TODO.checkSpec();
if(local.length()==0 || local.equals("##default"))
local = seed.getName();
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.elementFormDefault()) {
case QUALIFIED:
QName typeName = parent.getTypeName();
if(typeName!=null)
uri = typeName.getNamespaceURI();
else
uri = xs.namespace();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else {
uri = "";
}
}
return new QName(uri.intern(),local.intern());
}
public int compareTo(PropertyInfoImpl that) {
return this.getName().compareTo(that.getName());
}
public final <A extends Annotation> A readAnnotation(Class<A> annotationType) {
return seed.readAnnotation(annotationType);
}
public final boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return seed.hasAnnotation(annotationType);
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationSource;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
/**
* Exposes the core information that forms a {@link PropertyInfo}.
*/
interface PropertySeed<T,C,F,M> extends Locatable, AnnotationSource {
/**
* The name of the property is a spec defined concept --- although it doesn't do
* so explicitly in anywhere.
*
* @see PropertyInfo#getName()
*/
String getName();
/**
* Gets the actual data type of the field.
*
* <p>
* The data of the property is stored by using this type.
*
* <p>
* The difference between the {@link RuntimePropertyInfo#getIndividualType()}
* and this method is clear when the property is a multi-value property.
* The {@link RuntimePropertyInfo#getIndividualType()} method returns the type of the item,
* but this method returns the actual collection type.
*/
T getRawType();
}

View File

@@ -0,0 +1,392 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.bind.v2.model.core.ElementInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.WildcardMode;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import java.util.Iterator;
/**
* Implementation of {@link ReferencePropertyInfo}.
*
* @author Kohsuke Kawaguchi
*/
class ReferencePropertyInfoImpl<T,C,F,M>
extends ERPropertyInfoImpl<T,C,F,M>
implements ReferencePropertyInfo<T,C>, DummyPropertyInfo<T, C, F, M>
{
/**
* Lazily computed.
* @see #getElements()
*/
private Set<Element<T,C>> types;
private Set<ReferencePropertyInfoImpl<T,C,F,M>> subTypes = new LinkedHashSet<ReferencePropertyInfoImpl<T,C,F,M>>();
private final boolean isMixed;
private final WildcardMode wildcard;
private final C domHandler;
/**
* Lazily computed.
* @see #isRequired()
*/
private Boolean isRequired;
public ReferencePropertyInfoImpl(
ClassInfoImpl<T,C,F,M> classInfo,
PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
isMixed = seed.readAnnotation(XmlMixed.class) != null;
XmlAnyElement xae = seed.readAnnotation(XmlAnyElement.class);
if(xae==null) {
wildcard = null;
domHandler = null;
} else {
wildcard = xae.lax()?WildcardMode.LAX:WildcardMode.SKIP;
domHandler = nav().asDecl(reader().getClassValue(xae,"value"));
}
}
public Set<? extends Element<T,C>> ref() {
return getElements();
}
public PropertyKind kind() {
return PropertyKind.REFERENCE;
}
public Set<? extends Element<T,C>> getElements() {
if(types==null)
calcTypes(false);
assert types!=null;
return types;
}
/**
* Compute {@link #types}.
*
* @param last
* if true, every {@link XmlElementRef} must yield at least one type.
*/
private void calcTypes(boolean last) {
XmlElementRef[] ann;
types = new LinkedHashSet<Element<T,C>>();
XmlElementRefs refs = seed.readAnnotation(XmlElementRefs.class);
XmlElementRef ref = seed.readAnnotation(XmlElementRef.class);
if(refs!=null && ref!=null) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format(
nav().getClassName(parent.getClazz())+'#'+seed.getName(),
ref.annotationType().getName(), refs.annotationType().getName()),
ref, refs ));
}
if(refs!=null)
ann = refs.value();
else {
if(ref!=null)
ann = new XmlElementRef[]{ref};
else
ann = null;
}
isRequired = !isCollection(); // this is by default, to remain compatible with 2.1
if(ann!=null) {
Navigator<T,C,F,M> nav = nav();
AnnotationReader<T,C,F,M> reader = reader();
final T defaultType = nav.ref(XmlElementRef.DEFAULT.class);
final C je = nav.asDecl(JAXBElement.class);
for( XmlElementRef r : ann ) {
boolean yield;
T type = reader.getClassValue(r,"type");
if(nav().isSameType(type, defaultType))
type = nav.erasure(getIndividualType());
if(nav.getBaseClass(type,je)!=null)
yield = addGenericElement(r);
else
yield = addAllSubtypes(type);
// essentially "isRequired &= isRequired(r)" except that we'd like to skip evaluating isRequird(r)
// if the value is already false.
if(isRequired && !isRequired(r))
isRequired = false;
if(last && !yield) {
// a reference didn't produce any type.
// diagnose the problem
if(nav().isSameType(type, nav.ref(JAXBElement.class))) {
// no XmlElementDecl
parent.builder.reportError(new IllegalAnnotationException(
Messages.NO_XML_ELEMENT_DECL.format(
getEffectiveNamespaceFor(r), r.name()),
this
));
} else {
parent.builder.reportError(new IllegalAnnotationException(
Messages.INVALID_XML_ELEMENT_REF.format(type),this));
}
// reporting one error would do.
// often the element ref field is using @XmlElementRefs
// to point to multiple JAXBElements.
// reporting one error for each @XmlElemetnRef is thus often redundant.
return;
}
}
}
for (ReferencePropertyInfoImpl<T, C, F, M> info : subTypes) {
PropertySeed sd = info.seed;
refs = sd.readAnnotation(XmlElementRefs.class);
ref = sd.readAnnotation(XmlElementRef.class);
if (refs != null && ref != null) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format(
nav().getClassName(parent.getClazz())+'#'+seed.getName(),
ref.annotationType().getName(), refs.annotationType().getName()),
ref, refs ));
}
if (refs != null) {
ann = refs.value();
} else {
if (ref != null) {
ann = new XmlElementRef[]{ref};
} else {
ann = null;
}
}
if (ann != null) {
Navigator<T,C,F,M> nav = nav();
AnnotationReader<T,C,F,M> reader = reader();
final T defaultType = nav.ref(XmlElementRef.DEFAULT.class);
final C je = nav.asDecl(JAXBElement.class);
for( XmlElementRef r : ann ) {
boolean yield;
T type = reader.getClassValue(r,"type");
if (nav().isSameType(type, defaultType)) {
type = nav.erasure(getIndividualType());
}
if (nav.getBaseClass(type,je) != null) {
yield = addGenericElement(r, info);
} else {
yield = addAllSubtypes(type);
}
if(last && !yield) {
// a reference didn't produce any type.
// diagnose the problem
if(nav().isSameType(type, nav.ref(JAXBElement.class))) {
// no XmlElementDecl
parent.builder.reportError(new IllegalAnnotationException(
Messages.NO_XML_ELEMENT_DECL.format(
getEffectiveNamespaceFor(r), r.name()),
this
));
} else {
parent.builder.reportError(new IllegalAnnotationException(
Messages.INVALID_XML_ELEMENT_REF.format(),this));
}
// reporting one error would do.
// often the element ref field is using @XmlElementRefs
// to point to multiple JAXBElements.
// reporting one error for each @XmlElemetnRef is thus often redundant.
return;
}
}
}
}
types = Collections.unmodifiableSet(types);
}
public boolean isRequired() {
if(isRequired==null)
calcTypes(false);
return isRequired;
}
/**
* If we find out that we are working with 2.1 API, remember the fact so that
* we don't waste time generating exceptions every time we call {@link #isRequired(XmlElementRef)}.
*/
private static boolean is2_2 = true;
/**
* Reads the value of {@code XmlElementRef.required()}.
*
* If we are working as 2.1 RI, this defaults to true.
*/
private boolean isRequired(XmlElementRef ref) {
if(!is2_2) return true;
try {
return ref.required();
} catch(LinkageError e) {
is2_2 = false;
return true; // the value defaults to true
}
}
/**
* @return
* true if the reference yields at least one type
*/
private boolean addGenericElement(XmlElementRef r) {
String nsUri = getEffectiveNamespaceFor(r);
// TODO: check spec. defaulting of localName.
return addGenericElement(parent.owner.getElementInfo(parent.getClazz(),new QName(nsUri,r.name())));
}
private boolean addGenericElement(XmlElementRef r, ReferencePropertyInfoImpl<T,C,F,M> info) {
String nsUri = info.getEffectiveNamespaceFor(r);
ElementInfo ei = parent.owner.getElementInfo(info.parent.getClazz(), new QName(nsUri, r.name()));
types.add(ei);
return true;
}
private String getEffectiveNamespaceFor(XmlElementRef r) {
String nsUri = r.namespace();
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
if(xs!=null && xs.attributeFormDefault()== XmlNsForm.QUALIFIED) {
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(nsUri.length()==0)
nsUri = parent.builder.defaultNsUri;
}
return nsUri;
}
private boolean addGenericElement(ElementInfo<T,C> ei) {
if(ei==null)
return false;
types.add(ei);
for( ElementInfo<T,C> subst : ei.getSubstitutionMembers() )
addGenericElement(subst);
return true;
}
private boolean addAllSubtypes(T type) {
Navigator<T,C,F,M> nav = nav();
// this allows the explicitly referenced type to be sucked in to the model
NonElement<T,C> t = parent.builder.getClassInfo(nav.asDecl(type),this);
if(!(t instanceof ClassInfo))
// this is leaf.
return false;
boolean result = false;
ClassInfo<T,C> c = (ClassInfo<T,C>) t;
if(c.isElement()) {
types.add(c.asElement());
result = true;
}
// look for other possible types
for( ClassInfo<T,C> ci : parent.owner.beans().values() ) {
if(ci.isElement() && nav.isSubClassOf(ci.getType(),type)) {
types.add(ci.asElement());
result = true;
}
}
// don't allow local elements to substitute.
for( ElementInfo<T,C> ei : parent.owner.getElementMappings(null).values()) {
if(nav.isSubClassOf(ei.getType(),type)) {
types.add(ei);
result = true;
}
}
return result;
}
@Override
protected void link() {
super.link();
// until we get the whole thing into TypeInfoSet,
// we never really know what are all the possible types that can be assigned on this field.
// so recompute this value when we have all the information.
calcTypes(true);
}
public final void addType(PropertyInfoImpl<T,C,F,M> info) {
//noinspection unchecked
subTypes.add((ReferencePropertyInfoImpl)info);
}
public final boolean isMixed() {
return isMixed;
}
public final WildcardMode getWildcard() {
return wildcard;
}
public final C getDOMHandler() {
return domHandler;
}
}

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.xml.bind.annotation.XmlElementDecl;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.annotation.MethodLocatable;
import com.sun.xml.internal.bind.v2.model.core.RegistryInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.ContextFactory;
/**
* Implementation of {@link RegistryInfo}.
*
* @author Kohsuke Kawaguchi
*/
// experimenting with shorter type parameters for <T,C,F,M> quadruple.
// the idea is that they show so often that you'd understand the meaning
// without relying on the whole name.
final class RegistryInfoImpl<T,C,F,M> implements Locatable, RegistryInfo<T,C> {
final C registryClass;
private final Locatable upstream;
private final Navigator<T,C,F,M> nav;
/**
* Types that are referenced from this registry.
*/
private final Set<TypeInfo<T,C>> references = new LinkedHashSet<TypeInfo<T,C>>();
/**
* 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);
}
}
public Locatable getUpstream() {
return upstream;
}
public Location getLocation() {
return nav.getClassLocation(registryClass);
}
public Set<TypeInfo<T,C>> getReferences() {
return references;
}
/**
* Gets the name of the package that this registry governs.
*/
public String getPackageName() {
return nav.getPackageName(registryClass);
}
public C getClazz() {
return registryClass;
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Type;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeAnyTypeImpl extends AnyTypeImpl<Type,Class> implements RuntimeNonElement {
private RuntimeAnyTypeImpl() {
super(Utils.REFLECTION_NAVIGATOR);
}
public <V> Transducer<V> getTransducer() {
return null;
}
static final RuntimeNonElement theInstance = new RuntimeAnyTypeImpl();
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeArrayInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeArrayInfoImpl extends ArrayInfoImpl<Type,Class,Field,Method> implements RuntimeArrayInfo {
RuntimeArrayInfoImpl(RuntimeModelBuilder builder, Locatable upstream, Class arrayType) {
super(builder, upstream, arrayType);
}
public Class getType() {
return (Class)super.getType();
}
public RuntimeNonElement getItemType() {
return (RuntimeNonElement)super.getItemType();
}
public <V> Transducer<V> getTransducer() {
return null;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeAttributePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
/**
* @author Kohsuke Kawaguchi
*/
class RuntimeAttributePropertyInfoImpl extends AttributePropertyInfoImpl<Type,Class,Field,Method>
implements RuntimeAttributePropertyInfo {
RuntimeAttributePropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
super(classInfo, seed);
}
public boolean elementOnlyContent() {
return true;
}
public RuntimeNonElement getTarget() {
return (RuntimeNonElement) super.getTarget();
}
public List<? extends RuntimeNonElement> ref() {
return (List<? extends RuntimeNonElement>)super.ref();
}
public RuntimePropertyInfo getSource() {
return this;
}
public void link() {
getTransducer();
super.link();
}
}

View File

@@ -0,0 +1,403 @@
/*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.bind.AccessorFactory;
import com.sun.xml.internal.bind.AccessorFactoryImpl;
import com.sun.xml.internal.bind.InternalAccessorFactory;
import com.sun.xml.internal.bind.XmlAccessorFactory;
import com.sun.xml.internal.bind.annotation.XmlLocation;
import com.sun.xml.internal.bind.api.AccessorException;
import com.sun.xml.internal.bind.v2.ClassFactory;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeValuePropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.bind.v2.runtime.Name;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
import com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
class RuntimeClassInfoImpl extends ClassInfoImpl<Type,Class,Field,Method>
implements RuntimeClassInfo, RuntimeElement {
/**
* If this class has a property annotated with {@link XmlLocation},
* this field will get the accessor for it.
*
* TODO: support method based XmlLocation
*/
private Accessor<?,Locator> xmlLocationAccessor;
private AccessorFactory accessorFactory;
private boolean supressAccessorWarnings = false;
public RuntimeClassInfoImpl(RuntimeModelBuilder modelBuilder, Locatable upstream, Class clazz) {
super(modelBuilder, upstream, clazz);
accessorFactory = createAccessorFactory(clazz);
}
protected AccessorFactory createAccessorFactory(Class clazz) {
XmlAccessorFactory factoryAnn;
AccessorFactory accFactory = null;
// user providing class to be used.
JAXBContextImpl context = ((RuntimeModelBuilder) builder).context;
if (context!=null) {
this.supressAccessorWarnings = context.supressAccessorWarnings;
if (context.xmlAccessorFactorySupport) {
factoryAnn = findXmlAccessorFactoryAnnotation(clazz);
if (factoryAnn != null) {
try {
accFactory = factoryAnn.value().newInstance();
} catch (InstantiationException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ACCESSORFACTORY_INSTANTIATION_EXCEPTION.format(
factoryAnn.getClass().getName(), nav().getClassName(clazz)), this));
} catch (IllegalAccessException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ACCESSORFACTORY_ACCESS_EXCEPTION.format(
factoryAnn.getClass().getName(), nav().getClassName(clazz)),this));
}
}
}
}
// Fall back to local AccessorFactory when no
// user not providing one or as error recovery.
if (accFactory == null){
accFactory = AccessorFactoryImpl.getInstance();
}
return accFactory;
}
protected XmlAccessorFactory findXmlAccessorFactoryAnnotation(Class clazz) {
XmlAccessorFactory factoryAnn = reader().getClassAnnotation(XmlAccessorFactory.class,clazz,this);
if (factoryAnn == null) {
factoryAnn = reader().getPackageAnnotation(XmlAccessorFactory.class,clazz,this);
}
return factoryAnn;
}
public Method getFactoryMethod(){
return super.getFactoryMethod();
}
public final RuntimeClassInfoImpl getBaseClass() {
return (RuntimeClassInfoImpl)super.getBaseClass();
}
@Override
protected ReferencePropertyInfoImpl createReferenceProperty(PropertySeed<Type,Class,Field,Method> seed) {
return new RuntimeReferencePropertyInfoImpl(this,seed);
}
@Override
protected AttributePropertyInfoImpl createAttributeProperty(PropertySeed<Type,Class,Field,Method> seed) {
return new RuntimeAttributePropertyInfoImpl(this,seed);
}
@Override
protected ValuePropertyInfoImpl createValueProperty(PropertySeed<Type,Class,Field,Method> seed) {
return new RuntimeValuePropertyInfoImpl(this,seed);
}
@Override
protected ElementPropertyInfoImpl createElementProperty(PropertySeed<Type,Class,Field,Method> seed) {
return new RuntimeElementPropertyInfoImpl(this,seed);
}
@Override
protected MapPropertyInfoImpl createMapProperty(PropertySeed<Type,Class,Field,Method> seed) {
return new RuntimeMapPropertyInfoImpl(this,seed);
}
@Override
public List<? extends RuntimePropertyInfo> getProperties() {
return (List<? extends RuntimePropertyInfo>)super.getProperties();
}
@Override
public RuntimePropertyInfo getProperty(String name) {
return (RuntimePropertyInfo)super.getProperty(name);
}
public void link() {
getTransducer(); // populate the transducer
super.link();
}
private Accessor<?,Map<QName,String>> attributeWildcardAccessor;
public <B> Accessor<B,Map<QName,String>> getAttributeWildcard() {
for( RuntimeClassInfoImpl c=this; c!=null; c=c.getBaseClass() ) {
if(c.attributeWildcard!=null) {
if(c.attributeWildcardAccessor==null)
c.attributeWildcardAccessor = c.createAttributeWildcardAccessor();
return (Accessor<B,Map<QName,String>>)c.attributeWildcardAccessor;
}
}
return null;
}
private boolean computedTransducer = false;
private Transducer xducer = null;
public Transducer getTransducer() {
if(!computedTransducer) {
computedTransducer = true;
xducer = calcTransducer();
}
return xducer;
}
/**
* Creates a transducer if this class is bound to a text in XML.
*/
private Transducer calcTransducer() {
RuntimeValuePropertyInfo valuep=null;
if(hasAttributeWildcard())
return null; // has attribute wildcard. Can't be handled as a leaf
for (RuntimeClassInfoImpl ci = this; ci != null; ci = ci.getBaseClass()) {
for( RuntimePropertyInfo pi : ci.getProperties() )
if(pi.kind()==PropertyKind.VALUE) {
valuep = (RuntimeValuePropertyInfo)pi;
} else {
// this bean has something other than a value
return null;
}
}
if(valuep==null)
return null;
if( !valuep.getTarget().isSimpleType() )
return null; // if there's an error, recover from it by returning null.
return new TransducerImpl(getClazz(),TransducedAccessor.get(
((RuntimeModelBuilder)builder).context,valuep));
}
/**
* Creates
*/
private Accessor<?,Map<QName,String>> createAttributeWildcardAccessor() {
assert attributeWildcard!=null;
return ((RuntimePropertySeed)attributeWildcard).getAccessor();
}
@Override
protected RuntimePropertySeed createFieldSeed(Field field) {
final boolean readOnly = Modifier.isStatic(field.getModifiers());
Accessor acc;
try {
if (supressAccessorWarnings) {
acc = ((InternalAccessorFactory)accessorFactory).createFieldAccessor(clazz, field, readOnly, supressAccessorWarnings);
} else {
acc = accessorFactory.createFieldAccessor(clazz, field, readOnly);
}
} catch(JAXBException e) {
builder.reportError(new IllegalAnnotationException(
Messages.CUSTOM_ACCESSORFACTORY_FIELD_ERROR.format(
nav().getClassName(clazz), e.toString()), this ));
acc = Accessor.getErrorInstance(); // error recovery
}
return new RuntimePropertySeed(super.createFieldSeed(field), acc );
}
@Override
public RuntimePropertySeed createAccessorSeed(Method getter, Method setter) {
Accessor acc;
try {
acc = accessorFactory.createPropertyAccessor(clazz, getter, setter);
} catch(JAXBException e) {
builder.reportError(new IllegalAnnotationException(
Messages.CUSTOM_ACCESSORFACTORY_PROPERTY_ERROR.format(
nav().getClassName(clazz), e.toString()), this ));
acc = Accessor.getErrorInstance(); // error recovery
}
return new RuntimePropertySeed( super.createAccessorSeed(getter,setter),
acc );
}
@Override
protected void checkFieldXmlLocation(Field f) {
if(reader().hasFieldAnnotation(XmlLocation.class,f))
// TODO: check for XmlLocation signature
// TODO: check a collision with the super class
xmlLocationAccessor = new Accessor.FieldReflection<Object,Locator>(f);
}
public Accessor<?,Locator> getLocatorField() {
return xmlLocationAccessor;
}
static final class RuntimePropertySeed implements PropertySeed<Type,Class,Field,Method> {
/**
* @see #getAccessor()
*/
private final Accessor acc;
private final PropertySeed<Type,Class,Field,Method> core;
public RuntimePropertySeed(PropertySeed<Type,Class,Field,Method> core, Accessor acc) {
this.core = core;
this.acc = acc;
}
public String getName() {
return core.getName();
}
public <A extends Annotation> A readAnnotation(Class<A> annotationType) {
return core.readAnnotation(annotationType);
}
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return core.hasAnnotation(annotationType);
}
public Type getRawType() {
return core.getRawType();
}
public Location getLocation() {
return core.getLocation();
}
public Locatable getUpstream() {
return core.getUpstream();
}
public Accessor getAccessor() {
return acc;
}
}
/**
* {@link Transducer} implementation used when this class maps to PCDATA in XML.
*
* TODO: revisit the exception handling
*/
private static final class TransducerImpl<BeanT> implements Transducer<BeanT> {
private final TransducedAccessor<BeanT> xacc;
private final Class<BeanT> ownerClass;
public TransducerImpl(Class<BeanT> ownerClass,TransducedAccessor<BeanT> xacc) {
this.xacc = xacc;
this.ownerClass = ownerClass;
}
public boolean useNamespace() {
return xacc.useNamespace();
}
public boolean isDefault() {
return false;
}
public void declareNamespace(BeanT bean, XMLSerializer w) throws AccessorException {
try {
xacc.declareNamespace(bean,w);
} catch (SAXException e) {
throw new AccessorException(e);
}
}
public @NotNull CharSequence print(BeanT o) throws AccessorException {
try {
CharSequence value = xacc.print(o);
if(value==null)
throw new AccessorException(Messages.THERE_MUST_BE_VALUE_IN_XMLVALUE.format(o));
return value;
} catch (SAXException e) {
throw new AccessorException(e);
}
}
public BeanT parse(CharSequence lexical) throws AccessorException, SAXException {
UnmarshallingContext ctxt = UnmarshallingContext.getInstance();
BeanT inst;
if(ctxt!=null)
inst = (BeanT)ctxt.createInstance(ownerClass);
else
// when this runs for parsing enum constants,
// there's no UnmarshallingContext.
inst = ClassFactory.create(ownerClass);
xacc.parse(inst,lexical);
return inst;
}
public void writeText(XMLSerializer w, BeanT o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
if(!xacc.hasValue(o))
throw new AccessorException(Messages.THERE_MUST_BE_VALUE_IN_XMLVALUE.format(o));
xacc.writeText(w,o,fieldName);
}
public void writeLeafElement(XMLSerializer w, Name tagName, BeanT o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
if(!xacc.hasValue(o))
throw new AccessorException(Messages.THERE_MUST_BE_VALUE_IN_XMLVALUE.format(o));
xacc.writeLeafElement(w,tagName,o,fieldName);
}
public QName getTypeName(BeanT instance) {
return null;
}
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementPropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeRef;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeElementInfoImpl extends ElementInfoImpl<Type,Class,Field,Method>
implements RuntimeElementInfo {
public RuntimeElementInfoImpl(RuntimeModelBuilder modelBuilder, RegistryInfoImpl registry, Method method) throws IllegalAnnotationException {
super(modelBuilder, registry, method);
Adapter<Type,Class> a = getProperty().getAdapter();
if(a!=null)
adapterType = a.adapterType;
else
adapterType = null;
}
@Override
protected PropertyImpl createPropertyImpl() {
return new RuntimePropertyImpl();
}
class RuntimePropertyImpl extends PropertyImpl implements RuntimeElementPropertyInfo, RuntimeTypeRef {
public Accessor getAccessor() {
if(adapterType==null)
return Accessor.JAXB_ELEMENT_VALUE;
else
return Accessor.JAXB_ELEMENT_VALUE.adapt(
(Class)getAdapter().defaultType,(Class)adapterType);
}
public Type getRawType() {
return Collection.class;
}
public Type getIndividualType() {
return getContentType().getType();
}
public boolean elementOnlyContent() {
return false; // this method doesn't make sense here
}
public List<? extends RuntimeTypeRef> getTypes() {
return Collections.singletonList(this);
}
public List<? extends RuntimeNonElement> ref() {
return (List<? extends RuntimeNonElement>)super.ref();
}
public RuntimeNonElement getTarget() {
return (RuntimeNonElement)super.getTarget();
}
public RuntimePropertyInfo getSource() {
return this;
}
public Transducer getTransducer() {
return RuntimeModelBuilder.createTransducer(this);
}
}
/**
* The adapter specified by <code>getProperty().getAdapter()</code>.
*/
private final Class<? extends XmlAdapter> adapterType;
public RuntimeElementPropertyInfo getProperty() {
return (RuntimeElementPropertyInfo)super.getProperty();
}
public Class<? extends JAXBElement> getType() {
//noinspection unchecked
return (Class<? extends JAXBElement>) Utils.REFLECTION_NAVIGATOR.erasure(super.getType());
}
public RuntimeClassInfo getScope() {
return (RuntimeClassInfo)super.getScope();
}
public RuntimeNonElement getContentType() {
return (RuntimeNonElement)super.getContentType();
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementPropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
/**
* @author Kohsuke Kawaguchi
*/
class RuntimeElementPropertyInfoImpl extends ElementPropertyInfoImpl<Type,Class,Field,Method>
implements RuntimeElementPropertyInfo {
private final Accessor acc;
RuntimeElementPropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
super(classInfo, seed);
Accessor rawAcc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
if(getAdapter()!=null && !isCollection())
// adapter for a single-value property is handled by accessor.
// adapter for a collection property is handled by lister.
rawAcc = rawAcc.adapt(getAdapter());
this.acc = rawAcc;
}
public Accessor getAccessor() {
return acc;
}
public boolean elementOnlyContent() {
return true;
}
public List<? extends RuntimeTypeInfo> ref() {
return (List<? extends RuntimeTypeInfo>)super.ref();
}
@Override
protected RuntimeTypeRefImpl createTypeRef(QName name, Type type, boolean isNillable, String defaultValue) {
return new RuntimeTypeRefImpl(this,name,type,isNillable,defaultValue);
}
public List<RuntimeTypeRefImpl> getTypes() {
return (List<RuntimeTypeRefImpl>)super.getTypes();
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeEnumConstantImpl extends EnumConstantImpl<Type,Class,Field,Method> {
public RuntimeEnumConstantImpl(
RuntimeEnumLeafInfoImpl owner, String name, String lexical,
EnumConstantImpl<Type,Class,Field,Method> next) {
super(owner, name, lexical, next);
}
}

View File

@@ -0,0 +1,157 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import com.sun.xml.internal.bind.api.AccessorException;
import com.sun.xml.internal.bind.v2.model.annotation.FieldLocatable;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeEnumLeafInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Name;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
import org.xml.sax.SAXException;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeEnumLeafInfoImpl<T extends Enum<T>,B> extends EnumLeafInfoImpl<Type,Class,Field,Method>
implements RuntimeEnumLeafInfo, Transducer<T> {
public Transducer<T> getTransducer() {
return this;
}
/**
* {@link Transducer} that knows how to convert a lexical value
* into the Java value that we can handle.
*/
private final Transducer<B> baseXducer;
private final Map<B,T> parseMap = new HashMap<B,T>();
private final Map<T,B> printMap;
RuntimeEnumLeafInfoImpl(RuntimeModelBuilder builder, Locatable upstream, Class<T> enumType) {
super(builder,upstream,enumType,enumType);
this.printMap = new EnumMap<T,B>(enumType);
baseXducer = ((RuntimeNonElement)baseType).getTransducer();
}
@Override
public RuntimeEnumConstantImpl createEnumConstant(String name, String literal, Field constant, EnumConstantImpl<Type,Class,Field,Method> last) {
T t;
try {
try {
constant.setAccessible(true);
} catch (SecurityException e) {
// in case the constant is already accessible, swallow this error.
// if the constant is indeed not accessible, we will get IllegalAccessException
// in the following line, and that is not too late.
}
t = (T)constant.get(null);
} catch (IllegalAccessException e) {
// impossible, because this is an enum constant
throw new IllegalAccessError(e.getMessage());
}
B b = null;
try {
b = baseXducer.parse(literal);
} catch (Exception e) {
builder.reportError(new IllegalAnnotationException(
Messages.INVALID_XML_ENUM_VALUE.format(literal,baseType.getType().toString()), e,
new FieldLocatable<Field>(this,constant,nav()) ));
}
parseMap.put(b,t);
printMap.put(t,b);
return new RuntimeEnumConstantImpl(this, name, literal, last);
}
public QName[] getTypeNames() {
return new QName[]{getTypeName()};
}
public boolean isDefault() {
return false;
}
@Override
public Class getClazz() {
return clazz;
}
public boolean useNamespace() {
return baseXducer.useNamespace();
}
public void declareNamespace(T t, XMLSerializer w) throws AccessorException {
baseXducer.declareNamespace(printMap.get(t),w);
}
public CharSequence print(T t) throws AccessorException {
return baseXducer.print(printMap.get(t));
}
public T parse(CharSequence lexical) throws AccessorException, SAXException {
// TODO: error handling
B b = baseXducer.parse(lexical);
if (tokenStringType) {
b = (B) ((String)b).trim();
}
return parseMap.get(b);
}
public void writeText(XMLSerializer w, T t, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
baseXducer.writeText(w,printMap.get(t),fieldName);
}
public void writeLeafElement(XMLSerializer w, Name tagName, T o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
baseXducer.writeLeafElement(w,tagName,printMap.get(o),fieldName);
}
public QName getTypeName(T instance) {
return null;
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeMapPropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
/**
* @author Kohsuke Kawaguchi
*/
class RuntimeMapPropertyInfoImpl extends MapPropertyInfoImpl<Type,Class,Field,Method> implements RuntimeMapPropertyInfo {
private final Accessor acc;
RuntimeMapPropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
super(classInfo, seed);
this.acc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
}
public Accessor getAccessor() {
return acc;
}
public boolean elementOnlyContent() {
return true;
}
public RuntimeNonElement getKeyType() {
return (RuntimeNonElement)super.getKeyType();
}
public RuntimeNonElement getValueType() {
return (RuntimeNonElement)super.getValueType();
}
public List<? extends RuntimeTypeInfo> ref() {
return (List<? extends RuntimeTypeInfo>)super.ref();
}
}

View File

@@ -0,0 +1,179 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import javax.activation.MimeType;
import com.sun.xml.internal.bind.WhiteSpaceProcessor;
import com.sun.xml.internal.bind.api.AccessorException;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElementRef;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
import com.sun.xml.internal.bind.v2.runtime.FilterTransducer;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.InlineBinaryTransducer;
import com.sun.xml.internal.bind.v2.runtime.MimeTypedTransducer;
import com.sun.xml.internal.bind.v2.runtime.SchemaTypeTransducer;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import javax.xml.namespace.QName;
import org.xml.sax.SAXException;
/**
* {@link ModelBuilder} that works at the run-time by using
* the {@code java.lang.reflect} package.
*
* <p>
* This extends {@link ModelBuilder} by providing more functionalities such
* as accessing the fields and classes.
*
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
public class RuntimeModelBuilder extends ModelBuilder<Type,Class,Field,Method> {
/**
* The {@link JAXBContextImpl} for which the model is built.
* Null when created for reflection.
*/
public final @Nullable JAXBContextImpl context;
public RuntimeModelBuilder(JAXBContextImpl context, RuntimeAnnotationReader annotationReader, Map<Class, Class> subclassReplacements, String defaultNamespaceRemap) {
super(annotationReader, Utils.REFLECTION_NAVIGATOR, subclassReplacements, defaultNamespaceRemap);
this.context = context;
}
@Override
public RuntimeNonElement getClassInfo( Class clazz, Locatable upstream ) {
return (RuntimeNonElement)super.getClassInfo(clazz,upstream);
}
@Override
public RuntimeNonElement getClassInfo( Class clazz, boolean searchForSuperClass, Locatable upstream ) {
return (RuntimeNonElement)super.getClassInfo(clazz,searchForSuperClass,upstream);
}
@Override
protected RuntimeEnumLeafInfoImpl createEnumLeafInfo(Class clazz, Locatable upstream) {
return new RuntimeEnumLeafInfoImpl(this,upstream,clazz);
}
@Override
protected RuntimeClassInfoImpl createClassInfo( Class clazz, Locatable upstream ) {
return new RuntimeClassInfoImpl(this,upstream,clazz);
}
@Override
public RuntimeElementInfoImpl createElementInfo(RegistryInfoImpl<Type,Class,Field,Method> registryInfo, Method method) throws IllegalAnnotationException {
return new RuntimeElementInfoImpl(this,registryInfo, method);
}
@Override
public RuntimeArrayInfoImpl createArrayInfo(Locatable upstream, Type arrayType) {
return new RuntimeArrayInfoImpl(this, upstream, (Class)arrayType);
}
@Override
protected RuntimeTypeInfoSetImpl createTypeInfoSet() {
return new RuntimeTypeInfoSetImpl(reader);
}
@Override
public RuntimeTypeInfoSet link() {
return (RuntimeTypeInfoSet)super.link();
}
/**
* Creates a {@link Transducer} given a reference.
*
* Used to implement {@link RuntimeNonElementRef#getTransducer()}.
* Shouldn't be called from anywhere else.
*
* TODO: this is not the proper place for this class to be in.
*/
public static Transducer createTransducer(RuntimeNonElementRef ref) {
Transducer t = ref.getTarget().getTransducer();
RuntimePropertyInfo src = ref.getSource();
ID id = src.id();
if(id==ID.IDREF)
return RuntimeBuiltinLeafInfoImpl.STRING;
if(id==ID.ID)
t = new IDTransducerImpl(t);
MimeType emt = src.getExpectedMimeType();
if(emt!=null)
t = new MimeTypedTransducer(t,emt);
if(src.inlineBinaryData())
t = new InlineBinaryTransducer(t);
if(src.getSchemaType()!=null) {
if (src.getSchemaType().equals(createXSSimpleType())) {
return RuntimeBuiltinLeafInfoImpl.STRING;
}
t = new SchemaTypeTransducer(t,src.getSchemaType());
}
return t;
}
private static QName createXSSimpleType() {
return new QName(WellKnownNamespace.XML_SCHEMA,"anySimpleType");
}
/**
* Transducer implementation for ID.
*
* This transducer wraps another {@link Transducer} and adds
* handling for ID.
*/
private static final class IDTransducerImpl<ValueT> extends FilterTransducer<ValueT> {
public IDTransducerImpl(Transducer<ValueT> core) {
super(core);
}
@Override
public ValueT parse(CharSequence lexical) throws AccessorException, SAXException {
String value = WhiteSpaceProcessor.trim(lexical).toString();
UnmarshallingContext.getInstance().addToIdTable(value);
return core.parse(value);
}
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeReferencePropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
/**
* @author Kohsuke Kawaguchi
*/
class RuntimeReferencePropertyInfoImpl extends ReferencePropertyInfoImpl<Type,Class,Field,Method>
implements RuntimeReferencePropertyInfo {
private final Accessor acc;
public RuntimeReferencePropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
super(classInfo,seed);
Accessor rawAcc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
if(getAdapter()!=null && !isCollection())
// adapter for a single-value property is handled by accessor.
// adapter for a collection property is handled by lister.
rawAcc = rawAcc.adapt(getAdapter());
this.acc = rawAcc;
}
public Set<? extends RuntimeElement> getElements() {
return (Set<? extends RuntimeElement>)super.getElements();
}
public Set<? extends RuntimeElement> ref() {
return (Set<? extends RuntimeElement>)super.ref();
}
public Accessor getAccessor() {
return acc;
}
public boolean elementOnlyContent() {
return !isMixed();
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
/**
* {@link TypeInfoSet} specialized for runtime.
*
* @author Kohsuke Kawaguchi
*/
final class RuntimeTypeInfoSetImpl extends TypeInfoSetImpl<Type,Class,Field,Method> implements RuntimeTypeInfoSet {
public RuntimeTypeInfoSetImpl(AnnotationReader<Type,Class,Field,Method> reader) {
super(Utils.REFLECTION_NAVIGATOR,reader,RuntimeBuiltinLeafInfoImpl.LEAVES);
}
@Override
protected RuntimeNonElement createAnyType() {
return RuntimeAnyTypeImpl.theInstance;
}
public RuntimeNonElement getTypeInfo( Type type ) {
return (RuntimeNonElement)super.getTypeInfo(type);
}
public RuntimeNonElement getAnyTypeInfo() {
return (RuntimeNonElement)super.getAnyTypeInfo();
}
public RuntimeNonElement getClassInfo(Class clazz) {
return (RuntimeNonElement)super.getClassInfo(clazz);
}
public Map<Class,RuntimeClassInfoImpl> beans() {
return (Map<Class,RuntimeClassInfoImpl>)super.beans();
}
public Map<Type,RuntimeBuiltinLeafInfoImpl<?>> builtins() {
return (Map<Type,RuntimeBuiltinLeafInfoImpl<?>>)super.builtins();
}
public Map<Class,RuntimeEnumLeafInfoImpl<?,?>> enums() {
return (Map<Class,RuntimeEnumLeafInfoImpl<?,?>>)super.enums();
}
public Map<Class,RuntimeArrayInfoImpl> arrays() {
return (Map<Class,RuntimeArrayInfoImpl>)super.arrays();
}
public RuntimeElementInfoImpl getElementInfo(Class scope,QName name) {
return (RuntimeElementInfoImpl)super.getElementInfo(scope,name);
}
public Map<QName,RuntimeElementInfoImpl> getElementMappings(Class scope) {
return (Map<QName,RuntimeElementInfoImpl>)super.getElementMappings(scope);
}
public Iterable<RuntimeElementInfoImpl> getAllElements() {
return (Iterable<RuntimeElementInfoImpl>)super.getAllElements();
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Type;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeRef;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeTypeRefImpl extends TypeRefImpl<Type,Class> implements RuntimeTypeRef {
public RuntimeTypeRefImpl(RuntimeElementPropertyInfoImpl elementPropertyInfo, QName elementName, Type type, boolean isNillable, String defaultValue) {
super(elementPropertyInfo, elementName, type, isNillable, defaultValue);
}
public RuntimeNonElement getTarget() {
return (RuntimeNonElement)super.getTarget();
}
public Transducer getTransducer() {
return RuntimeModelBuilder.createTransducer(this);
}
public RuntimePropertyInfo getSource() {
return (RuntimePropertyInfo)owner;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElement;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeValuePropertyInfo;
/**
* @author Kohsuke Kawaguchi
*/
final class RuntimeValuePropertyInfoImpl extends ValuePropertyInfoImpl<Type,Class,Field,Method>
implements RuntimeValuePropertyInfo {
RuntimeValuePropertyInfoImpl(RuntimeClassInfoImpl classInfo, PropertySeed<Type,Class,Field,Method> seed) {
super(classInfo, seed);
}
public boolean elementOnlyContent() {
return false;
}
public RuntimePropertyInfo getSource() {
return (RuntimePropertyInfo)super.getSource();
}
public RuntimeNonElement getTarget() {
return (RuntimeNonElement)super.getTarget();
}
public List<? extends RuntimeNonElement> ref() {
return (List<? extends RuntimeNonElement>)super.ref();
}
public void link() {
getTransducer();
super.link();
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
/**
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
* classloader. This MUST be package private and defined in every package which
* uses such invocations.
* @author snajper
*/
class SecureLoader {
static ClassLoader getContextClassLoader() {
if (System.getSecurityManager() == null) {
return Thread.currentThread().getContextClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
}
}
static ClassLoader getClassClassLoader(final Class c) {
if (System.getSecurityManager() == null) {
return c.getClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return c.getClassLoader();
}
});
}
}
static ClassLoader getSystemClassLoader() {
if (System.getSecurityManager() == null) {
return ClassLoader.getSystemClassLoader();
} else {
return (ClassLoader) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
return ClassLoader.getSystemClassLoader();
}
});
}
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlList;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimeNonElementRef;
import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.Transducer;
import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
/**
* {@link PropertyInfoImpl} that can only have one type.
*
* Specifically, {@link AttributePropertyInfoImpl} and {@link ValuePropertyInfoImpl}.
*
* @author Kohsuke Kawaguchi
*/
abstract class SingleTypePropertyInfoImpl<T,C,F,M>
extends PropertyInfoImpl<T,C,F,M> {
/**
* Computed lazily.
*
* @see {@link #getTarget()}.
*/
private NonElement<T,C> type;
public SingleTypePropertyInfoImpl(ClassInfoImpl<T,C,F,M> classInfo, PropertySeed<T,C,F,M> seed) {
super(classInfo, seed);
if(this instanceof RuntimePropertyInfo) {
Accessor rawAcc = ((RuntimeClassInfoImpl.RuntimePropertySeed)seed).getAccessor();
if(getAdapter()!=null && !isCollection())
// adapter for a single-value property is handled by accessor.
// adapter for a collection property is handled by lister.
rawAcc = rawAcc.adapt(((RuntimePropertyInfo)this).getAdapter());
this.acc = rawAcc;
} else
this.acc = null;
}
public List<? extends NonElement<T,C>> ref() {
return Collections.singletonList(getTarget());
}
public NonElement<T,C> getTarget() {
if(type==null) {
assert parent.builder!=null : "this method must be called during the build stage";
type = parent.builder.getTypeInfo(getIndividualType(),this);
}
return type;
}
public PropertyInfo<T,C> getSource() {
return this;
}
public void link() {
super.link();
if (!(NonElement.ANYTYPE_NAME.equals(type.getTypeName()) || type.isSimpleType() || id()==ID.IDREF)) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.SIMPLE_TYPE_IS_REQUIRED.format(),
seed
));
}
if(!isCollection() && seed.hasAnnotation(XmlList.class)) {
parent.builder.reportError(new IllegalAnnotationException(
Messages.XMLLIST_ON_SINGLE_PROPERTY.format(), this
));
}
}
//
//
// technically these code belong to runtime implementation, but moving the code up here
// allows this to be shared between RuntimeValuePropertyInfoImpl and RuntimeAttributePropertyInfoImpl
//
//
private final Accessor acc;
/**
* Lazily created.
*/
private Transducer xducer;
public Accessor getAccessor() {
return acc;
}
public Transducer getTransducer() {
if(xducer==null) {
xducer = RuntimeModelBuilder.createTransducer((RuntimeNonElementRef)this);
if(xducer==null) {
// this situation is checked by by the link method.
// avoid repeating the same error by silently recovering
xducer = RuntimeBuiltinLeafInfoImpl.STRING;
}
}
return xducer;
}
}

View File

@@ -0,0 +1,165 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.api.impl.NameConverter;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
/**
* Common implementation between {@link ClassInfoImpl} and {@link ElementInfoImpl}.
*
* @author Kohsuke Kawaguchi
*/
abstract class TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
implements TypeInfo<TypeT,ClassDeclT>, Locatable {
/**
* The Java class that caused this Java class to be a part of the JAXB processing.
*
* null if it's specified explicitly by the user.
*/
private final Locatable upstream;
/**
* {@link TypeInfoSet} to which this class belongs.
*/
protected final TypeInfoSetImpl<TypeT,ClassDeclT,FieldT,MethodT> owner;
/**
* Reference to the {@link ModelBuilder}, only until we link {@link TypeInfo}s all together,
* because we don't want to keep {@link ModelBuilder} too long.
*/
protected ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder;
protected TypeInfoImpl(
ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder,
Locatable upstream) {
this.builder = builder;
this.owner = builder.typeInfoSet;
this.upstream = upstream;
}
public Locatable getUpstream() {
return upstream;
}
/*package*/ void link() {
builder = null;
}
protected final Navigator<TypeT,ClassDeclT,FieldT,MethodT> nav() {
return owner.nav;
}
protected final AnnotationReader<TypeT,ClassDeclT,FieldT,MethodT> reader() {
return owner.reader;
}
/**
* Parses an {@link XmlRootElement} annotation on a class
* and determine the element name.
*
* @return null
* if none was found.
*/
protected final QName parseElementName(ClassDeclT clazz) {
XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
if(e==null)
return null;
String local = e.name();
if(local.equals("##default")) {
// if defaulted...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
}
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
protected final QName parseTypeName(ClassDeclT clazz) {
return parseTypeName( clazz, reader().getClassAnnotation(XmlType.class,clazz,this) );
}
/**
* Parses a (potentially-null) {@link XmlType} annotation on a class
* and determine the actual value.
*
* @param clazz
* The class on which the XmlType annotation is checked.
* @param t
* The {@link XmlType} annotation on the clazz. This value
* is taken as a parameter to improve the performance for the case where
* 't' is pre-computed.
*/
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
String nsUri="##default";
String local="##default";
if(t!=null) {
nsUri = t.namespace();
local = t.name();
}
if(local.length()==0)
return null; // anonymous
if(local.equals("##default"))
// if defaulted ...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
}

View File

@@ -0,0 +1,391 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.core.BuiltinLeafInfo;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.model.core.LeafInfo;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.Ref;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
import com.sun.xml.internal.bind.v2.util.FlattenIterator;
/**
* Set of {@link TypeInfo}s.
*
* <p>
* This contains a fixed set of {@link LeafInfo}s and arbitrary set of {@link ClassInfo}s.
*
* <p>
* Members are annotated with JAXB annotations so that we can dump it easily.
*
* @author Kohsuke Kawaguchi
*/
class TypeInfoSetImpl<T,C,F,M> implements TypeInfoSet<T,C,F,M> {
@XmlTransient
public final Navigator<T,C,F,M> nav;
@XmlTransient
public final AnnotationReader<T,C,F,M> reader;
/**
* All the leaves.
*/
private final Map<T,BuiltinLeafInfo<T,C>> builtins =
new LinkedHashMap<T,BuiltinLeafInfo<T,C>>();
/** All {@link EnumLeafInfoImpl}s. */
private final Map<C,EnumLeafInfoImpl<T,C,F,M>> enums =
new LinkedHashMap<C,EnumLeafInfoImpl<T,C,F,M>>();
/** All {@link ArrayInfoImpl}s. */
private final Map<T,ArrayInfoImpl<T,C,F,M>> arrays =
new LinkedHashMap<T,ArrayInfoImpl<T,C,F,M>>();
/**
* All the user-defined classes.
*
* Using {@link LinkedHashMap} allows us to process classes
* in the order they are given to us. When the user incorrectly
* puts an unexpected class into a reference graph, this causes
* an error to be reported on a class closer to the user's code.
*/
@XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
private final Map<C,ClassInfoImpl<T,C,F,M>> beans
= new LinkedHashMap<C,ClassInfoImpl<T,C,F,M>>();
@XmlTransient
private final Map<C,ClassInfoImpl<T,C,F,M>> beansView =
Collections.unmodifiableMap(beans);
/**
* The element mapping.
*/
private final Map<C,Map<QName,ElementInfoImpl<T,C,F,M>>> elementMappings =
new LinkedHashMap<C,Map<QName,ElementInfoImpl<T,C,F,M>>>();
private final Iterable<? extends ElementInfoImpl<T,C,F,M>> allElements =
new Iterable<ElementInfoImpl<T,C,F,M>>() {
public Iterator<ElementInfoImpl<T,C,F,M>> iterator() {
return new FlattenIterator<ElementInfoImpl<T,C,F,M>>(elementMappings.values());
}
};
/**
* {@link TypeInfo} for <tt>xs:anyType</tt>.
*
* anyType is the only {@link TypeInfo} that works with an interface,
* and accordingly it requires a lot of special casing.
*/
private final NonElement<T,C> anyType;
/**
* Lazily parsed set of {@link XmlNs}s.
*
* @see #getXmlNs(String)
*/
private Map<String,Map<String,String>> xmlNsCache;
public TypeInfoSetImpl(Navigator<T,C,F,M> nav,
AnnotationReader<T,C,F,M> reader,
Map<T,? extends BuiltinLeafInfoImpl<T,C>> leaves) {
this.nav = nav;
this.reader = reader;
this.builtins.putAll(leaves);
this.anyType = createAnyType();
// register primitive types.
for (Map.Entry<Class, Class> e : RuntimeUtil.primitiveToBox.entrySet()) {
this.builtins.put( nav.getPrimitive(e.getKey()), leaves.get(nav.ref(e.getValue())) );
}
// make sure at lease we got a map for global ones.
elementMappings.put(null,new LinkedHashMap<QName,ElementInfoImpl<T,C,F,M>>());
}
protected NonElement<T,C> createAnyType() {
return new AnyTypeImpl<T,C>(nav);
}
public Navigator<T,C,F,M> getNavigator() {
return nav;
}
/**
* Adds a new {@link ClassInfo} to the set.
*/
public void add( ClassInfoImpl<T,C,F,M> ci ) {
beans.put( ci.getClazz(), ci );
}
/**
* Adds a new {@link LeafInfo} to the set.
*/
public void add( EnumLeafInfoImpl<T,C,F,M> li ) {
enums.put( li.clazz, li );
}
public void add(ArrayInfoImpl<T, C, F, M> ai) {
arrays.put( ai.getType(), ai );
}
/**
* Returns a {@link TypeInfo} for the given type.
*
* @return
* null if the specified type cannot be bound by JAXB, or
* not known to this set.
*/
public NonElement<T,C> getTypeInfo( T type ) {
type = nav.erasure(type); // replace type variables by their bounds
LeafInfo<T,C> l = builtins.get(type);
if(l!=null) return l;
if( nav.isArray(type) ) {
return arrays.get(type);
}
C d = nav.asDecl(type);
if(d==null) return null;
return getClassInfo(d);
}
public NonElement<T,C> getAnyTypeInfo() {
return anyType;
}
/**
* This method is used to add a root reference to a model.
*/
public NonElement<T,C> getTypeInfo(Ref<T,C> ref) {
// TODO: handle XmlValueList
assert !ref.valueList;
C c = nav.asDecl(ref.type);
if(c!=null && reader.getClassAnnotation(XmlRegistry.class,c,null/*TODO: is this right?*/)!=null) {
return null; // TODO: is this correct?
} else
return getTypeInfo(ref.type);
}
/**
* Returns all the {@link ClassInfo}s known to this set.
*/
public Map<C,? extends ClassInfoImpl<T,C,F,M>> beans() {
return beansView;
}
public Map<T, ? extends BuiltinLeafInfo<T,C>> builtins() {
return builtins;
}
public Map<C, ? extends EnumLeafInfoImpl<T,C,F,M>> enums() {
return enums;
}
public Map<? extends T, ? extends ArrayInfoImpl<T,C,F,M>> arrays() {
return arrays;
}
/**
* Returns a {@link ClassInfo} for the given bean.
*
* <p>
* This method is almost like refinement of {@link #getTypeInfo(Object)} except
* our C cannot derive from T.
*
* @return
* null if the specified type is not bound by JAXB or otherwise
* unknown to this set.
*/
public NonElement<T,C> getClassInfo( C type ) {
LeafInfo<T,C> l = builtins.get(nav.use(type));
if(l!=null) return l;
l = enums.get(type);
if(l!=null) return l;
if(nav.asDecl(Object.class).equals(type))
return anyType;
return beans.get(type);
}
public ElementInfoImpl<T,C,F,M> getElementInfo( C scope, QName name ) {
while(scope!=null) {
Map<QName,ElementInfoImpl<T,C,F,M>> m = elementMappings.get(scope);
if(m!=null) {
ElementInfoImpl<T,C,F,M> r = m.get(name);
if(r!=null) return r;
}
scope = nav.getSuperClass(scope);
}
return elementMappings.get(null).get(name);
}
/**
* @param builder
* used for reporting errors.
*/
public final void add( ElementInfoImpl<T,C,F,M> ei, ModelBuilder<T,C,F,M> builder ) {
C scope = null;
if(ei.getScope()!=null)
scope = ei.getScope().getClazz();
Map<QName,ElementInfoImpl<T,C,F,M>> m = elementMappings.get(scope);
if(m==null)
elementMappings.put(scope,m=new LinkedHashMap<QName,ElementInfoImpl<T,C,F,M>>());
ElementInfoImpl<T,C,F,M> existing = m.put(ei.getElementName(),ei);
if(existing!=null) {
QName en = ei.getElementName();
builder.reportError(
new IllegalAnnotationException(
Messages.CONFLICTING_XML_ELEMENT_MAPPING.format(en.getNamespaceURI(),en.getLocalPart()),
ei, existing ));
}
}
public Map<QName,? extends ElementInfoImpl<T,C,F,M>> getElementMappings( C scope ) {
return elementMappings.get(scope);
}
public Iterable<? extends ElementInfoImpl<T,C,F,M>> getAllElements() {
return allElements;
}
public Map<String,String> getXmlNs(String namespaceUri) {
if(xmlNsCache==null) {
xmlNsCache = new HashMap<String,Map<String,String>>();
for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
String uri = xs.namespace();
Map<String,String> m = xmlNsCache.get(uri);
if(m==null)
xmlNsCache.put(uri,m=new HashMap<String, String>());
for( XmlNs xns : xs.xmlns() ) {
m.put(xns.prefix(),xns.namespaceURI());
}
}
}
Map<String,String> r = xmlNsCache.get(namespaceUri);
if(r!=null) return r;
else return Collections.emptyMap();
}
public Map<String,String> getSchemaLocations() {
Map<String, String> r = new HashMap<String,String>();
for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
String loc = xs.location();
if(loc.equals(XmlSchema.NO_LOCATION))
continue; // unspecified
r.put(xs.namespace(),loc);
}
return r;
}
public final XmlNsForm getElementFormDefault(String nsUri) {
for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
if(!xs.namespace().equals(nsUri))
continue;
XmlNsForm xnf = xs.elementFormDefault();
if(xnf!=XmlNsForm.UNSET)
return xnf;
}
return XmlNsForm.UNSET;
}
public final XmlNsForm getAttributeFormDefault(String nsUri) {
for (ClassInfoImpl<T,C,F,M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
if(!xs.namespace().equals(nsUri))
continue;
XmlNsForm xnf = xs.attributeFormDefault();
if(xnf!=XmlNsForm.UNSET)
return xnf;
}
return XmlNsForm.UNSET;
}
/**
* Dumps this model into XML.
*
* For debug only.
*
* TODO: not sure if this actually works. We don't really know what are T,C.
*/
public void dump( Result out ) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(this.getClass());
Marshaller m = context.createMarshaller();
m.marshal(this,out);
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeRef;
/**
* @author Kohsuke Kawaguchi
*/
class TypeRefImpl<TypeT,ClassDeclT> implements TypeRef<TypeT,ClassDeclT> {
private final QName elementName;
private final TypeT type;
protected final ElementPropertyInfoImpl<TypeT,ClassDeclT,?,?> owner;
private NonElement<TypeT,ClassDeclT> ref;
private final boolean isNillable;
private String defaultValue;
public TypeRefImpl(ElementPropertyInfoImpl<TypeT, ClassDeclT, ?, ?> owner, QName elementName, TypeT type, boolean isNillable, String defaultValue) {
this.owner = owner;
this.elementName = elementName;
this.type = type;
this.isNillable = isNillable;
this.defaultValue = defaultValue;
assert owner!=null;
assert elementName!=null;
assert type!=null;
}
public NonElement<TypeT,ClassDeclT> getTarget() {
if(ref==null)
calcRef();
return ref;
}
public QName getTagName() {
return elementName;
}
public boolean isNillable() {
return isNillable;
}
public String getDefaultValue() {
return defaultValue;
}
protected void link() {
// if we have'nt computed the ref yet, do so now.
calcRef();
}
private void calcRef() {
// we can't do this eagerly because of a cyclic dependency
ref = owner.parent.builder.getTypeInfo(type,owner);
assert ref!=null;
}
public PropertyInfo<TypeT,ClassDeclT> getSource() {
return owner;
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlSchemaTypes;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationSource;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
/**
* Common code between {@link PropertyInfoImpl} and {@link ElementInfoImpl}.
*
* @author Kohsuke Kawaguchi
*/
final class Util {
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 MimeType calcExpectedMediaType(AnnotationSource primarySource,
ModelBuilder builder ) {
XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class);
if(xmt==null)
return null;
try {
return new MimeType(xmt.value());
} catch (MimeTypeParseException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()),
xmt
));
return null;
}
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utils class.
*
* WARNING: If you are doing any changes don't forget to change other Utils classes in different packages.
*
* Has *package private* access to avoid inappropriate usage.
*/
final class Utils {
private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
/**
* static ReflectionNavigator field to avoid usage of reflection every time we use it.
*/
static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
static { // we statically initializing REFLECTION_NAVIGATOR property
try {
final Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
// requires accessClassInPackage privilege
final Method getInstance = AccessController.doPrivileged(
new PrivilegedAction<Method>() {
@Override
public Method run() {
try {
Method getInstance = refNav.getDeclaredMethod("getInstance");
getInstance.setAccessible(true);
return getInstance;
} catch (NoSuchMethodException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance can't be found");
}
}
}
);
//noinspection unchecked
REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Can't find ReflectionNavigator class");
} catch (InvocationTargetException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception");
} catch (IllegalAccessException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible");
} catch (SecurityException e) {
LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e);
throw e;
}
}
/**
* private constructor to avoid util class instantiating
*/
private Utils() {
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.bind.v2.model.impl;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.ValuePropertyInfo;
/**
* @author Kohsuke Kawaguchi
*/
class ValuePropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
extends SingleTypePropertyInfoImpl<TypeT,ClassDeclT,FieldT,MethodT>
implements ValuePropertyInfo<TypeT,ClassDeclT> {
ValuePropertyInfoImpl(
ClassInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> parent,
PropertySeed<TypeT,ClassDeclT,FieldT,MethodT> seed) {
super(parent,seed);
}
public PropertyKind kind() {
return PropertyKind.VALUE;
}
}

Some files were not shown because too many files have changed in this diff Show More