org.eclipse.persistence.jaxb.javamodel.xjc.XJCJavaAnnotationImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink Show documentation
Show all versions of eclipselink Show documentation
EclipseLink build based upon Git transaction 346465e
/*******************************************************************************
* Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Rick Barkhouse - 2.1 - Initial implementation
******************************************************************************/
package org.eclipse.persistence.jaxb.javamodel.xjc;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlEnum;
import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.exceptions.JAXBException;
import org.eclipse.persistence.internal.oxm.XMLConversionManager;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.jaxb.javamodel.AnnotationProxy;
import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
import com.sun.codemodel.JAnnotationArrayMember;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JAnnotationValue;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JStringLiteral;
/**
* INTERNAL:
*
* Purpose: JavaAnnotation
implementation wrapping XJC's JAnnotationUse
. Used when
* bootstrapping a DynamicJAXBContext
from an XML Schema.
*
*
*
* Responsibilities:
*
* - Provide
Annotation
information from the underlying JAnnotationUse
.
*
*
*
* @since EclipseLink 2.1
*
* @see org.eclipse.persistence.jaxb.javamodel.JavaAnnotation
*/
public class XJCJavaAnnotationImpl implements JavaAnnotation {
private JAnnotationUse xjcAnnotation;
private DynamicClassLoader dynamicClassLoader;
private static Field JANNOTATIONUSE_CLAZZ = null;
private static Field JANNOTATIONUSE_MEMBERVALUES = null;
private static Field JANNOTATIONARRAYMEMBER_VALUES = null;
static {
try {
JANNOTATIONUSE_CLAZZ = PrivilegedAccessHelper.getDeclaredField(JAnnotationUse.class, "clazz", true);
JANNOTATIONUSE_MEMBERVALUES = PrivilegedAccessHelper.getDeclaredField(JAnnotationUse.class, "memberValues", true);
JANNOTATIONARRAYMEMBER_VALUES = PrivilegedAccessHelper.getDeclaredField(JAnnotationArrayMember.class, "values", true);
} catch (Exception e) {
throw JAXBException.errorCreatingDynamicJAXBContext(e);
}
}
/**
* Construct a new instance of XJCJavaAnnotationImpl
.
*
* @param annotation - the XJC JAnnotationUse
to be wrapped.
* @param loader - the ClassLoader
used to bootstrap the DynamicJAXBContext
.
*/
public XJCJavaAnnotationImpl(JAnnotationUse annotation, DynamicClassLoader loader) {
this.xjcAnnotation = annotation;
this.dynamicClassLoader = loader;
}
/**
* Return a Java Annotation
representation of this JavaAnnotation
.
*
* @return a Java Annotation
representation of this JavaAnnotation
.
*/
@SuppressWarnings("unchecked")
public Annotation getJavaAnnotation() {
try {
Map components = new HashMap();
// First, get all the default values for this annotation class.
Object xjcRefClass = PrivilegedAccessHelper.getValueFromField(JANNOTATIONUSE_CLAZZ, xjcAnnotation);
// Cannot cache this field because JReferencedClass is a protected class.
Field _classField = PrivilegedAccessHelper.getDeclaredField(xjcRefClass.getClass(), "_class", true);
Class annotationClass = (Class) PrivilegedAccessHelper.getValueFromField(_classField, xjcRefClass);
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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy