Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatej committed Jul 19, 2022
1 parent 72181ec commit 19fda59
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 55 deletions.
6 changes: 3 additions & 3 deletions appserver/featuresets/web/pom.xml
Expand Up @@ -672,7 +672,7 @@
</exclusion>
</exclusions>
</dependency>

<!-- Jakarta Athorization -->
<dependency>
<groupId>jakarta.authorization</groupId>
Expand All @@ -694,7 +694,7 @@
</exclusion>
</exclusions>
</dependency>

<!-- Jakarta Concurrency -->
<dependency>
<groupId>jakarta.enterprise.concurrent</groupId>
Expand Down Expand Up @@ -746,7 +746,7 @@
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.glassfish.main.transaction</groupId>
Expand Down
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,23 +17,27 @@

package org.glassfish.weld;

import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
import com.sun.enterprise.deployment.JndiNameEnvironment;
import com.sun.enterprise.deployment.WebBundleDescriptor;

import jakarta.inject.Inject;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.NamingException;

import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
import org.glassfish.api.naming.NamedNamingObjectProxy;
import org.glassfish.api.naming.NamespacePrefixes;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jvnet.hk2.annotations.Service;

import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
import com.sun.enterprise.deployment.JndiNameEnvironment;
import com.sun.enterprise.deployment.WebBundleDescriptor;

import jakarta.inject.Inject;

/**
* Proxy for java:comp/BeanManager lookups
*
Expand All @@ -41,6 +46,9 @@
@Service
@NamespacePrefixes(BeanManagerNamingProxy.BEAN_MANAGER_CONTEXT)
public class BeanManagerNamingProxy implements NamedNamingObjectProxy {
private static final Logger LOG = Logger.getLogger(BeanManagerNamingProxy.class.getName());

static final String BEAN_MANAGER_CONTEXT = "java:comp/BeanManager";

@Inject
private ComponentEnvManager compEnvManager;
Expand All @@ -51,57 +59,59 @@ public class BeanManagerNamingProxy implements NamedNamingObjectProxy {
@Inject
private WeldDeployer weldDeployer;

static final String BEAN_MANAGER_CONTEXT = "java:comp/BeanManager";

@Override
public Object handle(String name) throws NamingException {
LOG.log(Level.FINEST, "handle(name={0})", name);
if (!BEAN_MANAGER_CONTEXT.equals(name)) {
return null;
}
try {
// Use invocation context to find applicable BeanDeploymentArchive.
ComponentInvocation componentInvocation = invocationManager.getCurrentInvocation();
if (componentInvocation == null) {
return null;
}
final JndiNameEnvironment componentEnv = compEnvManager
.getJndiNameEnvironment(componentInvocation.getComponentId());
if (componentEnv == null) {
throw new IllegalStateException("No invocation context found");
}
final BundleDescriptor bundle = getBundleDescriptor(componentEnv);
final BeanManagerImpl beanManager = getBeanManager(bundle);
if (beanManager == null) {
throw new IllegalStateException("Cannot resolve bean manager");
}
return beanManager;
} catch (Throwable t) {
NamingException ne = new NamingException("Error retrieving java:comp/BeanManager");
ne.initCause(t);
throw ne;
}
}

Object beanManager = null;

if (BEAN_MANAGER_CONTEXT.equals(name)) {
try {

// Use invocation context to find applicable BeanDeploymentArchive.
ComponentInvocation componentInvocation = invocationManager.getCurrentInvocation();

if (componentInvocation != null) {

JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(componentInvocation.getComponentId());

if (componentEnv == null) {
throw new IllegalStateException("No invocation context found");
}

BundleDescriptor bundle = null;

if (componentEnv instanceof EjbDescriptor) {
bundle = (BundleDescriptor) ((EjbDescriptor) componentEnv).getEjbBundleDescriptor().getModuleDescriptor()
.getDescriptor();

} else if (componentEnv instanceof WebBundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
}

if (bundle != null) {
BeanDeploymentArchive beanDeploymentArchive = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
if (beanDeploymentArchive != null) {
beanManager = weldDeployer.getBootstrapForApp(bundle.getApplication()).getManager(beanDeploymentArchive);
}
}
private BundleDescriptor getBundleDescriptor(JndiNameEnvironment componentEnv) {
if (componentEnv instanceof EjbDescriptor) {
return (BundleDescriptor) ((EjbDescriptor) componentEnv).getEjbBundleDescriptor().getModuleDescriptor()
.getDescriptor();
} else if (componentEnv instanceof WebBundleDescriptor) {
return (BundleDescriptor) componentEnv;
} else {
return null;
}
}

if (beanManager == null) {
throw new IllegalStateException("Cannot resolve bean manager");
}
}

} catch (Throwable t) {
NamingException ne = new NamingException("Error retrieving java:comp/BeanManager");
ne.initCause(t);
throw ne;
}
private BeanManagerImpl getBeanManager(BundleDescriptor bundle) {
if (bundle == null) {
return null;
}

return beanManager;
BeanDeploymentArchive beanDeploymentArchive = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
if (beanDeploymentArchive == null) {
return null;
}
return weldDeployer.getBootstrapForApp(bundle.getApplication()).getManager(beanDeploymentArchive);
}

}
Expand Up @@ -140,7 +140,7 @@ public static List<Integer> findBundleIds(String message) {
bundleIds.add(Integer.valueOf(number));
}

return new ArrayList<Integer>(bundleIds);
return new ArrayList<>(bundleIds);
}

private static void printLn(StringBuilder messageBuilder, int indent, String message) {
Expand Down

0 comments on commit 19fda59

Please sign in to comment.