Skip to content

Commit

Permalink
Long process of resolving DOL cyclic dependencies resolved via reflec…
Browse files Browse the repository at this point in the history
…tion

- one of intermediate steps - moving methods

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Mar 19, 2023
1 parent bb5199f commit f7a9771
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 158 deletions.
Expand Up @@ -62,6 +62,7 @@ public abstract class EjbBundleDescriptor extends CommonResourceBundleDescriptor
private final Set<EjbDescriptor> ejbs = new HashSet<>();
/** EJB module level dependencies */
private final Set<EjbReferenceDescriptor> ejbReferences = new HashSet<>();
private final List<NameValuePairDescriptor> enterpriseBeansProperties = new ArrayList<>();
private final Set<EntityManagerFactoryReferenceDescriptor> entityManagerFactoryReferences = new HashSet<>();
private final Set<EntityManagerReferenceDescriptor> entityManagerReferences = new HashSet<>();
private final Set<EnvironmentProperty> environmentProperties = new HashSet<>();
Expand Down Expand Up @@ -326,6 +327,37 @@ public Collection<? extends PersistenceUnitDescriptor> findReferencedPUs() {
}


/**
* @return list of enterprise beans properties
*/
public List<NameValuePairDescriptor> getEnterpriseBeansProperties() {
return enterpriseBeansProperties;
}


/**
* @param key
* @return property value of enterprise beans
*/
public String getEnterpriseBeansProperty(String key) {
for (NameValuePairDescriptor property : enterpriseBeansProperties) {
if (property.getName().equals(key)) {
return property.getValue();
}
}
return null;
}


/**
* @param newProp property of enterprise beans
*/
// Reflection in EnterpriseBeansRuntimeNode
public void addEnterpriseBeansProperty(NameValuePairDescriptor newProp) {
enterpriseBeansProperties.add(newProp);
}


