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

org.eclipse.persistence.jaxb.javamodel.xjc.XJCJavaPackageImpl Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * Copyright (c) 2011, 2021 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.util.ArrayList;
import java.util.Collection;

import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
import org.eclipse.persistence.jaxb.javamodel.JavaClass;
import org.eclipse.persistence.jaxb.javamodel.JavaPackage;

import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JPackage;

/**
 * INTERNAL:
 * 

* Purpose: JavaPackage implementation wrapping XJC's JPackage. Used when * bootstrapping a DynamicJAXBContext from an XML Schema. *

* *

* Responsibilities: *

*
    *
  • Provide Package information from the underlying JPackage.
  • *
* * @since EclipseLink 2.1 * * @see org.eclipse.persistence.jaxb.javamodel.JavaPackage */ public class XJCJavaPackageImpl implements JavaPackage { protected JPackage xjcPackage; private DynamicClassLoader dynamicClassLoader; /** * Construct a new instance of XJCJavaPackageImpl. * * @param jPackage - the XJC JPackage to be wrapped. * @param loader - the ClassLoader used to bootstrap the DynamicJAXBContext. */ public XJCJavaPackageImpl(JPackage jPackage, DynamicClassLoader loader) { this.xjcPackage = jPackage; this.dynamicClassLoader = loader; } /** * If this JavaPackage is annotated with an Annotation matching aClass, * return its JavaAnnotation representation. * * @param aClass a JavaClass representing the Annotation to look for. * * @return the JavaAnnotation represented by aClass, if one exists, otherwise return null. */ @Override @SuppressWarnings("unchecked") public JavaAnnotation getAnnotation(JavaClass aClass) { if (aClass != null) { Collection annotations = xjcPackage.annotations(); for (JAnnotationUse annotationUse : annotations) { XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader); if (xjcAnnotation.getJavaAnnotationClass().getCanonicalName().equals(aClass.getQualifiedName())) { return xjcAnnotation; } } // Didn't find annotation so return null return null; } // aClass was null so return null return null; } /** * Return all of the Annotations for this JavaPackage. * * @return A Collection containing this JavaPackage's JavaAnnotations. */ @Override @SuppressWarnings("unchecked") public Collection getAnnotations() { ArrayList annotationsList = new ArrayList<>(); Collection annotations = xjcPackage.annotations(); for (JAnnotationUse annotationUse : annotations) { XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader); annotationsList.add(xjcAnnotation); } return annotationsList; } /** * Returns the name of this JavaPackage. * * @return the String name of this JavaPackage. */ public String getName() { if (xjcPackage != null){ return xjcPackage.name(); } return null; } /** * Returns the fully-qualified name of this JavaPackage. * * @return the String name of this JavaPackage. */ @Override public String getQualifiedName() { return getName(); } /** * Not supported. */ @Override public JavaAnnotation getDeclaredAnnotation(JavaClass arg0) { throw new UnsupportedOperationException("getDeclaredAnnotation"); } /** * Not supported. */ @Override public Collection getDeclaredAnnotations() { throw new UnsupportedOperationException("getDeclaredAnnotations"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy