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

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

There is a newer version: 5.0.0-B02
Show newest version
/*******************************************************************************
 * Copyright (c) 2011, 2014 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.reflect.Modifier;

import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.jaxb.javamodel.JavaClass;
import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;

import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JType;

/**
 * INTERNAL:
 * 

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

* *

* Responsibilities: *

*
    *
  • Provide Constructor information from the underlying JMethod.
  • *
* * @since EclipseLink 2.1 * * @see org.eclipse.persistence.jaxb.javamodel.JavaConstructor */ public class XJCJavaConstructorImpl implements JavaConstructor { private JMethod xjcConstructor; private JCodeModel jCodeModel; private DynamicClassLoader dynamicClassLoader; private JavaClass owningClass; /** * Construct a new instance of XJCJavaConstructorImpl. * * @param constructor - the XJC JMethod to be wrapped. * @param codeModel - the XJC JCodeModel this constructor belongs to. * @param loader - the ClassLoader used to bootstrap the DynamicJAXBContext. * @param owner - the JavaClass this constructor belongs to. */ public XJCJavaConstructorImpl(JMethod constructor, JCodeModel codeModel, DynamicClassLoader loader, JavaClass owner) { this.xjcConstructor = constructor; this.jCodeModel = codeModel; this.dynamicClassLoader = loader; this.owningClass = owner; } /** * Returns the Java language modifiers for this JavaConstructor, encoded in an integer. * * @return the int representing the modifiers for this constructor. * * @see java.lang.reflect.Modifier */ public int getModifiers() { return xjcConstructor.mods().getValue(); } /** * Returns the name of this JavaConstructor. * * @return the String name of this JavaConstructor. */ public String getName() { return xjcConstructor.name(); } /** * Returns the array of parameters for this JavaConstructor. * * @return a JavaClass[] representing the argument types for this constructor. */ public JavaClass[] getParameterTypes() { JType[] params = xjcConstructor.listParamTypes(); JavaClass[] paramArray = new JavaClass[params.length]; for (int i = 0; i < params.length; i++) { JavaClass dc; if (((XJCJavaClassImpl) getOwningClass()).getJavaModel() != null) { dc = ((XJCJavaClassImpl) getOwningClass()).getJavaModel().getClass(params[i].fullName()); } else { dc = new XJCJavaClassImpl((JDefinedClass) params[i], jCodeModel, dynamicClassLoader); } paramArray[i] = dc; } return paramArray; } /** * Indicates if this JavaConstructor is abstract. * * @return true if this JavaConstructor is abstract, otherwise false. */ public boolean isAbstract() { return Modifier.isAbstract(getModifiers()); } /** * Indicates if this JavaConstructor is private. * * @return true if this JavaConstructor is private, otherwise false. */ public boolean isPrivate() { return Modifier.isPrivate(getModifiers()); } /** * Indicates if this JavaConstructor is protected. * * @return true if this JavaConstructor is protected, otherwise false. */ public boolean isProtected() { return Modifier.isProtected(getModifiers()); } /** * Indicates if this JavaConstructor is public. * * @return true if this JavaConstructor is public, otherwise false. */ public boolean isPublic() { return Modifier.isPublic(getModifiers()); } /** * Indicates if this JavaConstructor is static. * * @return true if this JavaConstructor is static, otherwise false. */ public boolean isStatic() { return Modifier.isStatic(getModifiers()); } /** * Indicates if this JavaConstructor is final. * * @return true if this JavaConstructor is final, otherwise false. */ public boolean isFinal() { return Modifier.isFinal(getModifiers()); } /** * Not supported. */ public boolean isSynthetic() { throw new UnsupportedOperationException("isSynthetic"); } /** * Returns the JavaClass which contains this constructor. * * @return JavaClass representing the owner of this JavaConstructor. */ public JavaClass getOwningClass() { return owningClass; } /** * Set the JavaClass which contains this constructor. * * @param owningClass the JavaClass representing the owner of this JavaConstructor. */ public void setOwningClass(JavaClass owningClass) { this.owningClass = owningClass; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy