All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelImpl Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * 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.2 - Initial implementation
package org.eclipse.persistence.jaxb.javamodel.oxm;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.persistence.internal.jaxb.JaxbClassLoader;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.jaxb.javamodel.JavaClass;
import org.eclipse.persistence.jaxb.javamodel.JavaModel;
import org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl;
import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;

/**
 * INTERNAL:
 * 

* Purpose: JavaModel implementation backed by a collection of MOXY's * xmlmodel.JavaClasses. Used when bootstrapping a DynamicJAXBContext * from XML Bindings. *

* *

* Responsibilities: *

*
    *
  • Return a JavaClass based on a Class or Class name.
  • *
* * @since EclipseLink 2.2 * * @see org.eclipse.persistence.jaxb.javamodel.JavaModel */ public class OXMJavaModelImpl extends JavaModelImpl implements JavaModel { private Map javaModelClasses = new HashMap(); /** * Construct a new instance of OXMJavaModelImpl. * * @param loader - the ClassLoader used to bootstrap the DynamicJAXBContext. * @param javaClasses - an array of JavaClasses for which to generate mappings. * */ public OXMJavaModelImpl(ClassLoader loader, JavaClass[] javaClasses) { super(loader); for (int i = 0; i < javaClasses.length; i++) { this.javaModelClasses.put(javaClasses[i].getQualifiedName(), javaClasses[i]); } } /** * Obtain the JavaClass given the corresponding Java Class. * * @param jClass - the Java Class to search for. * * @return the JavaClass corresponding to jClass. */ @Override public JavaClass getClass(Class jClass) { if (jClass == null) { return null; } String className = jClass.getCanonicalName(); JavaClass cachedClass = this.javaModelClasses.get(className); if (cachedClass != null) { return cachedClass; } // try actually finding the class, might be concrete try { if (jClass.isArray()) { className = jClass.getName(); } Class realClass = PrivilegedAccessHelper.getClassForName(className, true, classLoader); if (realClass != null) { JavaModelImpl jm = new JavaModelImpl(classLoader); JavaClassImpl jc = new JavaClassImpl(realClass, jm); return jc; } } catch (Exception e) { } return new OXMJavaClassImpl(jClass.getCanonicalName()); } /** * Obtain the JavaClass given the corresponding Java Class' name. * * @param className - the name of the Java Class to search for. * * @return the JavaClass corresponding to className. */ @Override public JavaClass getClass(String className) { if (className == null) { return null; } // jakarta.xml.bind.annotation.XmlElement.DEFAULT if (className.contains(DEFAULT)) { return getClass(JAVA_LANG_OBJECT); } JavaClass cachedClass = this.javaModelClasses.get(className); if (cachedClass != null) { return cachedClass; } // try actually finding the class, might be concrete try { Class realClass = PrivilegedAccessHelper.getClassForName(className, true, classLoader); if (realClass != null) { JavaModelImpl jm = new JavaModelImpl(this.classLoader); JavaClassImpl jc = new JavaClassImpl(realClass, jm); return jc; } } catch (Exception e) { } return new OXMJavaClassImpl(className); } /** * Returns this JavaModel's ClassLoader. * * @return the ClassLoader used by this JavaModel. */ @Override public ClassLoader getClassLoader() { return this.classLoader; } /** * Returns this JavaModel's JaxbClassLoader, which * should be the parent ClassLoader. * * @return the JaxbClassLoader used by this JavaModel. */ public JaxbClassLoader getJaxbClassLoader() { ClassLoader parent = getClassLoader().getParent(); if (parent instanceof JaxbClassLoader) { return (JaxbClassLoader) parent; } return null; } // ======================================================================== private static String DEFAULT = "DEFAULT"; private static String JAVA_LANG_OBJECT = "java.lang.Object"; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy