use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class JavaMethodImpl method getAnnotation.
@Override
public JavaAnnotation getAnnotation(JavaClass arg0) {
if (arg0 != null && !isMetadataComplete) {
Class<?> annotationClass = ((JavaClassImpl) arg0).getJavaClass();
Annotation anno = javaModelImpl.getAnnotationHelper().getAnnotation(getAnnotatedElement(), annotationClass);
if (anno != null) {
return new JavaAnnotationImpl(anno);
}
}
return null;
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class XJCJavaAnnotationImpl method getJavaAnnotation.
/**
* Return a Java <code>Annotation</code> representation of this <code>JavaAnnotation</code>.
*
* @return a Java <code>Annotation</code> representation of this <code>JavaAnnotation</code>.
*/
@SuppressWarnings("unchecked")
public Annotation getJavaAnnotation() {
try {
Map<String, Object> components = new HashMap<>();
// First, get all the default values for this annotation class.
Class<Annotation> annotationClass = (Class<Annotation>) getJavaAnnotationClass();
Method[] methods = annotationClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
components.put(methods[i].getName(), methods[i].getDefaultValue());
}
// Get the property values for this annotation instance.
Map<String, JAnnotationValue> memberValues = xjcAnnotation.getAnnotationMembers();
if (memberValues == null) {
// Return an annotation with just the defaults set.
return AnnotationProxy.getProxy(components, annotationClass, dynamicClassLoader, XMLConversionManager.getDefaultManager());
}
boolean isXmlEnum = annotationClass.equals(XmlEnum.class);
// Now overwrite the default values with anything we find in the XJC annotation instance.
for (String key : memberValues.keySet()) {
JAnnotationValue xjcValue = memberValues.get(key);
if (xjcValue instanceof JAnnotationArrayMember) {
Collection<JAnnotationValue> values = ((JAnnotationArrayMember) xjcValue).annotations2();
List<Object> valuesArray = new ArrayList<>(values.size());
for (JAnnotationValue val : values) {
if (val instanceof JAnnotationUse) {
JAnnotationUse xjcAnno = (JAnnotationUse) val;
XJCJavaAnnotationImpl anno = new XJCJavaAnnotationImpl(xjcAnno, dynamicClassLoader);
valuesArray.add(anno.getJavaAnnotation());
} else if (val instanceof JAnnotationStringValue) {
JAnnotationStringValue value = (JAnnotationStringValue) val;
valuesArray.add(value.toString());
} else if (val instanceof JAnnotationClassValue) {
JAnnotationClassValue cval = (JAnnotationClassValue) val;
valuesArray.add(getValueFromClsValue(cval, isXmlEnum));
} else {
throw new RuntimeException("got " + val.getClass().getName());
}
}
components.put(key, valuesArray.toArray(new Object[valuesArray.size()]));
} else if (xjcValue instanceof JAnnotationStringValue) {
JAnnotationStringValue value = (JAnnotationStringValue) xjcValue;
components.put(key, value.toString());
} else if (xjcValue instanceof JAnnotationClassValue) {
JAnnotationClassValue cval = (JAnnotationClassValue) xjcValue;
components.put(key, getValueFromClsValue(cval, isXmlEnum));
} else {
throw new RuntimeException("got " + xjcValue.getClass().getName());
}
}
return AnnotationProxy.getProxy(components, annotationClass, dynamicClassLoader, XMLConversionManager.getDefaultManager());
} catch (Exception e) {
return null;
}
}
use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method createElementsForTypeMappingInfo.
public void createElementsForTypeMappingInfo() {
if (javaClassToTypeMappingInfos != null && !javaClassToTypeMappingInfos.isEmpty()) {
Set<JavaClass> classes = this.javaClassToTypeMappingInfos.keySet();
for (JavaClass nextClass : classes) {
List<TypeMappingInfo> nextInfos = this.javaClassToTypeMappingInfos.get(nextClass);
for (TypeMappingInfo nextInfo : nextInfos) {
if (nextInfo != null) {
boolean xmlAttachmentRef = false;
String xmlMimeType = null;
java.lang.annotation.Annotation[] annotations = getAnnotations(nextInfo);
Class<?> adapterClass = typeMappingInfoToAdapterClasses.get(nextInfo);
Class<?> declJavaType = null;
if (adapterClass != null) {
declJavaType = CompilerHelper.getTypeFromAdapterClass(adapterClass);
}
if (annotations != null) {
for (Annotation nextAnnotation : annotations) {
if (nextAnnotation != null) {
if (nextAnnotation instanceof XmlMimeType) {
XmlMimeType javaAnnotation = (XmlMimeType) nextAnnotation;
xmlMimeType = javaAnnotation.value();
} else if (nextAnnotation instanceof XmlAttachmentRef) {
xmlAttachmentRef = true;
if (!this.hasSwaRef) {
this.hasSwaRef = true;
}
}
}
}
}
QName qname;
String nextClassName = nextClass.getQualifiedName();
if (declJavaType != null) {
nextClassName = declJavaType.getCanonicalName();
}
if (typeMappingInfosToGeneratedClasses != null) {
Class<?> generatedClass = typeMappingInfosToGeneratedClasses.get(nextInfo);
if (generatedClass != null) {
nextClassName = generatedClass.getCanonicalName();
}
}
TypeInfo nextTypeInfo = typeInfos.get(nextClassName);
if (nextTypeInfo != null) {
qname = new QName(nextTypeInfo.getClassNamespace(), nextTypeInfo.getSchemaTypeName());
} else {
qname = getUserDefinedSchemaTypes().get(nextClassName);
if (qname == null) {
if (nextClassName.equals(ClassConstants.APBYTE.getName()) || nextClassName.equals(Image.class.getName()) || nextClassName.equals(Source.class.getName()) || nextClassName.equals("jakarta.activation.DataHandler")) {
if (xmlAttachmentRef) {
qname = Constants.SWA_REF_QNAME;
} else {
qname = Constants.BASE_64_BINARY_QNAME;
}
} else if (nextClassName.equals(ClassConstants.OBJECT.getName())) {
qname = Constants.ANY_TYPE_QNAME;
} else if (nextClassName.equals(ClassConstants.XML_GREGORIAN_CALENDAR.getName())) {
qname = Constants.ANY_SIMPLE_TYPE_QNAME;
} else {
Class<?> theClass = helper.getClassForJavaClass(nextClass);
qname = XMLConversionManager.getDefaultJavaTypes().get(theClass);
}
}
}
if (qname != null) {
typeMappingInfosToSchemaTypes.put(nextInfo, qname);
}
if (nextInfo.getXmlTagName() != null) {
ElementDeclaration element = new ElementDeclaration(nextInfo.getXmlTagName(), nextClass, nextClass.getQualifiedName(), false);
element.setTypeMappingInfo(nextInfo);
element.setXmlMimeType(xmlMimeType);
element.setXmlAttachmentRef(xmlAttachmentRef);
element.setNillable(nextInfo.isNillable());
if (declJavaType != null) {
element.setJavaType(helper.getJavaClass(declJavaType));
}
Class<?> generatedClass = typeMappingInfosToGeneratedClasses.get(nextInfo);
if (generatedClass != null) {
element.setJavaType(helper.getJavaClass(generatedClass));
}
if (nextInfo.getElementScope() == TypeMappingInfo.ElementScope.Global) {
ElementDeclaration currentElement = this.getGlobalElements().get(element.getElementName());
if (currentElement == null) {
addGlobalElement(element.getElementName(), element);
} else {
// if(currentElement.getTypeMappingInfo() == null) {
// the global element that exists came from an annotation
// } else {
this.localElements.add(element);
// }
}
} else {
this.localElements.add(element);
}
String rootNamespace = element.getElementName().getNamespaceURI();
if (rootNamespace == null) {
rootNamespace = Constants.EMPTY_STRING;
}
if (rootNamespace.equals(Constants.EMPTY_STRING)) {
isDefaultNamespaceAllowed = false;
}
}
}
}
}
}
}
Aggregations