forked from wildfly/wildfly
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WFLY-1370 Allow CDI Extension to be loaded from static modules
This commit changes the way CDI portable extensions are loaded, so they will be picked up from any module that has its services exposed to the deployment. This will both allow users to register portable extensions from static modules, and also allow subsystems to more easily register extensions.
- Loading branch information
1 parent
59ff359
commit e8ef344
Showing
8 changed files
with
143 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
weld/src/main/java/org/jboss/as/weld/deployment/WeldPortableExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.jboss.as.weld.deployment; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.inject.spi.Extension; | ||
|
||
import org.jboss.as.server.deployment.AttachmentKey; | ||
import org.jboss.as.server.deployment.DeploymentUnit; | ||
import org.jboss.as.server.deployment.DeploymentUnitProcessingException; | ||
import org.jboss.as.weld.WeldLogger; | ||
import org.jboss.as.weld.WeldMessages; | ||
import org.jboss.weld.bootstrap.spi.Metadata; | ||
import org.jboss.weld.metadata.MetadataImpl; | ||
|
||
/** | ||
* Container class that is attached to the top level deployment that holds all portable extension metadata. | ||
* <p/> | ||
* A portable extension may be available to multiple deployment class loaders, however for each PE we | ||
* only want to register a single instance. | ||
* <p/> | ||
* This container provides a mechanism for making sure that only a single PE of a given type is registered. | ||
* | ||
* @author Stuart Douglas | ||
*/ | ||
public class WeldPortableExtensions { | ||
|
||
private static final AttachmentKey<WeldPortableExtensions> ATTACHMENT_KEY = AttachmentKey.create(WeldPortableExtensions.class); | ||
|
||
public static WeldPortableExtensions getPortableExtensions(final DeploymentUnit deploymentUnit) { | ||
if (deploymentUnit.getParent() == null) { | ||
WeldPortableExtensions pes = deploymentUnit.getAttachment(WeldPortableExtensions.ATTACHMENT_KEY); | ||
if (pes == null) { | ||
deploymentUnit.putAttachment(ATTACHMENT_KEY, pes = new WeldPortableExtensions()); | ||
} | ||
return pes; | ||
} else { | ||
return getPortableExtensions(deploymentUnit.getParent()); | ||
} | ||
} | ||
|
||
private final Map<Class<?>, Metadata<Extension>> extensions = new HashMap<>(); | ||
|
||
public synchronized void tryRegisterExtension(final Class<?> extensionClass, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { | ||
if (!Extension.class.isAssignableFrom(extensionClass)) { | ||
throw WeldMessages.MESSAGES.extensionDoesNotImplementExtension(extensionClass); | ||
} | ||
if (extensions.containsKey(extensionClass)) { | ||
return; | ||
} | ||
try { | ||
extensions.put(extensionClass, new MetadataImpl<>((Extension) extensionClass.newInstance(), deploymentUnit.getName())); | ||
} catch (InstantiationException e) { | ||
WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(extensionClass.getName(), e); | ||
} catch (IllegalAccessException e) { | ||
WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(extensionClass.getName(), e); | ||
} | ||
|
||
} | ||
|
||
public synchronized void registerExtensionInstance(final Extension extension, final DeploymentUnit deploymentUnit) { | ||
extensions.put(extension.getClass(), new MetadataImpl<>(extension, deploymentUnit.getName())); | ||
} | ||
|
||
public Collection<Metadata<Extension>> getExtensions() { | ||
return new HashSet<>(extensions.values()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.