org.eclipse.persistence.internal.jaxb.JaxbClassLoader Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*
* Copyright (c) 1998, 2018 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:
// mmacivor - April 25/2008 - 1.0M8 - Initial implementation
package org.eclipse.persistence.internal.jaxb;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.persistence.jaxb.TypeMappingInfo;
/**
* INTERNAL:
* Purpose:Provide a ClassLoader implementation to allow the definition of ASM generated
* wrapper classes, and to lookup those classes when required.
*
Responsibilities:
* - Wrap the provided ClassLoader and pass method calls along
* - Maintain a map of generated wrapper classes and attempt lookups in that map if a class isn't found
* in the nested loader
* - Provide a public API to define a class from an array of bytes and a class name
* This class is a ClassLoader implementation that maintains a map of wrapper classes generated during
* JAXB generation. If a class is not found in the nested classLoader, then the map of generated classes
* is checked.
* @author mmacivor
*
*/
public class JaxbClassLoader extends ClassLoader {
private static final String GENERATED_CLASS_NAME = "org.eclipse.persistence.jaxb.generated";
private Map generatedClasses;
private AtomicInteger generatedClassCounter = new AtomicInteger();
public JaxbClassLoader(ClassLoader nestedClassLoader) {
super(nestedClassLoader);
this.generatedClasses = new HashMap();
}
public JaxbClassLoader(ClassLoader nestedClassLoader, Class[] classes) {
super(nestedClassLoader);
this.generatedClasses = new HashMap();
if(classes != null){
for(int i=0; i