use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processAdditionalClasses.
private void processAdditionalClasses(JavaClass cls, TypeMappingInfo tmi, ArrayList<JavaClass> extraClasses, ArrayList<JavaClass> classesToProcess) {
Class<?> xmlElementType = null;
JavaClass javaClass = cls;
if (tmi != null) {
Class<?> adapterClass = this.typeMappingInfoToAdapterClasses.get(tmi);
if (adapterClass != null) {
JavaClass adapterJavaClass = helper.getJavaClass(adapterClass);
JavaClass newType = helper.getJavaClass(Object.class);
// look for marshal method
for (Object nextMethod : adapterJavaClass.getDeclaredMethods()) {
JavaMethod method = (JavaMethod) nextMethod;
if (method.getName().equals("marshal")) {
JavaClass returnType = method.getReturnType();
if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
newType = returnType;
break;
}
}
}
if (!helper.isBuiltInJavaType(javaClass)) {
extraClasses.add(javaClass);
}
javaClass = newType;
}
java.lang.annotation.Annotation[] annotations = getAnnotations(tmi);
if (annotations != null) {
for (Annotation nextAnnotation : annotations) {
if (nextAnnotation != null && nextAnnotation instanceof XmlElement) {
XmlElement javaAnnotation = (XmlElement) nextAnnotation;
if (javaAnnotation.type() != XmlElement.DEFAULT.class) {
xmlElementType = javaAnnotation.type();
}
}
}
}
}
if (areEquals(javaClass, byte[].class) || areEquals(javaClass, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass, Source.class) || areEquals(javaClass, Image.class) || areEquals(javaClass, JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
if (tmi == null || tmi.getXmlTagName() == null) {
ElementDeclaration declaration = new ElementDeclaration(null, javaClass, javaClass.getQualifiedName(), false, XmlElementDecl.GLOBAL.class);
declaration.setTypeMappingInfo(tmi);
this.localElements.add(declaration);
}
} else if (javaClass.isArray()) {
if (!helper.isBuiltInJavaType(javaClass.getComponentType())) {
extraClasses.add(javaClass.getComponentType());
}
Class<?> generatedClass;
if (null == tmi) {
generatedClass = arrayClassesToGeneratedClasses.get(javaClass.getName());
} else {
generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
}
if (generatedClass == null) {
generatedClass = generateWrapperForArrayClass(javaClass, tmi, xmlElementType, extraClasses);
extraClasses.add(helper.getJavaClass(generatedClass));
arrayClassesToGeneratedClasses.put(javaClass.getName(), generatedClass);
}
generatedClassesToArrayClasses.put(generatedClass, javaClass);
typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
} else if (helper.isCollectionType(javaClass)) {
JavaClass componentClass;
Collection args = javaClass.getActualTypeArguments();
if (!args.isEmpty()) {
componentClass = (JavaClass) args.iterator().next();
if (!componentClass.isPrimitive()) {
extraClasses.add(componentClass);
}
} else {
componentClass = helper.getJavaClass(Object.class);
}
Class<?> generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
if (generatedClass == null) {
generatedClass = generateCollectionValue(javaClass, tmi, xmlElementType, extraClasses);
extraClasses.add(helper.getJavaClass(generatedClass));
}
typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
} else if (helper.isMapType(javaClass)) {
JavaClass keyClass;
JavaClass valueClass;
Collection args = javaClass.getActualTypeArguments();
Iterator argsIter = args.iterator();
if (!args.isEmpty()) {
keyClass = (JavaClass) argsIter.next();
if (!helper.isBuiltInJavaType(keyClass)) {
extraClasses.add(keyClass);
}
valueClass = (JavaClass) argsIter.next();
if (!helper.isBuiltInJavaType(valueClass)) {
extraClasses.add(valueClass);
}
} else {
keyClass = helper.getJavaClass(Object.class);
valueClass = helper.getJavaClass(Object.class);
}
Class<?> generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
if (generatedClass == null) {
generatedClass = generateWrapperForMapClass(javaClass, keyClass, valueClass, tmi);
extraClasses.add(helper.getJavaClass(generatedClass));
}
typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
} else {
// process @XmlRegistry, @XmlSeeAlso and inner classes
processClass(javaClass, classesToProcess);
}
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class XJCJavaPackageImpl method getAnnotations.
/**
* Return all of the <code>Annotations</code> for this <code>JavaPackage</code>.
*
* @return A <code>Collection</code> containing this <code>JavaPackage's</code> <code>JavaAnnotations</code>.
*/
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
Collection<JAnnotationUse> annotations = xjcPackage.annotations();
for (JAnnotationUse annotationUse : annotations) {
XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
annotationsList.add(xjcAnnotation);
}
return annotationsList;
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class JavaClassImpl method getDeclaredAnnotation.
@Override
public JavaAnnotation getDeclaredAnnotation(JavaClass arg0) {
// the only annotation we will return if isMetadataComplete == true is XmlRegistry
if (arg0 != null && (!isMetadataComplete || arg0.getQualifiedName().equals(XML_REGISTRY_CLASS_NAME))) {
Class<?> annotationClass = ((JavaClassImpl) arg0).getJavaClass();
Annotation[] annotations = javaModelImpl.getAnnotationHelper().getDeclaredAnnotations(getAnnotatedElement());
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationClass)) {
return new JavaAnnotationImpl(annotation);
}
}
}
return null;
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class XJCJavaFieldImpl method getAnnotations.
/**
* Return all of the <code>Annotations</code> for this <code>JavaField</code>.
*
* @return A <code>Collection</code> containing this <code>JavaField's</code> <code>JavaAnnotations</code>.
*/
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
Collection<JAnnotationUse> annotations = xjcField.annotations();
for (JAnnotationUse annotationUse : annotations) {
XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
annotationsList.add(xjcAnnotation);
}
return annotationsList;
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class XJCJavaMethodImpl method getAnnotations.
/**
* Return all of the <code>Annotations</code> for this <code>JavaMethod</code>.
*
* @return A <code>Collection</code> containing this <code>JavaMethod's</code> <code>JavaAnnotations</code>.
*/
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
Collection<JAnnotationUse> annotations = xjcMethod.annotations();
for (JAnnotationUse annotationUse : annotations) {
XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
annotationsList.add(xjcAnnotation);
}
return annotationsList;
}
Aggregations