@Override
public Set<EntityManagerFactoryReferenceDescriptor> getEntityManagerFactoryReferenceDescriptors() {
return entityManagerFactoryReferences;
Expand Down
Expand Up @@ -47,6 +47,7 @@
import com.sun.enterprise.container.common.spi.util.InjectionManager;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.EjbApplicationExceptionInfo;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.EnvironmentProperty;
import com.sun.enterprise.deployment.InterceptorDescriptor;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
Expand Down Expand Up @@ -135,7 +136,6 @@
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.ejb.LogFacade;
import org.glassfish.ejb.api.EjbEndpointFacade;
import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl;
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
import org.glassfish.ejb.deployment.descriptor.EjbInitInfo;
import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
Expand Down Expand Up @@ -644,7 +644,7 @@ protected BaseContainer(final ContainerType type, final EjbDescriptor ejbDesc, f
}

if (isStatelessSession || isSingleton) {
EjbBundleDescriptorImpl bundle = ejbDescriptor.getEjbBundleDescriptor();
EjbBundleDescriptor bundle = ejbDescriptor.getEjbBundleDescriptor();
WebServicesDescriptor webServices = bundle.getWebServices();
Collection<?> endpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);
// JSR 109 doesn't require support for a single ejb
Expand Down Expand Up @@ -1046,7 +1046,7 @@ private void warnIfNotFullProfile(String description) {
*/
protected void initializeHome() throws Exception {
if (isWebServiceEndpoint) {
final EjbBundleDescriptorImpl bundle = ejbDescriptor.getEjbBundleDescriptor();
final EjbBundleDescriptor bundle = ejbDescriptor.getEjbBundleDescriptor();
final WebServicesDescriptor webServices = bundle.getWebServices();
final Collection<WebServiceEndpoint> myEndpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);

Expand Down Expand Up @@ -1412,7 +1412,7 @@ protected SimpleJndiName getJavaGlobalJndiNamePrefix() {
// This method is used to create the ejb after the around_construct interceptor chain has completed.
public void createEjbInstanceForInterceptors(Object[] params, EJBContextImpl ctx) throws Exception {
final Object instance;
final EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
final EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
if (cdiService != null && cdiService.isCDIEnabled(ejbBundle)) {
// EJB creation for CDI is handled in CDIServiceImpl not here.
instance = ctx.getCDIInjectionContext().createEjbAfterAroundConstruct();
Expand All @@ -1428,7 +1428,7 @@ protected EJBContextImpl createEjbInstanceAndContext() throws Exception {
throw new IllegalStateException(localStrings.getLocalString("ejb.container_not_started",
"Attempt to invoke when container is in {0}", containerStateToString(containerState)));
}
EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();

Object instance = null;

Expand Down Expand Up @@ -1506,7 +1506,7 @@ protected Object _constructEJBInstance() throws Exception {
}

private void createEjbInterceptors(EJBContextImpl context, CDIService.CDIInjectionContext ejbInterceptorsCDIInjectionContext) throws Exception {
EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();

Object[] interceptorInstances;

Expand Down Expand Up @@ -1537,7 +1537,7 @@ private void createEjbInterceptors(EJBContextImpl context, CDIService.CDIInjecti

protected void injectEjbInstance(EJBContextImpl context) throws Exception {

EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();

if (cdiService != null && cdiService.isCDIEnabled(ejbBundle)) {
cdiService.injectEJBInstance(context.getCDIInjectionContext());
Expand Down
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,14 +17,16 @@

package org.glassfish.ejb.deployment.annotation.handlers;

import com.sun.enterprise.deployment.MethodDescriptor;
import com.sun.enterprise.deployment.annotation.context.EjbContext;

import jakarta.interceptor.ExcludeClassInterceptors;

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import jakarta.interceptor.ExcludeClassInterceptors;

import com.sun.enterprise.deployment.MethodDescriptor;
import com.sun.enterprise.deployment.annotation.context.EjbContext;
import org.glassfish.apf.AnnotationHandlerFor;
import org.glassfish.apf.AnnotationInfo;
import org.glassfish.apf.AnnotationProcessorException;
Expand All @@ -34,50 +37,43 @@
import org.jvnet.hk2.annotations.Service;

/**
* This handler is responsible for handling the
* jakarta.ejb.ExcludeClassInterceptors annotation.
*
* This handler is responsible for handling the {@link ExcludeClassInterceptors} annotation.
*/
@Service
@AnnotationHandlerFor(ExcludeClassInterceptors.class)
public class ExcludeClassInterceptorsHandler
extends AbstractAttributeHandler {

public ExcludeClassInterceptorsHandler() {
}
public class ExcludeClassInterceptorsHandler extends AbstractAttributeHandler {

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo,
EjbContext[] ejbContexts) throws AnnotationProcessorException {

EjbBundleDescriptorImpl ejbBundle =
((EjbDescriptor)ejbContexts[0].getDescriptor()).
getEjbBundleDescriptor();

for(EjbContext next : ejbContexts) {
@Override
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts)
throws AnnotationProcessorException {

// Assumption: there is just one possibility, same instance for all.
EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
for (EjbContext next : ejbContexts) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();

// Create binding information.
InterceptorBindingDescriptor binding =
new InterceptorBindingDescriptor();
InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();

binding.setEjbName(ejbDescriptor.getName());
binding.setExcludeClassInterceptors(true);

// Annotation can be defined at a method level or constructor level.
MethodDescriptor md = null;
if(ElementType.METHOD.equals(ainfo.getElementType())) {
final MethodDescriptor md;
if (ElementType.METHOD.equals(ainfo.getElementType())) {
Method m = (Method) ainfo.getAnnotatedElement();
md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
} else if(ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
Constructor c = (Constructor) ainfo.getAnnotatedElement();
Class cl = c.getDeclaringClass();
Class[] ctorParamTypes = c.getParameterTypes();
} else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
Constructor<?> c = (Constructor<?>) ainfo.getAnnotatedElement();
Class<?> cl = c.getDeclaringClass();
Class<?>[] ctorParamTypes = c.getParameterTypes();
String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);

md = new MethodDescriptor(cl.getSimpleName(), null,
parameterClassNames, MethodDescriptor.EJB_BEAN);
} // else throw Exception?
md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
} else {
// else throw Exception?
md = null;
}

binding.setBusinessMethod(md);
ejbBundle.prependInterceptorBinding(binding);
Expand All @@ -86,11 +82,8 @@ protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo,
return getDefaultProcessedResult();
}

/**
* @return an array of annotation types this annotation handler would
* require to be processed (if present) before it processes it's own
* annotation type.
*/

@Override
public Class<? extends Annotation>[] getTypeDependencies() {
return getEjbAnnotationTypes();
}
Expand Down

0 comments on commit f7a9771

Please sign in to comment.