Skip to content

Commit

Permalink
Fixes default package name processing
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Aug 29, 2023
1 parent 6fbf895 commit c6bc621
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -19,7 +19,6 @@

import com.sun.ejb.codegen.AsmSerializableBeanGenerator;
import com.sun.ejb.codegen.EjbClassGeneratorFactory;
import com.sun.ejb.codegen.Generator;
import com.sun.ejb.codegen.GeneratorException;
import com.sun.ejb.codegen.Remote30WrapperGenerator;
import com.sun.ejb.codegen.RemoteGenerator;
Expand Down Expand Up @@ -50,6 +49,9 @@

import org.glassfish.api.naming.SimpleJndiName;

import static com.sun.ejb.codegen.Generator.getBaseName;
import static com.sun.ejb.codegen.Generator.getFullClassName;
import static com.sun.ejb.codegen.Generator.getPackageName;
import static java.util.logging.Level.FINE;

/**
Expand Down Expand Up @@ -156,10 +158,10 @@ public java.lang.Object run() {
* @param ejbClassName full class name
*/
public static String getGeneratedOptionalInterfaceName(String ejbClassName) {
String packageName = Generator.getPackageName(ejbClassName);
String simpleName = Generator.getBaseName(ejbClassName);
String packageName = getPackageName(ejbClassName);
String simpleName = getBaseName(ejbClassName);
String optionalIntfName = "__EJB31_Generated__" + simpleName + "__Intf__";
return packageName == null ? optionalIntfName : packageName + "." + optionalIntfName;
return getFullClassName(packageName, optionalIntfName);
}


Expand Down
Expand Up @@ -26,6 +26,9 @@
import org.objectweb.asm.Type;

import static com.sun.ejb.codegen.ClassGenerator.defineClass;
import static com.sun.ejb.codegen.Generator.getBaseName;
import static com.sun.ejb.codegen.Generator.getFullClassName;
import static com.sun.ejb.codegen.Generator.getPackageName;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ALOAD;
Expand All @@ -45,10 +48,10 @@ public class AsmSerializableBeanGenerator extends BeanGeneratorBase {
* @param beanClass full class name
*/
public static String getGeneratedSerializableClassName(String beanClass) {
String packageName = Generator.getPackageName(beanClass);
String simpleName = Generator.getBaseName(beanClass);
String packageName = getPackageName(beanClass);
String simpleName = getBaseName(beanClass);
String generatedSimpleName = "_" + simpleName + "_Serializable";
return packageName == null ? generatedSimpleName : packageName + "." + generatedSimpleName;
return getFullClassName(packageName, generatedSimpleName);
}

public AsmSerializableBeanGenerator(ClassLoader loader, Class<?> superClass, String serializableSubclassName) {
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -47,6 +47,8 @@
public abstract class Generator {
private static final Logger LOG = Logger.getLogger(Generator.class.getName());

private static final String DEFAULT_PACKAGE_NAME = "";

private final ClassLoader loader;


Expand All @@ -58,7 +60,7 @@ public Generator(final ClassLoader loader) {
}

/**
* @return the name of the package of the generated class. Can be null.
* @return the name of the package of the generated class.
*/
protected abstract String getPackageName();

Expand Down Expand Up @@ -100,10 +102,11 @@ public ClassLoader getClassLoader() {
* @throws IllegalAccessException
*/
public Class<?> generate() throws IllegalAccessException {
if (getPackageName() == null) {
final String packageName = getPackageName();
if (DEFAULT_PACKAGE_NAME.equals(packageName)) {
_package();
} else {
_package(getPackageName());
_package(packageName);
}
final ImportList imports = Wrapper._import();
defineClassBody();
Expand All @@ -129,11 +132,11 @@ public Class<?> generate() throws IllegalAccessException {


/**
* @return the package name or null.
* @return the package name.
*/
public static String getPackageName(final String fullClassName) {
final int dot = fullClassName.lastIndexOf('.');
return dot == -1 ? null : fullClassName.substring(0, dot);
return dot == -1 ? DEFAULT_PACKAGE_NAME : fullClassName.substring(0, dot);
}

/**
Expand All @@ -144,6 +147,19 @@ public static String getBaseName(final String fullClassName) {
return dot == -1 ? fullClassName : fullClassName.substring(dot + 1);
}

/**
* Returns full qualified class name.
*
* @param packageName the package name
* @param baseName the base (simple) class name
* @return the full qualified class name
*/
public static String getFullClassName(final String packageName, final String baseName) {
if (DEFAULT_PACKAGE_NAME.equals(packageName)) {
return baseName;
}
return packageName + "." + baseName;
}

/**
* Remove duplicates from method array.
Expand All @@ -154,7 +170,7 @@ public static String getBaseName(final String fullClassName) {
* requires that the superclass/intf method have a superset of the
* exceptions in the derived method).
*
* @param methods
* @param methods the methods array without duplicates
* @return methods which can be generated in an interface
*/
protected Method[] removeRedundantMethods(final Method[] methods) {
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -71,7 +71,7 @@ public static String getGeneratedRemoteWrapperName(final String businessIntf) {
final String packageName = getPackageName(businessIntf);
final String simpleName = getBaseName(businessIntf);
final String generatedSimpleName = "_" + simpleName + "_Wrapper";
return packageName == null ? generatedSimpleName : packageName + "." + generatedSimpleName;
return getFullClassName(packageName, generatedSimpleName);
}

/**
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -40,9 +40,9 @@
*/
public final class RemoteGenerator extends Generator {

private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(RemoteGenerator.class);
private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(RemoteGenerator.class);

private Class<?> businessInterface;
private final Class<?> businessInterface;
private final Method[] methodsToGenerate;
private final String remoteInterfacePackageName;
private final String remoteInterfaceSimpleName;
Expand All @@ -58,16 +58,16 @@ public static String getGeneratedRemoteIntfName(String businessIntf) {
String packageName = getPackageName(businessIntf);
String simpleName = getBaseName(businessIntf);
String generatedSimpleName = "_" + simpleName + "_Remote";
return packageName == null ? generatedSimpleName : packageName + "." + generatedSimpleName;
return getFullClassName(packageName, generatedSimpleName);
}


/**
* Construct the Wrapper generator with the specified deployment
* descriptor and class loader.
*
* @param classLoader
* @param businessIntf
* @param classLoader the class loader
* @param businessIntf the full qualified class name
* @throws GeneratorException if the businessInterface doesn't exist.
*/
public RemoteGenerator(ClassLoader classLoader, String businessIntf) throws GeneratorException {
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -54,14 +54,14 @@ public class ServiceInterfaceGenerator extends Generator {
* descriptor and class loader.
*
* @param loader {@link ClassLoader} owning generated classes
* @param ejbClass
* @param ejbClass the wrapped class
*/
public ServiceInterfaceGenerator(final ClassLoader loader, final Class<?> ejbClass) {
super(loader);
this.ejbClass = ejbClass;
packageName = getPackageName(ejbClass.getName());
serviceIntfSimpleName = getServiceIntfName(ejbClass);
serviceIntfName = (packageName == null ? "" : packageName + ".") + serviceIntfSimpleName;
serviceIntfName = getFullClassName(packageName, serviceIntfSimpleName);
intfMethods = calculateMethods(ejbClass, removeRedundantMethods(ejbClass.getMethods()));

// NOTE : no need to remove ejb object methods because EJBObject
Expand Down

0 comments on commit c6bc621

Please sign in to comment.