Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2011, 2020 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// 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 jakarta.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