repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
---|---|---|---|---|---|---|
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/DeploymentRepositoryService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
/**
* Repository for information about deployed modules. This includes information on all the deployed Jakarta Enterprise Beans's in the module
*
* @author Stuart Douglas
*/
public class DeploymentRepositoryService implements DeploymentRepository, Service<DeploymentRepository> {
public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("ee", "deploymentRepository");
/**
* All deployed modules. This is a copy on write map that is updated infrequently and read often.
*/
private volatile Map<DeploymentModuleIdentifier, DeploymentHolder> modules;
private final List<DeploymentRepositoryListener> listeners = new ArrayList<DeploymentRepositoryListener>();
/**
* Keeps track of whether the repository is suspended or not
*/
private volatile boolean suspended = false;
@Override
public void start(StartContext context) throws StartException {
modules = Collections.emptyMap();
}
@Override
public void stop(StopContext context) {
modules = Collections.emptyMap();
}
@Override
public DeploymentRepository getValue() {
return this;
}
@Override
public void add(DeploymentModuleIdentifier identifier, ModuleDeployment deployment) {
final List<DeploymentRepositoryListener> listeners;
final boolean suspended;
synchronized (this) {
final Map<DeploymentModuleIdentifier, DeploymentHolder> modules = new HashMap<DeploymentModuleIdentifier, DeploymentHolder>(this.modules);
modules.put(identifier, new DeploymentHolder(deployment));
this.modules = Collections.unmodifiableMap(modules);
listeners = new ArrayList<DeploymentRepositoryListener>(this.listeners);
suspended = this.suspended;
}
for (final DeploymentRepositoryListener listener : listeners) {
try {
listener.deploymentAvailable(identifier, deployment);
if (suspended) {
listener.deploymentSuspended(identifier);
}
} catch (Throwable t) {
EjbLogger.DEPLOYMENT_LOGGER.deploymentAddListenerException(t);
}
}
}
@Override
public boolean startDeployment(DeploymentModuleIdentifier identifier) {
DeploymentHolder deployment;
final List<DeploymentRepositoryListener> listeners;
synchronized (this) {
deployment = modules.get(identifier);
if (deployment == null) return false;
deployment.started = true;
listeners = new ArrayList<DeploymentRepositoryListener>(this.listeners);
}
for (final DeploymentRepositoryListener listener : listeners) {
try {
listener.deploymentStarted(identifier, deployment.deployment);
} catch (Throwable t) {
EjbLogger.DEPLOYMENT_LOGGER.deploymentAddListenerException(t);
}
}
return true;
}
@Override
public void addListener(final DeploymentRepositoryListener listener) {
synchronized (this) {
listeners.add(listener);
}
listener.listenerAdded(this);
}
@Override
public synchronized void removeListener(final DeploymentRepositoryListener listener) {
listeners.remove(listener);
}
@Override
public void remove(DeploymentModuleIdentifier identifier) {
final List<DeploymentRepositoryListener> listeners;
synchronized (this) {
final Map<DeploymentModuleIdentifier, DeploymentHolder> modules = new HashMap<DeploymentModuleIdentifier, DeploymentHolder>(this.modules);
modules.remove(identifier);
this.modules = Collections.unmodifiableMap(modules);
listeners = new ArrayList<DeploymentRepositoryListener>(this.listeners);
}
for (final DeploymentRepositoryListener listener : listeners) {
try {
listener.deploymentRemoved(identifier);
} catch (Throwable t) {
EjbLogger.DEPLOYMENT_LOGGER.deploymentRemoveListenerException(t);
}
}
}
@Override
public boolean isSuspended() {
return suspended;
}
@Override
public void suspend() {
final List<DeploymentRepositoryListener> listeners;
final Set<DeploymentModuleIdentifier> moduleIdentifiers;
synchronized (this) {
moduleIdentifiers = new HashSet<>(this.modules.keySet());
listeners = new ArrayList<>(this.listeners);
suspended = true;
}
for (final DeploymentRepositoryListener listener : listeners) {
for (DeploymentModuleIdentifier moduleIdentifier : moduleIdentifiers)
try {
listener.deploymentSuspended(moduleIdentifier);
} catch (Throwable t) {
EjbLogger.DEPLOYMENT_LOGGER.deploymentAddListenerException(t);
}
}
}
@Override
public void resume() {
final List<DeploymentRepositoryListener> listeners;
final Set<DeploymentModuleIdentifier> moduleIdentifiers;
synchronized (this) {
moduleIdentifiers = new HashSet<>(this.modules.keySet());
listeners = new ArrayList<>(this.listeners);
suspended = false;
}
for (final DeploymentRepositoryListener listener : listeners) {
for (DeploymentModuleIdentifier moduleIdentifier : moduleIdentifiers)
try {
listener.deploymentResumed(moduleIdentifier);
} catch (Throwable t) {
EjbLogger.DEPLOYMENT_LOGGER.deploymentAddListenerException(t);
}
}
}
@Override
public Map<DeploymentModuleIdentifier, ModuleDeployment> getModules() {
Map<DeploymentModuleIdentifier, ModuleDeployment> modules = new HashMap<DeploymentModuleIdentifier, ModuleDeployment>();
for(Map.Entry<DeploymentModuleIdentifier, DeploymentHolder> entry : this.modules.entrySet()) {
modules.put(entry.getKey(), entry.getValue().deployment);
}
return modules;
}
@Override
public Map<DeploymentModuleIdentifier, ModuleDeployment> getStartedModules() {
Map<DeploymentModuleIdentifier, ModuleDeployment> modules = new HashMap<DeploymentModuleIdentifier, ModuleDeployment>();
for(Map.Entry<DeploymentModuleIdentifier, DeploymentHolder> entry : this.modules.entrySet()) {
if(entry.getValue().started) {
modules.put(entry.getKey(), entry.getValue().deployment);
}
}
return modules;
}
private static final class DeploymentHolder {
final ModuleDeployment deployment;
volatile boolean started = false;
private DeploymentHolder(ModuleDeployment deployment) {
this.deployment = deployment;
}
}
}
| 8,473 | 36.662222 | 150 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/EjbSecurityDeployer.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
import org.jboss.as.ee.security.AbstractSecurityDeployer;
import org.jboss.as.ee.security.JaccService;
import org.jboss.as.ejb3.security.EjbJaccConfig;
import org.jboss.as.ejb3.security.EjbJaccService;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.AttachmentList;
/**
* Handles Jakarta Enterprise Beans jar deployments
*
* @author <a href="mailto:[email protected]">Marcus Moyses</a>
*/
public class EjbSecurityDeployer extends AbstractSecurityDeployer<AttachmentList<EjbJaccConfig>> {
/**
* {@inheritDoc}
*/
@Override
protected AttachmentKey<AttachmentList<EjbJaccConfig>> getMetaDataType() {
return EjbDeploymentAttachmentKeys.JACC_PERMISSIONS;
}
/**
* {@inheritDoc}
*/
@Override
protected JaccService<AttachmentList<EjbJaccConfig>> createService(String contextId, AttachmentList<EjbJaccConfig> metaData, Boolean standalone) {
return new EjbJaccService(contextId, metaData, standalone);
}
}
| 2,077 | 36.781818 | 150 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/EJBSecurityDomainService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
import static java.security.AccessController.doPrivileged;
import static org.wildfly.security.auth.server.SecurityDomain.unregisterClassLoader;
import static org.wildfly.security.manager.WildFlySecurityManager.isChecking;
import java.security.PrivilegedAction;
import java.util.function.BiFunction;
import org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainService.ApplicationSecurityDomain;
import org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainService.Registration;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.modules.Module;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* A service that sets up the security domain mapping for an Jakarta Enterprise Beans deployment.
*
* This service is reponsible for deployment level actions such as registering a deployment with the resolved
* application-security-domain mapping or associating the {@code SecurityDomain} with the deployment's {@code ClassLoader}.
* Defined {@code ComponentConfigurator} instances will then provide the component specific installation.
*
* @author <a href="mailto:[email protected]">Farah</a>
*/
public class EJBSecurityDomainService implements Service<Void> {
public static final ServiceName SERVICE_NAME = ServiceName.of("ejb3", "security-domain");
private final InjectedValue<ApplicationSecurityDomain> applicationSecurityDomain = new InjectedValue<>();
private final InjectedValue<SecurityDomain> securityDomain = new InjectedValue<>();
private final DeploymentUnit deploymentUnit;
private volatile Runnable cleanUpTask;
public EJBSecurityDomainService(final DeploymentUnit deploymentUnit) {
this.deploymentUnit = deploymentUnit;
}
@Override
public synchronized void start(StartContext context) throws StartException {
final String deploymentName = deploymentUnit.getParent() == null ? deploymentUnit.getName()
: deploymentUnit.getParent().getName() + "." + deploymentUnit.getName();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ClassLoader classLoader = module.getClassLoader();
ApplicationSecurityDomain applicationSecurityDomain = this.applicationSecurityDomain.getOptionalValue();
if (applicationSecurityDomain != null) {
BiFunction<String, ClassLoader, Registration> securityFunction = applicationSecurityDomain.getSecurityFunction();
if (securityFunction != null) {
Registration registration = securityFunction.apply(deploymentName, classLoader);
cleanUpTask = registration::cancel;
}
} else {
final SecurityDomain securityDomain = this.securityDomain.getValue(); // At least one must be injected.
if (isChecking()) {
doPrivileged((PrivilegedAction<Void>) () -> {
securityDomain.registerWithClassLoader(classLoader);
return null;
});
} else {
securityDomain.registerWithClassLoader(classLoader);
}
cleanUpTask = new Runnable() {
@Override
public void run() {
if (WildFlySecurityManager.isChecking()) {
doPrivileged((PrivilegedAction<Void>) () -> {
unregisterClassLoader(classLoader);
return null;
});
} else {
unregisterClassLoader(classLoader);
}
}
};
}
}
@Override
public synchronized void stop(StopContext context) {
if (cleanUpTask != null) {
cleanUpTask.run();
}
}
@Override
public Void getValue() throws IllegalStateException, IllegalArgumentException {
return null;
}
public Injector<ApplicationSecurityDomain> getApplicationSecurityDomainInjector() {
return applicationSecurityDomain;
}
public Injector<SecurityDomain> getSecurityDomainInjector() {
return securityDomain;
}
}
| 5,616 | 40.301471 | 125 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/EjbDeploymentAttachmentKeys.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
import org.jboss.as.ejb3.deployment.processors.EjbInjectionSource;
import org.jboss.as.ejb3.remote.EJBClientContextService;
import org.jboss.as.ejb3.security.EjbJaccConfig;
import org.jboss.as.ejb3.subsystem.deployment.InstalledComponent;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.AttachmentList;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.msc.service.ServiceName;
/**
* {@link org.jboss.as.server.deployment.DeploymentUnitProcessor} attachment keys specific to EJB3 deployment
* unit processors
* <p/>
* Author: Jaikiran Pai
*/
public class EjbDeploymentAttachmentKeys {
/**
* Attachment key to the {@link EjbJarMetaData} attachment representing the metadata created out of the ejb-jar.xml
* deployment descriptor
*/
public static final AttachmentKey<EjbJarMetaData> EJB_JAR_METADATA = AttachmentKey.create(EjbJarMetaData.class);
public static final AttachmentKey<EjbJarDescription> EJB_JAR_DESCRIPTION = AttachmentKey.create(EjbJarDescription.class);
public static final AttachmentKey<ApplicationExceptionDescriptions> APPLICATION_EXCEPTION_DESCRIPTIONS = AttachmentKey.create(ApplicationExceptionDescriptions.class);
public static final AttachmentKey<ApplicationExceptions> APPLICATION_EXCEPTION_DETAILS = AttachmentKey.create(ApplicationExceptions.class);
public static final AttachmentKey<AttachmentList<EjbInjectionSource>> EJB_INJECTIONS = AttachmentKey.createList(EjbInjectionSource.class);
public static final AttachmentKey<EJBClientContextService> EJB_CLIENT_CONTEXT_SERVICE = AttachmentKey.create(EJBClientContextService.class);
public static final AttachmentKey<ServiceName> EJB_CLIENT_CONTEXT_SERVICE_NAME = AttachmentKey.create(ServiceName.class);
public static final AttachmentKey<ServiceName> EJB_REMOTING_PROFILE_SERVICE_NAME = AttachmentKey.create(ServiceName.class);
/**
* components that have been registered with the management API
*/
public static final AttachmentKey<AttachmentList<InstalledComponent>> MANAGED_COMPONENTS = AttachmentKey.createList(InstalledComponent.class);
public static final AttachmentKey<AttachmentList<EjbJaccConfig>> JACC_PERMISSIONS = AttachmentKey.createList(EjbJaccConfig.class);
}
| 3,357 | 48.382353 | 170 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/DeploymentRepositoryListener.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
/**
* Listener class that notifies on deployment availability changes
*
* @author Stuart Douglas
*/
public interface DeploymentRepositoryListener {
/**
* Called when the listener is added to the repository. This method runs in a synchronized block,
* so the listener can get the current state of the repository.
*/
void listenerAdded(final DeploymentRepository repository);
/**
* Callback when a deployment becomes available
* @param deployment The deployment
* @param moduleDeployment module deployment
*/
void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment);
/**
* Callback when a deployment has started, i.e. all components have started
* @param deployment The deployment
* @param moduleDeployment module deployment
*/
void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment);
/**
* Called when a deployment is no longer available
*
* @param deployment The deployment
*/
void deploymentRemoved(final DeploymentModuleIdentifier deployment);
/**
* Called when a deployment is suspended, as a result of server suspension.
* @param deployment The deployment
*/
default void deploymentSuspended(final DeploymentModuleIdentifier deployment){}
/**
* Called when a deployment is no longer suspended, as a result of server resume.
* <br>
* Can only be invoked after {@link #deploymentSuspended(DeploymentModuleIdentifier)}, i.e, if none of these two
* methods have been invoked is because the server is not suspended.
*
* @param deployment The deployment
*/
default void deploymentResumed(final DeploymentModuleIdentifier deployment) {}
}
| 2,882 | 37.44 | 116 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/EjbDeploymentInformation.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment;
import static org.wildfly.common.Assert.checkNotNullParam;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.iiop.EjbIIOPService;
import org.jboss.msc.value.InjectedValue;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Runtime information about an Jakarta Enterprise Beans in a module
*
* @author Stuart Douglas
*/
public class EjbDeploymentInformation {
private final String ejbName;
private final ClassLoader deploymentClassLoader;
private final InjectedValue<EJBComponent> ejbComponent;
private final Map<String, InjectedValue<ComponentView>> componentViews;
private final InjectedValue<EjbIIOPService> iorFactory;
private final Set<String> remoteViewClassNames = new HashSet<String>();
/**
* @param ejbName The EJB name
* @param ejbComponent The EJB component
* @param componentViews The views exposed by the EJB component
* @param deploymentClassLoader The deployment classloader of the EJB component
* @param iorFactory The {@link EjbIIOPService}
* @deprecated since 7.1.1.Final - Use {@link #EjbDeploymentInformation(String, org.jboss.msc.value.InjectedValue, java.util.Map, java.util.Map, ClassLoader, org.jboss.msc.value.InjectedValue)} instead
*/
@Deprecated
public EjbDeploymentInformation(final String ejbName, final InjectedValue<EJBComponent> ejbComponent, final Map<String, InjectedValue<ComponentView>> componentViews, final ClassLoader deploymentClassLoader, final InjectedValue<EjbIIOPService> iorFactory) {
this.ejbName = ejbName;
this.ejbComponent = ejbComponent;
this.componentViews = componentViews;
this.deploymentClassLoader = deploymentClassLoader;
this.iorFactory = iorFactory;
}
/**
* @param ejbName Name of the EJB
* @param ejbComponent The EJB component
* @param remoteViews The component views, which are exposed remotely, by the EJB. Can be null.
* @param localViews The component views which are exposed locally by the EJB. Can be null.
* @param deploymentClassLoader The deployment classloader of the EJB component
* @param iorFactory The {@link EjbIIOPService}
*/
public EjbDeploymentInformation(final String ejbName, final InjectedValue<EJBComponent> ejbComponent,
final Map<String, InjectedValue<ComponentView>> remoteViews, final Map<String, InjectedValue<ComponentView>> localViews,
final ClassLoader deploymentClassLoader, final InjectedValue<EjbIIOPService> iorFactory) {
this.ejbName = ejbName;
this.ejbComponent = ejbComponent;
this.componentViews = new HashMap<String, InjectedValue<ComponentView>>();
if (remoteViews != null) {
this.componentViews.putAll(remoteViews);
this.remoteViewClassNames.addAll(remoteViews.keySet());
}
if (localViews != null) {
this.componentViews.putAll(localViews);
}
this.deploymentClassLoader = deploymentClassLoader;
this.iorFactory = iorFactory;
}
public String getEjbName() {
return ejbName;
}
public EJBComponent getEjbComponent() {
return ejbComponent.getValue();
}
public Collection<String> getViewNames() {
return componentViews.keySet();
}
public ComponentView getView(String name) {
final InjectedValue<ComponentView> value = checkNotNullParam(String.valueOf(name), componentViews.get(name));
return value.getValue();
}
public ClassLoader getDeploymentClassLoader() {
return deploymentClassLoader;
}
public EjbIIOPService getIorFactory() {
return iorFactory.getOptionalValue();
}
/**
* Returns true if the passed <code>viewClassName</code> represents a remote view of the Jakarta Enterprise Beans component.
* Else returns false.
*
* @param viewClassName The fully qualified classname of the view
* @return
*/
public boolean isRemoteView(final String viewClassName) {
return this.remoteViewClassNames.contains(viewClassName);
}
}
| 5,444 | 39.634328 | 260 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/AroundTimeoutAnnotationParsingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.List;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.InvocationContext;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
/**
* Deployment processor responsible for finding @AroundTimeout annotated methods in classes within a deployment.
*
* @author John Bailey
* @author Stuart Douglas
*/
public class AroundTimeoutAnnotationParsingProcessor implements DeploymentUnitProcessor {
private static final DotName AROUND_TIMEOUT_ANNOTATION_NAME = DotName.createSimple(AroundTimeout.class.getName());
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if(MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> aroundInvokes = index.getAnnotations(AROUND_TIMEOUT_ANNOTATION_NAME);
for (AnnotationInstance annotation : aroundInvokes) {
processAroundInvoke(annotation.target(), eeModuleDescription);
}
}
private void processAroundInvoke(final AnnotationTarget target, final EEModuleDescription eeModuleDescription) {
if (!(target instanceof MethodInfo)) {
throw EjbLogger.ROOT_LOGGER.annotationApplicableOnlyForMethods(AROUND_TIMEOUT_ANNOTATION_NAME.toString());
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
validateArgumentType(classInfo, methodInfo);
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
builder.setAroundTimeout(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class));
classDescription.setInterceptorClassDescription(builder.build());
}
private void validateArgumentType(final ClassInfo classInfo, final MethodInfo methodInfo) {
final Type[] args = methodInfo.args();
switch (args.length) {
case 0:
throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString());
case 1:
if (!InvocationContext.class.getName().equals(args[0].name().toString())) {
throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString());
}
break;
default:
throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodExpectedWithInvocationContextParam(methodInfo.name(), classInfo.toString());
}
if (!methodInfo.returnType().name().toString().equals(Object.class.getName())) {
throw EjbLogger.ROOT_LOGGER.aroundTimeoutMethodMustReturnObjectType(methodInfo.name(), classInfo.toString());
}
}
}
| 5,308 | 48.616822 | 147 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/DeploymentRepositoryProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.deployers.StartupCountdown;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier;
import org.jboss.as.ejb3.deployment.DeploymentRepository;
import org.jboss.as.ejb3.deployment.DeploymentRepositoryService;
import org.jboss.as.ejb3.deployment.EjbDeploymentInformation;
import org.jboss.as.ejb3.deployment.ModuleDeployment;
import org.jboss.as.ejb3.iiop.EjbIIOPService;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
/**
* @author Stuart Douglas
*/
public class DeploymentRepositoryProcessor implements DeploymentUnitProcessor {
public DeploymentRepositoryProcessor() {
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (eeModuleDescription == null) {
return;
}
if(DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
//don't create this for EAR's, as they cannot hold Jakarta Enterprise Beans's
return;
}
// Note, we do not use the EEModuleDescription.getApplicationName() because that API returns the
// module name if the top level unit isn't a .ear, which is not what we want. We really want a
// .ear name as application name (that's the semantic in Jakarta Enterprise Beans spec). So use EEModuleDescription.getEarApplicationName
String applicationName = eeModuleDescription.getEarApplicationName();
// if it's not a .ear deployment then set app name to empty string
applicationName = applicationName == null ? "" : applicationName;
final DeploymentModuleIdentifier identifier = new DeploymentModuleIdentifier(applicationName, eeModuleDescription.getModuleName(), eeModuleDescription.getDistinctName());
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
final Map<String, EjbDeploymentInformation> deploymentInformationMap = new HashMap<String, EjbDeploymentInformation>();
final Set<ServiceName> componentStartServices = new HashSet<ServiceName>();
final Map<ServiceName, InjectedValue<?>> injectedValues = new HashMap<ServiceName, InjectedValue<?>>();
for (final ComponentDescription component : componentDescriptions) {
if (component instanceof EJBComponentDescription) {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) component;
componentStartServices.add(component.getStartServiceName());
final InjectedValue<EJBComponent> componentInjectedValue = new InjectedValue<EJBComponent>();
injectedValues.put(component.getCreateServiceName(), componentInjectedValue);
final Map<String, InjectedValue<ComponentView>> remoteViews = new HashMap<String, InjectedValue<ComponentView>>();
final Map<String, InjectedValue<ComponentView>> localViews = new HashMap<String, InjectedValue<ComponentView>>();
for (final ViewDescription view : ejbComponentDescription.getViews()) {
boolean remoteView = false;
if (view instanceof EJBViewDescription) {
final MethodInterfaceType viewType = ((EJBViewDescription) view).getMethodIntf();
if (viewType == MethodInterfaceType.Home || viewType == MethodInterfaceType.Remote) {
remoteView = true;
}
}
final InjectedValue<ComponentView> componentViewInjectedValue = new InjectedValue<ComponentView>();
if (remoteView) {
remoteViews.put(view.getViewClassName(), componentViewInjectedValue);
} else {
localViews.put(view.getViewClassName(), componentViewInjectedValue);
}
injectedValues.put(view.getServiceName(), componentViewInjectedValue);
}
final InjectedValue<EjbIIOPService> iorFactory = new InjectedValue<EjbIIOPService>();
if (ejbComponentDescription.isExposedViaIiop()) {
injectedValues.put(ejbComponentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), iorFactory);
}
final EjbDeploymentInformation info = new EjbDeploymentInformation(ejbComponentDescription.getEJBName(), componentInjectedValue, remoteViews, localViews, module.getClassLoader(), iorFactory);
deploymentInformationMap.put(ejbComponentDescription.getEJBName(), info);
}
}
final StartupCountdown countdown = deploymentUnit.getAttachment(Attachments.STARTUP_COUNTDOWN);
final ModuleDeployment deployment = new ModuleDeployment(identifier, deploymentInformationMap);
ServiceName moduleDeploymentService = deploymentUnit.getServiceName().append(ModuleDeployment.SERVICE_NAME);
final ServiceBuilder<ModuleDeployment> builder = phaseContext.getServiceTarget().addService(moduleDeploymentService, deployment);
for (Map.Entry<ServiceName, InjectedValue<?>> entry : injectedValues.entrySet()) {
builder.addDependency(entry.getKey(), Object.class, (InjectedValue<Object>) entry.getValue());
}
builder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deployment.getDeploymentRepository());
builder.install();
final ModuleDeployment.ModuleDeploymentStartService deploymentStart = new ModuleDeployment.ModuleDeploymentStartService(identifier, countdown);
final ServiceBuilder<Void> startBuilder = phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ModuleDeployment.START_SERVICE_NAME), deploymentStart);
for (final ServiceName componentStartService : componentStartServices) {
startBuilder.requires(componentStartService);
}
startBuilder.requires(moduleDeploymentService);
startBuilder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
startBuilder.install();
}
}
| 8,701 | 57.797297 | 207 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbIIOPDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jakarta.ejb.TransactionManagementType;
import com.arjuna.ats.jbossatx.jta.TransactionManagerService;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.ViewConfiguration;
import org.jboss.as.ee.component.ViewConfigurator;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.iiop.EjbIIOPService;
import org.jboss.as.ejb3.iiop.EjbIIOPTransactionInterceptor;
import org.jboss.as.ejb3.iiop.POARegistry;
import org.jboss.as.ejb3.subsystem.IIOPSettingsService;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.as.txn.service.TxnServices;
import org.jboss.metadata.ejb.jboss.IIOPMetaData;
import org.jboss.metadata.ejb.jboss.IORSecurityConfigMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceTarget;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.PortableServer.POA;
import org.wildfly.iiop.openjdk.deployment.IIOPDeploymentMarker;
import org.wildfly.iiop.openjdk.rmi.AttributeAnalysis;
import org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis;
import org.wildfly.iiop.openjdk.rmi.OperationAnalysis;
import org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException;
import org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy;
import org.wildfly.iiop.openjdk.service.CorbaNamingService;
import org.wildfly.iiop.openjdk.service.CorbaORBService;
import org.wildfly.iiop.openjdk.service.CorbaPOAService;
import org.wildfly.iiop.openjdk.service.IORSecConfigMetaDataService;
/**
* This is the DUP that sets up IIOP for Jakarta Enterprise Beans's
*/
public class EjbIIOPDeploymentUnitProcessor implements DeploymentUnitProcessor {
private final IIOPSettingsService settingsService;
public EjbIIOPDeploymentUnitProcessor(final IIOPSettingsService settingsService) {
this.settingsService = settingsService;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
return;
}
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
// a bean-name -> IIOPMetaData map, reflecting the assembly descriptor IIOP configuration.
Map<String, IIOPMetaData> iiopMetaDataMap = new HashMap<String, IIOPMetaData>();
final EjbJarMetaData ejbMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbMetaData != null && ejbMetaData.getAssemblyDescriptor() != null) {
List<IIOPMetaData> iiopMetaDatas = ejbMetaData.getAssemblyDescriptor().getAny(IIOPMetaData.class);
if (iiopMetaDatas != null && !iiopMetaDatas.isEmpty()) {
for (IIOPMetaData metaData : iiopMetaDatas) {
iiopMetaDataMap.put(metaData.getEjbName(), metaData);
}
}
}
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (moduleDescription != null) {
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription instanceof EJBComponentDescription) {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
if (ejbComponentDescription.getEjbRemoteView() != null && ejbComponentDescription.getEjbHomeView() != null) {
// check if there is IIOP metadata for the bean - first using the bean name, then the wildcard "*" if needed.
IIOPMetaData iiopMetaData = iiopMetaDataMap.get(ejbComponentDescription.getEJBName());
if (iiopMetaData == null) {
iiopMetaData = iiopMetaDataMap.get(IIOPMetaData.WILDCARD_BEAN_NAME);
}
// the bean will be exposed via IIOP if it has IIOP metadata that applies to it or if IIOP access
// has been enabled by default in the EJB3 subsystem.
if (iiopMetaData != null || settingsService.isEnabledByDefault()) {
processEjb(ejbComponentDescription, deploymentReflectionIndex, module,
phaseContext.getServiceTarget(), iiopMetaData);
}
}
}
}
}
}
private void processEjb(final EJBComponentDescription componentDescription,
final DeploymentReflectionIndex deploymentReflectionIndex, final Module module,
final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
componentDescription.setExposedViaIiop(true);
// Create bean method mappings for container invoker
final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
final Class<?> remoteClass;
try {
remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
}
final EJBViewDescription homeView = componentDescription.getEjbHomeView();
final Class<?> homeClass;
try {
homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
}
componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
final InterfaceAnalysis remoteInterfaceAnalysis;
try {
//TODO: change all this to use the deployment reflection index
remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
} catch (RMIIIOPViolationException e) {
throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
}
final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
for (int i = 0; i < remoteAttrs.length; i++) {
final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
if (op != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", op.getJavaName(), op.getIDLName());
//translate to the deployment reflection index method
//TODO: this needs to be fixed so it just returns the correct method
final Method method = translateMethod(deploymentReflectionIndex, op);
beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
if (setop != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", setop.getJavaName(), setop.getIDLName());
//translate to the deployment reflection index method
//TODO: this needs to be fixed so it just returns the correct method
final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
}
}
}
final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
for (int i = 0; i < ops.length; i++) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", ops[i].getJavaName(), ops[i].getIDLName());
beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
}
// Initialize repository ids of remote interface
final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
// Create home method mappings for container invoker
final InterfaceAnalysis homeInterfaceAnalysis;
try {
//TODO: change all this to use the deployment reflection index
homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
} catch (RMIIIOPViolationException e) {
throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
}
final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
for (int i = 0; i < attrs.length; i++) {
final OperationAnalysis op = attrs[i].getAccessorAnalysis();
if (op != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", op.getJavaName(), op.getIDLName());
homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
if (setop != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", setop.getJavaName(), setop.getIDLName());
homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
}
}
}
final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
for (int i = 0; i < homeops.length; i++) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", homeops[i].getJavaName(), homeops[i].getIDLName());
homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
}
// Initialize repository ids of home interface
final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds,
settingsService.isUseQualifiedName(), iiopMetaData, module);
final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
builder.install();
}
private Method translateMethod(final DeploymentReflectionIndex deploymentReflectionIndex, final OperationAnalysis op) {
final Method nonMethod = op.getMethod();
return deploymentReflectionIndex.getClassIndex(nonMethod.getDeclaringClass()).getMethod(nonMethod);
}
private static class IIOPInterceptorViewConfigurator implements ViewConfigurator {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentConfiguration.getComponentDescription();
if (ejbComponentDescription.getTransactionManagementType() == TransactionManagementType.CONTAINER) {
configuration.addViewInterceptor(EjbIIOPTransactionInterceptor.FACTORY, InterceptorOrder.View.EJB_IIOP_TRANSACTION);
}
}
}
}
| 15,707 | 55.913043 | 237 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/TimerServiceJndiBindingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.deployers.AbstractComponentConfigProcessor;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.timerservice.TimerServiceBindingSource;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
/**
* Deployment processor responsible for detecting Jakarta Enterprise Beans components and adding a {@link BindingConfiguration} for the
* java:comp/TimerService entry.
* <p/>
*
* User: Jaikiran Pai
*/
public class TimerServiceJndiBindingProcessor extends AbstractComponentConfigProcessor {
@Override
protected void processComponentConfig(DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, CompositeIndex index, ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
if (!(componentDescription instanceof EJBComponentDescription)) {
return; // Only process Jakarta Enterprise Beans
}
// if the Jakarta Enterprise Beans are packaged in a .war, then we need to bind the java:comp/TimerService only once for the entire module
if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
// get the module description
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
// the java:module/TimerService binding configuration
// Note that we bind to java:module/TimerService since it's a .war. End users can still lookup java:comp/TimerService
// and that will internally get translated to java:module/TimerService for .war, since java:comp == java:module in
// a web ENC. So binding to java:module/TimerService is OK.
final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:module/TimerService", new TimerServiceBindingSource());
moduleDescription.getBindingConfigurations().add(timerServiceBinding);
} else { // Jakarta Enterprise Beans packaged outside of a .war. So process normally.
// add the binding configuration to the component description
final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:comp/TimerService", new TimerServiceBindingSource());
componentDescription.getBindingConfigurations().add(timerServiceBinding);
}
}
}
| 3,846 | 55.573529 | 217 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/ApplicationExceptionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.List;
import jakarta.ejb.ApplicationException;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
/**
* User: jpai
*/
public class ApplicationExceptionAnnotationProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if(MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
return;
}
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (compositeIndex == null) {
return;
}
List<AnnotationInstance> applicationExceptionAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ApplicationException.class.getName()));
if (applicationExceptionAnnotations == null || applicationExceptionAnnotations.isEmpty()) {
return;
}
ApplicationExceptionDescriptions descriptions = new ApplicationExceptionDescriptions();
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS, descriptions);
for (AnnotationInstance annotationInstance : applicationExceptionAnnotations) {
AnnotationTarget target = annotationInstance.target();
if (!(target instanceof ClassInfo)) {
throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(ApplicationException.class.getName(), target);
}
String exceptionClassName = ((ClassInfo) target).name().toString();
boolean rollback = false;
AnnotationValue rollBackAnnValue = annotationInstance.value("rollback");
if (rollBackAnnValue != null) {
rollback = rollBackAnnValue.asBoolean();
}
// default "inherited" is true
boolean inherited = true;
AnnotationValue inheritedAnnValue = annotationInstance.value("inherited");
if (inheritedAnnValue != null) {
inherited = inheritedAnnValue.asBoolean();
}
descriptions.addApplicationException(exceptionClassName, rollback, inherited);
}
}
}
| 4,089 | 44.955056 | 157 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EJBClientDescriptorMetaDataProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.as.ee.structure.Attachments;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.remote.EJBClientContextService;
import org.jboss.as.ejb3.remote.LocalTransportProvider;
import org.jboss.as.ejb3.remote.RemotingProfileService;
import org.jboss.as.ejb3.subsystem.EJBClientConfiguratorService;
import org.jboss.as.network.OutboundConnection;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.ejb.client.ClusterNodeSelector;
import org.jboss.ejb.client.DeploymentNodeSelector;
import org.jboss.ejb.client.EJBClientCluster;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBTransportProvider;
import org.jboss.modules.Module;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.remoting3.RemotingOptions;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
import org.xnio.Option;
import org.xnio.OptionMap;
/**
* A deployment unit processor which processing only top level deployment units and checks for the presence of a
* {@link Attachments#EJB_CLIENT_METADATA} key corresponding to {@link EJBClientDescriptorMetaData}, in the deployment unit.
* <p/>
* If a {@link EJBClientDescriptorMetaData} is available then this deployment unit processor creates and installs a
* {@link EJBClientContextService}.
*
* TODO Elytron emulate old configuration using discovery, clustering
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
public class EJBClientDescriptorMetaDataProcessor implements DeploymentUnitProcessor {
private static final String INTERNAL_REMOTING_PROFILE = "internal-remoting-profile";
private static final String OUTBOUND_CONNECTION_CAPABILITY_NAME = "org.wildfly.remoting.outbound-connection";
private static final String REMOTING_PROFILE_CAPABILITY_NAME = "org.wildfly.ejb3.remoting-profile";
private final boolean appclient;
public EJBClientDescriptorMetaDataProcessor(boolean appclient) {
this.appclient = appclient;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// we only process top level deployment units
if (deploymentUnit.getParent() != null) {
return;
}
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (module == null) {
return;
}
// support for using capabilities to resolve service names
CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
// check for EJB client interceptor configuration
final List<EJBClientInterceptor> deploymentEjbClientInterceptors = getClassPathInterceptors(module.getClassLoader());
List<EJBClientInterceptor> staticEjbClientInterceptors = deploymentUnit.getAttachment(org.jboss.as.ejb3.subsystem.Attachments.STATIC_EJB_CLIENT_INTERCEPTORS);
List<EJBClientInterceptor> ejbClientInterceptors = new ArrayList<>();
if(deploymentEjbClientInterceptors != null){
ejbClientInterceptors.addAll(deploymentEjbClientInterceptors);
}
if(staticEjbClientInterceptors != null){
ejbClientInterceptors.addAll(staticEjbClientInterceptors);
}
final boolean interceptorsDefined = ejbClientInterceptors != null && ! ejbClientInterceptors.isEmpty();
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
// no explicit EJB client configuration in this deployment, so nothing to do
if (ejbClientDescriptorMetaData == null && ! interceptorsDefined) {
return;
}
// install the descriptor based EJB client context service
final ServiceName ejbClientContextServiceName = EJBClientContextService.DEPLOYMENT_BASE_SERVICE_NAME.append(deploymentUnit.getName());
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
// create the service
final EJBClientContextService service = new EJBClientContextService();
// add the service
final ServiceBuilder<EJBClientContextService> serviceBuilder = serviceTarget.addService(ejbClientContextServiceName, service);
if (appclient) {
serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_URI_SERVICE_NAME, URI.class, service.getAppClientUri());
serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_EJB_PROPERTIES_SERVICE_NAME, String.class, service.getAppClientEjbProperties());
}
//default transport providers: remote from config, local from service, in "else" below.
serviceBuilder.addDependency(EJBClientConfiguratorService.SERVICE_NAME, EJBClientConfiguratorService.class, service.getConfiguratorServiceInjector());
if (ejbClientDescriptorMetaData != null) {
// profile and remoting-ejb-receivers cannot be used together
checkDescriptorConfiguration(ejbClientDescriptorMetaData);
final Injector<RemotingProfileService> profileServiceInjector = new Injector<RemotingProfileService>() {
final Injector<EJBTransportProvider> injector = service.getLocalProviderInjector();
boolean injected = false;
public void inject(final RemotingProfileService value) throws InjectionException {
final Supplier<EJBTransportProvider> transportSupplier = value.getLocalTransportProviderSupplier();
final EJBTransportProvider provider = transportSupplier != null ? transportSupplier.get() : null;
if (provider != null) {
injected = true;
injector.inject(provider);
}
}
public void uninject() {
if (injected) {
injected = false;
injector.uninject();
}
}
};
final String profile = ejbClientDescriptorMetaData.getProfile();
final ServiceName profileServiceName;
if (profile != null) {
// set up a service for the named remoting profile
profileServiceName = capabilityServiceSupport.getCapabilityServiceName(REMOTING_PROFILE_CAPABILITY_NAME, profile);
// why below?
serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
} else {
// if descriptor defines list of ejb-receivers instead of profile then we create internal ProfileService for this
// application which contains defined receivers
profileServiceName = ejbClientContextServiceName.append(INTERNAL_REMOTING_PROFILE);
final Map<String, RemotingProfileService.RemotingConnectionSpec> remotingConnectionMap = new HashMap<>();
final List<RemotingProfileService.HttpConnectionSpec> httpConnections = new ArrayList<>();
final ServiceBuilder<?> profileServiceBuilder = serviceTarget.addService(profileServiceName);
final Consumer<RemotingProfileService> consumer = profileServiceBuilder.provides(profileServiceName);
Supplier<EJBTransportProvider> localTransportProviderSupplier = null;
if (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE) {
final Boolean passByValue = ejbClientDescriptorMetaData.isLocalReceiverPassByValue();
localTransportProviderSupplier = profileServiceBuilder.requires(passByValue == Boolean.FALSE ? LocalTransportProvider.BY_REFERENCE_SERVICE_NAME : LocalTransportProvider.BY_VALUE_SERVICE_NAME);
}
final Collection<EJBClientDescriptorMetaData.RemotingReceiverConfiguration> receiverConfigurations = ejbClientDescriptorMetaData.getRemotingReceiverConfigurations();
for (EJBClientDescriptorMetaData.RemotingReceiverConfiguration receiverConfiguration : receiverConfigurations) {
final String connectionRef = receiverConfiguration.getOutboundConnectionRef();
final long connectTimeout = receiverConfiguration.getConnectionTimeout();
final Properties channelCreationOptions = receiverConfiguration.getChannelCreationOptions();
final OptionMap optionMap = getOptionMapFromProperties(channelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
final ServiceName internalServiceName = capabilityServiceSupport.getCapabilityServiceName(OUTBOUND_CONNECTION_CAPABILITY_NAME, connectionRef);
final Supplier<OutboundConnection> supplier = profileServiceBuilder.requires(internalServiceName);
final RemotingProfileService.RemotingConnectionSpec connectionSpec = new RemotingProfileService.RemotingConnectionSpec(connectionRef, supplier, optionMap, connectTimeout);
remotingConnectionMap.put(connectionRef, connectionSpec);
}
for (EJBClientDescriptorMetaData.HttpConnectionConfiguration httpConfigurations : ejbClientDescriptorMetaData.getHttpConnectionConfigurations()) {
final String uri = httpConfigurations.getUri();
RemotingProfileService.HttpConnectionSpec httpConnectionSpec = new RemotingProfileService.HttpConnectionSpec(uri);
httpConnections.add(httpConnectionSpec);
}
final RemotingProfileService profileService = new RemotingProfileService(consumer, localTransportProviderSupplier, Collections.emptyList(), remotingConnectionMap, httpConnections);
profileServiceBuilder.setInstance(profileService);
profileServiceBuilder.install();
serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
}
// these items are the same no matter how we were configured
final String deploymentNodeSelectorClassName = ejbClientDescriptorMetaData.getDeploymentNodeSelector();
if (deploymentNodeSelectorClassName != null) {
final DeploymentNodeSelector deploymentNodeSelector;
try {
deploymentNodeSelector = module.getClassLoader().loadClass(deploymentNodeSelectorClassName).asSubclass(DeploymentNodeSelector.class).getConstructor().newInstance();
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failedToCreateDeploymentNodeSelector(e, deploymentNodeSelectorClassName);
}
service.setDeploymentNodeSelector(deploymentNodeSelector);
}
final long invocationTimeout = ejbClientDescriptorMetaData.getInvocationTimeout();
service.setInvocationTimeout(invocationTimeout);
final int defaultCompression = ejbClientDescriptorMetaData.getDefaultCompression();
service.setDefaultCompression(defaultCompression);
// clusters
final Collection<EJBClientDescriptorMetaData.ClusterConfig> clusterConfigs = ejbClientDescriptorMetaData.getClusterConfigs();
if (!clusterConfigs.isEmpty()) {
final List<EJBClientCluster> clientClusters = new ArrayList<>(clusterConfigs.size());
AuthenticationContext clustersAuthenticationContext = AuthenticationContext.empty();
for (EJBClientDescriptorMetaData.ClusterConfig clusterConfig : clusterConfigs) {
MatchRule defaultRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
AuthenticationConfiguration defaultAuthenticationConfiguration = AuthenticationConfiguration.empty();
final EJBClientCluster.Builder clientClusterBuilder = new EJBClientCluster.Builder();
final String clusterName = clusterConfig.getClusterName();
clientClusterBuilder.setName(clusterName);
defaultRule = defaultRule.matchProtocol("cluster");
defaultRule = defaultRule.matchUrnName(clusterName);
final long maxAllowedConnectedNodes = clusterConfig.getMaxAllowedConnectedNodes();
clientClusterBuilder.setMaximumConnectedNodes(maxAllowedConnectedNodes);
final String clusterNodeSelectorClassName = clusterConfig.getNodeSelector();
if (clusterNodeSelectorClassName != null) {
final ClusterNodeSelector clusterNodeSelector;
try {
clusterNodeSelector = module.getClassLoader().loadClass(clusterNodeSelectorClassName).asSubclass(ClusterNodeSelector.class).getConstructor().newInstance();
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failureDuringLoadOfClusterNodeSelector(clusterNodeSelectorClassName, clusterName, e);
}
clientClusterBuilder.setClusterNodeSelector(clusterNodeSelector);
}
final Properties clusterChannelCreationOptions = clusterConfig.getChannelCreationOptions();
final OptionMap clusterChannelCreationOptionMap = getOptionMapFromProperties(clusterChannelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
final Properties clusterConnectionOptions = clusterConfig.getConnectionOptions();
final OptionMap clusterConnectionOptionMap = getOptionMapFromProperties(clusterConnectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
final long clusterConnectTimeout = clusterConfig.getConnectTimeout();
clientClusterBuilder.setConnectTimeoutMilliseconds(clusterConnectTimeout);
if (clusterConnectionOptionMap != null) {
RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(clusterConnectionOptionMap, defaultAuthenticationConfiguration);
}
clustersAuthenticationContext = clustersAuthenticationContext.with(defaultRule, defaultAuthenticationConfiguration);
final Collection<EJBClientDescriptorMetaData.ClusterNodeConfig> clusterNodeConfigs = clusterConfig.getClusterNodeConfigs();
for (EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig : clusterNodeConfigs) {
MatchRule nodeRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
AuthenticationConfiguration nodeAuthenticationConfiguration = AuthenticationConfiguration.empty();
final String nodeName = clusterNodeConfig.getNodeName();
nodeRule = nodeRule.matchProtocol("node");
nodeRule = nodeRule.matchUrnName(nodeName);
final Properties channelCreationOptions = clusterNodeConfig.getChannelCreationOptions();
final Properties connectionOptions = clusterNodeConfig.getConnectionOptions();
final OptionMap connectionOptionMap = getOptionMapFromProperties(connectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
final long connectTimeout = clusterNodeConfig.getConnectTimeout();
if (connectionOptionMap != null) {
RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectionOptionMap, nodeAuthenticationConfiguration);
}
clustersAuthenticationContext = clustersAuthenticationContext.with(0, nodeRule, nodeAuthenticationConfiguration);
}
final EJBClientCluster clientCluster = clientClusterBuilder.build();
clientClusters.add(clientCluster);
}
service.setClientClusters(clientClusters);
service.setClustersAuthenticationContext(clustersAuthenticationContext);
}
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME, profileServiceName);
} else {
if(!appclient) {
serviceBuilder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, service.getLocalProviderInjector());
}
}
if (interceptorsDefined) {
service.setClientInterceptors(ejbClientInterceptors);
}
// install the service
serviceBuilder.install();
EjbLogger.DEPLOYMENT_LOGGER.debugf("Deployment unit %s will use %s as the EJB client context service", deploymentUnit,
ejbClientContextServiceName);
// attach the service name of this EJB client context to the deployment unit
phaseContext.addDeploymentDependency(ejbClientContextServiceName, EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE);
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME, ejbClientContextServiceName);
}
private void checkDescriptorConfiguration(final EJBClientDescriptorMetaData ejbClientDescriptorMetaData)
throws DeploymentUnitProcessingException {
final boolean profileDefined = ejbClientDescriptorMetaData.getProfile() != null;
final boolean receiversDefined = (!ejbClientDescriptorMetaData.getRemotingReceiverConfigurations().isEmpty())
|| (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != null)
|| (ejbClientDescriptorMetaData.isLocalReceiverPassByValue() != null);
if (profileDefined && receiversDefined) {
throw EjbLogger.ROOT_LOGGER.profileAndRemotingEjbReceiversUsedTogether();
}
}
private OptionMap getOptionMapFromProperties(final Properties properties, final ClassLoader classLoader) {
final OptionMap.Builder optionMapBuilder = OptionMap.builder();
if (properties != null) for (final String propertyName : properties.stringPropertyNames()) {
try {
final Option<?> option = Option.fromString(propertyName, classLoader);
optionMapBuilder.parse(option, properties.getProperty(propertyName), classLoader);
} catch (IllegalArgumentException e) {
EjbLogger.DEPLOYMENT_LOGGER.failedToCreateOptionForProperty(propertyName, e.getMessage());
}
}
return optionMapBuilder.getMap();
}
private List<EJBClientInterceptor> getClassPathInterceptors(final ClassLoader classLoader) throws DeploymentUnitProcessingException {
try {
final Enumeration<URL> resources = classLoader.getResources("META-INF/services/org.jboss.ejb.client.EJBClientInterceptor");
final ArrayList<EJBClientInterceptor> interceptors = new ArrayList<>();
if (resources.hasMoreElements()) {
do {
final URL url = resources.nextElement();
try (InputStream st = url.openStream();
InputStreamReader isr = new InputStreamReader(st, StandardCharsets.UTF_8);
BufferedReader r = new BufferedReader(isr)) {
String line;
while ((line = r.readLine()) != null) {
line = line.trim();
if (line.isEmpty() || line.charAt(0) == '#') {
continue;
}
try {
final EJBClientInterceptor interceptor = Class.forName(line, true, classLoader).asSubclass(EJBClientInterceptor.class).getConstructor().newInstance();
interceptors.add(interceptor);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failedToCreateEJBClientInterceptor(e, line);
}
}
}
} while (resources.hasMoreElements());
}
return interceptors;
} catch (IOException e) {
return Collections.emptyList();
}
}
}
| 23,245 | 60.173684 | 212 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/PassivationAnnotationParsingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.List;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.interceptor.InvocationContext;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* Deployment processor responsible for finding @PostConstruct and @PreDestroy annotated methods.
*
* @author Stuart Douglas
*/
public class PassivationAnnotationParsingProcessor implements DeploymentUnitProcessor {
private static final DotName POST_ACTIVATE = DotName.createSimple(PostActivate.class.getName());
private static final DotName PRE_PASSIVATE = DotName.createSimple(PrePassivate.class.getName());
private static DotName[] PASSIVATION_ANNOTATIONS = {POST_ACTIVATE, PRE_PASSIVATE};
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
for (DotName annotationName : PASSIVATION_ANNOTATIONS) {
final List<AnnotationInstance> lifecycles = index.getAnnotations(annotationName);
for (AnnotationInstance annotation : lifecycles) {
processPassivation(eeModuleDescription, annotation.target(), annotationName);
}
}
}
private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType) throws DeploymentUnitProcessingException {
if (!(target instanceof MethodInfo)) {
throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final Type[] args = methodInfo.args();
if (args.length > 1) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
return;
} else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
return;
}
final MethodIdentifier methodIdentifier;
if (args.length == 0) {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
} else {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
}
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
if (annotationType == POST_ACTIVATE) {
builder.setPostActivate(methodIdentifier);
} else {
builder.setPrePassivate(methodIdentifier);
}
classDescription.setInterceptorClassDescription(builder.build());
}
}
| 5,490 | 49.842593 | 186 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/ImplicitLocalViewProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.deployers.AbstractComponentConfigProcessor;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.modules.Module;
/**
* Processes a {@link SessionBeanComponentDescription}'s bean class and checks whether it exposes:
* <ul>
* <li>An implicit no-interface, as specified by Enterprise Beans 3.1 spec, section 4.9.8.</li>
* <li>A default local business interface view, as specified by Enterprise Beans 3.1 spec, section 4.9.7.</li>
* </ul>
* The {@link SessionBeanComponentDescription} is updated with this info accordingly.
* <p/>
* This processor MUST run <b>before</b> the {@link EjbJndiBindingsDeploymentUnitProcessor Jakarta Enterprise Beans jndi binding} processor is run.
*
* @author Jaikiran Pai
*/
public class ImplicitLocalViewProcessor extends AbstractComponentConfigProcessor {
@Override
protected void processComponentConfig(DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, CompositeIndex index, ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
if (!(componentDescription instanceof SessionBeanComponentDescription)) {
return;
}
SessionBeanComponentDescription sessionBeanComponentDescription = (SessionBeanComponentDescription) componentDescription;
// if it already has a no-interface view, then no need to check for the implicit rules
if (sessionBeanComponentDescription.hasNoInterfaceView()) {
return;
}
// if the bean already exposes some view(s) then it isn't eligible for an implicit no-interface view.
if (!sessionBeanComponentDescription.getViews().isEmpty()) {
return;
}
String ejbClassName = sessionBeanComponentDescription.getComponentClassName();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (module == null) {
throw EjbLogger.ROOT_LOGGER.moduleNotAttachedToDeploymentUnit(deploymentUnit);
}
ClassLoader cl = module.getClassLoader();
Class<?> ejbClass = null;
try {
ejbClass = cl.loadClass(ejbClassName);
} catch (ClassNotFoundException cnfe) {
throw new DeploymentUnitProcessingException(cnfe);
}
// check whether it's eligible for implicit no-interface view
if (this.exposesNoInterfaceView(ejbClass)) {
EjbLogger.DEPLOYMENT_LOGGER.debugf("Bean: %s will be marked for (implicit) no-interface view", sessionBeanComponentDescription.getEJBName());
sessionBeanComponentDescription.addNoInterfaceView();
return;
}
// check for default local view
Class<?> defaultLocalView = this.getDefaultLocalView(ejbClass);
if (defaultLocalView != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf("Bean: %s will be marked for default local view: %s", sessionBeanComponentDescription.getEJBName(), defaultLocalView.getName());
sessionBeanComponentDescription.addLocalBusinessInterfaceViews(Collections.singleton(defaultLocalView.getName()));
return;
}
}
/**
* Returns true if the passed <code>beanClass</code> is eligible for implicit no-interface view. Else returns false.
* <p/>
* Enterprise Beans 3.1 spec, section 4.9.8 states the rules for an implicit no-interface view on a bean class.
* If the "implements" clause of the bean class is empty then the bean is considered to be exposing a no-interface view.
* During this implements clause check, the {@link java.io.Serializable} or {@link java.io.Externalizable} or
* any class from jakarta.ejb.* packages are excluded.
*
* @param beanClass The bean class.
* @return
*/
private boolean exposesNoInterfaceView(Class<?> beanClass) {
Class<?>[] interfaces = beanClass.getInterfaces();
if (interfaces.length == 0) {
return true;
}
// As per section 4.9.8 (bullet 1.3) of Enterprise Beans 3.1 spec
// java.io.Serializable; java.io.Externalizable; any of the interfaces defined by the jakarta.ejb
// are excluded from interface check
List<Class<?>> implementedInterfaces = new ArrayList<Class<?>>(Arrays.asList(interfaces));
List<Class<?>> filteredInterfaces = this.filterInterfaces(implementedInterfaces);
// Now that we have removed the interfaces that should be excluded from the check,
// if the filtered interfaces collection is empty then this bean can be considered for no-interface view
return filteredInterfaces.isEmpty();
}
/**
* Returns the default local view class of the {@link Class beanClass}, if one is present.
* Enterprise Beans 3.1 spec, section 4.9.7 specifies the rules for a default local view of a bean. If the bean implements
* just one interface, then that interface is returned as the default local view by this method.
* If no such, interface is found, then this method returns null.
*
* @param beanClass The bean class
* @return
*/
private Class<?> getDefaultLocalView(Class<?> beanClass) {
Class<?>[] interfaces = beanClass.getInterfaces();
if (interfaces.length == 0) {
return null;
}
List<Class<?>> implementedInterfaces = new ArrayList<Class<?>>(Arrays.asList(interfaces));
List<Class<?>> filteredInterfaces = this.filterInterfaces(implementedInterfaces);
if (filteredInterfaces.isEmpty() || filteredInterfaces.size() > 1) {
return null;
}
return filteredInterfaces.get(0);
}
/**
* Returns a filtered list for the passed <code>interfaces</code> list, excluding the
* {@link java.io.Serializable}, {@link java.io.Externalizable} and any interfaces belonging to <code>jakarta.ejb</code>
* package.
*
* @param interfaces The list of interfaces
* @return
*/
private List<Class<?>> filterInterfaces(List<Class<?>> interfaces) {
if (interfaces == null) {
return null;
}
List<Class<?>> filteredInterfaces = new ArrayList<Class<?>>();
for (Class<?> intf : interfaces) {
if (intf.equals(java.io.Serializable.class)
|| intf.equals(java.io.Externalizable.class)
|| intf.getName().startsWith("jakarta.ejb.")) {
continue;
}
filteredInterfaces.add(intf);
}
return filteredInterfaces;
}
}
| 8,158 | 45.622857 | 217 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbJarParsingDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLResolver;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ee.structure.JBossDescriptorPropertyReplacement;
import org.jboss.as.ee.structure.SpecDescriptorPropertyReplacement;
import org.jboss.as.ejb3.cache.EJBBoundCacheParser;
import org.jboss.as.ejb3.clustering.ClusteringSchema;
import org.jboss.as.ejb3.clustering.EJBBoundClusteringMetaDataParser;
import org.jboss.as.ejb3.deliveryactive.parser.EJBBoundMdbDeliveryMetaDataParser;
import org.jboss.as.ejb3.deliveryactive.parser.EJBBoundMdbDeliveryMetaDataParser11;
import org.jboss.as.ejb3.deliveryactive.parser.EJBBoundMdbDeliveryMetaDataParser12;
import org.jboss.as.ejb3.deliveryactive.parser.EJBBoundMdbDeliveryMetaDataParser20;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.ejb3.interceptor.ContainerInterceptorsParser;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.pool.EJBBoundPoolParser;
import org.jboss.as.ejb3.resourceadapterbinding.parser.EJBBoundResourceAdapterBindingMetaDataParser;
import org.jboss.as.ejb3.security.parser.EJBBoundSecurityMetaDataParser;
import org.jboss.as.ejb3.security.parser.EJBBoundSecurityMetaDataParser11;
import org.jboss.as.ejb3.security.parser.EJBBoundSecurityMetaDataParser20;
import org.jboss.as.ejb3.security.parser.SecurityRoleMetaDataParser;
import org.jboss.as.ejb3.timerservice.TimerServiceMetaDataParser;
import org.jboss.as.ejb3.timerservice.TimerServiceMetaDataSchema;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ejb.parser.jboss.ejb3.IIOPMetaDataParser;
import org.jboss.metadata.ejb.parser.jboss.ejb3.JBossEjb3MetaDataParser;
import org.jboss.metadata.ejb.parser.jboss.ejb3.TransactionTimeoutMetaDataParser;
import org.jboss.metadata.ejb.parser.spec.AbstractMetaDataParser;
import org.jboss.metadata.ejb.parser.spec.EjbJarMetaDataParser;
import org.jboss.metadata.ejb.spec.AbstractEnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EjbType;
import org.jboss.metadata.parser.util.MetaDataElementParser;
import org.jboss.vfs.VirtualFile;
/**
* Processes a {@link DeploymentUnit} containing an ejb-jar.xml and creates {@link EjbJarMetaData}
* for that unit.
* <p/>
* This {@link DeploymentUnitProcessor deployment unit processor} looks for ejb-jar.xml in META-INF of a .jar
* and WEB-INF of a .war file. If it finds the ejb-jar.xml in these locations, it parses that file and creates
* {@link EjbJarMetaData} out of it. The {@link EjbJarMetaData} is then attached to the {@link DeploymentUnit}
* with {@link org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys#EJB_JAR_METADATA} as the key.
* <p/>
* <p/>
* Author: Jaikiran Pai
*/
public class EjbJarParsingDeploymentUnitProcessor implements DeploymentUnitProcessor {
/**
* .war file extension
*/
private static final String WAR_FILE_EXTENSION = ".war";
/**
* .jar file extension
*/
private static final String JAR_FILE_EXTENSION = ".jar";
private static final String EJB_JAR_XML = "ejb-jar.xml";
private static final String JBOSS_EJB3_XML = "jboss-ejb3.xml";
private static final String META_INF = "META-INF";
private static final String WEB_INF = "WEB-INF";
/**
* Finds an ejb-jar.xml (at WEB-INF of a .war or META-INF of a .jar) parses the file and creates
* metadata out of it. The metadata is then attached to the deployment unit.
*
* @param deploymentPhase
* @throws DeploymentUnitProcessingException
*
*/
@Override
public void deploy(DeploymentPhaseContext deploymentPhase) throws DeploymentUnitProcessingException {
// get hold of the deployment unit.
final DeploymentUnit deploymentUnit = deploymentPhase.getDeploymentUnit();
// get the root of the deployment unit
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EjbJarMetaData ejbJarMetaData;
final EjbJarMetaData specMetaData = parseEjbJarXml(deploymentUnit);
final EjbJarMetaData jbossMetaData = parseJBossEjb3Xml(deploymentUnit);
if (specMetaData == null) {
if (jbossMetaData == null)
return;
ejbJarMetaData = jbossMetaData;
} else if (jbossMetaData == null) {
ejbJarMetaData = specMetaData;
} else {
ejbJarMetaData = jbossMetaData.createMerged(specMetaData);
}
// Mark it as an EJB deployment
EjbDeploymentMarker.mark(deploymentUnit);
if (!deploymentUnit.hasAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION)) {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final EjbJarDescription ejbModuleDescription = new EjbJarDescription(moduleDescription, deploymentUnit.getName().endsWith(".war"));
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbModuleDescription);
}
// attach the EjbJarMetaData to the deployment unit
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA, ejbJarMetaData);
// if the jboss-ejb3.xml has a distinct-name configured then attach it to the deployment unit
if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
}
if (ejbJarMetaData.getModuleName() != null) {
eeModuleDescription.setModuleName(ejbJarMetaData.getModuleName());
}
if (ejbJarMetaData.isMetadataComplete()) {
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
if (!ejbJarMetaData.isEJB3x() && !ejbJarMetaData.isEJB40()) {
//EJB spec 20.5.1, we do not process annotations for older deployments
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
if(ejbJarMetaData.getEnterpriseBeans() != null) {
//check for entity beans
StringBuilder beans = new StringBuilder();
boolean error = false;
for (AbstractEnterpriseBeanMetaData bean : ejbJarMetaData.getEnterpriseBeans()) {
if (bean.getEjbType() == EjbType.ENTITY) {
if (!error) {
error = true;
} else {
beans.append(", ");
}
beans.append(bean.getEjbName());
}
}
if (error) {
throw EjbLogger.ROOT_LOGGER.entityBeansAreNotSupported(beans.toString());
}
}
}
private static VirtualFile getDescriptor(final DeploymentUnit deploymentUnit, final VirtualFile deploymentRoot, final String descriptorName) {
final String deploymentUnitName = deploymentUnit.getName().toLowerCase(Locale.ENGLISH);
// Locate the descriptor
final VirtualFile descriptor;
// EJB 3.1 FR 20.4 Enterprise Beans Packaged in a .war
if (deploymentUnitName.endsWith(WAR_FILE_EXTENSION)) {
// it's a .war file, so look for the ejb-jar.xml in WEB-INF
descriptor = deploymentRoot.getChild(WEB_INF + "/" + descriptorName);
} else if (deploymentUnitName.endsWith(JAR_FILE_EXTENSION)) {
descriptor = deploymentRoot.getChild(META_INF + "/" + descriptorName);
} else {
// neither a .jar nor a .war. Return
return null;
}
if (descriptor == null || !descriptor.exists()) {
// no descriptor found, nothing to do!
return null;
}
return descriptor;
}
/**
* Creates and returns a {@link XMLStreamReader} for the passed {@link VirtualFile ejb-jar.xml}
*
* @param stream The input stream
* @param ejbJarXml
* @return
* @throws DeploymentUnitProcessingException
*
*/
private static XMLStreamReader getXMLStreamReader(InputStream stream, VirtualFile ejbJarXml, XMLResolver resolver) throws DeploymentUnitProcessingException {
try {
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(resolver);
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(stream);
return xmlReader;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + ejbJarXml.getPathName());
}
}
private static InputStream open(final VirtualFile file) throws DeploymentUnitProcessingException {
try {
return file.openStream();
} catch (IOException e) {
throw new DeploymentUnitProcessingException(e);
}
}
private static EjbJarMetaData parseEjbJarXml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR);
//this is a bit tri
// Locate the descriptor
final VirtualFile descriptor;
if (alternateDescriptor != null) {
descriptor = alternateDescriptor;
} else {
descriptor = getDescriptor(deploymentUnit, deploymentRoot.getRoot(), EJB_JAR_XML);
}
if (descriptor == null) {
// no descriptor found, nothing to do!
return null;
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + descriptor.getPathName());
} finally {
try {
stream.close();
} catch (IOException ioe) {
EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
}
}
}
private static EjbJarMetaData parseJBossEjb3Xml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
// Locate the descriptor
final VirtualFile descriptor = getDescriptor(deploymentUnit, deploymentRoot, JBOSS_EJB3_XML);
if (descriptor == null) {
// no descriptor found
//but there may have been an ejb-jar element in jboss-all.xml
return deploymentUnit.getAttachment(EjbJarJBossAllParser.ATTACHMENT_KEY);
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
final JBossEjb3MetaDataParser parser = new JBossEjb3MetaDataParser(createJbossEjbJarParsers());
final EjbJarMetaData ejbJarMetaData = parser.parse(reader, dtdInfo, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, JBOSS_EJB3_XML + ": " + descriptor.getPathName());
} finally {
try {
stream.close();
} catch (IOException ioe) {
EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
}
}
}
static Map<String, AbstractMetaDataParser<?>> createJbossEjbJarParsers() {
Map<String, AbstractMetaDataParser<?>> parsers = new HashMap<String, AbstractMetaDataParser<?>>();
for (ClusteringSchema schema : EnumSet.allOf(ClusteringSchema.class)) {
parsers.put(schema.getNamespace().getUri(), new EJBBoundClusteringMetaDataParser(schema));
}
parsers.put(EJBBoundSecurityMetaDataParser.LEGACY_NAMESPACE_URI, EJBBoundSecurityMetaDataParser.INSTANCE);
parsers.put(EJBBoundSecurityMetaDataParser.NAMESPACE_URI_1_0, EJBBoundSecurityMetaDataParser.INSTANCE);
parsers.put(EJBBoundSecurityMetaDataParser11.NAMESPACE_URI_1_1, EJBBoundSecurityMetaDataParser11.INSTANCE);
parsers.put(EJBBoundSecurityMetaDataParser20.NAMESPACE_URI_2_0, EJBBoundSecurityMetaDataParser20.INSTANCE);
parsers.put(SecurityRoleMetaDataParser.LEGACY_NAMESPACE_URI, SecurityRoleMetaDataParser.INSTANCE);
parsers.put(SecurityRoleMetaDataParser.NAMESPACE_URI_1_0, SecurityRoleMetaDataParser.INSTANCE);
parsers.put(SecurityRoleMetaDataParser.NAMESPACE_URI_2_0, SecurityRoleMetaDataParser.INSTANCE);
parsers.put(EJBBoundResourceAdapterBindingMetaDataParser.LEGACY_NAMESPACE_URI, EJBBoundResourceAdapterBindingMetaDataParser.INSTANCE);
parsers.put(EJBBoundResourceAdapterBindingMetaDataParser.NAMESPACE_URI_1_0, EJBBoundResourceAdapterBindingMetaDataParser.INSTANCE);
parsers.put(EJBBoundResourceAdapterBindingMetaDataParser.NAMESPACE_URI_2_0, EJBBoundResourceAdapterBindingMetaDataParser.INSTANCE);
parsers.put(EJBBoundMdbDeliveryMetaDataParser.NAMESPACE_URI_1_0, EJBBoundMdbDeliveryMetaDataParser.INSTANCE);
parsers.put(EJBBoundMdbDeliveryMetaDataParser11.NAMESPACE_URI_1_1, EJBBoundMdbDeliveryMetaDataParser11.INSTANCE);
parsers.put(EJBBoundMdbDeliveryMetaDataParser12.NAMESPACE_URI_1_2, EJBBoundMdbDeliveryMetaDataParser12.INSTANCE);
parsers.put(EJBBoundMdbDeliveryMetaDataParser20.NAMESPACE_URI_2_0, EJBBoundMdbDeliveryMetaDataParser20.INSTANCE);
parsers.put("urn:iiop", new IIOPMetaDataParser());
parsers.put("urn:iiop:1.0", new IIOPMetaDataParser());
parsers.put("urn:iiop:2.0", new IIOPMetaDataParser());
parsers.put("urn:trans-timeout", new TransactionTimeoutMetaDataParser());
parsers.put("urn:trans-timeout:1.0", new TransactionTimeoutMetaDataParser());
parsers.put("urn:trans-timeout:2.0", new TransactionTimeoutMetaDataParser());
parsers.put(EJBBoundPoolParser.NAMESPACE_URI_1_0, new EJBBoundPoolParser());
parsers.put(EJBBoundPoolParser.NAMESPACE_URI_2_0, new EJBBoundPoolParser());
parsers.put(EJBBoundCacheParser.NAMESPACE_URI_1_0, new EJBBoundCacheParser());
parsers.put(EJBBoundCacheParser.NAMESPACE_URI_2_0, new EJBBoundCacheParser());
parsers.put(ContainerInterceptorsParser.NAMESPACE_URI_1_0, ContainerInterceptorsParser.INSTANCE);
parsers.put(ContainerInterceptorsParser.NAMESPACE_URI_2_0, ContainerInterceptorsParser.INSTANCE);
for (TimerServiceMetaDataSchema schema : EnumSet.allOf(TimerServiceMetaDataSchema.class)) {
parsers.put(schema.getNamespace().getUri(), new TimerServiceMetaDataParser(schema));
}
return parsers;
}
}
| 17,641 | 48.977337 | 170 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EJBComponentSuspendDeploymentUnitProcessor.java | package org.jboss.as.ejb3.deployment.processors;
import java.util.EnumSet;
import java.util.Set;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.DependencyConfigurator;
import org.jboss.as.ee.component.ViewConfiguration;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.component.EJBComponentCreateService;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewConfiguration;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.msc.service.ServiceBuilder;
import org.wildfly.extension.requestcontroller.ControlPoint;
import org.wildfly.extension.requestcontroller.ControlPointService;
import org.wildfly.extension.requestcontroller.RequestControllerActivationMarker;
/**
* @author Stuart Douglas
*/
public class EJBComponentSuspendDeploymentUnitProcessor implements DeploymentUnitProcessor {
public static final String ENTRY_POINT_NAME = "ejb.";
static final Set<MethodInterfaceType> INTERFACES = EnumSet.of(MethodInterfaceType.Remote, MethodInterfaceType.Home, MethodInterfaceType.MessageEndpoint);
@Override
public void deploy(DeploymentPhaseContext context) {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final String topLevelName;
//check if the controller is installed
if (!RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
return;
}
if (deploymentUnit.getParent() == null) {
topLevelName = deploymentUnit.getName();
} else {
topLevelName = deploymentUnit.getParent().getName();
}
for (ComponentDescription component : deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION).getComponentDescriptions()) {
if (component instanceof EJBComponentDescription) {
final String entryPoint = ENTRY_POINT_NAME + deploymentUnit.getName() + "." + component.getComponentName();
ControlPointService.install(context.getServiceTarget(), topLevelName, entryPoint);
component.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
EjbSuspendInterceptor interceptor = null;
ImmediateInterceptorFactory factory = null;
for (ViewConfiguration view: configuration.getViews()) {
EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
if (INTERFACES.contains(ejbView.getMethodIntf())) {
if (factory == null) {
interceptor = new EjbSuspendInterceptor();
factory = new ImmediateInterceptorFactory(interceptor);
}
view.addViewInterceptor(factory, InterceptorOrder.View.GRACEFUL_SHUTDOWN);
}
}
configuration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {
@Override
public void configureDependency(ServiceBuilder<?> serviceBuilder, EJBComponentCreateService service) {
serviceBuilder.addDependency(ControlPointService.serviceName(topLevelName, entryPoint), ControlPoint.class, service.getControlPointInjector());
}
});
}
});
}
}
}
}
| 4,202 | 49.035714 | 175 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/SessionBeanComponentDescriptionFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription;
import java.lang.reflect.Modifier;
import java.util.List;
import jakarta.ejb.SessionBean;
import jakarta.ejb.Singleton;
import jakarta.ejb.Stateful;
import jakarta.ejb.Stateless;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ee.structure.EJBAnnotationPropertyReplacement;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.component.singleton.SingletonComponentDescription;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.component.stateless.StatelessComponentDescription;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.metadata.ejb.spec.EjbType;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.GenericBeanMetaData;
import org.jboss.metadata.ejb.spec.SessionBean32MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.metadata.ejb.spec.SessionType;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.msc.service.ServiceName;
/**
* User: jpai
*/
public class SessionBeanComponentDescriptionFactory extends EJBComponentDescriptionFactory {
private static final DotName STATELESS_ANNOTATION = DotName.createSimple(Stateless.class.getName());
private static final DotName STATEFUL_ANNOTATION = DotName.createSimple(Stateful.class.getName());
private static final DotName SINGLETON_ANNOTATION = DotName.createSimple(Singleton.class.getName());
private static final DotName SESSION_BEAN_INTERFACE = DotName.createSimple(SessionBean.class.getName());
private final boolean defaultSlsbPoolAvailable;
public SessionBeanComponentDescriptionFactory(final boolean appclient, final boolean defaultSlsbPoolAvailable) {
super(appclient);
this.defaultSlsbPoolAvailable = defaultSlsbPoolAvailable;
}
/**
* Process annotations and merge any available metadata at the same time.
*/
@Override
protected void processAnnotations(final DeploymentUnit deploymentUnit, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
return;
}
// Find and process any @Stateless bean annotations
final List<AnnotationInstance> slsbAnnotations = compositeIndex.getAnnotations(STATELESS_ANNOTATION);
if (!slsbAnnotations.isEmpty()) {
processSessionBeans(deploymentUnit, slsbAnnotations, SessionBeanComponentDescription.SessionBeanType.STATELESS);
}
// Find and process any @Stateful bean annotations
final List<AnnotationInstance> sfsbAnnotations = compositeIndex.getAnnotations(STATEFUL_ANNOTATION);
if (!sfsbAnnotations.isEmpty()) {
processSessionBeans(deploymentUnit, sfsbAnnotations, SessionBeanComponentDescription.SessionBeanType.STATEFUL);
}
// Find and process any @Singleton bean annotations
final List<AnnotationInstance> sbAnnotations = compositeIndex.getAnnotations(SINGLETON_ANNOTATION);
if (!sbAnnotations.isEmpty()) {
processSessionBeans(deploymentUnit, sbAnnotations, SessionBeanComponentDescription.SessionBeanType.SINGLETON);
}
}
@Override
protected void processBeanMetaData(final DeploymentUnit deploymentUnit, final EnterpriseBeanMetaData enterpriseBeanMetaData) throws DeploymentUnitProcessingException {
if (enterpriseBeanMetaData.isSession()) {
assert enterpriseBeanMetaData instanceof SessionBeanMetaData : enterpriseBeanMetaData + " is not a SessionBeanMetaData";
processSessionBeanMetaData(deploymentUnit, (SessionBeanMetaData) enterpriseBeanMetaData);
}
}
private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
// process these session bean annotations and create component descriptions out of it
for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
final AnnotationTarget target = sessionBeanAnnotation.target();
if (!(target instanceof ClassInfo)) {
// Let's just WARN and move on. No need to throw an error
EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
continue;
}
final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
// skip if it's not a valid class for session bean
if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
continue;
}
final String ejbName = sessionBeanClassInfo.name().local();
final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
final String beanClassName;
if (beanMetaData != null) {
beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
} else {
beanClassName = sessionBeanClassInfo.name().toString();
sessionBeanType = annotatedSessionBeanType;
}
final SessionBeanComponentDescription sessionBeanDescription;
switch (sessionBeanType) {
case STATELESS:
sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData, defaultSlsbPoolAvailable);
break;
case STATEFUL:
sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
// If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
// description appropriately
final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
final Boolean passivationCapableDeploymentDescriptorValue;
if ((beanMetaData instanceof SessionBean32MetaData)) {
passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
} else {
passivationCapableDeploymentDescriptorValue = null;
}
final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
break;
case SINGLETON:
if (sessionBeanClassInfo.interfaceNames().contains(SESSION_BEAN_INTERFACE)) {
EjbLogger.ROOT_LOGGER.singletonCantImplementSessionBean(beanClassName);
}
sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
break;
default:
throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
}
addComponent(deploymentUnit, sessionBeanDescription);
final AnnotationValue mappedNameValue = sessionBeanAnnotation.value("mappedName");
if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "",
ejbName);
}
}
EjbDeploymentMarker.mark(deploymentUnit);
}
private static SessionBeanComponentDescription.SessionBeanType descriptionOf(final SessionType sessionType) {
if (sessionType == null)
return null;
switch (sessionType) {
case Stateless:
return SessionBeanComponentDescription.SessionBeanType.STATELESS;
case Stateful:
return SessionBeanComponentDescription.SessionBeanType.STATEFUL;
case Singleton:
return SessionBeanComponentDescription.SessionBeanType.SINGLETON;
default:
throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionType.name());
}
}
/**
* Returns true if the passed <code>sessionBeanClass</code> meets the requirements set by the EJB3 spec about
* bean implementation classes. The passed <code>sessionBeanClass</code> must not be an interface and must be public
* and not final and not abstract. If it passes these requirements then this method returns true. Else it returns false.
*
* @param sessionBeanClass The session bean class
* @return
*/
private static boolean assertSessionBeanClassValidity(final ClassInfo sessionBeanClass) {
final short flags = sessionBeanClass.flags();
final String className = sessionBeanClass.name().toString();
// must *not* be an interface
if (Modifier.isInterface(flags)) {
EjbLogger.DEPLOYMENT_LOGGER.sessionBeanClassCannotBeAnInterface(className);
return false;
}
// bean class must be public, must *not* be abstract or final
if (!Modifier.isPublic(flags) || Modifier.isAbstract(flags) || Modifier.isFinal(flags)) {
EjbLogger.DEPLOYMENT_LOGGER.sessionBeanClassMustBePublicNonAbstractNonFinal(className);
return false;
}
// valid class
return true;
}
private void processSessionBeanMetaData(final DeploymentUnit deploymentUnit, final SessionBeanMetaData sessionBean) throws DeploymentUnitProcessingException {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final String beanName = sessionBean.getName();
SessionType sessionType = sessionBean.getSessionType();
if (sessionType == null && sessionBean instanceof GenericBeanMetaData) {
final GenericBeanMetaData bean = (GenericBeanMetaData) sessionBean;
if (bean.getEjbType() == EjbType.SESSION) {
sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex);
if (sessionType == null) {
throw EjbLogger.ROOT_LOGGER.sessionTypeNotSpecified(beanName);
}
} else {
//it is not a session bean, so we ignore it
return;
}
} else if (sessionType == null) {
sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex);
if (sessionType == null) {
throw EjbLogger.ROOT_LOGGER.sessionTypeNotSpecified(beanName);
}
}
final String beanClassName = sessionBean.getEjbClass();
final SessionBeanComponentDescription sessionBeanDescription;
switch (sessionType) {
case Stateless:
sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, sessionBean, defaultSlsbPoolAvailable);
break;
case Stateful:
sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, sessionBean);
if (sessionBean instanceof SessionBean32MetaData && ((SessionBean32MetaData) sessionBean).isPassivationCapable() != null) {
((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(((SessionBean32MetaData) sessionBean).isPassivationCapable());
}
break;
case Singleton:
sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, sessionBean);
break;
default:
throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionType.name());
}
addComponent(deploymentUnit, sessionBeanDescription);
}
private SessionType determineSessionType(final String ejbClass, final CompositeIndex compositeIndex) {
if(ejbClass == null) {
return null;
}
final ClassInfo info = compositeIndex.getClassByName(DotName.createSimple(ejbClass));
if (info == null) {
return null;
}
if(info.annotationsMap().get(STATEFUL_ANNOTATION) != null) {
return SessionType.Stateful;
} else if(info.annotationsMap().get(STATELESS_ANNOTATION) != null) {
return SessionType.Stateless;
} else if(info.annotationsMap().get(SINGLETON_ANNOTATION) != null) {
return SessionType.Singleton;
}
return null;
}
}
| 15,785 | 52.877133 | 210 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EJBDefaultSecurityDomainProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION;
import static org.jboss.as.server.security.SecurityMetaData.ATTACHMENT_KEY;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EJBSecurityDomainService;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.security.ApplicationSecurityDomainConfig;
import org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainDefinition;
import org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainService.ApplicationSecurityDomain;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.security.SecurityMetaData;
import org.jboss.as.server.security.VirtualDomainMarkerUtility;
import org.jboss.as.server.security.VirtualDomainMetaData;
import org.jboss.as.server.security.VirtualDomainUtil;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.wildfly.security.auth.server.SecurityDomain;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
/**
* A {@link DeploymentUnitProcessor} which looks for {@link EJBComponentDescription}s in the deployment
* unit and sets the default security domain name, that's configured at the Jakarta Enterprise Beans subsystem level,
* {@link EJBComponentDescription#setDefaultSecurityDomain(String) to each of the Jakarta Enterprise Beans component descriptions}.
*
* @author Jaikiran Pai
*/
public class EJBDefaultSecurityDomainProcessor implements DeploymentUnitProcessor, Function<String, ApplicationSecurityDomainConfig>, BooleanSupplier {
private final AtomicReference<String> defaultSecurityDomainName;
private final Iterable<ApplicationSecurityDomainConfig> knownApplicationSecurityDomains;
private final Iterable<String> outflowSecurityDomains;
public EJBDefaultSecurityDomainProcessor(AtomicReference<String> defaultSecurityDomainName, Iterable<ApplicationSecurityDomainConfig> knownApplicationSecurityDomains, Iterable<String> outflowSecurityDomains) {
this.defaultSecurityDomainName = defaultSecurityDomainName;
this.knownApplicationSecurityDomains = knownApplicationSecurityDomains;
this.outflowSecurityDomains = outflowSecurityDomains;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
if (eeModuleDescription == null) {
return;
}
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
if (componentDescriptions == null || componentDescriptions.isEmpty()) {
return;
}
final String defaultSecurityDomain;
if(eeModuleDescription.getDefaultSecurityDomain() == null) {
defaultSecurityDomain = this.defaultSecurityDomainName.get();
} else {
defaultSecurityDomain = eeModuleDescription.getDefaultSecurityDomain();
}
final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
final SecurityMetaData securityMetaData = deploymentUnit.getAttachment(ATTACHMENT_KEY);
// If we have a ServiceName for a security domain it should be used for all components.
ServiceName elytronDomainServiceName = securityMetaData != null ? securityMetaData.getSecurityDomain() : null;
final ServiceName ejbSecurityDomainServiceName = deploymentUnit.getServiceName().append(EJBSecurityDomainService.SERVICE_NAME);
final ApplicationSecurityDomainConfig defaultDomainMapping = this.apply(defaultSecurityDomain);
final ServiceName defaultElytronDomainServiceName;
if (defaultDomainMapping != null) {
defaultElytronDomainServiceName = support
.getCapabilityServiceName(ApplicationSecurityDomainDefinition.APPLICATION_SECURITY_DOMAIN_CAPABILITY_NAME, defaultSecurityDomain)
.append("security-domain");
} else {
defaultElytronDomainServiceName = null;
}
ApplicationSecurityDomainConfig selectedElytronDomainConfig = null;
VirtualDomainMetaData virtualDomainMetaData = null;
boolean isDefinedSecurityDomainVirtual = false;
if (elytronDomainServiceName == null) {
String selectedElytronDomainName = null;
boolean legacyDomainDefined = false;
boolean defaultRequired = false;
for (ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription instanceof EJBComponentDescription) {
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
ejbComponentDescription.setDefaultSecurityDomain(defaultSecurityDomain);
// Ensure the Jakarta Enterprise Beans components within a deployment are associated with at most one Elytron security domain
String definedSecurityDomain = ejbComponentDescription.getDefinedSecurityDomain();
defaultRequired = defaultRequired || definedSecurityDomain == null;
ApplicationSecurityDomainConfig definedDomainMapping = definedSecurityDomain != null ? this.apply(definedSecurityDomain) : null;
if (definedDomainMapping != null) {
if (selectedElytronDomainName == null) {
selectedElytronDomainName = definedSecurityDomain;
selectedElytronDomainConfig = definedDomainMapping;
} else if (selectedElytronDomainName.equals(definedSecurityDomain) == false) {
throw EjbLogger.ROOT_LOGGER.multipleSecurityDomainsDetected();
}
} else if (definedSecurityDomain != null) {
virtualDomainMetaData = getVirtualDomainMetaData(definedSecurityDomain, phaseContext);
if (virtualDomainMetaData != null) {
elytronDomainServiceName = VirtualDomainMarkerUtility.virtualDomainName(definedSecurityDomain);
isDefinedSecurityDomainVirtual = true;
}
if (elytronDomainServiceName != null) {
selectedElytronDomainName = definedSecurityDomain;
} else {
legacyDomainDefined = true;
}
}
}
}
final boolean useDefaultElytronMapping;
/*
* We only need to fall into the default handling if at least one Jakarta Enterprise Beans Component has no defined
* security domain.
*/
if (defaultRequired && selectedElytronDomainName == null) {
DeploymentUnit topLevelDeployment = toRoot(deploymentUnit);
final SecurityMetaData topLevelSecurityMetaData = topLevelDeployment.getAttachment(ATTACHMENT_KEY);
ServiceName topLevelElytronDomainServiceName = topLevelSecurityMetaData != null ? topLevelSecurityMetaData.getSecurityDomain() : null;
if (topLevelElytronDomainServiceName != null) {
// use the ServiceName from the top level deployment if the security domain has not been explicitly defined
elytronDomainServiceName = topLevelElytronDomainServiceName;
useDefaultElytronMapping = true;
} else if (defaultDomainMapping != null) {
selectedElytronDomainName = defaultSecurityDomain;
selectedElytronDomainConfig = defaultDomainMapping;
elytronDomainServiceName = defaultElytronDomainServiceName;
// Only apply a default domain to the whole deployment if no legacy domain was defined.
useDefaultElytronMapping = !legacyDomainDefined;
} else {
useDefaultElytronMapping = false;
}
} else {
useDefaultElytronMapping = false;
}
// If this Jakarta Enterprise Beans deployment is associated with an Elytron security domain, set up the security domain mapping
if (selectedElytronDomainConfig != null) {
final EJBSecurityDomainService ejbSecurityDomainService = new EJBSecurityDomainService(deploymentUnit);
ServiceName applicationSecurityDomainServiceName = support.getCapabilityServiceName(
ApplicationSecurityDomainDefinition.APPLICATION_SECURITY_DOMAIN_CAPABILITY_NAME, selectedElytronDomainName);
elytronDomainServiceName = applicationSecurityDomainServiceName.append("security-domain");
final ServiceBuilder<Void> builder = phaseContext.getServiceTarget().addService(ejbSecurityDomainServiceName, ejbSecurityDomainService)
.addDependency(applicationSecurityDomainServiceName, ApplicationSecurityDomain.class, ejbSecurityDomainService.getApplicationSecurityDomainInjector());
builder.install();
for(final ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription instanceof EJBComponentDescription) {
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
String definedSecurityDomain = ejbComponentDescription.getDefinedSecurityDomain();
/*
* Only apply the Elytron domain if one of the following is true:
* - No security domain was defined within the deployment so the default is being applied to all components.
* - The security domain defined on the Jakarta Enterprise Beans Component matches the name mapped to the Elytron domain.
*
* Otherwise Jakarta Enterprise Beans Components will be in one of the following states:
* - No associated security domain.
* - Using configured domain as PicketBox domain.
* - Fallback to subsystem defined default PicketBox domain.
*/
// The component may have had a legacy SecurityDomain defined.
if (useDefaultElytronMapping
|| selectedElytronDomainName.equals(definedSecurityDomain)) {
ejbComponentDescription.setOutflowSecurityDomainsConfigured(this);
ejbComponentDescription.setSecurityDomainServiceName(elytronDomainServiceName);
ejbComponentDescription.setRequiresJacc(selectedElytronDomainConfig.isEnableJacc());
ejbComponentDescription.setLegacyCompliantPrincipalPropagation(selectedElytronDomainConfig.isLegacyCompliantPrincipalPropagation());
ejbComponentDescription.getConfigurators().add((context, description, configuration) ->
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.requires(ejbSecurityDomainServiceName))
);
} else if (definedSecurityDomain == null && defaultDomainMapping != null) {
ejbComponentDescription.setOutflowSecurityDomainsConfigured(this);
ejbComponentDescription.setSecurityDomainServiceName(defaultElytronDomainServiceName);
ejbComponentDescription.setRequiresJacc(defaultDomainMapping.isEnableJacc());
ejbComponentDescription.setLegacyCompliantPrincipalPropagation(defaultDomainMapping.isLegacyCompliantPrincipalPropagation());
ejbComponentDescription.getConfigurators().add((context, description, configuration) ->
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.requires(ejbSecurityDomainServiceName))
);
}
}
}
} else if (elytronDomainServiceName != null) {
// virtual domain
final EJBSecurityDomainService ejbSecurityDomainService = new EJBSecurityDomainService(deploymentUnit);
if (isDefinedSecurityDomainVirtual && ! VirtualDomainUtil.isVirtualDomainCreated(deploymentUnit)) {
VirtualDomainUtil.createVirtualDomain(phaseContext.getServiceRegistry(), virtualDomainMetaData, elytronDomainServiceName, phaseContext.getServiceTarget());
}
final ServiceBuilder<Void> builder = phaseContext.getServiceTarget().addService(ejbSecurityDomainServiceName, ejbSecurityDomainService)
.addDependency(elytronDomainServiceName, SecurityDomain.class, ejbSecurityDomainService.getSecurityDomainInjector());
builder.install();
for (final ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription instanceof EJBComponentDescription) {
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
ejbComponentDescription.setSecurityDomainServiceName(elytronDomainServiceName);
ejbComponentDescription.setOutflowSecurityDomainsConfigured(this);
componentDescription.getConfigurators()
.add((context, description, configuration) -> configuration.getCreateDependencies()
.add((serviceBuilder, service) -> serviceBuilder.requires(ejbSecurityDomainServiceName)));
}
}
}
} else {
// We will use the defined Elytron domain for all Jakarta Enterprise Beans and ignore individual configuration.
// Bean level activation remains dependent on configuration of bean - i.e. does it actually need security?
final EJBSecurityDomainService ejbSecurityDomainService = new EJBSecurityDomainService(deploymentUnit);
final ServiceBuilder<Void> builder = phaseContext.getServiceTarget().addService(ejbSecurityDomainServiceName, ejbSecurityDomainService)
.addDependency(elytronDomainServiceName, SecurityDomain.class, ejbSecurityDomainService.getSecurityDomainInjector());
builder.install();
for (ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription instanceof EJBComponentDescription) {
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
ejbComponentDescription.setSecurityDomainServiceName(elytronDomainServiceName);
ejbComponentDescription.setOutflowSecurityDomainsConfigured(this);
componentDescription.getConfigurators()
.add((context, description, configuration) -> configuration.getCreateDependencies()
.add((serviceBuilder, service) -> serviceBuilder.requires(ejbSecurityDomainServiceName)));
}
}
}
}
@Override
public ApplicationSecurityDomainConfig apply(String name) {
for (ApplicationSecurityDomainConfig applicationSecurityDomainConfig : this.knownApplicationSecurityDomains) {
if (applicationSecurityDomainConfig.isSameDomain(name)) {
return applicationSecurityDomainConfig;
}
}
return null;
}
@Override
public boolean getAsBoolean() {
return this.outflowSecurityDomains.iterator().hasNext();
}
private <T> ServiceController<T> getService(ServiceRegistry serviceRegistry, ServiceName serviceName, Class<T> serviceType) {
ServiceController<?> controller = serviceRegistry.getService(serviceName);
return (ServiceController<T>) controller;
}
private VirtualDomainMetaData getVirtualDomainMetaData(String definedSecurityDomain, DeploymentPhaseContext phaseContext) {
if (definedSecurityDomain != null && ! definedSecurityDomain.isEmpty()) {
ServiceName virtualDomainMetaDataName = VirtualDomainMarkerUtility.virtualDomainMetaDataName(phaseContext, definedSecurityDomain);
ServiceController<VirtualDomainMetaData> serviceContainer = getService(phaseContext.getServiceRegistry(), virtualDomainMetaDataName, VirtualDomainMetaData.class);
if (serviceContainer != null) {
ServiceController.State serviceState = serviceContainer.getState();
if (serviceState == ServiceController.State.UP) {
return serviceContainer.getValue();
}
}
}
return null;
}
private static DeploymentUnit toRoot(final DeploymentUnit deploymentUnit) {
DeploymentUnit result = deploymentUnit;
DeploymentUnit parent = result.getParent();
while (parent != null) {
result = parent;
parent = result.getParent();
}
return result;
}
}
| 19,444 | 60.147799 | 213 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/IIOPJndiBindingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ejb3.iiop.handle.HandleDelegateImpl;
import org.jboss.as.naming.ManagedReferenceInjector;
import org.jboss.as.naming.ServiceBasedNamingStore;
import org.jboss.as.naming.ValueManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.BinderService;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.omg.CORBA.ORB;
import org.wildfly.iiop.openjdk.deployment.IIOPDeploymentMarker;
import org.wildfly.iiop.openjdk.service.CorbaORBService;
/**
* Processor responsible for binding IIOP related resources to JNDI.
* </p>
* Unlike other resource injections this binding happens for all eligible components,
* regardless of the presence of the {@link jakarta.annotation.Resource} annotation.
*
* @author Stuart Douglas
*/
public class IIOPJndiBindingProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (moduleDescription == null) {
return;
}
//do not bind if jacORB not present
if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
return;
}
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
//if this is a war we need to bind to the modules comp namespace
if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit) || DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
bindService(serviceTarget, moduleContextServiceName, module);
}
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component.getNamingMode() == ComponentNamingMode.CREATE) {
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(), moduleDescription.getModuleName(), component.getComponentName());
bindService(serviceTarget, compContextServiceName, module);
}
}
}
/**
* Binds java:comp/ORB
*
* @param serviceTarget The service target
* @param contextServiceName The service name of the context to bind to
*/
private void bindService(final ServiceTarget serviceTarget, final ServiceName contextServiceName, final Module module) {
final ServiceName orbServiceName = contextServiceName.append("ORB");
final BinderService orbService = new BinderService("ORB");
serviceTarget.addService(orbServiceName, orbService)
.addDependency(CorbaORBService.SERVICE_NAME, ORB.class,
new ManagedReferenceInjector<ORB>(orbService.getManagedObjectInjector()))
.addDependency(contextServiceName, ServiceBasedNamingStore.class, orbService.getNamingStoreInjector())
.install();
final ServiceName handleDelegateServiceName = contextServiceName.append("HandleDelegate");
final BinderService handleDelegateBindingService = new BinderService("HandleDelegate");
handleDelegateBindingService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new HandleDelegateImpl(module.getClassLoader())));
serviceTarget.addService(handleDelegateServiceName, handleDelegateBindingService)
.addDependency(contextServiceName, ServiceBasedNamingStore.class, handleDelegateBindingService.getNamingStoreInjector())
.install();
}
}
| 5,722 | 49.201754 | 207 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbContextJndiBindingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.Collection;
import jakarta.ejb.EJBContext;
import jakarta.ejb.EntityContext;
import jakarta.ejb.MessageDrivenContext;
import jakarta.ejb.SessionContext;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.context.CurrentInvocationContext;
import org.jboss.as.ejb3.context.EjbContextResourceReferenceProcessor;
import org.jboss.as.naming.ContextListManagedReferenceFactory;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
/**
* Deployment processor responsible for detecting Jakarta Enterprise Beans components and adding a {@link BindingConfiguration} for the
* java:comp/EJBContext entry.
*
* @author John Bailey
*/
public class EjbContextJndiBindingProcessor implements DeploymentUnitProcessor {
/**
* {@inheritDoc} *
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
//setup ejb context jndi handlers
registry.registerResourceReferenceProcessor(new EjbContextResourceReferenceProcessor(EJBContext.class));
registry.registerResourceReferenceProcessor(new EjbContextResourceReferenceProcessor(SessionContext.class));
registry.registerResourceReferenceProcessor(new EjbContextResourceReferenceProcessor(EntityContext.class));
registry.registerResourceReferenceProcessor(new EjbContextResourceReferenceProcessor(MessageDrivenContext.class));
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> componentConfigurations = eeModuleDescription.getComponentDescriptions();
if (componentConfigurations == null || componentConfigurations.isEmpty()) {
return;
}
for (ComponentDescription componentConfiguration : componentConfigurations) {
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index != null) {
processComponentConfig(componentConfiguration);
}
}
}
protected void processComponentConfig(final ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
if (!(componentDescription instanceof EJBComponentDescription)) {
return; // Only process Jakarta Enterprise Beans
}
// if the Jakarta Enterprise Beans are packaged in a .war, then we need to bind the java:comp/EJBContext only once for the entire module
if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
// get the module description
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
// the java:module/EJBContext binding configuration
// Note that we bind to java:module/EJBContext since it's a .war. End users can still lookup java:comp/EJBContext
// and that will internally get translated to java:module/EJBContext for .war, since java:comp == java:module in
// a web ENC. So binding to java:module/EJBContext is OK.
final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:module/EJBContext", directEjbContextReferenceSource);
moduleDescription.getBindingConfigurations().add(ejbContextBinding);
} else { // Jakarta Enterprise Beans packaged outside of a .war. So process normally.
// add the binding configuration to the component description
final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:comp/EJBContext", directEjbContextReferenceSource);
componentDescription.getBindingConfigurations().add(ejbContextBinding);
}
}
private static final ManagedReference ejbContextManagedReference = new ManagedReference() {
public void release() {
}
public Object getInstance() {
return CurrentInvocationContext.getEjbContext();
}
};
private static final ManagedReferenceFactory ejbContextManagedReferenceFactory = new ContextListManagedReferenceFactory() {
public ManagedReference getReference() {
return ejbContextManagedReference;
}
@Override
public String getInstanceClassName() {
return EJBContext.class.getName();
}
};
private static final InjectionSource directEjbContextReferenceSource = new InjectionSource() {
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
injector.inject(ejbContextManagedReferenceFactory);
}
public boolean equals(Object o) {
return o != null && o.getClass() == this.getClass();
}
public int hashCode() {
return 1;
}
};
}
| 7,184 | 48.551724 | 255 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.List;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData;
/**
* Make sure we process annotations first and then start on the descriptors.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public class AnnotatedEJBComponentDescriptionDeploymentUnitProcessor implements DeploymentUnitProcessor {
/**
* If this is an appclient we want to make the components as not installable, so we can still look up which Jakarta Enterprise Beans's are in
* the deployment, but do not actual install them
*/
private final boolean appclient;
private final EJBComponentDescriptionFactory[] factories;
public AnnotatedEJBComponentDescriptionDeploymentUnitProcessor(final boolean appclient, final boolean defaultMdbPoolAvailable, final boolean defaultSlsbPoolAvailable) {
this.appclient = appclient;
this.factories = new EJBComponentDescriptionFactory[] {
new MessageDrivenComponentDescriptionFactory(appclient, defaultMdbPoolAvailable),
new SessionBeanComponentDescriptionFactory(appclient, defaultSlsbPoolAvailable)
};
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
// get hold of the deployment unit
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (compositeIndex == null) {
EjbLogger.DEPLOYMENT_LOGGER.tracef("Skipping Jakarta Enterprise Beans annotation processing since no composite annotation index found in unit: %s", deploymentUnit);
} else {
if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
EjbLogger.DEPLOYMENT_LOGGER.trace("Skipping Jakarta Enterprise Beans annotation processing due to deployment being metadata-complete. ");
} else {
processAnnotations(deploymentUnit, compositeIndex);
}
}
processDeploymentDescriptor(deploymentUnit);
}
protected static EjbJarDescription getEjbJarDescription(final DeploymentUnit deploymentUnit) {
EjbJarDescription ejbJarDescription = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION);
if (ejbJarDescription == null) {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
ejbJarDescription = new EjbJarDescription(moduleDescription, deploymentUnit.getName().endsWith(".war"));
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbJarDescription);
}
return ejbJarDescription;
}
private void processDeploymentDescriptor(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
// find the Jakarta Enterprise Beans jar metadata and start processing it
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData == null) {
return;
}
final SimpleSet<String> annotatedEJBs;
if (appclient) {
final List<ComponentDescription> additionalComponents = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS);
annotatedEJBs = new SimpleSet<String>() {
@Override
public boolean contains(Object o) {
for (final ComponentDescription component : additionalComponents) {
if (component.getComponentName().equals(o)) {
return true;
}
}
return false;
}
};
} else {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
annotatedEJBs = new SimpleSet<String>() {
@Override
public boolean contains(Object o) {
return ejbJarDescription.hasComponent((String) o);
}
};
}
// process Jakarta Enterprise Beans
final EnterpriseBeansMetaData ejbs = ejbJarMetaData.getEnterpriseBeans();
if (ejbs != null && !ejbs.isEmpty()) {
for (final EnterpriseBeanMetaData ejb : ejbs) {
final String beanName = ejb.getName();
// the important bit is to skip already processed Jakarta Enterprise Beans via annotations
if (annotatedEJBs.contains(beanName)) {
continue;
}
processBeanMetaData(deploymentUnit, ejb);
}
}
EjbDeploymentMarker.mark(deploymentUnit);
}
private void processAnnotations(final DeploymentUnit deploymentUnit, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
for (final EJBComponentDescriptionFactory factory : factories) {
factory.processAnnotations(deploymentUnit, compositeIndex);
}
}
private void processBeanMetaData(final DeploymentUnit deploymentUnit, final EnterpriseBeanMetaData ejb) throws DeploymentUnitProcessingException {
for (final EJBComponentDescriptionFactory factory : factories) {
factory.processBeanMetaData(deploymentUnit, ejb);
}
}
private interface SimpleSet<E> {
boolean contains(Object o);
}
}
| 7,771 | 47.880503 | 176 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbJndiBindingsDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.remote.RemoteViewInjectionSource;
import org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DelegatingSupplier;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.extension.requestcontroller.ControlPoint;
import org.wildfly.extension.requestcontroller.ControlPointService;
import org.wildfly.extension.requestcontroller.RequestControllerActivationMarker;
import org.wildfly.extension.requestcontroller.RunResult;
/**
* Sets up JNDI bindings for each of the views exposed by a {@link SessionBeanComponentDescription session bean}
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class EjbJndiBindingsDeploymentUnitProcessor implements DeploymentUnitProcessor {
private final boolean appclient;
public EjbJndiBindingsDeploymentUnitProcessor(final boolean appclient) {
this.appclient = appclient;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Only process Jakarta Enterprise Beans deployments
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
Map<String, SessionBeanComponentDescription> sessionBeanComponentDescriptions = new HashMap<>();
if (componentDescriptions != null) {
for (ComponentDescription componentDescription : componentDescriptions) {
// process only Jakarta Enterprise Beans session beans
if (componentDescription instanceof SessionBeanComponentDescription) {
SessionBeanComponentDescription sessionBeanComponentDescription = (SessionBeanComponentDescription) componentDescription;
String ejbClassName = sessionBeanComponentDescription.getEJBClassName();
SessionBeanComponentDescription existingDescription = sessionBeanComponentDescriptions.putIfAbsent(ejbClassName, sessionBeanComponentDescription);
if ((existingDescription == null) || existingDescription.getSessionBeanType() == sessionBeanComponentDescription.getSessionBeanType()) {
this.setupJNDIBindings(sessionBeanComponentDescription, deploymentUnit);
} else {
EjbLogger.DEPLOYMENT_LOGGER.typeSpecViolation(ejbClassName);
}
}
}
}
if (appclient) {
for (final ComponentDescription component : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
this.setupJNDIBindings((EJBComponentDescription) component, deploymentUnit);
}
}
}
/**
* Sets up jndi bindings for each of the views exposed by the passed <code>sessionBean</code>
*
* @param sessionBean The session bean
* @param deploymentUnit The deployment unit containing the session bean
*/
private void setupJNDIBindings(EJBComponentDescription sessionBean, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final Collection<ViewDescription> views = sessionBean.getViews();
if (views == null || views.isEmpty()) {
EjbLogger.DEPLOYMENT_LOGGER.noJNDIBindingsForSessionBean(sessionBean.getEJBName());
return;
}
// In case of Jakarta Enterprise Beans bindings, appname == .ear file name/application-name set in the application.xml (if it's an .ear deployment)
// NOTE: Do NOT use the app name from the EEModuleDescription.getApplicationName() because the Jakarta EE spec has a different and conflicting meaning for app name
// (where app name == module name in the absence of a .ear). Use EEModuleDescription.getEarApplicationName() instead
final String applicationName = sessionBean.getModuleDescription().getEarApplicationName();
final String distinctName = sessionBean.getModuleDescription().getDistinctName(); // default to empty string
final String globalJNDIBaseName = "java:global/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String appJNDIBaseName = "java:app/" + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String moduleJNDIBaseName = "java:module/" + sessionBean.getEJBName();
final String remoteExportedJNDIBaseName = "java:jboss/exported/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String ejbNamespaceBindingBaseName = "ejb:" + (applicationName != null ? applicationName : "") + "/" + sessionBean.getModuleName() + "/" + (!"".equals(distinctName) ? distinctName + "/" : "") + sessionBean.getEJBName();
// the base ServiceName which will be used to create the ServiceName(s) for each of the view bindings
final StringBuilder jndiBindingsLogMessage = new StringBuilder();
jndiBindingsLogMessage.append(System.lineSeparator()).append(System.lineSeparator());
// now create the bindings for each view under the java:global, java:app and java:module namespaces
EJBViewDescription ejbViewDescription = null;
for (ViewDescription viewDescription : views) {
boolean isEjbNamespaceBindingBaseName = false;
ejbViewDescription = (EJBViewDescription) viewDescription;
if (appclient && ejbViewDescription.getMethodIntf() != MethodInterfaceType.Remote && ejbViewDescription.getMethodIntf() != MethodInterfaceType.Home) {
continue;
}
if (ejbViewDescription.getMethodIntf() != MethodInterfaceType.Remote) {
isEjbNamespaceBindingBaseName = true;
}
if (!ejbViewDescription.hasJNDIBindings()) continue;
final String viewClassName = ejbViewDescription.getViewClassName();
// java:global bindings
final String globalJNDIName = globalJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, globalJNDIName);
logBinding(jndiBindingsLogMessage, globalJNDIName);
// java:app bindings
final String appJNDIName = appJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, appJNDIName);
logBinding(jndiBindingsLogMessage, appJNDIName);
// java:module bindings
final String moduleJNDIName = moduleJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, moduleJNDIName);
logBinding(jndiBindingsLogMessage, moduleJNDIName);
// If it a remote or (remote) home view then bind the java:jboss/exported jndi names for the view
if(ejbViewDescription.getMethodIntf() == MethodInterfaceType.Remote || ejbViewDescription.getMethodIntf() == MethodInterfaceType.Home) {
final String remoteJNDIName = remoteExportedJNDIBaseName + "!" + viewClassName;
if(RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
registerControlPointBinding(sessionBean, viewDescription, remoteJNDIName, deploymentUnit);
} else {
registerBinding(sessionBean, viewDescription, remoteJNDIName);
}
logBinding(jndiBindingsLogMessage, remoteJNDIName);
}
// log Jakarta Enterprise Beans's ejb:/ namespace binding
final String ejbNamespaceBindingName = sessionBean.isStateful() ? ejbNamespaceBindingBaseName + "!" + viewClassName + "?stateful" : ejbNamespaceBindingBaseName + "!" + viewClassName;
if(!isEjbNamespaceBindingBaseName){
logBinding(jndiBindingsLogMessage, ejbNamespaceBindingName);
}
}
// Enterprise Beans 3.1 spec, section 4.4.1 Global JNDI Access states:
// In addition to the previous requirements, if the bean exposes only one of the
// applicable client interfaces(or alternatively has only a no-interface view), the container
// registers an entry for that view with the following syntax :
//
// java:global[/<app-name>]/<module-name>/<bean-name>
//
// Note that this also applies to java:app and java:module bindings
// as can be seen by the examples in 4.4.2.1
if (views.size() == 1) {
final EJBViewDescription viewDescription = (EJBViewDescription) views.iterator().next();
if (ejbViewDescription.hasJNDIBindings()) {
// java:global binding
registerBinding(sessionBean, viewDescription, globalJNDIBaseName);
logBinding(jndiBindingsLogMessage, globalJNDIBaseName);
// java:app binding
registerBinding(sessionBean, viewDescription, appJNDIBaseName);
logBinding(jndiBindingsLogMessage, appJNDIBaseName);
// java:module binding
registerBinding(sessionBean, viewDescription, moduleJNDIBaseName);
logBinding(jndiBindingsLogMessage, moduleJNDIBaseName);
}
}
// log the jndi bindings
EjbLogger.DEPLOYMENT_LOGGER.jndiBindings(sessionBean.getEJBName(), deploymentUnit, jndiBindingsLogMessage);
}
private void registerBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName) {
if (appclient) {
registerRemoteBinding(componentDescription, viewDescription, jndiName);
} else {
viewDescription.getBindingNames().add(jndiName);
}
}
private void registerRemoteBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final DelegatingSupplier<ClassLoader> viewClassLoader = new DelegatingSupplier<>();
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient)));
componentDescription.getConfigurators().add(new ComponentConfigurator() {
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
viewClassLoader.set(() -> configuration.getModuleClassLoader());
}
});
}
private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final DelegatingSupplier<ClassLoader> viewClassLoader = new DelegatingSupplier<>();
final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
componentDescription.getConfigurators().add((context, description, configuration) -> {
viewClassLoader.set(() -> configuration.getModuleClassLoader());
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
});
//we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
//as it will also reject local lookups as well, although in general local code should never be looking up the
//exported bindings
//the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
final InjectionSource is = new InjectionSource() {
@Override
public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
injector.inject(new RemoteViewManagedReferenceFactory(moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient) {
@Override
public ManagedReference getReference() {
ControlPoint cp = controlPointInjectedValue.getValue();
try {
RunResult res = cp.beginRequest();
if(res != RunResult.RUN) {
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return delegateInjection.getValue().getReference();
} finally {
cp.requestComplete();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
};
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
private void logBinding(final StringBuilder jndiBindingsLogMessage, final String jndiName) {
jndiBindingsLogMessage.append("\t");
jndiBindingsLogMessage.append(jndiName);
jndiBindingsLogMessage.append(System.lineSeparator());
}
}
| 17,621 | 60.1875 | 385 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/CacheDependenciesProcessor.java | package org.jboss.as.ejb3.deployment.processors;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.CapabilityServiceConfigurator;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleConfiguration;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.cache.CacheInfo;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance;
import org.jboss.as.ejb3.component.stateful.cache.StatefulSessionBeanCacheProvider;
import org.jboss.as.ejb3.component.stateful.cache.StatefulSessionBeanCacheProviderServiceNameProvider;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.ejb.client.SessionID;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.ChildTargetService;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class CacheDependenciesProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext context) {
DeploymentUnit unit = context.getDeploymentUnit();
final ServiceName name = unit.getServiceName();
EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
return;
}
final CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceTarget target = context.getServiceTarget();
Set<SupplierDependency<StatefulSessionBeanCacheProvider<SessionID, StatefulSessionComponentInstance>>> dependencies = new HashSet<>();
for (ComponentDescription description : moduleDescription.getComponentDescriptions()) {
if (description instanceof StatefulComponentDescription) {
StatefulComponentDescription statefulDescription = (StatefulComponentDescription) description;
dependencies.add(new ServiceSupplierDependency<>(getCacheFactoryBuilderServiceName(statefulDescription)));
}
}
EEModuleConfiguration moduleConfiguration = unit.getAttachment(Attachments.EE_MODULE_CONFIGURATION);
Service service = new ChildTargetService(new Consumer<ServiceTarget>() {
@Override
public void accept(ServiceTarget target) {
// Cache factory builder dependencies might still contain duplicates (if referenced via alias), so ensure we collect only distinct instances.
Set<StatefulSessionBeanCacheProvider<SessionID, StatefulSessionComponentInstance>> providers = new HashSet<>(dependencies.size());
for (Supplier<StatefulSessionBeanCacheProvider<SessionID, StatefulSessionComponentInstance>> dependency : dependencies) {
providers.add(dependency.get());
}
for (StatefulSessionBeanCacheProvider<SessionID, StatefulSessionComponentInstance> provider : providers) {
for (CapabilityServiceConfigurator configurator : provider.getDeploymentServiceConfigurators(unit, moduleConfiguration)) {
configurator.configure(support).build(target).install();
}
}
}
});
ServiceBuilder<?> builder = target.addService(name.append("cache-dependencies-installer"));
for (Dependency dependency : dependencies) {
dependency.register(builder);
}
builder.setInstance(service).install();
}
private static ServiceName getCacheFactoryBuilderServiceName(StatefulComponentDescription description) {
if (!description.isPassivationApplicable()) return StatefulSessionBeanCacheProviderServiceNameProvider.DEFAULT_PASSIVATION_DISABLED_CACHE_SERVICE_NAME;
CacheInfo cache = description.getCache();
return (cache != null) ? new StatefulSessionBeanCacheProviderServiceNameProvider(cache.getName()).getServiceName() : StatefulSessionBeanCacheProviderServiceNameProvider.DEFAULT_CACHE_SERVICE_NAME;
}
}
| 4,749 | 52.977273 | 204 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/DiscoveryRegistrationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.as.ee.structure.Attachments;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.remote.AssociationService;
import org.jboss.as.ejb3.remote.RemotingProfileService;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.ejb.protocol.remote.RemoteEJBDiscoveryConfigurator;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.wildfly.discovery.Discovery;
import org.wildfly.httpclient.ejb.HttpDiscoveryConfigurator;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Processor responsible for ensuring that the discovery service for each deployment unit exists.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class DiscoveryRegistrationProcessor implements DeploymentUnitProcessor {
private final boolean appClient;
public DiscoveryRegistrationProcessor(final boolean appClient) {
this.appClient = appClient;
}
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// we only process top level deployment units
if (deploymentUnit.getParent() != null) {
return;
}
final ServiceName profileServiceName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME);
final ServiceName discoveryServiceName = DiscoveryService.BASE_NAME.append(deploymentUnit.getName());
final ServiceBuilder<?> builder = phaseContext.getServiceTarget().addService(discoveryServiceName);
final Consumer<Discovery> discoveryConsumer = builder.provides(discoveryServiceName);
final Supplier<RemotingProfileService> remotingProfileServiceSupplier = profileServiceName != null ? builder.requires(profileServiceName) : null;
// only add association service dependency if the context is configured to use the local EJB receiver & we are not app client
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
final boolean useLocalReceiver = ejbClientDescriptorMetaData == null || ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE;
final Supplier<AssociationService> associationServiceSupplier = (useLocalReceiver && !appClient) ? builder.requires(AssociationService.SERVICE_NAME) : null;
final DiscoveryService discoveryService = new DiscoveryService(discoveryConsumer, remotingProfileServiceSupplier, associationServiceSupplier);
new RemoteEJBDiscoveryConfigurator().configure(discoveryService.getDiscoveryProviderConsumer(), registryProvider -> {});
new HttpDiscoveryConfigurator().configure(discoveryService.getDiscoveryProviderConsumer(), registryProvider -> {});
builder.setInstance(discoveryService);
builder.install();
}
}
| 4,420 | 54.962025 | 164 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbResourceInjectionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.FieldInjectionTarget;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.InjectionTarget;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.MethodInjectionTarget;
import org.jboss.as.ee.component.ResourceInjectionConfiguration;
import org.jboss.as.ee.structure.EJBAnnotationPropertyReplacement;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.metadata.property.PropertyReplacer;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBs;
import java.util.List;
import java.util.Locale;
/**
* Deployment processor responsible for processing @EJB annotations within components. Each @EJB annotation will be registered
* as an injection binding for the component.
*
* @author John Bailey
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class EjbResourceInjectionAnnotationProcessor implements DeploymentUnitProcessor {
private static final DotName EJB_ANNOTATION_NAME = DotName.createSimple(EJB.class.getName());
private static final DotName EJBS_ANNOTATION_NAME = DotName.createSimple(EJBs.class.getName());
private final boolean appclient;
public EjbResourceInjectionAnnotationProcessor(final boolean appclient) {
this.appclient = appclient;
}
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer);
if (annotationTarget instanceof FieldInfo) {
processField(deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof MethodInfo) {
processMethod(deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof ClassInfo) {
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
}
final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
for (AnnotationInstance annotation : ejbsAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof ClassInfo) {
final AnnotationValue annotationValue = annotation.value();
final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer);
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
} else {
throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
}
}
}
private void processField(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final FieldInfo fieldInfo, final EEModuleDescription eeModuleDescription) {
final String fieldName = fieldInfo.name();
final String fieldType = fieldInfo.type().name().toString();
final InjectionTarget targetDescription = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldType);
final String localContextName = isEmpty(annotation.name()) ? fieldInfo.declaringClass().name().toString() + "/" + fieldInfo.name() : annotation.name();
final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? fieldType : annotation.beanInterface();
process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), fieldInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription);
}
private void processMethod(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final MethodInfo methodInfo, final EEModuleDescription eeModuleDescription) {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
throw EjbLogger.ROOT_LOGGER.onlySetterMethodsAllowedToHaveEJBAnnotation(methodInfo);
}
final String methodParamType = methodInfo.args()[0].name().toString();
final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodParamType);
final String localContextName = isEmpty(annotation.name()) ? methodInfo.declaringClass().name().toString() + "/" + methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4) : annotation.name();
final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? methodParamType : annotation.beanInterface();
process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), methodInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription);
}
private void processClass(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final ClassInfo classInfo, final EEModuleDescription eeModuleDescription) throws DeploymentUnitProcessingException {
if (isEmpty(annotation.name())) {
throw EjbLogger.ROOT_LOGGER.nameAttributeRequiredForEJBAnnotationOnClass(classInfo.toString());
}
if (isEmpty(annotation.beanInterface())) {
throw EjbLogger.ROOT_LOGGER.beanInterfaceAttributeRequiredForEJBAnnotationOnClass(classInfo.toString());
}
process(deploymentUnit, annotation.beanInterface(), annotation.beanName(), annotation.lookup(), classInfo, null, annotation.name(), eeModuleDescription);
}
private void process(final DeploymentUnit deploymentUnit, final String beanInterface, final String beanName, final String lookup, final ClassInfo classInfo, final InjectionTarget targetDescription, final String localContextName, final EEModuleDescription eeModuleDescription) {
if (!isEmpty(lookup) && !isEmpty(beanName)) {
EjbLogger.DEPLOYMENT_LOGGER.debugf("Both beanName = %s and lookup = %s have been specified in @EJB annotation. Lookup will be given preference. Class: %s"
, beanName, lookup, classInfo.name());
}
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final InjectionSource valueSource;
EjbInjectionSource ejbInjectionSource = null;
//give preference to lookup
if (!isEmpty(lookup)) {
if (!lookup.startsWith("java:")) {
valueSource = new EjbLookupInjectionSource(lookup, targetDescription == null ? null : targetDescription.getDeclaredValueClassName());
} else {
valueSource = createLookup(lookup, appclient);
}
} else if (!isEmpty(beanName)) {
valueSource = ejbInjectionSource = new EjbInjectionSource(beanName, beanInterface, localContextName, deploymentUnit, appclient);
} else {
valueSource = ejbInjectionSource = new EjbInjectionSource(beanInterface, localContextName, deploymentUnit, appclient);
}
if (ejbInjectionSource != null) {
deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
}
// our injection comes from the local lookup, no matter what.
final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ?
new ResourceInjectionConfiguration(targetDescription, createLookup(localContextName, appclient)) : null;
// Create the binding from whence our injection comes.
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
if (injectionConfiguration != null) {
classDescription.addResourceInjection(injectionConfiguration);
}
}
private InjectionSource createLookup(final String localContextName, final boolean appclient) {
//appclient lookups are always optional
//as they could reference local interfaces that are not present
return new LookupInjectionSource(localContextName, appclient);
}
private boolean isEmpty(final String string) {
return string == null || string.isEmpty();
}
private class EJBResourceWrapper {
private final String name;
private final String beanInterface;
private final String beanName;
private final String lookup;
private final PropertyReplacer propertyReplacer;
public EJBResourceWrapper(AnnotationInstance annotation, PropertyReplacer propertyReplacer) {
this.propertyReplacer = propertyReplacer;
name = stringValueOrNull(annotation, "name");
beanInterface = classValueOrNull(annotation, "beanInterface");
beanName = stringValueOrNull(annotation, "beanName");
String lookupValue = stringValueOrNull(annotation, "lookup");
// if "lookup" isn't specified, then fallback on "mappedName". We treat "mappedName" the same as "lookup"
if (isEmpty(lookupValue)) {
lookupValue = stringValueOrNull(annotation, "mappedName");
}
this.lookup = lookupValue;
}
private String name() {
return name;
}
private String beanInterface() {
return beanInterface;
}
private String beanName() {
return beanName;
}
private String lookup() {
return lookup;
}
private String stringValueOrNull(final AnnotationInstance annotation, final String attribute) {
final AnnotationValue value = annotation.value(attribute);
return (value != null) ? propertyReplacer.replaceProperties(value.asString()) : null;
}
private String classValueOrNull(final AnnotationInstance annotation, final String attribute) {
final AnnotationValue value = annotation.value(attribute);
return (value != null) ? value.asClass().name().toString() : null;
}
}
}
| 13,247 | 54.430962 | 281 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbSuspendInterceptor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.component.interceptors.InvocationType;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.interceptors.AbstractEJBInterceptor;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.invocation.InterceptorContext;
import org.wildfly.extension.requestcontroller.ControlPoint;
import org.wildfly.extension.requestcontroller.RunResult;
/**
* An interceptor that allows the component to shutdown gracefully.
*
* @author Stuart Douglas
* @author Flavia Rainone
*/
public class EjbSuspendInterceptor extends AbstractEJBInterceptor {
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
InvocationType invocation = context.getPrivateData(InvocationType.class);
if (invocation != InvocationType.REMOTE && invocation != InvocationType.MESSAGE_DELIVERY) {
return context.proceed();
}
// see if control point accepts or rejects this invocation
EJBComponent component = getComponent(context, EJBComponent.class);
ControlPoint entryPoint = component.getControlPoint();
RunResult result = entryPoint.beginRequest();
if (result == RunResult.REJECTED
&& !component.getEjbSuspendHandlerService().acceptInvocation(context)) {
// if control point rejected, check with suspend handler
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return context.proceed();
} finally {
if (result == RunResult.REJECTED)
component.getEjbSuspendHandlerService().invocationComplete();
else
entryPoint.requestComplete();
}
}
}
| 2,804 | 41.5 | 99 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/StartupAwaitInterceptor.java | package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ee.component.deployers.StartupCountdown;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
/**
* Interceptor forcing invocation to wait until passed CountDownLatch value is decreased to 0.
* Is used to suspend external requests to Jakarta Enterprise Beans methods until all startup beans in the deployment are started as per spec.
* @author Fedor Gavrilov
*/
public class StartupAwaitInterceptor implements Interceptor {
private final StartupCountdown countdown;
StartupAwaitInterceptor(final StartupCountdown countdown) {
this.countdown = countdown;
}
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
countdown.await();
return context.proceed();
}
}
| 837 | 32.52 | 142 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/TimerServiceDeploymentProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.DependencyConfigurator;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.component.EJBComponentCreateService;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.subsystem.deployment.TimerServiceResource;
import org.jboss.as.ejb3.timerservice.NonFunctionalTimerServiceFactoryServiceConfigurator;
import org.jboss.as.ejb3.timerservice.TimedObjectInvokerFactoryImpl;
import org.jboss.as.ejb3.timerservice.TimerServiceFactoryServiceConfigurator;
import org.jboss.as.ejb3.timerservice.TimerServiceMetaData;
import org.jboss.as.ejb3.timerservice.TimerServiceRegistryImpl;
import org.jboss.as.ejb3.timerservice.composite.CompositeTimerServiceFactoryServiceConfigurator;
import org.jboss.as.ejb3.timerservice.distributable.DistributableTimerServiceFactoryServiceConfigurator;
import org.jboss.as.ejb3.timerservice.spi.ManagedTimerServiceConfiguration.TimerFilter;
import org.jboss.as.ejb3.timerservice.spi.ManagedTimerServiceFactory;
import org.jboss.as.ejb3.timerservice.spi.ManagedTimerServiceFactoryConfiguration;
import org.jboss.as.ejb3.timerservice.spi.TimedObjectInvokerFactory;
import org.jboss.as.ejb3.timerservice.spi.TimerListener;
import org.jboss.as.ejb3.timerservice.spi.TimerServiceRegistry;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.ejb.timer.TimerManagementProvider;
import org.wildfly.clustering.ejb.timer.TimerServiceConfiguration;
import org.wildfly.clustering.ejb.timer.TimerServiceRequirement;
import org.wildfly.clustering.service.ChildTargetService;
/**
* Deployment processor that sets up the timer service for singletons and stateless session beans
*
* NOTE: References in this document to Enterprise JavaBeans (EJB) refer to the Jakarta Enterprise Beans unless otherwise noted.
*
* @author Stuart Douglas
*/
public class TimerServiceDeploymentProcessor implements DeploymentUnitProcessor {
private final String threadPoolName;
private final TimerServiceMetaData defaultMetaData;
public TimerServiceDeploymentProcessor(final String threadPoolName, final TimerServiceMetaData defaultMetaData) {
this.threadPoolName = threadPoolName;
this.defaultMetaData = defaultMetaData;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) return;
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
// support for using capabilities to resolve service names
CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
// if this is an EJB deployment then create an EJB module level TimerServiceRegistry which can be used by the timer services
// of all EJB components that belong to this EJB module.
final TimerServiceRegistry timerServiceRegistry = new TimerServiceRegistryImpl();
Map<String, TimerServiceMetaData> timerServiceMetaData = new HashMap<>();
timerServiceMetaData.put(null, this.defaultMetaData);
// determine the per-EJB timer persistence service names required
if (ejbJarMetaData != null && ejbJarMetaData.getAssemblyDescriptor() != null) {
List<TimerServiceMetaData> timerService = ejbJarMetaData.getAssemblyDescriptor().getAny(TimerServiceMetaData.class);
if (timerService != null) {
for (TimerServiceMetaData metaData : timerService) {
if ((metaData.getDataStoreName() == null) && (metaData.getPersistentTimerManagementProvider() == null)) {
metaData.setDataStoreName(this.defaultMetaData.getDataStoreName());
metaData.setPersistentTimerManagementProvider(this.defaultMetaData.getPersistentTimerManagementProvider());
}
if (metaData.getTransientTimerManagementProvider() == null) {
metaData.setTransientTimerManagementProvider(this.defaultMetaData.getTransientTimerManagementProvider());
}
String name = metaData.getEjbName().equals("*") ? null : metaData.getEjbName();
timerServiceMetaData.put(name, metaData);
}
}
}
String threadPoolName = this.threadPoolName;
TimerServiceMetaData defaultMetaData = timerServiceMetaData.get(null);
StringBuilder deploymentNameBuilder = new StringBuilder();
deploymentNameBuilder.append(moduleDescription.getApplicationName()).append('.').append(moduleDescription.getModuleName());
String distinctName = moduleDescription.getDistinctName();
if ((distinctName != null) && !distinctName.isEmpty()) {
deploymentNameBuilder.append('.').append(distinctName);
}
String deploymentName = deploymentNameBuilder.toString();
TimedObjectInvokerFactory invokerFactory = new TimedObjectInvokerFactoryImpl(module, deploymentName);
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
// Install per-EJB timer service factories
if (componentDescription.isTimerServiceApplicable()) {
ServiceName serviceName = componentDescription.getServiceName().append("timer-service-factory");
componentDescription.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
ROOT_LOGGER.debugf("Installing timer service factory for component %s", componentDescription.getComponentName());
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
ServiceTarget target = context.getServiceTarget();
TimerServiceResource resource = new TimerServiceResource();
ManagedTimerServiceFactoryConfiguration factoryConfiguration = new ManagedTimerServiceFactoryConfiguration() {
@Override
public TimerServiceRegistry getTimerServiceRegistry() {
return timerServiceRegistry;
}
@Override
public TimerListener getTimerListener() {
return resource;
}
@Override
public TimedObjectInvokerFactory getInvokerFactory() {
return invokerFactory;
}
};
if (componentDescription.isTimerServiceRequired()) {
// the component has timeout methods, it needs a 'real' timer service
// Only register the TimerService resource if the component requires a TimerService.
ejbComponentDescription.setTimerServiceResource(resource);
TimerServiceMetaData componentMetaData = timerServiceMetaData.getOrDefault(ejbComponentDescription.getEJBName(), defaultMetaData);
if ((threadPoolName != null) && (componentMetaData.getDataStoreName() != null)) {
// Install in-memory timer service factory w/persistence support
new TimerServiceFactoryServiceConfigurator(serviceName, factoryConfiguration, threadPoolName, componentMetaData.getDataStoreName()).configure(capabilityServiceSupport).build(target).install();
} else {
// Use composite timer service, with separate transient vs persistent implementations.
ServiceName transientServiceName = TimerFilter.TRANSIENT.apply(serviceName);
ServiceName persistentServiceName = TimerFilter.PERSISTENT.apply(serviceName);
if (componentMetaData.getTransientTimerManagementProvider() != null) {
installDistributableTimerServiceFactory(phaseContext, transientServiceName, componentMetaData.getTransientTimerManagementProvider(), factoryConfiguration, componentDescription, TimerFilter.TRANSIENT);
} else {
// Install in-memory timer service factory w/out persistence support
new TimerServiceFactoryServiceConfigurator(transientServiceName, factoryConfiguration, threadPoolName, null).filter(TimerFilter.TRANSIENT).configure(capabilityServiceSupport).build(target).install();
}
installDistributableTimerServiceFactory(phaseContext, persistentServiceName, componentMetaData.getPersistentTimerManagementProvider(), factoryConfiguration, componentDescription, TimerFilter.PERSISTENT);
new CompositeTimerServiceFactoryServiceConfigurator(serviceName, factoryConfiguration).build(target).install();
}
} else {
// the EJB is of a type that could have a timer service, but has no timer methods. just bind the non-functional timer service
String message = ejbComponentDescription.isStateful() ? EjbLogger.ROOT_LOGGER.timerServiceMethodNotAllowedForSFSB(ejbComponentDescription.getComponentName()) : EjbLogger.ROOT_LOGGER.ejbHasNoTimerMethods();
new NonFunctionalTimerServiceFactoryServiceConfigurator(serviceName, message, factoryConfiguration).build(target).install();
}
configuration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {
@Override
public void configureDependency(ServiceBuilder<?> builder, EJBComponentCreateService service) {
builder.addDependency(serviceName, ManagedTimerServiceFactory.class, service.getTimerServiceFactoryInjector());
}
});
}
});
}
}
}
static void installDistributableTimerServiceFactory(DeploymentPhaseContext context, ServiceName name, String providerName, ManagedTimerServiceFactoryConfiguration factoryConfiguration, ComponentDescription description, TimerFilter filter) {
DeploymentUnit unit = context.getDeploymentUnit();
List<String> parts = new ArrayList<>(3);
if (unit.getParent() != null) {
parts.add(unit.getParent().getName());
}
parts.add(unit.getName());
parts.add(description.getComponentName());
parts.add(filter.name());
String timerServiceName = String.join(".", parts);
TimerServiceConfiguration configuration = new TimerServiceConfiguration() {
@Override
public String getName() {
return timerServiceName;
}
@Override
public String getDeploymentName() {
return unit.getName();
}
@Override
public ServiceName getDeploymentServiceName() {
return unit.getServiceName();
}
@Override
public Module getModule() {
return unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
}
};
CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
ServiceName providerServiceName = TimerServiceRequirement.TIMER_MANAGEMENT_PROVIDER.getServiceName(support, providerName);
ServiceBuilder<?> builder = context.getServiceTarget().addService(name.append("installer"));
Supplier<TimerManagementProvider> dependency = builder.requires(providerServiceName);
builder.setInstance(new ChildTargetService(new Consumer<ServiceTarget>() {
@Override
public void accept(ServiceTarget target) {
TimerManagementProvider provider = dependency.get();
new DistributableTimerServiceFactoryServiceConfigurator(name, factoryConfiguration, configuration, provider, filter).configure(support).build(target).install();
}
})).install();
}
}
| 15,332 | 57.30038 | 244 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/ViewInterfaces.java | /*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import java.io.Externalizable;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
class ViewInterfaces {
/**
* Returns all interfaces implemented by a bean that are eligible to be view interfaces
*
* @param beanClass The bean class
* @return A collection of all potential view interfaces
*/
static Set<Class<?>> getPotentialViewInterfaces(Class<?> beanClass) {
Class<?>[] interfaces = beanClass.getInterfaces();
if (interfaces.length == 0) {
return Collections.emptySet();
}
final Set<Class<?>> potentialBusinessInterfaces = new HashSet<>();
for (Class<?> klass : interfaces) {
// Enterprise Beans 3.1 FR 4.9.7 bullet 5.3
if (klass.equals(Serializable.class) ||
klass.equals(Externalizable.class) ||
klass.getName().startsWith("jakarta.ejb.") ||
klass.getName().startsWith("groovy.lang.")) {
continue;
}
potentialBusinessInterfaces.add(klass);
}
return potentialBusinessInterfaces;
}
/**
* Returns all interfaces implemented by a bean that are eligible to be view interfaces
*
* @param beanClass The bean class
* @return A collection of all potential view interfaces
*/
static Set<DotName> getPotentialViewInterfaces(ClassInfo beanClass) {
List<DotName> interfaces = beanClass.interfaceNames();
if (interfaces.isEmpty()) {
return Collections.emptySet();
}
final Set<DotName> names = new HashSet<>();
for (DotName dotName : interfaces) {
String name = dotName.toString();
// Enterprise Beans 3.1 FR 4.9.7 bullet 5.3
// & FR 5.4.2
if (name.equals(Serializable.class.getName()) ||
name.equals(Externalizable.class.getName()) ||
name.startsWith("jakarta.ejb.") ||
name.startsWith("groovy.lang.")) {
continue;
}
names.add(dotName);
}
return names;
}
}
| 3,429 | 37.111111 | 91 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbJarJBossAllParser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.jboss.as.ee.structure.JBossDescriptorPropertyReplacement;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.jbossallxml.JBossAllXMLParser;
import org.jboss.metadata.ejb.parser.jboss.ejb3.JBossEjb3MetaDataParser;
import org.jboss.metadata.ejb.parser.spec.AbstractMetaDataParser;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EjbJarVersion;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* The app client handler for jboss-all.xml
*
* @author Stuart Douglas
*/
public class EjbJarJBossAllParser implements JBossAllXMLParser<EjbJarMetaData> {
public static final AttachmentKey<EjbJarMetaData> ATTACHMENT_KEY = AttachmentKey.create(EjbJarMetaData.class);
public static final QName ROOT_ELEMENT = new QName("http://www.jboss.com/xml/ns/javaee", "ejb-jar");
@Override
public EjbJarMetaData parse(final XMLExtendedStreamReader reader, final DeploymentUnit deploymentUnit) throws XMLStreamException {
return new EjbJarParser(EjbJarParsingDeploymentUnitProcessor.createJbossEjbJarParsers()).parse(reader, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
}
//TODO: move this to JBMETA
private static final class EjbJarParser extends JBossEjb3MetaDataParser {
public EjbJarParser(Map<String, AbstractMetaDataParser<?>> parsers) {
super(parsers);
}
@Override
public EjbJarMetaData parse(final XMLStreamReader reader, final PropertyReplacer propertyReplacer) throws XMLStreamException {
final EjbJarMetaData metaData = new EjbJarMetaData(EjbJarVersion.EJB_3_1);
processAttributes(metaData, reader);
processElements(metaData, reader, propertyReplacer);
return metaData;
}
}
}
| 3,161 | 41.16 | 180 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbLookupInjectionSource.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
/**
* Injection source for remote Jakarta Enterprise Beans lookups. If the target type is known
* then the bean will be narrowed to that type
*
* @author Stuart Douglas
*/
public class EjbLookupInjectionSource extends InjectionSource {
private final String lookup;
private final String targetTypeName;
private final Class<?> targetType;
public EjbLookupInjectionSource(final String lookup, final String targetType) {
this.lookup = lookup;
this.targetTypeName = targetType;
this.targetType = null;
}
public EjbLookupInjectionSource(final String lookup, final Class<?> targetType) {
this.lookup = lookup;
this.targetType = targetType;
this.targetTypeName = null;
}
@Override
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final Class<?> type;
if (targetType != null) {
type = targetType;
} else if (targetTypeName != null) {
try {
type = ClassLoadingUtils.loadClass(targetTypeName, phaseContext.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
type = null;
}
injector.inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
final Object value = new InitialContext().lookup(lookup);
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
if(type != null && value instanceof org.omg.CORBA.Object) {
return PortableRemoteObject.narrow(value, type);
} else {
return value;
}
}
};
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
});
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final EjbLookupInjectionSource that = (EjbLookupInjectionSource) o;
if (lookup != null ? !lookup.equals(that.lookup) : that.lookup != null) return false;
return true;
}
@Override
public int hashCode() {
return lookup != null ? lookup.hashCode() : 0;
}
}
| 4,458 | 35.54918 | 251 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/MdbDeliveryDependenciesProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleConfiguration;
import org.jboss.as.ejb3.clustering.SingletonBarrierService;
import org.jboss.as.ejb3.component.messagedriven.MdbDeliveryControllerService;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponent;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_CONFIGURATION;
import static org.jboss.as.ejb3.subsystem.EJB3SubsystemRootResourceDefinition.CLUSTERED_SINGLETON_CAPABILITY;
import static org.jboss.as.ejb3.subsystem.MdbDeliveryGroupResourceDefinition.MDB_DELIVERY_GROUP_CAPABILITY_NAME;
/**
* MdbDeliveryDependencies DUP, creates an MdbDeliveryControllerService to enable/disable delivery according to that MDBs
* delivery group configuration, and according to whether the Mdb is clustered singleton or not.
*
* @author Flavia Rainone
*/
public class MdbDeliveryDependenciesProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleConfiguration moduleConfiguration = deploymentUnit.getAttachment(EE_MODULE_CONFIGURATION);
if (moduleConfiguration == null) {
return;
}
// support for using capabilities to resolve service names
CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
boolean clusteredSingletonFound = false;
for (final ComponentConfiguration configuration : moduleConfiguration.getComponentConfigurations()) {
ComponentDescription description = configuration.getComponentDescription();
if (description instanceof MessageDrivenComponentDescription) {
final MessageDrivenComponentDescription mdbDescription = (MessageDrivenComponentDescription) description;
if (mdbDescription.isDeliveryControlled()) {
final MdbDeliveryControllerService mdbDeliveryControllerService = new MdbDeliveryControllerService();
final ServiceBuilder<MdbDeliveryControllerService> builder = serviceTarget.addService(mdbDescription.getDeliveryControllerName(), mdbDeliveryControllerService)
.addDependency(description.getCreateServiceName(), MessageDrivenComponent.class, mdbDeliveryControllerService.getMdbComponent())
.setInitialMode(Mode.PASSIVE);
if (mdbDescription.isClusteredSingleton()) {
clusteredSingletonFound = true;
builder.requires(CLUSTERED_SINGLETON_CAPABILITY.getCapabilityServiceName());
}
if (mdbDescription.getDeliveryGroups() != null) {
for (String deliveryGroup : mdbDescription.getDeliveryGroups()) {
final ServiceName deliveryGroupServiceName = capabilityServiceSupport.getCapabilityServiceName(MDB_DELIVERY_GROUP_CAPABILITY_NAME, deliveryGroup);
if (phaseContext.getServiceRegistry().getService(deliveryGroupServiceName) == null) {
throw EjbLogger.DEPLOYMENT_LOGGER.missingMdbDeliveryGroup(deliveryGroup);
}
builder.requires(deliveryGroupServiceName);
}
}
builder.install();
}
}
}
if (clusteredSingletonFound) {
// Add dependency on the singleton barrier, which starts on-demand
// (the MDB delivery controller won't demand the singleton barrier service to start)
serviceTarget.addDependency(SingletonBarrierService.SERVICE_NAME);
}
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
final EEModuleConfiguration moduleConfiguration = deploymentUnit.getAttachment(EE_MODULE_CONFIGURATION);
if (moduleConfiguration == null) {
return;
}
final ServiceRegistry serviceRegistry = deploymentUnit.getServiceRegistry();
boolean clusteredSingletonFound = false;
for (final ComponentConfiguration configuration : moduleConfiguration.getComponentConfigurations()) {
final ComponentDescription description = configuration.getComponentDescription();
if (description instanceof MessageDrivenComponentDescription) {
MessageDrivenComponentDescription mdbDescription = (MessageDrivenComponentDescription) description;
clusteredSingletonFound = clusteredSingletonFound || mdbDescription.isClusteredSingleton();
if (mdbDescription.isDeliveryControlled()) {
serviceRegistry.getRequiredService(mdbDescription.getDeliveryControllerName()).setMode(Mode.REMOVE);
}
}
}
}
}
| 6,958 | 56.040984 | 179 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbCleanUpProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* @author Stuart Douglas
*/
public class EjbCleanUpProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
deploymentUnit.removeAttachment(EjbDeploymentAttachmentKeys.EJB_INJECTIONS);
deploymentUnit.removeAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DETAILS);
deploymentUnit.removeAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION);
deploymentUnit.removeAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
}
}
| 2,061 | 46.953488 | 108 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbDependencyDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.server.deployment.EjbDeploymentMarker.isEjbDeployment;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleDependency;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoader;
import org.wildfly.iiop.openjdk.deployment.IIOPDeploymentMarker;
/**
* Responsible for adding appropriate Jakarta EE {@link org.jboss.as.server.deployment.module.ModuleDependency module dependencies}
* <p/>
* Author : Jaikiran Pai
*/
public class EjbDependencyDeploymentUnitProcessor implements DeploymentUnitProcessor {
/**
* Needed for timer handle persistence
* TODO: restrict visibility
*/
private static final String EJB_SUBSYSTEM = "org.jboss.as.ejb3";
private static final String EJB_CLIENT = "org.jboss.ejb-client";
private static final String EJB_NAMING_CLIENT = "org.wildfly.naming-client";
private static final String EJB_IIOP_CLIENT = "org.jboss.iiop-client";
private static final String IIOP_OPENJDK = "org.wildfly.iiop-openjdk";
private static final String EJB_API = "jakarta.ejb.api";
private static final String HTTP_EJB = "org.wildfly.http-client.ejb";
private static final String HTTP_TRANSACTION = "org.wildfly.http-client.transaction";
private static final String HTTP_NAMING = "org.wildfly.http-client.naming";
private static final String CLUSTERING_EJB_CLIENT = "org.wildfly.clustering.ejb.client";
/**
* Adds Jakarta EE module as a dependency to any deployment unit which is an Jakarta Enterprise Beans deployment
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*
*/
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
// get hold of the deployment unit
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleLoader moduleLoader = Module.getBootModuleLoader();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
//always add EE API
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_API, false, false, true, false));
//we always give them the Jakarta Enterprise Beans client
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_CLIENT, false, false, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_NAMING_CLIENT, false, false, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_IIOP_CLIENT, false, false, false, false));
//we always have to add this, as even non-ejb deployments may still lookup IIOP ejb's
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_SUBSYSTEM, false, false, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, HTTP_EJB, false, false, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, HTTP_NAMING, false, false, true, false));
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, HTTP_TRANSACTION, false, false, true, false));
// Marshalling support for EJB SessionIDs
// TODO Move this to distributable-ejb subsystem
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, CLUSTERING_EJB_CLIENT, false, false, true, false));
if (IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
//needed for dynamic IIOP stubs
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, IIOP_OPENJDK, false, false, false, false));
}
// fetch the EjbJarMetaData
//TODO: remove the app client bit after the next Jakarta Enterprise Beans release
if (!isEjbDeployment(deploymentUnit) && !DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
// nothing to do
return;
}
// FIXME: still not the best way to do it
//this must be the first dep listed in the module
if (Boolean.getBoolean("org.jboss.as.ejb3.EMBEDDED"))
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, "Classpath", false, false, false, false));
}
}
| 5,961 | 50.843478 | 134 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/StartupAwaitDeploymentUnitProcessor.java | package org.jboss.as.ejb3.deployment.processors;
import java.util.EnumSet;
import java.util.Set;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.ViewConfiguration;
import org.jboss.as.ee.component.deployers.StartupCountdown;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewConfiguration;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
/**
* Adds StartupAwaitInterceptor to exposed methods of Jakarta Enterprise Beans, forcing users to wait until all startup beans in the deployment are done with post-construct methods.
* @author Fedor Gavrilov
*/
// adding an abstraction for the whole deployment unit to depend on while blocking external client calls is a better solution probably
// it requires a lot of rewriting in Jakarta Enterprise Beans code right now, hence this class to satisfy Enterprise Beans 3.1 spec, section 4.8.1
// feel free to remove this class as well as StartupAwaitInterceptor and StartupCountDownInterceptor when if easier way to satisfy spec will appear
public class StartupAwaitDeploymentUnitProcessor implements DeploymentUnitProcessor {
private static final Set<MethodInterfaceType> INTFS = EnumSet.of(MethodInterfaceType.MessageEndpoint, MethodInterfaceType.Remote, MethodInterfaceType.ServiceEndpoint, MethodInterfaceType.Local);
@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component instanceof EJBComponentDescription) {
component.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
for (ViewConfiguration view : configuration.getViews()) {
EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
if (INTFS.contains(ejbView.getMethodIntf())) {
ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
}
}
}
});
}
}
}
}
| 3,195 | 57.109091 | 196 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/SessionBeanHomeProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import jakarta.ejb.EJBHome;
import jakarta.ejb.Handle;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentStartService;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ee.component.DependencyConfigurator;
import org.jboss.as.ee.component.ViewConfiguration;
import org.jboss.as.ee.component.ViewConfigurator;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.ViewService;
import org.jboss.as.ee.component.deployers.AbstractComponentConfigProcessor;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptor;
import org.jboss.as.ejb3.component.interceptors.HomeRemoveInterceptor;
import org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory;
import org.jboss.as.ejb3.component.session.InvalidRemoveExceptionMethodInterceptor;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.component.stateless.StatelessComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.msc.service.ServiceBuilder;
/**
* Processor that hooks up home interfaces for session beans
*
* @author Stuart Douglas
*/
public class SessionBeanHomeProcessor extends AbstractComponentConfigProcessor {
@Override
protected void processComponentConfig(final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext, final CompositeIndex index, final ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
if (componentDescription instanceof SessionBeanComponentDescription) {
final SessionBeanComponentDescription ejbComponentDescription = (SessionBeanComponentDescription) componentDescription;
//check for EJB's with a local home interface
if (ejbComponentDescription.getEjbLocalHomeView() != null) {
final EJBViewDescription view = ejbComponentDescription.getEjbLocalHomeView();
final EJBViewDescription ejbLocalView = ejbComponentDescription.getEjbLocalView();
configureHome(componentDescription, ejbComponentDescription, view, ejbLocalView);
}
if (ejbComponentDescription.getEjbHomeView() != null) {
final EJBViewDescription view = ejbComponentDescription.getEjbHomeView();
final EJBViewDescription ejbRemoteView = ejbComponentDescription.getEjbRemoteView();
configureHome(componentDescription, ejbComponentDescription, view, ejbRemoteView);
}
}
}
private void configureHome(final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
homeView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
//loop over methods looking for create methods:
for (Method method : configuration.getProxyFactory().getCachedMethods()) {
if (method.getName().startsWith("create")) {
//we have a create method
if (ejbObjectView == null) {
throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
}
Method initMethod;
if (ejbComponentDescription instanceof StatelessComponentDescription) {
initMethod = null;
} else if (ejbComponentDescription instanceof StatefulComponentDescription) {
initMethod = resolveStatefulInitMethod((StatefulComponentDescription) ejbComponentDescription, method);
if (initMethod == null) {
continue;
}
} else {
throw EjbLogger.ROOT_LOGGER.localHomeNotAllow(ejbComponentDescription);
}
final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
//add a dependency on the view to create
configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("getEJBMetaData") && method.getParameterCount() == 0 && ((EJBViewDescription)description).getMethodIntf() == MethodInterfaceType.Home) {
final Class<?> ejbObjectClass;
try {
ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
}
final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
//add a dependency on the view to create
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("remove") && method.getParameterCount() == 1 && method.getParameterTypes()[0] == Object.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
} else if (method.getName().equals("remove") && method.getParameterCount() == 1 && method.getParameterTypes()[0] == Handle.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
}
}
}
});
}
private Method resolveStatefulInitMethod(final StatefulComponentDescription description, final Method method) throws DeploymentUnitProcessingException {
//for a SFSB we need to resolve the corresponding init method for this create method
Method initMethod = null;
//first we try and resolve methods that have additiona resolution data associated with them
for (Map.Entry<Method, String> entry : description.getInitMethods().entrySet()) {
String name = entry.getValue();
Method init = entry.getKey();
if (name != null
&& Arrays.equals(init.getParameterTypes(), method.getParameterTypes())
&& init.getName().equals(name)) {
initMethod = init;
}
}
//now try and resolve the init methods with no additional resolution data
if (initMethod == null) {
for (Map.Entry<Method, String> entry : description.getInitMethods().entrySet()) {
Method init = entry.getKey();
if (entry.getValue() == null
&& Arrays.equals(init.getParameterTypes(), method.getParameterTypes())) {
initMethod = init;
break;
}
}
}
if (initMethod == null) {
for (Class<?> exceptionClass : method.getExceptionTypes()) {
if (jakarta.ejb.CreateException.class == exceptionClass) {
throw EjbLogger.ROOT_LOGGER.failToCallEjbCreateForHomeInterface(method, description.getEJBClassName());
}
}
}
return initMethod;
}
}
| 12,092 | 58.866337 | 241 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/MessageDrivenComponentDescriptionFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription;
import static org.jboss.as.ejb3.deployment.processors.ViewInterfaces.getPotentialViewInterfaces;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import jakarta.ejb.MessageDriven;
import jakarta.jms.MessageListener;
import org.jboss.as.ee.component.DeploymentDescriptorEnvironment;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ee.structure.EJBAnnotationPropertyReplacement;
import org.jboss.as.ejb3.component.messagedriven.DefaultResourceAdapterService;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.util.EjbValidationsUtil;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.metadata.ejb.spec.ActivationConfigMetaData;
import org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData;
import org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
/**
* User: jpai
*/
public class MessageDrivenComponentDescriptionFactory extends EJBComponentDescriptionFactory {
private static final DotName MESSAGE_DRIVEN_ANNOTATION_NAME = DotName.createSimple(MessageDriven.class.getName());
private final boolean defaultMdbPoolAvailable;
public MessageDrivenComponentDescriptionFactory(final boolean appclient, final boolean defaultMdbPoolAvailable) {
super(appclient);
this.defaultMdbPoolAvailable = defaultMdbPoolAvailable;
}
@Override
protected void processAnnotations(DeploymentUnit deploymentUnit, CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
return;
}
processMessageBeans(deploymentUnit, compositeIndex.getAnnotations(MESSAGE_DRIVEN_ANNOTATION_NAME), compositeIndex);
}
@Override
protected void processBeanMetaData(final DeploymentUnit deploymentUnit, final EnterpriseBeanMetaData enterpriseBeanMetaData) throws DeploymentUnitProcessingException {
if (enterpriseBeanMetaData.isMessageDriven()) {
assert enterpriseBeanMetaData instanceof MessageDrivenBeanMetaData : enterpriseBeanMetaData + " is not a MessageDrivenBeanMetaData";
processMessageDrivenBeanMetaData(deploymentUnit, (MessageDrivenBeanMetaData) enterpriseBeanMetaData);
}
}
private void processMessageBeans(final DeploymentUnit deploymentUnit, final Collection<AnnotationInstance> messageBeanAnnotations, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
if (messageBeanAnnotations.isEmpty())
return;
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
DeploymentDescriptorEnvironment deploymentDescriptorEnvironment = null;
for (final AnnotationInstance messageBeanAnnotation : messageBeanAnnotations) {
final AnnotationTarget target = messageBeanAnnotation.target();
final ClassInfo beanClassInfo = (ClassInfo) target;
if (! EjbValidationsUtil.assertEjbClassValidity(beanClassInfo).isEmpty() ) {
continue;
}
final String ejbName = beanClassInfo.name().local();
final AnnotationValue nameValue = messageBeanAnnotation.value("name");
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class);
final String beanClassName;
final String messageListenerInterfaceName;
final Properties activationConfigProperties = getActivationConfigProperties(messageBeanAnnotation, propertyReplacer);
final String messagingType;
if (beanMetaData != null) {
beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass());
deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData);
messagingType = beanMetaData.getMessagingType();
final ActivationConfigMetaData activationConfigMetaData = beanMetaData.getActivationConfig();
if (activationConfigMetaData != null) {
final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData
.getActivationConfigProperties();
if (propertiesMetaData != null) {
for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) {
activationConfigProperties.put(propertyMetaData.getKey(), propertyMetaData.getValue());
}
}
}
messageListenerInterfaceName = messagingType != null ? messagingType : getMessageListenerInterface(compositeIndex, messageBeanAnnotation, deploymentUnit);
} else {
beanClassName = beanClassInfo.name().toString();
messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation, deploymentUnit);
}
final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry());
final MessageDrivenComponentDescription beanDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, messageListenerInterfaceName, activationConfigProperties, defaultResourceAdapterName, beanMetaData, defaultMdbPoolAvailable);
beanDescription.setDeploymentDescriptorEnvironment(deploymentDescriptorEnvironment);
addComponent(deploymentUnit, beanDescription);
final AnnotationValue mappedNameValue = messageBeanAnnotation.value("mappedName");
if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "",
ejbName);
}
}
EjbDeploymentMarker.mark(deploymentUnit);
}
private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface");
if (value != null)
return value.asClass().name().toString();
final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target();
final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass));
// check super class(es) of the bean
DotName superClassDotName = beanClass.superName();
while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) {
ClassInfo superClass = compositeIndex.getClassByName(superClassDotName);
if (superClass == null) {
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
final CompositeIndex parentIndex = parent.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (parentIndex != null) {
superClass = parentIndex.getClassByName(superClassDotName);
}
}
}
if (superClass == null) {
break;
}
interfaces.addAll(getPotentialViewInterfaces(superClass));
// move to next super class
superClassDotName = superClass.superName();
}
if (interfaces.size() != 1)
throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
return interfaces.iterator().next().toString();
}
private Properties getActivationConfigProperties(final ActivationConfigMetaData activationConfig) {
final Properties activationConfigProps = new Properties();
if (activationConfig == null || activationConfig.getActivationConfigProperties() == null) {
return activationConfigProps;
}
final ActivationConfigPropertiesMetaData activationConfigPropertiesMetaData = activationConfig.getActivationConfigProperties();
for (ActivationConfigPropertyMetaData activationConfigProp : activationConfigPropertiesMetaData) {
if (activationConfigProp == null) {
continue;
}
final String propName = activationConfigProp.getActivationConfigPropertyName();
final String propValue = activationConfigProp.getValue();
if (propName != null) {
activationConfigProps.put(propName, propValue);
}
}
return activationConfigProps;
}
private void processMessageDrivenBeanMetaData(final DeploymentUnit deploymentUnit, final MessageDrivenBeanMetaData mdb) throws DeploymentUnitProcessingException {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final String beanName = mdb.getName();
final String beanClassName = mdb.getEjbClass();
String messageListenerInterface = mdb.getMessagingType();
if (messageListenerInterface == null || messageListenerInterface.trim().isEmpty()) {
// TODO: This isn't really correct to default to MessageListener
messageListenerInterface = MessageListener.class.getName();
}
final Properties activationConfigProps = getActivationConfigProperties(mdb.getActivationConfig());
final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry());
final MessageDrivenComponentDescription mdbComponentDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, messageListenerInterface, activationConfigProps, defaultResourceAdapterName, mdb, defaultMdbPoolAvailable);
mdbComponentDescription.setDeploymentDescriptorEnvironment(new DeploymentDescriptorEnvironment("java:comp/env/", mdb));
addComponent(deploymentUnit, mdbComponentDescription);
}
private Properties getActivationConfigProperties(final AnnotationInstance messageBeanAnnotation, PropertyReplacer propertyReplacer) {
final Properties props = new Properties();
final AnnotationValue activationConfig = messageBeanAnnotation.value("activationConfig");
if (activationConfig == null)
return props;
for (final AnnotationInstance propAnnotation : activationConfig.asNestedArray()) {
String propertyName = propAnnotation.value("propertyName").asString();
String propertyValue = propAnnotation.value("propertyValue").asString();
props.put(propertyReplacer.replaceProperties(propertyName), propertyReplacer.replaceProperties(propertyValue));
}
return props;
}
/**
* Returns the name of the resource adapter which will be used as the default RA for MDBs (unless overridden by
* the MDBs).
*
* @param serviceRegistry
* @return
*/
private String getDefaultResourceAdapterName(final ServiceRegistry serviceRegistry) {
if (appclient) {
// we must report the MDB, but we can't use any MDB/Jakarta Connectors facilities
return "n/a";
}
final ServiceController<DefaultResourceAdapterService> serviceController = (ServiceController<DefaultResourceAdapterService>) serviceRegistry.getRequiredService(DefaultResourceAdapterService.DEFAULT_RA_NAME_SERVICE_NAME);
return serviceController.getValue().getDefaultResourceAdapterName();
}
}
| 14,240 | 56.192771 | 293 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbRefProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.util.ArrayList;
import java.util.List;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.DeploymentDescriptorEnvironment;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.ResourceInjectionTarget;
import org.jboss.as.ee.component.deployers.AbstractDeploymentDescriptorBindingsProcessor;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData;
import org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData;
import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
import org.jboss.metadata.javaee.spec.EJBReferencesMetaData;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
/**
* Deployment processor responsible for processing Jakarta Enterprise Beans references from deployment descriptors
*
* @author Stuart Douglas
*/
public class EjbRefProcessor extends AbstractDeploymentDescriptorBindingsProcessor {
private final boolean appclient;
public EjbRefProcessor(boolean appclient) {
this.appclient = appclient;
}
/**
* Resolves ejb-ref and ejb-local-ref elements
*
*
* @param deploymentUnit
* @param environment The environment to resolve the elements for
* @param componentDescription
*@param classLoader The deployment class loader
* @param deploymentReflectionIndex The reflection index
* @param applicationClasses @return The bindings for the environment entries
*/
protected List<BindingConfiguration> processDescriptorEntries(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
List<BindingConfiguration> bindingDescriptions = new ArrayList<BindingConfiguration>();
EJBReferencesMetaData ejbRefs = remoteEnvironment.getEjbReferences();
if (ejbRefs != null) {
for (EJBReferenceMetaData ejbRef : ejbRefs) {
String name = ejbRef.getEjbRefName();
String ejbName = ejbRef.getLink();
String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
String remoteInterface = ejbRef.getRemote();
String home = ejbRef.getHome();
Class<?> remoteInterfaceType = null;
//if a home is specified this is the type that is bound
if (!isEmpty(home)) {
try {
remoteInterfaceType = ClassLoadingUtils.loadClass(home, deploymentUnit);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, home);
}
} else if (!isEmpty(remoteInterface)) {
try {
remoteInterfaceType = ClassLoadingUtils.loadClass(remoteInterface, deploymentUnit);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, remoteInterface);
}
}
if (!name.startsWith("java:")) {
name = environment.getDefaultContext() + name;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
//add any injection targets
remoteInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, remoteInterfaceType);
final BindingConfiguration bindingConfiguration;
EjbInjectionSource ejbInjectionSource = null;
if (!isEmpty(lookup)) {
if (!lookup.startsWith("java:")) {
bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, remoteInterfaceType));
} else {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
}
} else {
if (remoteInterfaceType == null) {
throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbRefForInjectionTarget(name, resourceInjectionTarget);
}
if (!isEmpty(ejbName)) {
bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, remoteInterfaceType.getName(), name, deploymentUnit, appclient));
} else {
bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(remoteInterfaceType.getName(), name, deploymentUnit, appclient));
}
}
if (ejbInjectionSource != null) {
deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
}
bindingDescriptions.add(bindingConfiguration);
}
}
if (remoteEnvironment instanceof Environment && !appclient) {
EJBLocalReferencesMetaData ejbLocalRefs = ((Environment) remoteEnvironment).getEjbLocalReferences();
if (ejbLocalRefs != null) {
for (EJBLocalReferenceMetaData ejbRef : ejbLocalRefs) {
String name = ejbRef.getEjbRefName();
String ejbName = ejbRef.getLink();
String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
String localInterface = ejbRef.getLocal();
String localHome = ejbRef.getLocalHome();
Class<?> localInterfaceType = null;
//if a home is specified this is the type that is bound
if (!isEmpty(localHome)) {
try {
localInterfaceType = ClassLoadingUtils.loadClass(localHome, deploymentUnit);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localHome);
}
} else if (!isEmpty(localInterface)) {
try {
localInterfaceType = ClassLoadingUtils.loadClass(localInterface, deploymentUnit);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localInterface);
}
}
if (!name.startsWith("java:")) {
name = environment.getDefaultContext() + name;
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
LookupInjectionSource injectionSource = new LookupInjectionSource(name);
//add any injection targets
localInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, localInterfaceType);
if (localInterfaceType == null) {
throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbLocalRefForInjectionTarget(name, resourceInjectionTarget);
}
final BindingConfiguration bindingConfiguration;
EjbInjectionSource ejbInjectionSource = null;
if (!isEmpty(lookup)) {
if (!lookup.startsWith("java:")) {
bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, localInterfaceType));
} else {
bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
}
} else if (!isEmpty(ejbName)) {
bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, localInterfaceType.getName(), name, deploymentUnit, appclient));
} else {
bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(localInterfaceType.getName(), name, deploymentUnit, appclient));
}
if (ejbInjectionSource != null) {
deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
}
bindingDescriptions.add(bindingConfiguration);
}
}
}
return bindingDescriptions;
}
private boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
}
| 10,894 | 51.63285 | 407 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbDefaultDistinctNameProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ejb3.subsystem.DefaultDistinctNameService;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* processor that sets the default distinct name for a deployment.
*
* @author Stuart Douglas
*/
public class EjbDefaultDistinctNameProcessor implements DeploymentUnitProcessor {
private final DefaultDistinctNameService defaultDistinctNameService;
public EjbDefaultDistinctNameProcessor(final DefaultDistinctNameService defaultDistinctNameService) {
this.defaultDistinctNameService = defaultDistinctNameService;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final String defaultDistinctName = defaultDistinctNameService.getDefaultDistinctName();
if(defaultDistinctName != null) {
phaseContext.getDeploymentUnit().putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, defaultDistinctName);
}
}
}
| 2,193 | 42.019608 | 133 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbClientContextSetupProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static java.security.AccessController.doPrivileged;
import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.net.ssl.SSLContext;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.remote.EJBClientContextService;
import org.jboss.as.ejb3.remote.RemotingProfileService;
import org.jboss.as.network.OutboundConnection;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleClassLoader;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.jboss.remoting3.RemotingOptions;
import org.wildfly.common.context.ContextManager;
import org.wildfly.discovery.Discovery;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.AuthenticationContextConfigurationClient;
import org.wildfly.security.auth.client.MatchRule;
import org.xnio.OptionMap;
/**
* A deployment processor which associates the {@link EJBClientContext}, belonging to a deployment unit,
* with the deployment unit's classloader.
*
* @author Stuart Douglas
* @author Jaikiran Pai
*/
public class EjbClientContextSetupProcessor implements DeploymentUnitProcessor {
private static final AuthenticationContextConfigurationClient CLIENT = doPrivileged(AuthenticationContextConfigurationClient.ACTION);
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (module == null) {
return;
}
RegistrationService registrationService = new RegistrationService(module);
ServiceName registrationServiceName = deploymentUnit.getServiceName().append("ejb3","client-context","registration-service");
final ServiceName profileServiceName = getProfileServiceName(phaseContext);
final ServiceBuilder<Void> builder = phaseContext.getServiceTarget().addService(registrationServiceName, registrationService)
.addDependency(getEJBClientContextServiceName(phaseContext), EJBClientContextService.class, registrationService.ejbClientContextInjectedValue)
.addDependency(getDiscoveryServiceName(phaseContext), Discovery.class, registrationService.discoveryInjector);
if (profileServiceName != null) {
builder.addDependency(profileServiceName, RemotingProfileService.class, registrationService.profileServiceInjectedValue);
}
builder.install();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
return;
}
//we need to make sure all our components have a dependency on the EJB client context registration, which in turn implies a dependency on the context
for(final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
component.addDependency(registrationServiceName);
}
}
private ServiceName getEJBClientContextServiceName(final DeploymentPhaseContext phaseContext) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parentDeploymentUnit = deploymentUnit.getParent();
// The top level parent deployment unit will have the attachment containing the EJB client context
// service name
ServiceName serviceName;
if (parentDeploymentUnit != null) {
serviceName = parentDeploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME);
} else {
serviceName = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME);
}
if (serviceName != null) {
return serviceName;
}
return EJBClientContextService.DEFAULT_SERVICE_NAME;
}
private ServiceName getDiscoveryServiceName(final DeploymentPhaseContext phaseContext) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parentDeploymentUnit = deploymentUnit.getParent();
if (parentDeploymentUnit != null) {
return DiscoveryService.BASE_NAME.append(parentDeploymentUnit.getName());
} else {
return DiscoveryService.BASE_NAME.append(deploymentUnit.getName());
}
}
private ServiceName getProfileServiceName(final DeploymentPhaseContext phaseContext) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parentDeploymentUnit = deploymentUnit.getParent();
if (parentDeploymentUnit != null) {
return parentDeploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME);
} else {
return deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME);
}
}
private static final class RegistrationService implements Service<Void> {
private final Module module;
final InjectedValue<EJBClientContextService> ejbClientContextInjectedValue = new InjectedValue<>();
final InjectedValue<Discovery> discoveryInjector = new InjectedValue<>();
final InjectedValue<RemotingProfileService> profileServiceInjectedValue = new InjectedValue<>();
private RegistrationService(Module module) {
this.module = module;
}
@Override
public void start(StartContext context) throws StartException {
try {
doPrivileged((PrivilegedExceptionAction<Void>) () -> {
// associate the EJB client context and discovery setup with the deployment classloader
final EJBClientContextService ejbClientContextService = ejbClientContextInjectedValue.getValue();
final EJBClientContext ejbClientContext = ejbClientContextService.getClientContext();
final AuthenticationContext ejbClientClustersAuthenticationContext = ejbClientContextService.getClustersAuthenticationContext();
final ModuleClassLoader classLoader = module.getClassLoader();
EjbLogger.DEPLOYMENT_LOGGER.debugf("Registering EJB client context %s for classloader %s", ejbClientContext, classLoader);
final ContextManager<AuthenticationContext> authenticationContextManager = AuthenticationContext.getContextManager();
final RemotingProfileService profileService = profileServiceInjectedValue.getOptionalValue();
if (profileService != null || ejbClientClustersAuthenticationContext != null) {
// this is cheating but it works for our purposes
AuthenticationContext authenticationContext = authenticationContextManager.getClassLoaderDefault(classLoader);
if (authenticationContext == null) {
authenticationContext = authenticationContextManager.get();
}
final AuthenticationContext finalAuthenticationContext = authenticationContext;
authenticationContextManager.setClassLoaderDefaultSupplier(classLoader, () -> {
AuthenticationContext transformed = finalAuthenticationContext;
// now transform it
if (profileService != null) {
for (RemotingProfileService.RemotingConnectionSpec connectionSpec : profileService.getConnectionSpecs()) {
transformed = transformOne(connectionSpec, transformed);
}
}
if (ejbClientClustersAuthenticationContext != null) {
transformed = ejbClientClustersAuthenticationContext.with(transformed);
}
return transformed;
});
}
EJBClientContext.getContextManager().setClassLoaderDefault(classLoader, ejbClientContext);
Discovery.getContextManager().setClassLoaderDefault(classLoader, discoveryInjector.getValue());
return null;
});
} catch (PrivilegedActionException e) {
throw (StartException) e.getCause();
}
}
@Override
public void stop(StopContext context) {
// de-associate the EJB client context with the deployment classloader
doPrivileged((PrivilegedAction<Void>) () -> {
final ModuleClassLoader classLoader = module.getClassLoader();
EjbLogger.DEPLOYMENT_LOGGER.debugf("unRegistering EJB client context for classloader %s", classLoader);
EJBClientContext.getContextManager().setClassLoaderDefault(classLoader, null);
Discovery.getContextManager().setClassLoaderDefault(classLoader, null);
// this is redundant but should be safe
AuthenticationContext.getContextManager().setClassLoaderDefault(classLoader, null);
return null;
});
}
@Override
public Void getValue() throws IllegalStateException, IllegalArgumentException {
return null;
}
private static AuthenticationContext transformOne(RemotingProfileService.RemotingConnectionSpec connectionSpec, AuthenticationContext context) {
final OutboundConnection connectionService = connectionSpec.getSupplier().get();
AuthenticationConfiguration authenticationConfiguration = connectionService.getAuthenticationConfiguration();
SSLContext sslContext = connectionService.getSSLContext();
final URI destinationUri = connectionService.getDestinationUri();
MatchRule rule = MatchRule.ALL;
final String scheme = destinationUri.getScheme();
if (scheme != null) {
rule = rule.matchProtocol(scheme);
}
final String host = destinationUri.getHost();
if (host != null) {
rule = rule.matchHost(host);
}
final int port = destinationUri.getPort();
if (port != -1) {
rule = rule.matchPort(port);
}
final String path = destinationUri.getPath();
if (path != null && ! path.isEmpty()) {
rule = rule.matchPath(path);
}
MatchRule ejbRule = rule.matchAbstractType("ejb", "jboss");
MatchRule jtaRule = rule.matchAbstractType("jta", "jboss");
final OptionMap connectOptions = connectionSpec.getConnectOptions();
authenticationConfiguration = RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectOptions, authenticationConfiguration);
AuthenticationConfiguration ejbConfiguration = CLIENT.getAuthenticationConfiguration(destinationUri, context, - 1, "ejb", "jboss");
AuthenticationConfiguration jtaConfiguration = CLIENT.getAuthenticationConfiguration(destinationUri, context, - 1, "jta", "jboss");
if (sslContext == null) {
try {
sslContext = CLIENT.getSSLContext(destinationUri, context);
} catch (GeneralSecurityException e) {
throw EjbLogger.ROOT_LOGGER.failedToObtainSSLContext(e);
}
}
final SSLContext finalSSLContext = sslContext;
AuthenticationContext mergedAuthenticationContext = context.with(0, ejbRule, ejbConfiguration.with(authenticationConfiguration)).with(jtaRule, jtaConfiguration.with(authenticationConfiguration));
return mergedAuthenticationContext.withSsl(0, rule, () -> finalSSLContext);
}
}
}
| 14,109 | 53.478764 | 207 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/HibernateValidatorDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ejb3.validator.EjbProxyNormalizerCdiExtension;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.weld.WeldCapability;
import org.wildfly.common.Assert;
/**
* This processor is used to register {@link org.jboss.as.ejb3.validator.EjbProxyBeanMetaDataClassNormalizer} in the
* hibernate validator subsystem. Normalizer is used to provide validator with an interface implemented by a proxy.
*
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
public class HibernateValidatorDeploymentUnitProcessor implements DeploymentUnitProcessor {
private static final String BEAN_VALIDATION_CAPABILITY = "org.wildfly.bean-validation";
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
if (support.hasCapability(WELD_CAPABILITY_NAME) && support.hasCapability(BEAN_VALIDATION_CAPABILITY)) {
try {
final WeldCapability weldCapability = support.getCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class);
weldCapability.registerExtensionInstance(new EjbProxyNormalizerCdiExtension(), deploymentUnit);
} catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
Assert.unreachableCode();
}
}
}
} | 2,994 | 47.306452 | 130 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbInjectionSource.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ee.component.EEApplicationDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.ViewManagedReferenceFactory;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.modules.Module;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* Implementation of {@link InjectionSource} responsible for finding a specific bean instance with a bean name and interface.
*
* @author John Bailey
* @author Stuart Douglas
*/
public class EjbInjectionSource extends InjectionSource {
private final String beanName;
private final String typeName;
private final String bindingName;
private final DeploymentUnit deploymentUnit;
private final boolean appclient;
private volatile String error = null;
private volatile ServiceName resolvedViewName;
private volatile RemoteViewManagedReferenceFactory remoteFactory;
private volatile boolean resolved = false;
public EjbInjectionSource(final String beanName, final String typeName, final String bindingName, final DeploymentUnit deploymentUnit, final boolean appclient) {
this.beanName = beanName;
this.typeName = typeName;
this.bindingName = bindingName;
this.deploymentUnit = deploymentUnit;
this.appclient = appclient;
}
public EjbInjectionSource(final String typeName, final String bindingName, final DeploymentUnit deploymentUnit, final boolean appclient) {
this.bindingName = bindingName;
this.deploymentUnit = deploymentUnit;
this.appclient = appclient;
this.beanName = null;
this.typeName = typeName;
}
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
resolve();
if (error != null) {
throw new DeploymentUnitProcessingException(error);
}
if (remoteFactory != null) {
//because we are using the Jakarta Enterprise Beans: lookup namespace we do not need a dependency
injector.inject(remoteFactory);
} else if (!appclient) {
//we do not add a dependency if this is the appclient
//as local injections are simply ignored
serviceBuilder.addDependency(resolvedViewName, ComponentView.class, new ViewManagedReferenceFactory.Injector(injector));
}
}
/**
* Checks if this Jakarta Enterprise Beans injection has been resolved yet, and if not resolves it.
*/
private void resolve() {
if (!resolved) {
synchronized (this) {
if (!resolved) {
final Set<ViewDescription> views = getViews();
final Set<EJBViewDescription> ejbsForViewName = new HashSet<EJBViewDescription>();
for (final ViewDescription view : views) {
if (view instanceof EJBViewDescription) {
final MethodInterfaceType viewType = ((EJBViewDescription) view).getMethodIntf();
// @EJB injection *shouldn't* consider the @WebService endpoint view or MDBs
if (viewType == MethodInterfaceType.ServiceEndpoint || viewType == MethodInterfaceType.MessageEndpoint) {
continue;
}
ejbsForViewName.add((EJBViewDescription) view);
}
}
if (ejbsForViewName.isEmpty()) {
if (beanName == null) {
error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, bindingName);
} else {
error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, beanName, bindingName);
}
} else if (ejbsForViewName.size() > 1) {
if (beanName == null) {
error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, bindingName, ejbsForViewName);
} else {
error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, beanName, bindingName, ejbsForViewName);
}
} else {
final EJBViewDescription description = ejbsForViewName.iterator().next();
final EJBViewDescription ejbViewDescription = (EJBViewDescription) description;
//for remote interfaces we do not want to use a normal binding
//we need to bind the remote proxy factory into JNDI instead to get the correct behaviour
if (ejbViewDescription.getMethodIntf() == MethodInterfaceType.Remote || ejbViewDescription.getMethodIntf() == MethodInterfaceType.Home) {
final EJBComponentDescription componentDescription = (EJBComponentDescription) description.getComponentDescription();
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final String earApplicationName = moduleDescription.getEarApplicationName();
final Supplier<ClassLoader> viewClassLoader = new Supplier<>() {
@Override
public ClassLoader get() throws IllegalStateException, IllegalArgumentException {
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
return module != null ? module.getClassLoader() : null;
}
};
remoteFactory = new RemoteViewManagedReferenceFactory(earApplicationName, moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), description.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
}
final ServiceName serviceName = description.getServiceName();
resolvedViewName = serviceName;
}
resolved = true;
}
}
}
}
private Set<ViewDescription> getViews() {
final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(EE_APPLICATION_DESCRIPTION);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final Set<ViewDescription> componentsForViewName;
if (beanName != null) {
componentsForViewName = applicationDescription.getComponents(beanName, typeName, deploymentRoot.getRoot());
} else {
componentsForViewName = applicationDescription.getComponentsForViewName(typeName, deploymentRoot.getRoot());
}
return componentsForViewName;
}
public boolean equals(Object o) {
if (this == o) { return true; }
if (!(o instanceof EjbInjectionSource)) { return false; }
resolve();
if (error != null) {
//we can't do a real equals comparison in this case, so just return false
return false;
}
final EjbInjectionSource other = (EjbInjectionSource) o;
return eq(typeName, other.typeName) && eq(resolvedViewName, other.resolvedViewName);
}
public int hashCode() {
return typeName.hashCode();
}
private static boolean eq(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}
}
| 9,842 | 47.727723 | 310 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/DiscoveryService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import org.jboss.as.ejb3.remote.AssociationService;
import org.jboss.as.ejb3.remote.RemotingProfileService;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.discovery.Discovery;
import org.wildfly.discovery.spi.DiscoveryProvider;
import org.wildfly.discovery.impl.StaticDiscoveryProvider;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* A service that provides discovery services.
* <p>
* Note: this service is going to move elsewhere in the future.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class DiscoveryService implements Service {
private static final DiscoveryProvider[] NO_PROVIDERS = new DiscoveryProvider[0];
public static final ServiceName BASE_NAME = ServiceName.JBOSS.append("deployment", "discovery");
private final Collection<DiscoveryProvider> providers = new LinkedHashSet<>();
private final Consumer<Discovery> discoveryConsumer;
private final Supplier<RemotingProfileService> remotingProfileServiceSupplier;
private final Supplier<AssociationService> associationServiceSupplier;
private volatile DiscoveryProvider remotingDP;
private volatile DiscoveryProvider assocationDP;
public DiscoveryService(final Consumer<Discovery> discoveryConsumer, final Supplier<RemotingProfileService> remotingProfileServiceSupplier, final Supplier<AssociationService> associationServiceSupplier) {
this.discoveryConsumer = discoveryConsumer;
this.remotingProfileServiceSupplier = remotingProfileServiceSupplier;
this.associationServiceSupplier = associationServiceSupplier;
}
public void start(final StartContext context) throws StartException {
final RemotingProfileService remotingProfileService = remotingProfileServiceSupplier != null ? remotingProfileServiceSupplier.get() : null;
final AssociationService associationService = associationServiceSupplier != null ? associationServiceSupplier.get() : null;
if (remotingProfileService != null) {
remotingDP = new StaticDiscoveryProvider(remotingProfileService.getServiceUrls());
}
if (associationService != null) {
assocationDP = associationService.getLocalDiscoveryProvider();
}
final DiscoveryProvider[] providersArray;
synchronized (providers) {
if (remotingDP != null) providers.add(remotingDP);
if (assocationDP != null) providers.add(assocationDP);
providersArray = providers.toArray(NO_PROVIDERS);
}
discoveryConsumer.accept(Discovery.create(providersArray));
}
public void stop(final StopContext context) {
discoveryConsumer.accept(null);
synchronized (providers) {
if (remotingDP != null) {
providers.remove(remotingDP);
remotingDP = null;
}
if (assocationDP != null) {
providers.remove(assocationDP);
assocationDP = null;
}
}
}
Consumer<DiscoveryProvider> getDiscoveryProviderConsumer() {
return new Consumer<DiscoveryProvider>() {
@Override
public void accept(final DiscoveryProvider discoveryProvider) {
synchronized (providers) {
providers.add(discoveryProvider);
}
}
};
}
}
| 4,771 | 41.990991 | 208 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EJBComponentDescriptionFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public abstract class EJBComponentDescriptionFactory {
/**
* If this is an appclient we want to make the components as not installable, so we can still look up which Jakarta Enterprise Beans's are in
* the deployment, but do not actually install them
*/
protected final boolean appclient;
protected EJBComponentDescriptionFactory(final boolean appclient) {
this.appclient = appclient;
}
protected void addComponent(final DeploymentUnit deploymentUnit, final EJBComponentDescription beanDescription) {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
if (appclient) {
deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS, beanDescription);
} else {
// Add this component description to module description
ejbJarDescription.getEEModuleDescription().addComponent(beanDescription);
}
}
static EnterpriseBeansMetaData getEnterpriseBeansMetaData(final DeploymentUnit deploymentUnit) {
final EjbJarMetaData jarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (jarMetaData == null)
return null;
return jarMetaData.getEnterpriseBeans();
}
static <B extends EnterpriseBeanMetaData> B getEnterpriseBeanMetaData(final DeploymentUnit deploymentUnit, final String name, final Class<B> expectedType) {
final EnterpriseBeansMetaData enterpriseBeansMetaData = getEnterpriseBeansMetaData(deploymentUnit);
if (enterpriseBeansMetaData == null)
return null;
return expectedType.cast(enterpriseBeansMetaData.get(name));
}
/**
* Process annotations and merge any available metadata at the same time.
*/
protected abstract void processAnnotations(final DeploymentUnit deploymentUnit, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException;
protected abstract void processBeanMetaData(final DeploymentUnit deploymentUnit, final EnterpriseBeanMetaData enterpriseBeanMetaData) throws DeploymentUnitProcessingException;
protected static <T> T override(T original, T override) {
return override != null ? override : original;
}
}
| 4,146 | 46.666667 | 179 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/BusinessViewAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import jakarta.ejb.Local;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Remote;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EjbJarVersion;
import org.jboss.modules.Module;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION;
import static org.jboss.as.ejb3.deployment.processors.ViewInterfaces.getPotentialViewInterfaces;
/**
* Processes {@link Local @Local} and {@link @Remote} annotation of a session bean and sets up the {@link SessionBeanComponentDescription}
* out of it.
* <p/>
*
* @author Jaikiran Pai
*/
public class BusinessViewAnnotationProcessor implements DeploymentUnitProcessor {
private final boolean appclient;
public BusinessViewAnnotationProcessor(final boolean appclient) {
this.appclient = appclient;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if(module == null) {
return;
}
final ClassLoader moduleClassLoader = module.getClassLoader();
if (componentDescriptions != null) {
for (ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription instanceof SessionBeanComponentDescription == false) {
continue;
}
final Class<?> ejbClass = this.getEjbClass(componentDescription.getComponentClassName(), moduleClassLoader);
try {
this.processViewAnnotations(deploymentUnit, ejbClass, (SessionBeanComponentDescription) componentDescription);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failedToProcessBusinessInterfaces(ejbClass, e);
}
}
}
if (appclient) {
for (ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
if (componentDescription instanceof SessionBeanComponentDescription == false) {
continue;
}
final Class<?> ejbClass = this.getEjbClass(componentDescription.getComponentClassName(), moduleClassLoader);
try {
this.processViewAnnotations(deploymentUnit, ejbClass, (SessionBeanComponentDescription) componentDescription);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failedToProcessBusinessInterfaces(ejbClass, e);
}
}
}
}
/**
* Processes the session bean for remote and local views and updates the {@link SessionBeanComponentDescription}
* accordingly
*
* @param deploymentUnit The deployment unit
* @param sessionBeanClass The bean class
* @param sessionBeanComponentDescription
* The component description
* @throws DeploymentUnitProcessingException
*
*/
private void processViewAnnotations(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass, final SessionBeanComponentDescription sessionBeanComponentDescription) throws DeploymentUnitProcessingException {
final Collection<Class<?>> remoteBusinessInterfaces = this.getRemoteBusinessInterfaces(deploymentUnit, sessionBeanClass);
if (remoteBusinessInterfaces != null && !remoteBusinessInterfaces.isEmpty()) {
sessionBeanComponentDescription.addRemoteBusinessInterfaceViews(this.toString(remoteBusinessInterfaces));
}
// fetch the local business interfaces of the bean
Collection<Class<?>> localBusinessInterfaces = this.getLocalBusinessInterfaces(deploymentUnit, sessionBeanClass);
if (localBusinessInterfaces != null && !localBusinessInterfaces.isEmpty()) {
sessionBeanComponentDescription.addLocalBusinessInterfaceViews(this.toString(localBusinessInterfaces));
}
if (hasNoInterfaceView(sessionBeanClass)) {
sessionBeanComponentDescription.addNoInterfaceView();
}
// Enterprise Beans 3.1 FR 4.9.7 & 4.9.8, if the bean exposes no views
if (hasNoViews(sessionBeanComponentDescription)) {
final Set<Class<?>> potentialBusinessInterfaces = getPotentialBusinessInterfaces(sessionBeanClass);
if (potentialBusinessInterfaces.isEmpty()) {
sessionBeanComponentDescription.addNoInterfaceView();
} else if (potentialBusinessInterfaces.size() == 1) {
sessionBeanComponentDescription.addLocalBusinessInterfaceViews(potentialBusinessInterfaces.iterator().next().getName());
} else if (isEjbVersionGreaterThanOrEqualTo32(deploymentUnit)) {
// Jakarta Enterprise Beans 3.2 spec states (section 4.9.7):
// ... or if the bean class is annotated with neither the Local nor the Remote annotation, all implemented interfaces (excluding the interfaces listed above)
// are assumed to be local business interfaces of the bean
sessionBeanComponentDescription.addLocalBusinessInterfaceViews(toString(potentialBusinessInterfaces));
}
}
}
private Collection<Class<?>> getRemoteBusinessInterfaces(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass) throws DeploymentUnitProcessingException {
final Remote remoteViewAnnotation;
try {
remoteViewAnnotation = sessionBeanClass.getAnnotation(Remote.class);
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(Remote.class.getSimpleName(), sessionBeanClass.getName());
}
if (remoteViewAnnotation == null) {
Collection<Class<?>> interfaces = getBusinessInterfacesFromInterfaceAnnotations(sessionBeanClass, Remote.class);
if (!interfaces.isEmpty()) {
return interfaces;
}
return Collections.emptySet();
}
Class<?>[] remoteViews = remoteViewAnnotation.value();
if (remoteViews == null || remoteViews.length == 0) {
Set<Class<?>> interfaces = getPotentialBusinessInterfaces(sessionBeanClass);
// For version < 3.2, the Jakarta Enterprise Beans spec didn't allow more than one implementing interfaces to be considered as remote when the bean class had the @Remote annotation without any explicit value.
// Jakarta Enterprise Beans 3.2 allows it (core spec, section 4.9.7)
if (interfaces.size() != 1 && !isEjbVersionGreaterThanOrEqualTo32(deploymentUnit)) {
throw EjbLogger.ROOT_LOGGER.beanWithRemoteAnnotationImplementsMoreThanOneInterface(sessionBeanClass);
}
return interfaces;
}
return Arrays.asList(remoteViews);
}
private Collection<Class<?>> getLocalBusinessInterfaces(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass) throws DeploymentUnitProcessingException {
final Local localViewAnnotation;
try {
localViewAnnotation = sessionBeanClass.getAnnotation(Local.class);
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(Local.class.getSimpleName(), sessionBeanClass.getName());
}
if (localViewAnnotation == null) {
Collection<Class<?>> interfaces = getBusinessInterfacesFromInterfaceAnnotations(sessionBeanClass, Local.class);
if (!interfaces.isEmpty()) {
return interfaces;
}
return Collections.emptySet();
}
Class<?>[] localViews = localViewAnnotation.value();
if (localViews == null || localViews.length == 0) {
Set<Class<?>> interfaces = getPotentialBusinessInterfaces(sessionBeanClass);
// For version < 3.2, the Jakarta Enterprise Beans spec didn't allow more than one implementing interfaces to be considered as local when the bean class had the @Local annotation without any explicit value.
// Jakarta Enterprise Beans 3.2 allows it (core spec, section 4.9.7)
if (interfaces.size() != 1 && !isEjbVersionGreaterThanOrEqualTo32(deploymentUnit)) {
throw EjbLogger.ROOT_LOGGER.beanWithLocalAnnotationImplementsMoreThanOneInterface(sessionBeanClass);
}
return interfaces;
}
return Arrays.asList(localViews);
}
private static Collection<Class<?>> getBusinessInterfacesFromInterfaceAnnotations(Class<?> sessionBeanClass, Class<? extends Annotation> annotation) throws DeploymentUnitProcessingException {
final Set<Class<?>> potentialBusinessInterfaces = getPotentialBusinessInterfaces(sessionBeanClass);
final Set<Class<?>> businessInterfaces = new HashSet<Class<?>>();
for (Class<?> iface : potentialBusinessInterfaces) {
try {
if (iface.getAnnotation(annotation) != null) {
businessInterfaces.add(iface);
}
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(annotation.getSimpleName(), iface.getName());
}
}
return businessInterfaces;
}
/**
* Returns all interfaces implemented by a bean that are eligible to be business interfaces
*
* @param sessionBeanClass The bean class
* @return A collection of all potential business interfaces
*/
private static Set<Class<?>> getPotentialBusinessInterfaces(Class<?> sessionBeanClass) {
return getPotentialViewInterfaces(sessionBeanClass);
}
/**
* Returns true if the <code>sessionBeanClass</code> has a {@link LocalBean no-interface view annotation}.
* Else returns false.
*
* @param sessionBeanClass The session bean {@link Class class}
* @return
*/
private static boolean hasNoInterfaceView(Class<?> sessionBeanClass) {
return sessionBeanClass.getAnnotation(LocalBean.class) != null;
}
private static boolean hasNoViews(SessionBeanComponentDescription sessionBeanComponentDescription) {
return sessionBeanComponentDescription.getViews() == null || sessionBeanComponentDescription.getViews().isEmpty();
}
private Class<?> getEjbClass(String className, ClassLoader cl) throws DeploymentUnitProcessingException {
try {
return cl.loadClass(className);
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException(e);
}
}
private Collection<String> toString(Collection<Class<?>> classes) {
final Collection<String> classNames = new ArrayList<String>(classes.size());
for (Class<?> klass : classes) {
classNames.add(klass.getName());
}
return classNames;
}
private boolean isEjbVersionGreaterThanOrEqualTo32(final DeploymentUnit deploymentUnit) {
if (deploymentUnit == null) {
return false;
}
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
// if there's no EjbJarMetadata then it means that there's no ejb-jar.xml. That effectively means that the version of this Jakarta Enterprise Beans deployment is the "latest"
// which in this case (i.e. starting WildFly 8 version) is "greater than or equal to 3.2". Hence return true.
if (ejbJarMetaData == null) {
return true;
}
// let the ejb jar metadata tell us what the version is
return ejbJarMetaData.isVersionGreaterThanOrEqual(EjbJarVersion.EJB_3_2);
}
}
| 14,620 | 50.122378 | 223 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/EjbManagementDeploymentUnitProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_CONFIGURATION;
import static org.jboss.as.server.deployment.DeploymentModelUtils.DEPLOYMENT_RESOURCE;
import java.util.ArrayList;
import java.util.List;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleConfiguration;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.subsystem.EJB3Extension;
import org.jboss.as.ejb3.subsystem.EJB3SubsystemModel;
import org.jboss.as.ejb3.subsystem.deployment.AbstractEJBComponentRuntimeHandler;
import org.jboss.as.ejb3.subsystem.deployment.EJBComponentType;
import org.jboss.as.ejb3.subsystem.deployment.InstalledComponent;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentResourceSupport;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* {@link org.jboss.as.server.deployment.Phase#INSTALL} processor that adds management resources describing EJB components.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class EjbManagementDeploymentUnitProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleConfiguration moduleDescription = deploymentUnit.getAttachment(EE_MODULE_CONFIGURATION);
if (moduleDescription == null) {
// Nothing to do
return;
}
if (deploymentUnit.getParent() != null && deploymentUnit.getParent().getParent() != null) {
// We only expose management resources 2 levels deep
return;
}
// Iterate through each component, installing it into the container
for (final ComponentConfiguration configuration : moduleDescription.getComponentConfigurations()) {
try {
final ComponentDescription componentDescription = configuration.getComponentDescription();
if (componentDescription instanceof EJBComponentDescription) {
installManagementResource(configuration, deploymentUnit);
}
} catch (RuntimeException e) {
throw EjbLogger.ROOT_LOGGER.failedToInstallManagementResource(e, configuration.getComponentName());
}
}
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
if (deploymentUnit.getParent() != null && deploymentUnit.getParent().getParent() != null) {
// We only expose management resources 2 levels deep
return;
}
// Iterate through each component, uninstalling it
for (final InstalledComponent configuration : deploymentUnit.getAttachmentList(EjbDeploymentAttachmentKeys.MANAGED_COMPONENTS)) {
try {
uninstallManagementResource(configuration, deploymentUnit);
} catch (RuntimeException e) {
EjbLogger.DEPLOYMENT_LOGGER.failedToRemoveManagementResources(configuration, e.getLocalizedMessage());
}
}
deploymentUnit.removeAttachment(EjbDeploymentAttachmentKeys.MANAGED_COMPONENTS);
}
private void installManagementResource(ComponentConfiguration configuration, DeploymentUnit deploymentUnit) {
final EJBComponentType type = EJBComponentType.getComponentType(configuration);
PathAddress addr = getComponentAddress(type, configuration, deploymentUnit);
final AbstractEJBComponentRuntimeHandler<?> handler = type.getRuntimeHandler();
handler.registerComponent(addr, configuration.getComponentDescription().getStartServiceName());
deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.MANAGED_COMPONENTS, new InstalledComponent(type, addr));
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
deploymentResourceSupport.getDeploymentSubModel(EJB3Extension.SUBSYSTEM_NAME, addr.getLastElement());
final EJBComponentDescription description = (EJBComponentDescription) configuration.getComponentDescription();
Resource timerServiceResource = description.getTimerServiceResource();
if (timerServiceResource != null) {
final PathAddress timerServiceAddress = PathAddress.pathAddress(addr.getLastElement(), EJB3SubsystemModel.TIMER_SERVICE_PATH);
deploymentResourceSupport.registerDeploymentSubResource(EJB3Extension.SUBSYSTEM_NAME, timerServiceAddress, timerServiceResource);
}
}
private void uninstallManagementResource(final InstalledComponent component, DeploymentUnit deploymentUnit) {
component.getType().getRuntimeHandler().unregisterComponent(component.getAddress());
// Deregister possible /service=timer-service
Resource root = deploymentUnit.getAttachment(DEPLOYMENT_RESOURCE);
Resource subResource = root.getChild(component.getAddress().getParent().getLastElement());
if (subResource != null) {
Resource componentResource = subResource.getChild(component.getAddress().getLastElement());
if (componentResource != null) {
componentResource.removeChild(EJB3SubsystemModel.TIMER_SERVICE_PATH);
}
}
}
private static PathAddress getComponentAddress(EJBComponentType type, ComponentConfiguration configuration, DeploymentUnit deploymentUnit) {
List<PathElement> elements = new ArrayList<PathElement>();
if (deploymentUnit.getParent() == null) {
elements.add(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, deploymentUnit.getName()));
} else {
elements.add(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, deploymentUnit.getParent().getName()));
elements.add(PathElement.pathElement(ModelDescriptionConstants.SUBDEPLOYMENT, deploymentUnit.getName()));
}
elements.add(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, EJB3Extension.SUBSYSTEM_NAME));
elements.add(PathElement.pathElement(type.getResourceType(), configuration.getComponentName()));
return PathAddress.pathAddress(elements);
}
}
| 7,979 | 51.5 | 144 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/SecurityRoleRefDDProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleRefMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleRefsMetaData;
/**
* Sets up the {@link EJBComponentDescription} with the <security-role-ref>s declared for an Jakarta Enterprise Beans
*
* User: Jaikiran Pai
*/
public class SecurityRoleRefDDProcessor extends AbstractEjbXmlDescriptorProcessor<EnterpriseBeanMetaData> {
@Override
protected Class<EnterpriseBeanMetaData> getMetaDataType() {
return EnterpriseBeanMetaData.class;
}
@Override
protected void processBeanMetaData(final EnterpriseBeanMetaData beanMetaData, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final SecurityRoleRefsMetaData securityRoleRefs = beanMetaData.getSecurityRoleRefs();
if (securityRoleRefs == null) {
return;
}
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) moduleDescription.getComponentByName(beanMetaData.getEjbName());
for (final SecurityRoleRefMetaData securityRoleRef : securityRoleRefs) {
final String fromRole = securityRoleRef.getRoleName();
String toRole = securityRoleRef.getRoleLink();
if (fromRole == null || fromRole.trim().isEmpty()) {
throw EjbLogger.ROOT_LOGGER.roleNamesIsNull(ejbComponentDescription.getEJBName());
}
// if role-link hasn't been specified, then it links to the same role name as the one specified
// in the role-name
if (toRole == null) {
toRole = fromRole;
}
ejbComponentDescription.linkSecurityRoles(fromRole, toRole);
}
}
}
| 3,453 | 46.315068 | 167 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/InterceptorClassDeploymentDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import jakarta.interceptor.InvocationContext;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.DeploymentDescriptorEnvironment;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InterceptorEnvironment;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.AroundInvokeMetaData;
import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
import org.jboss.metadata.ejb.spec.AroundTimeoutMetaData;
import org.jboss.metadata.ejb.spec.AroundTimeoutsMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.InterceptorMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
/**
* Processor that handles the <interceptor\> element of an ejb-jar.xml file.
*
* @author Stuart Douglas
*/
public class InterceptorClassDeploymentDescriptorProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (metaData == null) {
return;
}
if (metaData.getInterceptors() == null) {
return;
}
for (InterceptorMetaData interceptor : metaData.getInterceptors()) {
String interceptorClassName = interceptor.getInterceptorClass();
AroundInvokesMetaData aroundInvokes = interceptor.getAroundInvokes();
if (aroundInvokes != null) {
for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = aroundInvoke.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
builder.setAroundInvoke(methodIdentifier);
if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build());
}
}
}
AroundTimeoutsMetaData aroundTimeouts = interceptor.getAroundTimeouts();
if (aroundTimeouts != null) {
for (AroundTimeoutMetaData aroundTimeout : aroundTimeouts) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = aroundTimeout.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
builder.setAroundTimeout(methodIdentifier);
if (aroundTimeout.getClassName() == null || aroundTimeout.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(aroundTimeout.getClassName(), builder.build());
}
}
}
// post-construct(s) of the interceptor configured (if any) in the deployment descriptor
LifecycleCallbacksMetaData postConstructs = interceptor.getPostConstructs();
if (postConstructs != null) {
for (LifecycleCallbackMetaData postConstruct : postConstructs) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = postConstruct.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
builder.setPostConstruct(methodIdentifier);
if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(postConstruct.getClassName(), builder.build());
}
}
}
// pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
LifecycleCallbacksMetaData preDestroys = interceptor.getPreDestroys();
if (preDestroys != null) {
for (LifecycleCallbackMetaData preDestroy : preDestroys) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = preDestroy.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
builder.setPreDestroy(methodIdentifier);
if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(preDestroy.getClassName(), builder.build());
}
}
}
// pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
LifecycleCallbacksMetaData prePassivates = interceptor.getPrePassivates();
if (prePassivates != null) {
for (LifecycleCallbackMetaData prePassivate : prePassivates) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = prePassivate.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
builder.setPrePassivate(methodIdentifier);
if (prePassivate.getClassName() == null || prePassivate.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(prePassivate.getClassName(), builder.build());
}
}
}
// pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
LifecycleCallbacksMetaData postActivates = interceptor.getPostActivates();
if (postActivates != null) {
for (LifecycleCallbackMetaData postActivate : postActivates) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = postActivate.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
builder.setPostActivate(methodIdentifier);
if (postActivate.getClassName() == null || postActivate.getClassName().isEmpty()) {
eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
} else {
eeModuleDescription.addInterceptorMethodOverride(postActivate.getClassName(), builder.build());
}
}
}
if(interceptor.getJndiEnvironmentRefsGroup() != null) {
final DeploymentDescriptorEnvironment environment = new DeploymentDescriptorEnvironment("java:comp/env", interceptor.getJndiEnvironmentRefsGroup());
eeModuleDescription.addInterceptorEnvironment(interceptor.getInterceptorClass(), new InterceptorEnvironment(environment));
}
}
}
}
| 10,055 | 58.152941 | 164 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/DeploymentDescriptorInterceptorBindingsProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InterceptorDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.subsystem.EjbNameRegexService;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
import org.jboss.metadata.ejb.spec.InterceptorMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.modules.Module;
/**
* Processor that handles interceptor bindings that are defined in the deployment descriptor.
*
* @author Stuart Douglas
*/
public class DeploymentDescriptorInterceptorBindingsProcessor implements DeploymentUnitProcessor {
private final EjbNameRegexService ejbNameRegexService;
public DeploymentDescriptorInterceptorBindingsProcessor(EjbNameRegexService ejbNameRegexService) {
this.ejbNameRegexService = ejbNameRegexService;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
if (metaData == null) {
return;
}
if (metaData.getAssemblyDescriptor() == null) {
return;
}
if (metaData.getAssemblyDescriptor().getInterceptorBindings() == null) {
return;
}
//default interceptors must be mentioned in the interceptors section
final Set<String> interceptorClasses = new HashSet<String>();
if (metaData.getInterceptors() != null) {
for (final InterceptorMetaData interceptor : metaData.getInterceptors()) {
interceptorClasses.add(interceptor.getInterceptorClass());
}
}
final Map<String, List<InterceptorBindingMetaData>> bindingsPerComponent = new HashMap<String, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> defaultInterceptorBindings = new ArrayList<InterceptorBindingMetaData>();
for (final InterceptorBindingMetaData binding : metaData.getAssemblyDescriptor().getInterceptorBindings()) {
if (binding.getEjbName().equals("*")) {
if (binding.getMethod() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotBindToMethod();
}
if(binding.getInterceptorOrder() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotSpecifyOrder();
}
defaultInterceptorBindings.add(binding);
} else if(ejbNameRegexService.isEjbNameRegexAllowed()) {
Pattern pattern = Pattern.compile(binding.getEjbName());
for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
if(componentDescription instanceof EJBComponentDescription) {
String ejbName = ((EJBComponentDescription) componentDescription).getEJBName();
if(pattern.matcher(ejbName).matches()) {
List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(ejbName);
if (bindings == null) {
bindingsPerComponent.put(ejbName, bindings = new ArrayList<InterceptorBindingMetaData>());
}
bindings.add(binding);
}
}
}
} else {
List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(binding.getEjbName());
if (bindings == null) {
bindingsPerComponent.put(binding.getEjbName(), bindings = new ArrayList<InterceptorBindingMetaData>());
}
bindings.add(binding);
}
}
final List<InterceptorDescription> defaultInterceptors = new ArrayList<InterceptorDescription>();
for (InterceptorBindingMetaData binding : defaultInterceptorBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String clazz : binding.getInterceptorClasses()) {
//we only want default interceptors referenced in the interceptors section
if (interceptorClasses.contains(clazz)) {
defaultInterceptors.add(new InterceptorDescription(clazz));
} else {
ROOT_LOGGER.defaultInterceptorClassNotListed(clazz);
}
}
}
}
//now we need to process the components, and add interceptor information
//we iterate over all components, as we need to process default interceptors
for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
final Class<?> componentClass;
try {
componentClass = module.getClassLoader().loadClass(componentDescription.getComponentClassName());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, componentDescription.getComponentClassName());
}
final List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(componentDescription.getComponentName());
final Map<Method, List<InterceptorBindingMetaData>> methodInterceptors = new HashMap<Method, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> classLevelBindings = new ArrayList<InterceptorBindingMetaData>();
//we only want to exclude default and class level interceptors if every binding
//has the exclude element.
boolean classLevelExcludeDefaultInterceptors = false;
Map<Method, Boolean> methodLevelExcludeDefaultInterceptors = new HashMap<Method, Boolean>();
Map<Method, Boolean> methodLevelExcludeClassInterceptors = new HashMap<Method, Boolean>();
//if an absolute order has been defined at any level
//absolute ordering takes precedence
boolean classLevelAbsoluteOrder = false;
final Map<Method, Boolean> methodLevelAbsoluteOrder = new HashMap<Method, Boolean>();
if (bindings != null) {
for (final InterceptorBindingMetaData binding : bindings) {
if (binding.getMethod() == null) {
classLevelBindings.add(binding);
//if even one binding does not say exclude default then we do not exclude
if (binding.isExcludeDefaultInterceptors()) {
classLevelExcludeDefaultInterceptors = true;
}
if (binding.isTotalOrdering()) {
if (classLevelAbsoluteOrder) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(componentClass.toString());
} else {
classLevelAbsoluteOrder = true;
}
}
} else {
//method level bindings
//first find the right method
final NamedMethodMetaData methodData = binding.getMethod();
final ClassReflectionIndex classIndex = index.getClassIndex(componentClass);
Method resolvedMethod = null;
if (methodData.getMethodParams() == null) {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
if (methods.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass.getName(), methodData.getMethodName());
} else if (methods.size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), componentClass.getName());
}
resolvedMethod = methods.iterator().next();
} else {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
for (final Method method : methods) {
boolean match = true;
for (int i = 0; i < method.getParameterCount(); ++i) {
if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
match = false;
break;
}
}
if (match) {
resolvedMethod = method;
break;
}
}
if (resolvedMethod == null) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
}
}
List<InterceptorBindingMetaData> list = methodInterceptors.get(resolvedMethod);
if (list == null) {
methodInterceptors.put(resolvedMethod, list = new ArrayList<InterceptorBindingMetaData>());
}
list.add(binding);
if (binding.isExcludeDefaultInterceptors()) {
methodLevelExcludeDefaultInterceptors.put(resolvedMethod, true);
}
if (binding.isExcludeClassInterceptors()) {
methodLevelExcludeClassInterceptors.put(resolvedMethod, true);
}
if (binding.isTotalOrdering()) {
if (methodLevelAbsoluteOrder.containsKey(resolvedMethod)) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(resolvedMethod.toString());
} else {
methodLevelAbsoluteOrder.put(resolvedMethod, true);
}
}
}
}
}
//now we have all the bindings in a format we can use
//build the list of default interceptors
componentDescription.setDefaultInterceptors(defaultInterceptors);
if(classLevelExcludeDefaultInterceptors) {
componentDescription.setExcludeDefaultInterceptors(true);
}
final List<InterceptorDescription> classLevelInterceptors = new ArrayList<InterceptorDescription>();
if (classLevelAbsoluteOrder) {
//we have an absolute ordering for the class level interceptors
for (final InterceptorBindingMetaData binding : classLevelBindings) {
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
//we have merged the default interceptors into the class interceptors
componentDescription.setExcludeDefaultInterceptors(true);
} else {
//the order we want is default interceptors (this will be empty if they are excluded)
//the annotation interceptors
//then dd interceptors
classLevelInterceptors.addAll(componentDescription.getClassInterceptors());
for (InterceptorBindingMetaData binding : classLevelBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
componentDescription.setClassInterceptors(classLevelInterceptors);
for (Map.Entry<Method, List<InterceptorBindingMetaData>> entry : methodInterceptors.entrySet()) {
final Method method = entry.getKey();
final List<InterceptorBindingMetaData> methodBindings = entry.getValue();
boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method);
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
Boolean excludeDefaultInterceptors = methodLevelExcludeDefaultInterceptors.get(method);
excludeDefaultInterceptors = excludeDefaultInterceptors == null ? Boolean.FALSE : excludeDefaultInterceptors;
if (!excludeDefaultInterceptors) {
excludeDefaultInterceptors = componentDescription.isExcludeDefaultInterceptors() || componentDescription.isExcludeDefaultInterceptors(methodIdentifier);
}
Boolean excludeClassInterceptors = methodLevelExcludeClassInterceptors.get(method);
excludeClassInterceptors = excludeClassInterceptors == null ? Boolean.FALSE : excludeClassInterceptors;
if (!excludeClassInterceptors) {
excludeClassInterceptors = componentDescription.isExcludeClassInterceptors(methodIdentifier);
}
final List<InterceptorDescription> methodLevelInterceptors = new ArrayList<InterceptorDescription>();
if (totalOrder) {
//if there is a total order we just use it
for (final InterceptorBindingMetaData binding : methodBindings) {
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
} else {
//add class level and default interceptors, if not excluded
//class level interceptors also includes default interceptors
if (!excludeDefaultInterceptors) {
methodLevelInterceptors.addAll(defaultInterceptors);
}
if (!excludeClassInterceptors) {
for (InterceptorDescription interceptor : classLevelInterceptors) {
methodLevelInterceptors.add(interceptor);
}
}
List<InterceptorDescription> annotationMethodLevel = componentDescription.getMethodInterceptors().get(methodIdentifier);
if (annotationMethodLevel != null) {
methodLevelInterceptors.addAll(annotationMethodLevel);
}
//now add all the interceptors from the bindings
for (InterceptorBindingMetaData binding : methodBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
//we have already taken component and default interceptors into account
componentDescription.excludeClassInterceptors(methodIdentifier);
componentDescription.excludeDefaultInterceptors(methodIdentifier);
componentDescription.setMethodInterceptors(methodIdentifier, methodLevelInterceptors);
}
}
}
}
| 18,925 | 53.074286 | 179 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/ContainerInterceptorBindingsDDProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.InterceptorDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.interceptor.ContainerInterceptorsMetaData;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.modules.Module;
/**
* A {@link DeploymentUnitProcessor} which processes the container interceptor bindings that are configured the jboss-ejb3.xml
* deployment descriptor of a deployment
*
* @author Jaikiran Pai
*/
public class ContainerInterceptorBindingsDDProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null || metaData.getAssemblyDescriptor() == null) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
// fetch the container-interceptors
final List<ContainerInterceptorsMetaData> containerInterceptorConfigurations = metaData.getAssemblyDescriptor().getAny(ContainerInterceptorsMetaData.class);
if (containerInterceptorConfigurations == null || containerInterceptorConfigurations.isEmpty()) {
return;
}
final ContainerInterceptorsMetaData containerInterceptorsMetaData = containerInterceptorConfigurations.get(0);
if (containerInterceptorsMetaData == null) {
return;
}
final InterceptorBindingsMetaData containerInterceptorBindings = containerInterceptorsMetaData.getInterceptorBindings();
// no interceptor-binding == nothing to do
if (containerInterceptorBindings == null || containerInterceptorBindings.isEmpty()) {
return;
}
// we have now found some container interceptors which are bound to certain Jakarta Enterprise Beans, start the real work!
final Map<String, List<InterceptorBindingMetaData>> bindingsPerEJB = new HashMap<String, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> bindingsForAllEJBs = new ArrayList<InterceptorBindingMetaData>();
for (final InterceptorBindingMetaData containerInterceptorBinding : containerInterceptorBindings) {
if (containerInterceptorBinding.getEjbName().equals("*")) {
// container interceptor bindings that are applicable for all Jakarta Enterprise Beans are *not* expected to specify a method
// since all Jakarta Enterprise Beans having the same method is not really practical
if (containerInterceptorBinding.getMethod() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotBindToMethod();
}
if (containerInterceptorBinding.getInterceptorOrder() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotSpecifyOrder();
}
// Make a note that this container interceptor binding is applicable for all Jakarta Enterprise Beans
bindingsForAllEJBs.add(containerInterceptorBinding);
} else {
// fetch existing container interceptor bindings for the Jakarta Enterprise Beans, if any.
List<InterceptorBindingMetaData> bindings = bindingsPerEJB.get(containerInterceptorBinding.getEjbName());
if (bindings == null) {
bindings = new ArrayList<InterceptorBindingMetaData>();
bindingsPerEJB.put(containerInterceptorBinding.getEjbName(), bindings);
}
// Make a note that the container interceptor binding is applicable for this specific Jakarta Enterprise Beans
bindings.add(containerInterceptorBinding);
}
}
// At this point we now know which container interceptor bindings have been configured for which Jakarta Enterprise Beans.
// Next, we create InterceptorDescription(s) out of those.
final List<InterceptorDescription> interceptorDescriptionsForAllEJBs = new ArrayList<InterceptorDescription>();
// first process container interceptors applicable for all Jakarta Enterprise Beans
for (InterceptorBindingMetaData binding : bindingsForAllEJBs) {
if (binding.getInterceptorClasses() != null) {
for (final String clazz : binding.getInterceptorClasses()) {
interceptorDescriptionsForAllEJBs.add(new InterceptorDescription(clazz));
}
}
}
// Now process container interceptors for each Jakarta Enterprise Beans
for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
if (!(componentDescription instanceof EJBComponentDescription)) {
continue;
}
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
final Class<?> componentClass;
try {
componentClass = module.getClassLoader().loadClass(ejbComponentDescription.getComponentClassName());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, ejbComponentDescription.getComponentClassName());
}
final List<InterceptorBindingMetaData> bindingsApplicableForCurrentEJB = bindingsPerEJB.get(ejbComponentDescription.getComponentName());
final Map<Method, List<InterceptorBindingMetaData>> methodInterceptors = new HashMap<Method, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> classLevelBindings = new ArrayList<InterceptorBindingMetaData>();
// we only want to exclude default and class level interceptors if every binding
// has the exclude element.
boolean classLevelExcludeDefaultInterceptors = false;
Map<Method, Boolean> methodLevelExcludeDefaultInterceptors = new HashMap<Method, Boolean>();
Map<Method, Boolean> methodLevelExcludeClassInterceptors = new HashMap<Method, Boolean>();
// if an absolute order has been defined at any level then absolute ordering takes precedence
boolean classLevelAbsoluteOrder = false;
final Map<Method, Boolean> methodLevelAbsoluteOrder = new HashMap<Method, Boolean>();
if (bindingsApplicableForCurrentEJB != null) {
for (final InterceptorBindingMetaData binding : bindingsApplicableForCurrentEJB) {
if (binding.getMethod() == null) {
// The container interceptor is expected to be fired for all methods of that Jakarta Enterprise Beans
classLevelBindings.add(binding);
// if even one binding does not say exclude default then we do not exclude
if (binding.isExcludeDefaultInterceptors()) {
classLevelExcludeDefaultInterceptors = true;
}
if (binding.isTotalOrdering()) {
if (classLevelAbsoluteOrder) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(componentClass.toString());
} else {
classLevelAbsoluteOrder = true;
}
}
} else {
// Method level bindings
// First find the right method
final NamedMethodMetaData methodData = binding.getMethod();
final ClassReflectionIndex classIndex = index.getClassIndex(componentClass);
Method resolvedMethod = null;
if (methodData.getMethodParams() == null) {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
if (methods.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass.getName(), methodData.getMethodName());
} else if (methods.size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), componentClass.getName());
}
resolvedMethod = methods.iterator().next();
} else {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
for (final Method method : methods) {
boolean match = true;
for (int i = 0; i < method.getParameterCount(); ++i) {
if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
match = false;
break;
}
}
if (match) {
resolvedMethod = method;
break;
}
}
if (resolvedMethod == null) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
}
}
List<InterceptorBindingMetaData> methodSpecificInterceptorBindings = methodInterceptors.get(resolvedMethod);
if (methodSpecificInterceptorBindings == null) {
methodSpecificInterceptorBindings = new ArrayList<InterceptorBindingMetaData>();
methodInterceptors.put(resolvedMethod, methodSpecificInterceptorBindings);
}
methodSpecificInterceptorBindings.add(binding);
if (binding.isExcludeDefaultInterceptors()) {
methodLevelExcludeDefaultInterceptors.put(resolvedMethod, true);
}
if (binding.isExcludeClassInterceptors()) {
methodLevelExcludeClassInterceptors.put(resolvedMethod, true);
}
if (binding.isTotalOrdering()) {
if (methodLevelAbsoluteOrder.containsKey(resolvedMethod)) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(resolvedMethod.toString());
} else {
methodLevelAbsoluteOrder.put(resolvedMethod, true);
}
}
}
}
}
// Now we have all the bindings in a format we can use
// Build the list of default interceptors
ejbComponentDescription.setDefaultContainerInterceptors(interceptorDescriptionsForAllEJBs);
if (classLevelExcludeDefaultInterceptors) {
ejbComponentDescription.setExcludeDefaultContainerInterceptors(true);
}
final List<InterceptorDescription> classLevelInterceptors = new ArrayList<InterceptorDescription>();
if (classLevelAbsoluteOrder) {
// We have an absolute ordering for the class level interceptors
for (final InterceptorBindingMetaData binding : classLevelBindings) {
// Find the class level container interceptor binding which specifies the total ordering (there will
// only be one since we have already validated in an earlier step, then more than one binding cannot
// specify an ordering
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
break;
}
}
// We have merged the default interceptors into the class interceptors
ejbComponentDescription.setExcludeDefaultContainerInterceptors(true);
} else {
for (InterceptorBindingMetaData binding : classLevelBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
// We now know about the class level container interceptors for this Jakarta Enterprise Beans
ejbComponentDescription.setClassLevelContainerInterceptors(classLevelInterceptors);
// Now process method level container interceptors for the Jakarta Enterprise Beans
for (Map.Entry<Method, List<InterceptorBindingMetaData>> entry : methodInterceptors.entrySet()) {
final Method method = entry.getKey();
final List<InterceptorBindingMetaData> methodBindings = entry.getValue();
boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method);
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
Boolean excludeDefaultInterceptors = methodLevelExcludeDefaultInterceptors.get(method);
excludeDefaultInterceptors = excludeDefaultInterceptors == null ? Boolean.FALSE : excludeDefaultInterceptors;
if (!excludeDefaultInterceptors) {
excludeDefaultInterceptors = ejbComponentDescription.isExcludeDefaultContainerInterceptors() || ejbComponentDescription.isExcludeDefaultContainerInterceptors(methodIdentifier);
}
Boolean excludeClassInterceptors = methodLevelExcludeClassInterceptors.get(method);
excludeClassInterceptors = excludeClassInterceptors == null ? Boolean.FALSE : excludeClassInterceptors;
if (!excludeClassInterceptors) {
excludeClassInterceptors = ejbComponentDescription.isExcludeClassLevelContainerInterceptors(methodIdentifier);
}
final List<InterceptorDescription> methodLevelInterceptors = new ArrayList<InterceptorDescription>();
if (totalOrder) {
// If there is a total order we just use it
for (final InterceptorBindingMetaData binding : methodBindings) {
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
} else {
// First add default interceptors and then class level interceptors for the method and finally
// the method specific interceptors
if (!excludeDefaultInterceptors) {
methodLevelInterceptors.addAll(interceptorDescriptionsForAllEJBs);
}
if (!excludeClassInterceptors) {
for (InterceptorDescription interceptor : classLevelInterceptors) {
methodLevelInterceptors.add(interceptor);
}
}
for (final InterceptorBindingMetaData binding : methodBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
// We have already taken component and default interceptors into account
ejbComponentDescription.excludeClassLevelContainerInterceptors(methodIdentifier);
ejbComponentDescription.excludeDefaultContainerInterceptors(methodIdentifier);
ejbComponentDescription.setMethodContainerInterceptors(methodIdentifier, methodLevelInterceptors);
}
}
}
}
| 19,449 | 61.339744 | 196 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/SessionBeanXmlDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.DeploymentDescriptorEnvironment;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
/**
* @author Jaikiran Pai
*/
public class SessionBeanXmlDescriptorProcessor extends AbstractEjbXmlDescriptorProcessor<SessionBeanMetaData> {
private final boolean appclient;
public SessionBeanXmlDescriptorProcessor(final boolean appclient) {
this.appclient = appclient;
}
@Override
protected Class<SessionBeanMetaData> getMetaDataType() {
return SessionBeanMetaData.class;
}
/**
* Processes the passed {@link org.jboss.metadata.ejb.spec.SessionBeanMetaData} and creates appropriate {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} out of it.
* The {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} is then added to the {@link org.jboss.as.ee.component.EEModuleDescription module description} available
* in the deployment unit of the passed {@link DeploymentPhaseContext phaseContext}
*
* @param sessionBean The session bean metadata
* @param phaseContext
* @throws DeploymentUnitProcessingException
*
*/
@Override
protected void processBeanMetaData(final SessionBeanMetaData sessionBean, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// get the module description
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final String beanName = sessionBean.getName();
ComponentDescription bean = moduleDescription.getComponentByName(beanName);
if (appclient && bean == null) {
for (final ComponentDescription component : deploymentUnit
.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
if (component.getComponentName().equals(beanName)) {
bean = component;
break;
}
}
}
if (!(bean instanceof SessionBeanComponentDescription)) {
//TODO: this is a hack to deal with descriptor merging
//if this is a GenericBeanMetadata it may actually represent an MDB
return;
}
SessionBeanComponentDescription sessionBeanDescription = (SessionBeanComponentDescription) bean;
sessionBeanDescription.setDeploymentDescriptorEnvironment(new DeploymentDescriptorEnvironment("java:comp/env/", sessionBean));
// mapped-name
sessionBeanDescription.setMappedName(sessionBean.getMappedName());
// local business interface views
final BusinessLocalsMetaData businessLocals = sessionBean.getBusinessLocals();
if (businessLocals != null && !businessLocals.isEmpty()) {
sessionBeanDescription.addLocalBusinessInterfaceViews(businessLocals);
}
final String local = sessionBean.getLocal();
if (local != null) {
sessionBeanDescription.addEjbLocalObjectView(local);
}
final String remote = sessionBean.getRemote();
if (remote != null) {
sessionBeanDescription.addEjbObjectView(remote);
}
// remote business interface views
final BusinessRemotesMetaData businessRemotes = sessionBean.getBusinessRemotes();
if (businessRemotes != null && !businessRemotes.isEmpty()) {
sessionBeanDescription.addRemoteBusinessInterfaceViews(businessRemotes);
}
// process Enterprise Beans 3.1 specific session bean description
if (sessionBean instanceof SessionBean31MetaData) {
this.processSessionBean31((SessionBean31MetaData) sessionBean, sessionBeanDescription);
}
}
private void processSessionBean31(final SessionBean31MetaData sessionBean31MetaData, final SessionBeanComponentDescription sessionBeanComponentDescription) {
// no-interface view
if (sessionBean31MetaData.isNoInterfaceBean()) {
sessionBeanComponentDescription.addNoInterfaceView();
}
}
}
| 5,882 | 43.908397 | 194 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/AbstractEjbXmlDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData;
/**
* User: jpai
*/
public abstract class AbstractEjbXmlDescriptorProcessor<T extends EnterpriseBeanMetaData> implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
// get the deployment unit
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// find the Jakarta Enterprise Beans jar metadata and start processing it
EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData == null) {
return;
}
// process Jakarta Enterprise Beans
EnterpriseBeansMetaData ejbs = ejbJarMetaData.getEnterpriseBeans();
if (ejbs != null && !ejbs.isEmpty()) {
for (EnterpriseBeanMetaData ejb : ejbs) {
if (this.getMetaDataType().isInstance(ejb)) {
this.processBeanMetaData((T) ejb, phaseContext);
}
}
}
}
protected abstract Class<T> getMetaDataType();
protected abstract void processBeanMetaData(T beanMetaData, DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException;
}
| 2,807 | 42.2 | 142 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/AssemblyDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.deployment.EjbJarDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
/**
* Processes the assembly-descriptor section of a ejb-jar.xml of an Jakarta Enterprise Beans deployment and updates the {@link EjbJarDescription}
* appropriately with this info.
*
* @author Jaikiran Pai
* @author Stuart Douglas
*/
public class AssemblyDescriptorProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
// get the deployment unit
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// find the Jakarta Enterprise Beans jar metadata and start processing it
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData == null) {
return;
}
// process assembly-descriptor stuff
final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
// get hold of the ejb jar description (to which we'll be adding this assembly description metadata)
final EjbJarDescription ejbJarDescription = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
// process security-role(s)
this.processSecurityRoles(assemblyDescriptor.getSecurityRoles(), ejbJarDescription);
final MessageDestinationsMetaData destinations = assemblyDescriptor.getMessageDestinations();
if(destinations != null) {
processMessageDestinations(destinations, eeModuleDescription);
}
}
}
private void processMessageDestinations(final MessageDestinationsMetaData destinations, final EEModuleDescription eeModuleDescription) {
for(final MessageDestinationMetaData destination : destinations) {
//TODO: should these be two separate metadata attributes?
if(destination.getJndiName() != null) {
eeModuleDescription.addMessageDestination(destination.getName(), destination.getJndiName());
} else if(destination.getLookupName() != null) {
eeModuleDescription.addMessageDestination(destination.getName(), destination.getLookupName());
}
}
}
private void processSecurityRoles(final SecurityRolesMetaData securityRoles, final EjbJarDescription ejbJarDescription) {
if (securityRoles == null || securityRoles.isEmpty()) {
return;
}
for (final SecurityRoleMetaData securityRole : securityRoles) {
final String roleName = securityRole.getRoleName();
if (roleName != null && !roleName.trim().isEmpty()) {
// Augment the security roles
// Enterprise Beans 3.1 spec, section 17.3.1:
// The Bean Provider may augment the set of security roles defined for the application by annotations in
// this way by means of the security-role deployment descriptor element.
ejbJarDescription.addSecurityRole(roleName);
}
}
}
}
| 5,182 | 48.836538 | 145 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/DeploymentDescriptorMethodProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import java.lang.reflect.Method;
import jakarta.interceptor.InvocationContext;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.component.stateless.StatelessComponentDescription;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndexUtil;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.AroundInvokeMetaData;
import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
import org.jboss.modules.Module;
/**
* Deployment descriptor that resolves interceptor methods defined in ejb-jar.xml that could not be resolved at
* DD parse time.
*
* @author Stuart Douglas
*/
public class DeploymentDescriptorMethodProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (eeModuleDescription != null) {
for (final ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
if (component instanceof EJBComponentDescription) {
try {
if (component instanceof SessionBeanComponentDescription || component instanceof MessageDrivenComponentDescription)
handleSessionBean((EJBComponentDescription) component, module, reflectionIndex);
if (component instanceof StatelessComponentDescription || component instanceof MessageDrivenComponentDescription) {
handleStatelessSessionBean((EJBComponentDescription) component, module, reflectionIndex);
}
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, component.getComponentName());
}
}
}
}
}
/**
* Handles setting up the ejbCreate and ejbRemove methods for stateless session beans and MDB's
*
* @param component The component
* @param module The module
* @param reflectionIndex The reflection index
*/
private void handleStatelessSessionBean(final EJBComponentDescription component, final Module module, final DeploymentReflectionIndex reflectionIndex) throws ClassNotFoundException, DeploymentUnitProcessingException {
final Class<?> componentClass = ClassLoadingUtils.loadClass(component.getComponentClassName(), module);
final MethodIdentifier ejbCreateId = MethodIdentifier.getIdentifier(void.class, "ejbCreate");
final Method ejbCreate = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentClass, ejbCreateId);
if (ejbCreate != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPostConstruct(ejbCreateId);
component.addInterceptorMethodOverride(ejbCreate.getDeclaringClass().getName(), builder.build());
}
final MethodIdentifier ejbRemoveId = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
final Method ejbRemove = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentClass, ejbRemoveId);
if (ejbRemove != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPreDestroy(ejbRemoveId);
component.addInterceptorMethodOverride(ejbRemove.getDeclaringClass().getName(), builder.build());
}
}
private void handleSessionBean(final EJBComponentDescription component, final Module module, final DeploymentReflectionIndex reflectionIndex) throws ClassNotFoundException, DeploymentUnitProcessingException {
if (component.getDescriptorData() == null) {
return;
}
final Class<?> componentClass = ClassLoadingUtils.loadClass(component.getComponentClassName(), module);
final EnterpriseBeanMetaData metaData = component.getDescriptorData();
AroundInvokesMetaData aroundInvokes = null;
if (metaData instanceof SessionBeanMetaData) {
aroundInvokes = ((SessionBeanMetaData) metaData).getAroundInvokes();
} else if (metaData instanceof MessageDrivenBeanMetaData) {
aroundInvokes = ((MessageDrivenBeanMetaData) metaData).getAroundInvokes();
}
if (aroundInvokes != null) {
for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = aroundInvoke.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
builder.setAroundInvoke(methodIdentifier);
if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) {
final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
component.addInterceptorMethodOverride(className, builder.build());
} else {
component.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build());
}
}
}
// post-construct(s) of the interceptor configured (if any) in the deployment descriptor
LifecycleCallbacksMetaData postConstructs = metaData.getPostConstructs();
if (postConstructs != null) {
for (LifecycleCallbackMetaData postConstruct : postConstructs) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
String methodName = postConstruct.getMethodName();
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
builder.setPostConstruct(methodIdentifier);
if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) {
final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
component.addInterceptorMethodOverride(className, builder.build());
} else {
component.addInterceptorMethodOverride(postConstruct.getClassName(), builder.build());
}
}
}
// pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
final LifecycleCallbacksMetaData preDestroys = metaData.getPreDestroys();
if (preDestroys != null) {
for (final LifecycleCallbackMetaData preDestroy : preDestroys) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
final String methodName = preDestroy.getMethodName();
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
builder.setPreDestroy(methodIdentifier);
if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) {
final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
component.addInterceptorMethodOverride(className, builder.build());
} else {
component.addInterceptorMethodOverride(preDestroy.getClassName(), builder.build());
}
}
}
if (component.isStateful()) {
final SessionBeanMetaData sessionBeanMetadata = (SessionBeanMetaData) metaData;
// pre-passivate(s) of the interceptor configured (if any) in the deployment descriptor
final LifecycleCallbacksMetaData prePassivates = sessionBeanMetadata.getPrePassivates();
if (prePassivates != null) {
for (final LifecycleCallbackMetaData prePassivate : prePassivates) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
final String methodName = prePassivate.getMethodName();
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
builder.setPrePassivate(methodIdentifier);
if (prePassivate.getClassName() == null || prePassivate.getClassName().isEmpty()) {
final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
component.addInterceptorMethodOverride(className, builder.build());
} else {
component.addInterceptorMethodOverride(prePassivate.getClassName(), builder.build());
}
}
}
final LifecycleCallbacksMetaData postActivates = sessionBeanMetadata.getPostActivates();
if (postActivates != null) {
for (final LifecycleCallbackMetaData postActivate : postActivates) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
final String methodName = postActivate.getMethodName();
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
builder.setPostActivate(methodIdentifier);
if (postActivate.getClassName() == null || postActivate.getClassName().isEmpty()) {
final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
component.addInterceptorMethodOverride(className, builder.build());
} else {
component.addInterceptorMethodOverride(postActivate.getClassName(), builder.build());
}
}
}
}
}
}
| 12,929 | 58.585253 | 221 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/dd/MethodResolutionUtils.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.dd;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.MethodMetaData;
import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
/**
* @author Stuart Douglas
*/
public class MethodResolutionUtils {
public static Method resolveMethod(final NamedMethodMetaData methodData, final Class<?> componentClass, final DeploymentReflectionIndex reflectionIndex) throws DeploymentUnitProcessingException {
return resolveMethod(methodData.getMethodName(), methodData.getMethodParams(), componentClass, reflectionIndex);
}
public static Method resolveMethod(final MethodMetaData methodData, final Class<?> componentClass, final DeploymentReflectionIndex reflectionIndex) throws DeploymentUnitProcessingException {
return resolveMethod(methodData.getMethodName(), methodData.getMethodParams(), componentClass, reflectionIndex);
}
public static Collection<Method> resolveMethods(final NamedMethodMetaData methodData, final Class<?> componentClass, final DeploymentReflectionIndex reflectionIndex) throws DeploymentUnitProcessingException {
return resolveMethods(methodData.getMethodName(), methodData.getMethodParams(), componentClass, reflectionIndex);
}
public static Method resolveMethod(final String methodName, final MethodParametersMetaData parameters, final Class<?> componentClass, final DeploymentReflectionIndex reflectionIndex) throws DeploymentUnitProcessingException {
final Collection<Method> method = resolveMethods(methodName, parameters, componentClass, reflectionIndex);
if(method.size() >1) {
throw EjbLogger.ROOT_LOGGER.moreThanOneMethodWithSameNameOnComponent(methodName, componentClass);
}
return method.iterator().next();
}
public static Collection<Method> resolveMethods(final String methodName, final MethodParametersMetaData parameters, final Class<?> componentClass, final DeploymentReflectionIndex reflectionIndex) throws DeploymentUnitProcessingException {
Class<?> clazz = componentClass;
while (clazz != Object.class && clazz != null) {
final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz);
if (parameters == null) {
final Collection<Method> methods = classIndex.getAllMethods(methodName);
if(!methods.isEmpty()) {
return methods;
}
} else {
final Collection<Method> methods = classIndex.getAllMethods(methodName, parameters.size());
for (final Method method : methods) {
boolean match = true;
for (int i = 0; i < method.getParameterCount(); ++i) {
if (!method.getParameterTypes()[i].getName().equals(parameters.get(i))) {
match = false;
break;
}
}
if (match) {
return Collections.singleton(method);
}
}
}
clazz = clazz.getSuperclass();
}
throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass != null ? componentClass.getName() : "null", methodName);
}
}
| 4,725 | 49.817204 | 242 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/security/JaccEjbDeploymentProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.security;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_CONFIGURATION;
import jakarta.security.jacc.PolicyConfiguration;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.EEModuleConfiguration;
import org.jboss.as.ee.security.AbstractSecurityDeployer;
import org.jboss.as.ee.security.JaccService;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbSecurityDeployer;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
/**
* A {@code DeploymentUnitProcessor} for JACC policies.
*
* @author Marcus Moyses
* @author Anil Saldhana
*/
public class JaccEjbDeploymentProcessor implements DeploymentUnitProcessor {
private final String jaccCapabilityName;
public JaccEjbDeploymentProcessor(final String jaccCapabilityName) {
this.jaccCapabilityName = jaccCapabilityName;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentContainsEjbs(deploymentUnit) == false) {
return;
}
AbstractSecurityDeployer<?> deployer = null;
deployer = new EjbSecurityDeployer();
JaccService<?> service = deployer.deploy(deploymentUnit);
if (service != null) {
final DeploymentUnit parentDU = deploymentUnit.getParent();
// Jakarta Enterprise Beans maybe included directly in war deployment
ServiceName jaccServiceName = getJaccServiceName(deploymentUnit);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
ServiceBuilder<?> builder = serviceTarget.addService(jaccServiceName, service);
if (parentDU != null) {
// add dependency to parent policy
builder.addDependency(parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class,
service.getParentPolicyInjector());
}
CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
builder.requires(capabilitySupport.getCapabilityServiceName(jaccCapabilityName));
builder.setInitialMode(Mode.ACTIVE).install();
}
}
private static boolean deploymentContainsEjbs(final DeploymentUnit deploymentUnit) {
final EEModuleConfiguration moduleConfiguration = deploymentUnit.getAttachment(EE_MODULE_CONFIGURATION);
for (ComponentConfiguration current : moduleConfiguration.getComponentConfigurations()) {
if (current.getComponentDescription() instanceof EJBComponentDescription) {
return true;
}
}
return false;
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
AbstractSecurityDeployer<?> deployer = null;
deployer = new EjbSecurityDeployer();
deployer.undeploy(deploymentUnit);
// Jakarta Enterprise Beans maybe included directly in war deployment
ServiceName jaccServiceName = getJaccServiceName(deploymentUnit);
ServiceRegistry registry = deploymentUnit.getServiceRegistry();
if(registry != null){
ServiceController<?> serviceController = registry.getService(jaccServiceName);
if (serviceController != null) {
serviceController.setMode(ServiceController.Mode.REMOVE);
}
}
}
private ServiceName getJaccServiceName(DeploymentUnit deploymentUnit){
final DeploymentUnit parentDU = deploymentUnit.getParent();
// Jakarta Enterprise Beans maybe included directly in war deployment
ServiceName jaccServiceName = deploymentUnit.getServiceName().append(JaccService.SERVICE_NAME).append("ejb");
//Qualify the service name properly with parent DU
if(parentDU != null) {
jaccServiceName = jaccServiceName.append(parentDU.getName());
}
return jaccServiceName;
}
}
| 5,779 | 44.15625 | 126 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/SecurityRolesMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.structure.Attachments;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
import org.jboss.metadata.merge.javaee.spec.SecurityRolesMetaDataMerger;
/**
* A processor which sets the {@link EJBComponentDescription#setSecurityRoles(org.jboss.metadata.javaee.spec.SecurityRolesMetaData)}
* with the principal to role mapping defined in the assembly descriptor section of the jboss-ejb3.xml via elements from
* urn:security-roles namespace.
* <p/>
* Additionally, we also merge the security roles metadata from the ear.
*
* @author Jaikiran Pai
* @see {@link org.jboss.as.ejb3.security.parser.SecurityRoleMetaDataParser}
*/
public class SecurityRolesMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public SecurityRolesMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(DeploymentUnit deploymentUnit, EEApplicationClasses applicationClasses, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, EJBComponentDescription description) throws DeploymentUnitProcessingException {
// no-op
}
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, EJBComponentDescription ejbComponentDescription) throws DeploymentUnitProcessingException {
final SecurityRolesMetaData roleMappings = new SecurityRolesMetaData();
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData != null) {
final AssemblyDescriptorMetaData assemblyDescriptorMetaData = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyDescriptorMetaData != null) {
// get the mapping between principal to rolename, defined in the assembly descriptor
final List<SecurityRoleMetaData> securityRoleMetaDatas = assemblyDescriptorMetaData.getAny(SecurityRoleMetaData.class);
if (securityRoleMetaDatas != null) {
for (SecurityRoleMetaData securityRoleMetaData : securityRoleMetaDatas) {
roleMappings.add(securityRoleMetaData);
}
}
}
}
//Let us look at the ear metadata also
DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA);
if (earMetaData != null) {
SecurityRolesMetaData earSecurityRolesMetaData = earMetaData.getSecurityRoles();
SecurityRolesMetaDataMerger.merge(roleMappings, roleMappings, earSecurityRolesMetaData);
}
}
// add it to the Jakarta Enterprise Beans component description
ejbComponentDescription.setSecurityRoles(roleMappings);
}
}
| 4,695 | 50.604396 | 266 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/TransactionAttributeMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.util.MethodInfoHelper;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.TransactionTimeout;
import org.jboss.metadata.ejb.jboss.ejb3.TransactionTimeoutMetaData;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
import org.jboss.metadata.ejb.spec.ContainerTransactionsMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.metadata.ejb.spec.MethodMetaData;
import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
import org.jboss.metadata.ejb.spec.MethodsMetaData;
/**
* Because trans-attr and trans-timeout are both contained in container-transaction
* process both annotations and container-transaction metadata in one spot.
*
* @author Stuart Douglas
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public class TransactionAttributeMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public TransactionAttributeMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
}
private void processTransactionAttributeAnnotation(final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, MethodInterfaceType methodIntf, final EJBComponentDescription componentConfiguration) {
final RuntimeAnnotationInformation<TransactionAttributeType> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, TransactionAttribute.class);
for (Map.Entry<String, List<TransactionAttributeType>> entry : data.getClassAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
//we can't specify both methodIntf and class name
final String className = methodIntf == null ? entry.getKey() : null;
componentConfiguration.getTransactionAttributes().setAttribute(methodIntf, className, entry.getValue().get(0));
}
}
for (Map.Entry<Method, List<TransactionAttributeType>> entry : data.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
String[] parameterTypes = MethodInfoHelper.getCanonicalParameterTypes(entry.getKey());
componentConfiguration.getTransactionAttributes().setAttribute(methodIntf, entry.getValue().get(0), entry.getKey().getDeclaringClass().getName(), entry.getKey().getName(), parameterTypes);
}
}
}
private void processTransactionTimeoutAnnotation(final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, MethodInterfaceType methodIntf, final EJBComponentDescription componentConfiguration) {
final RuntimeAnnotationInformation<Integer> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, TransactionTimeout.class);
for (Map.Entry<String, List<Integer>> entry : data.getClassAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
//we can't specify both methodIntf and class name
final String className = methodIntf == null ? entry.getKey() : null;
componentConfiguration.getTransactionTimeouts().setAttribute(methodIntf, className, entry.getValue().get(0));
}
}
for (Map.Entry<Method, List<Integer>> entry : data.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
final String className = entry.getKey().getDeclaringClass().getName();
String[] parameterTypes = MethodInfoHelper.getCanonicalParameterTypes(entry.getKey());
componentConfiguration.getTransactionTimeouts().setAttribute(methodIntf, entry.getValue().get(0), className, entry.getKey().getName(), parameterTypes);
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentDescription) throws DeploymentUnitProcessingException {
// CMT Tx attributes
//DO NOT USE componentConfiguration.getDescriptorData()
//It will return null if there is no <enterprise-beans/> declaration even if there is an assembly descriptor entry
EjbJarMetaData ejbJarMetadata = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetadata != null) {
boolean wildcardAttributeSet = false;
boolean wildcardTimeoutSet = false;
ContainerTransactionMetaData global = null;
final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetadata.getAssemblyDescriptor();
if(assemblyDescriptor != null) {
final ContainerTransactionsMetaData globalTransactions = assemblyDescriptor.getContainerTransactionsByEjbName("*");
if (globalTransactions != null) {
if (globalTransactions.size() > 1) {
throw EjbLogger.ROOT_LOGGER.mustOnlyBeSingleContainerTransactionElementWithWildcard();
}
global = globalTransactions.iterator().next();
for(MethodMetaData method : global.getMethods()) {
if(!method.getMethodName().equals("*")) {
throw EjbLogger.ROOT_LOGGER.wildcardContainerTransactionElementsMustHaveWildcardMethodName();
}
}
}
final ContainerTransactionsMetaData containerTransactions = assemblyDescriptor.getContainerTransactionsByEjbName(componentDescription.getEJBName());
if (containerTransactions != null) {
for (final ContainerTransactionMetaData containerTx : containerTransactions) {
final TransactionAttributeType txAttr = containerTx.getTransAttribute();
final Integer timeout = timeout(containerTx);
final MethodsMetaData methods = containerTx.getMethods();
for (final MethodMetaData method : methods) {
final String methodName = method.getMethodName();
final MethodInterfaceType defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodInterfaceType.MessageEndpoint : MethodInterfaceType.Bean;
final MethodInterfaceType methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
if (methodName.equals("*")) {
if (txAttr != null){
wildcardAttributeSet = true;
componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, txAttr);
}
if (timeout != null) {
wildcardTimeoutSet = true;
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
}
} else {
final MethodParametersMetaData methodParams = method.getMethodParams();
// update the session bean description with the tx attribute info
if (methodParams == null) {
if (txAttr != null)
componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, methodName);
if (timeout != null)
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, methodName);
} else {
if (txAttr != null)
componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, null, methodName, this.getMethodParams(methodParams));
if (timeout != null)
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, null, methodName, this.getMethodParams(methodParams));
}
}
}
}
}
}
if(global != null) {
if(!wildcardAttributeSet && global.getTransAttribute() != null) {
for(MethodMetaData method : global.getMethods()) {
final MethodInterfaceType defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodInterfaceType.MessageEndpoint : MethodInterfaceType.Bean;
final MethodInterfaceType methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, global.getTransAttribute());
}
}
final Integer timeout = timeout(global);
if(!wildcardTimeoutSet && timeout != null) {
for(MethodMetaData method : global.getMethods()) {
final MethodInterfaceType defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodInterfaceType.MessageEndpoint : MethodInterfaceType.Bean;
final MethodInterfaceType methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
}
}
}
}
}
private static Integer timeout(final ContainerTransactionMetaData containerTransaction) {
final List<TransactionTimeoutMetaData> transactionTimeouts = containerTransaction.getAny(TransactionTimeoutMetaData.class);
if (transactionTimeouts == null || transactionTimeouts.isEmpty())
return null;
final TransactionTimeoutMetaData transactionTimeout = transactionTimeouts.get(0);
final TimeUnit unit = transactionTimeout.getUnit() == null ? TimeUnit.SECONDS : transactionTimeout.getUnit();
return (int)unit.toSeconds(transactionTimeout.getTimeout());
}
}
| 13,268 | 63.412621 | 307 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/MissingMethodPermissionsDenyAccessMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* A {@link org.jboss.as.server.deployment.DeploymentUnitProcessor} which processes EJB deployments and configures the
* <code>missing-method-permissions-deny-access</code> on the {@link EJBComponentDescription}s
*
* @author Jaikiran Pai
*/
public class MissingMethodPermissionsDenyAccessMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
private final AtomicBoolean denyAccessByDefault;
public MissingMethodPermissionsDenyAccessMergingProcessor(AtomicBoolean denyAccessByDefault) {
super(EJBComponentDescription.class);
this.denyAccessByDefault = denyAccessByDefault;
}
@Override
protected void handleAnnotations(DeploymentUnit deploymentUnit, EEApplicationClasses applicationClasses, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, EJBComponentDescription description) throws DeploymentUnitProcessingException {
// we don't support annotations (for now).
}
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, EJBComponentDescription description) throws DeploymentUnitProcessingException {
Boolean missingMethodPermissionsDenyAccess = null;
Boolean missingMethodPermissionsDenyAccessApplicableForAllBeans = null;
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData != null) {
final AssemblyDescriptorMetaData assemblyMetadata = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyMetadata != null) {
final List<EJBBoundSecurityMetaData> securityMetaDatas = assemblyMetadata.getAny(EJBBoundSecurityMetaData.class);
if (securityMetaDatas != null) {
for (final EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
if (securityMetaData.getEjbName().equals(description.getComponentName())) {
missingMethodPermissionsDenyAccess = securityMetaData.getMissingMethodPermissionsDenyAccess();
break;
}
// check missing-method-permissions-excluded-mode that's applicable for all EJBs.
if (securityMetaData.getEjbName().equals("*")) {
missingMethodPermissionsDenyAccessApplicableForAllBeans = securityMetaData.getMissingMethodPermissionsDenyAccess();
continue;
}
}
}
}
}
if (missingMethodPermissionsDenyAccess != null) {
description.setMissingMethodPermissionsDenyAccess(missingMethodPermissionsDenyAccess);
} else if (missingMethodPermissionsDenyAccessApplicableForAllBeans != null) {
description.setMissingMethodPermissionsDenyAccess(missingMethodPermissionsDenyAccessApplicableForAllBeans);
} else {
description.setMissingMethodPermissionsDenyAccess(this.denyAccessByDefault.get());
}
}
}
| 4,894 | 52.791209 | 266 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/HomeViewMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.modules.Module;
import jakarta.ejb.LocalHome;
import jakarta.ejb.RemoteHome;
import java.lang.reflect.Method;
import java.util.Collection;
/**
* Merging processor for home and local home views
*
* @author Stuart Douglas
*/
public class HomeViewMergingProcessor implements DeploymentUnitProcessor {
private final boolean appclient;
public HomeViewMergingProcessor(final boolean appclient) {
this.appclient = appclient;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if(eeModuleDescription == null) {
return;
}
final Collection<ComponentDescription> componentConfigurations = eeModuleDescription.getComponentDescriptions();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
for (ComponentDescription componentConfiguration : componentConfigurations) {
if (componentConfiguration instanceof SessionBeanComponentDescription) {
try {
processComponentConfig(deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentConfiguration);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failToMergeData(componentConfiguration.getComponentName(), e);
}
}
}
if (appclient) {
for (ComponentDescription componentDescription : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
if (componentDescription instanceof SessionBeanComponentDescription) {
try {
processComponentConfig(deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (SessionBeanComponentDescription) componentDescription);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failToMergeData(componentDescription.getComponentName(), e);
}
}
}
}
}
private void processComponentConfig(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException, ClassNotFoundException {
String home = null;
String localHome = null;
//first check for annotations
if (!MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(description.getComponentClassName());
//we only care about annotations on the bean class itself
if (clazz != null) {
final ClassAnnotationInformation<LocalHome, String> localAnnotations = clazz.getAnnotationInformation(LocalHome.class);
if (localAnnotations != null
&& !localAnnotations.getClassLevelAnnotations().isEmpty()) {
localHome = localAnnotations.getClassLevelAnnotations().get(0);
if (description.getEjbLocalView() == null) {
// If the local home is specified via annotation then the corresponding business interface is implied
// by the signature of the create method
// See EJB 3.1 21.4.5
final String localClassName = this.inferLocalInterfaceFromLocalHome(localHome, module,
deploymentReflectionIndex, description);
description.addEjbLocalObjectView(localClassName);
}
}
final ClassAnnotationInformation<RemoteHome, String> remoteAnnotations = clazz.getAnnotationInformation(RemoteHome.class);
if (remoteAnnotations != null
&& !remoteAnnotations.getClassLevelAnnotations().isEmpty()) {
home = remoteAnnotations.getClassLevelAnnotations().get(0);
if (description.getEjbRemoteView() == null) {
// If the remote home is specified via annotation then the corresponding business interface is implied
// by the signature of the create method
// See EJB 3.1 21.4.5
final String remoteClassName = this.inferRemoteInterfaceFromHome(home, module,
deploymentReflectionIndex, description);
description.addEjbObjectView(remoteClassName);
}
}
}
}
//now allow the annotations to be overridden by the DD
final SessionBeanMetaData descriptorData = description.getDescriptorData();
if (descriptorData != null) {
if (descriptorData.getHome() != null) {
home = descriptorData.getHome();
}
if (descriptorData.getLocalHome() != null) {
localHome = descriptorData.getLocalHome();
}
}
if (localHome != null) {
description.addLocalHome(localHome);
}
if (home != null) {
description.addRemoteHome(home);
}
// finally see if we have to infer the remote or local interface from the home/local home views, respectively
if (description.getEjbHomeView() != null && description.getEjbRemoteView() == null) {
final String remoteClassName = this.inferRemoteInterfaceFromHome(description.getEjbHomeView().getViewClassName(), module, deploymentReflectionIndex, description);
description.addEjbObjectView(remoteClassName);
}
if (description.getEjbLocalHomeView() != null && description.getEjbLocalView() == null) {
final String localClassName = this.inferLocalInterfaceFromLocalHome(description.getEjbLocalHomeView().getViewClassName(), module, deploymentReflectionIndex, description);
description.addEjbLocalObjectView(localClassName);
}
}
private String inferRemoteInterfaceFromHome(final String homeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException {
final Class<?> homeClass = module.getClassLoader().loadClass(homeClassName);
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(homeClass);
Class<?> remote = null;
for (final Method method : (Iterable<Method>)index.getMethods()) {
if (method.getName().startsWith("create")) {
if (remote != null && remote != method.getReturnType()) {
throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(homeClass);
}
remote = method.getReturnType();
}
}
if(remote == null) {
throw EjbLogger.ROOT_LOGGER.couldNotDetermineRemoteInterfaceFromHome(homeClassName, description.getEJBName());
}
return remote.getName();
}
private String inferLocalInterfaceFromLocalHome(final String localHomeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException {
final Class<?> localHomeClass = module.getClassLoader().loadClass(localHomeClassName);
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(localHomeClass);
Class<?> localClass = null;
for (final Method method : (Iterable<Method>)index.getMethods()) {
if (method.getName().startsWith("create")) {
if (localClass != null && localClass != method.getReturnType()) {
throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(localHomeClass);
}
localClass = method.getReturnType();
}
}
if (localClass == null) {
throw EjbLogger.ROOT_LOGGER.couldNotDetermineLocalInterfaceFromLocalHome(localHomeClassName, description.getEJBName());
}
return localClass.getName();
}
}
| 10,934 | 53.402985 | 321 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/StatefulTimeoutMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData;
import jakarta.ejb.StatefulTimeout;
import java.util.concurrent.TimeUnit;
/**
* Handles the {@link jakarta.annotation.security.RunAs} annotation merging
*
* @author Stuart DouglasrunAs
*/
public class StatefulTimeoutMergingProcessor extends AbstractMergingProcessor<StatefulComponentDescription> {
public StatefulTimeoutMergingProcessor() {
super(StatefulComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<StatefulTimeout, StatefulTimeoutInfo> timeout = clazz.getAnnotationInformation(StatefulTimeout.class);
if (timeout == null) {
return;
}
if (!timeout.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setStatefulTimeout(timeout.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final SessionBeanMetaData data = componentConfiguration.getDescriptorData();
if (data == null) {
return;
}
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData sessionBean31MetaData = (SessionBean31MetaData) data;
final StatefulTimeoutMetaData statefulTimeout = sessionBean31MetaData.getStatefulTimeout();
if (statefulTimeout != null) {
TimeUnit unit = TimeUnit.MINUTES;
if (statefulTimeout.getUnit() != null) {
unit = statefulTimeout.getUnit();
}
componentConfiguration.setStatefulTimeout(new StatefulTimeoutInfo(statefulTimeout.getTimeout(), unit));
}
}
}
}
| 4,163 | 47.988235 | 312 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/RemoveMethodMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.metadata.ejb.spec.RemoveMethodMetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import jakarta.ejb.Remove;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Class that can merge {@link jakarta.ejb.Remove}
*
* @author Stuart Douglas
*/
public class RemoveMethodMergingProcessor extends AbstractMergingProcessor<StatefulComponentDescription> {
public RemoveMethodMergingProcessor() {
super(StatefulComponentDescription.class);
}
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final RuntimeAnnotationInformation<Boolean> removeMethods = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Remove.class);
for (Map.Entry<Method, List<Boolean>> entry : removeMethods.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
final Boolean retainIfException = entry.getValue().get(0);
final MethodIdentifier removeMethodIdentifier = MethodIdentifier.getIdentifierForMethod(entry.getKey());
componentConfiguration.addRemoveMethod(removeMethodIdentifier, retainIfException);
}
}
}
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
SessionBeanMetaData beanMetaData = componentConfiguration.getDescriptorData();
if (beanMetaData == null) {
return;
}
if (beanMetaData.getRemoveMethods() == null || beanMetaData.getRemoveMethods().isEmpty()) {
return;
}
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final Set<MethodIdentifier> annotationRemoveMethods = new HashSet<MethodIdentifier>();
for(final StatefulComponentDescription.StatefulRemoveMethod method : componentConfiguration.getRemoveMethods()) {
annotationRemoveMethods.add(method.getMethodIdentifier());
}
//We loop through twice, as the more more general form with no parameters is applied to all methods with that name
//while the method that specifies the actual parameters override this
for (final RemoveMethodMetaData removeMethod : beanMetaData.getRemoveMethods()) {
if(removeMethod.getBeanMethod().getMethodParams() == null) {
final NamedMethodMetaData methodData = removeMethod.getBeanMethod();
final Collection<Method> methods = MethodResolutionUtils.resolveMethods(methodData, componentClass, reflectionIndex);
for(final Method method : methods) {
final Boolean retainIfException = removeMethod.getRetainIfException();
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
if(retainIfException == null) {
//if this is null we have to allow annotation values of retainIfException to take precidence
if(!annotationRemoveMethods.contains(methodIdentifier)) {
componentConfiguration.addRemoveMethod(methodIdentifier, false);
}
} else {
componentConfiguration.addRemoveMethod(methodIdentifier, retainIfException);
}
}
}
}
for (final RemoveMethodMetaData removeMethod : beanMetaData.getRemoveMethods()) {
if(removeMethod.getBeanMethod().getMethodParams() != null) {
final NamedMethodMetaData methodData = removeMethod.getBeanMethod();
final Collection<Method> methods = MethodResolutionUtils.resolveMethods(methodData, componentClass, reflectionIndex);
for(final Method method : methods) {
final Boolean retainIfException = removeMethod.getRetainIfException();
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
if(retainIfException == null) {
//if this is null we have to allow annotation values of retainIfException to take precidence
if(!annotationRemoveMethods.contains(methodIdentifier)) {
componentConfiguration.addRemoveMethod(methodIdentifier, false);
}
} else {
componentConfiguration.addRemoveMethod(methodIdentifier, retainIfException);
}
}
}
}
}
}
| 6,915 | 54.328 | 312 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/CacheMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.cache.CacheInfo;
import org.jboss.as.ejb3.cache.EJBBoundCacheMetaData;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
public class CacheMergingProcessor extends AbstractMergingProcessor<StatefulComponentDescription> {
public CacheMergingProcessor() {
super(StatefulComponentDescription.class);
}
@Override
protected void handleAnnotations(DeploymentUnit deploymentUnit, EEApplicationClasses applicationClasses,
DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass,
StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<Cache, CacheInfo> cache = clazz.getAnnotationInformation(Cache.class);
if (cache == null) {
return;
}
if (!cache.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setCache(cache.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit,
DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass,
StatefulComponentDescription description) throws DeploymentUnitProcessingException {
final String ejbName = description.getEJBName();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null) {
return;
}
final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
if (assemblyDescriptor == null) {
return;
}
// get the pool metadata
final List<EJBBoundCacheMetaData> caches = assemblyDescriptor.getAny(EJBBoundCacheMetaData.class);
String cacheName = null;
if (caches != null) {
for (final EJBBoundCacheMetaData cacheMetaData : caches) {
// if this applies for all Jakarta Enterprise Beans and if there isn't a pool name already explicitly specified
// for the specific bean (i.e. via an ejb-name match)
if ("*".equals(cacheMetaData.getEjbName()) && cacheName == null) {
cacheName = cacheMetaData.getCacheName();
} else if (ejbName.equals(cacheMetaData.getEjbName())) {
cacheName = cacheMetaData.getCacheName();
}
}
}
if (cacheName != null) {
description.setCache(new CacheInfo(cacheName));
}
}
}
| 4,540 | 45.336735 | 127 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/MethodPermissionsMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.security.EJBMethodSecurityAttribute;
import org.jboss.as.ejb3.security.EjbJaccConfigurator;
import org.jboss.as.ejb3.util.MethodInfoHelper;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.metadata.ejb.spec.MethodMetaData;
import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
import org.jboss.metadata.ejb.spec.MethodsMetaData;
/**
* Handles the {@link jakarta.annotation.security.RolesAllowed} {@link DenyAll} {@link jakarta.annotation.security.PermitAll} annotations
* <p/>
* Also processes the <method-permission> elements of an Jakarta Enterprise Beans and sets up appropriate security permissions on the Jakarta Enterprise Beans.
* <p/>
* This processor should be run *after* all the views of the Jakarta Enterprise Beans have been identified and set in the {@link EJBComponentDescription}
*
* @author Stuart Douglas
*/
public class MethodPermissionsMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public MethodPermissionsMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final RuntimeAnnotationInformation<Boolean> permitData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, PermitAll.class);
for (Map.Entry<String, List<Boolean>> entry : permitData.getClassAnnotations().entrySet()) {
description.getAnnotationMethodPermissions().setAttribute(null, entry.getKey(), EJBMethodSecurityAttribute.permitAll());
}
for (Map.Entry<Method, List<Boolean>> entry : permitData.getMethodAnnotations().entrySet()) {
final Method method = entry.getKey();
description.getAnnotationMethodPermissions().setAttribute(null, EJBMethodSecurityAttribute.permitAll(), method.getDeclaringClass().getName(), method.getName(), MethodInfoHelper.getCanonicalParameterTypes(method));
}
final RuntimeAnnotationInformation<String[]> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, RolesAllowed.class);
for (Map.Entry<String, List<String[]>> entry : data.getClassAnnotations().entrySet()) {
description.getAnnotationMethodPermissions().setAttribute(null, entry.getKey(), EJBMethodSecurityAttribute.rolesAllowed(new HashSet<String>(Arrays.<String>asList(entry.getValue().get(0)))));
}
for (Map.Entry<Method, List<String[]>> entry : data.getMethodAnnotations().entrySet()) {
final Method method = entry.getKey();
description.getAnnotationMethodPermissions().setAttribute(null, EJBMethodSecurityAttribute.rolesAllowed(new HashSet<String>(Arrays.<String>asList(entry.getValue().get(0)))), method.getDeclaringClass().getName(), method.getName(), MethodInfoHelper.getCanonicalParameterTypes(method));
}
final RuntimeAnnotationInformation<Boolean> denyData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, DenyAll.class);
for (Map.Entry<String, List<Boolean>> entry : denyData.getClassAnnotations().entrySet()) {
description.getAnnotationMethodPermissions().setAttribute(null, entry.getKey(), EJBMethodSecurityAttribute.denyAll());
}
for (Map.Entry<Method, List<Boolean>> entry : denyData.getMethodAnnotations().entrySet()) {
final Method method = entry.getKey();
description.getAnnotationMethodPermissions().setAttribute(null, EJBMethodSecurityAttribute.denyAll(), method.getDeclaringClass().getName(), method.getName(), MethodInfoHelper.getCanonicalParameterTypes(method));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentDescription) throws DeploymentUnitProcessingException {
//Add the configurator that calculates JACC permissions
//TODO: should this be elsewhere?
componentDescription.getConfigurators().add(new EjbJaccConfigurator());
//DO NOT USE componentConfiguration.getDescriptorData()
//It will return null if there is no <enterprise-beans/> declaration even if there is an assembly descriptor entry
EjbJarMetaData ejbJarMetadata = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetadata != null) {
final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetadata.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
//handle wildcard exclude-list
final ExcludeListMetaData wildCardExcludeList = assemblyDescriptor.getExcludeListByEjbName("*");
if(wildCardExcludeList != null && wildCardExcludeList.getMethods() != null) {
handleExcludeMethods(componentDescription, wildCardExcludeList);
}
//handle ejb-specific exclude-list
final ExcludeListMetaData excludeList = assemblyDescriptor.getExcludeListByEjbName(componentDescription.getEJBName());
if (excludeList != null && excludeList.getMethods() != null) {
handleExcludeMethods(componentDescription, excludeList);
}
//handle wildcard method permissions
final MethodPermissionsMetaData wildCardMethodPermissions = assemblyDescriptor.getMethodPermissionsByEjbName("*");
if (wildCardMethodPermissions != null) {
handleMethodPermissions(componentDescription, wildCardMethodPermissions);
}
//handle ejb-specific method permissions
final MethodPermissionsMetaData methodPermissions = assemblyDescriptor.getMethodPermissionsByEjbName(componentDescription.getEJBName());
if (methodPermissions != null) {
handleMethodPermissions(componentDescription, methodPermissions);
}
}
}
}
private void handleMethodPermissions(final EJBComponentDescription componentDescription, final MethodPermissionsMetaData methodPermissions) {
for (final MethodPermissionMetaData methodPermissionMetaData : methodPermissions) {
final MethodsMetaData methods = methodPermissionMetaData.getMethods();
for (final MethodMetaData method : methods) {
EJBMethodSecurityAttribute ejbMethodSecurityMetaData;
// Enterprise Beans 3.1 FR 17.3.2.2 The unchecked element is used instead of a role name in the method-permission element to indicate that all roles are permitted.
if (methodPermissionMetaData.isNotChecked()) {
ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.permitAll();
} else {
ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.rolesAllowed(methodPermissionMetaData.getRoles());
}
final String methodName = method.getMethodName();
final MethodInterfaceType defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodInterfaceType.MessageEndpoint : MethodInterfaceType.Bean;
final MethodInterfaceType methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
if (methodName.equals("*")) {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle1(methodIntf, null);
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, ejbMethodSecurityMetaData);
} else {
final MethodParametersMetaData methodParams = method.getMethodParams();
// update the session bean description with the tx attribute info
if (methodParams == null) {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle2(methodIntf, methodName);
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, methodName);
} else {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle3(methodIntf, null, methodName, this.getMethodParams(methodParams));
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, null, methodName, this.getMethodParams(methodParams));
}
}
}
}
}
private void handleExcludeMethods(final EJBComponentDescription componentDescription, final ExcludeListMetaData excludeList) {
for (final MethodMetaData method : excludeList.getMethods()) {
final String methodName = method.getMethodName();
final MethodInterfaceType defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodInterfaceType.MessageEndpoint : MethodInterfaceType.Bean;
final MethodInterfaceType methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
if (methodName.equals("*")) {
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, EJBMethodSecurityAttribute.denyAll());
} else {
final MethodParametersMetaData methodParams = method.getMethodParams();
// update the session bean description with the tx attribute info
if (methodParams == null) {
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), methodName);
} else {
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), null, methodName, this.getMethodParams(methodParams));
}
}
}
}
private EJBMethodSecurityAttribute mergeExistingRoles(EJBMethodSecurityAttribute ejbMethodSecurityMetaData, final EJBMethodSecurityAttribute existingRoles) {
if (existingRoles != null && !existingRoles.getRolesAllowed().isEmpty()) {
final Set<String> roles = new HashSet<String>(existingRoles.getRolesAllowed());
roles.addAll(ejbMethodSecurityMetaData.getRolesAllowed());
ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.rolesAllowed(roles);
}
return ejbMethodSecurityMetaData;
}
}
| 13,763 | 61.849315 | 296 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/InitMethodMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import jakarta.ejb.Init;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.InitMethodMetaData;
import org.jboss.metadata.ejb.spec.InitMethodsMetaData;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
/**
* Merging processor that handles SFSB init methods.
* <p/>
* Note that the corresponding home methods are not resolved as this time
*
* @author Stuart Douglas
*/
public class InitMethodMergingProcessor extends AbstractMergingProcessor<StatefulComponentDescription> {
public InitMethodMergingProcessor() {
super(StatefulComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription description) throws DeploymentUnitProcessingException {
RuntimeAnnotationInformation<String> init = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Init.class);
for (Map.Entry<Method, List<String>> entry : init.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
final String value = entry.getValue().get(0);
if (value != null && !value.isEmpty()) {
description.addInitMethod(entry.getKey(), value);
} else {
description.addInitMethod(entry.getKey(), null);
}
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription description) throws DeploymentUnitProcessingException {
//first look for old school ejbCreate methods
//we are only looking on the bean class, not sure if that is correct or not
Class<?> clazz = componentClass;
while (clazz != Object.class && clazz != null) {
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(clazz);
for (Method method : (Iterable<Method>)index.getMethods()) {
// if there is additional metadata specified for this method
// it will be overridden below
if (method.getName().startsWith("ejbCreate")
&& !description.getInitMethods().containsKey(method)) {
description.addInitMethod(method, null);
}
}
clazz = clazz.getSuperclass();
}
SessionBeanMetaData data = description.getDescriptorData();
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData metaData = (SessionBean31MetaData) data;
final InitMethodsMetaData inits = metaData.getInitMethods();
if (inits != null) {
for (InitMethodMetaData method : inits) {
Method beanMethod = MethodResolutionUtils.resolveMethod(method.getBeanMethod(), componentClass, deploymentReflectionIndex);
if (method.getCreateMethod() != null) {
description.addInitMethod(beanMethod, method.getCreateMethod().getMethodName());
} else {
description.addInitMethod(beanMethod, null);
}
}
}
}
}
}
| 5,286 | 46.630631 | 301 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/EjbConcurrencyMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.Lock;
import jakarta.ejb.LockType;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.concurrency.AccessTimeoutDetails;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.ConcurrentMethodMetaData;
import org.jboss.metadata.ejb.spec.ConcurrentMethodsMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
/**
* Class that can merge {@link jakarta.ejb.Lock} and {@link jakarta.ejb.AccessTimeout} metadata
*
* @author Stuart Douglas
*/
public class EjbConcurrencyMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
public EjbConcurrencyMergingProcessor() {
super(SessionBeanComponentDescription.class);
}
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) {
//handle lock annotations
final RuntimeAnnotationInformation<LockType> lockData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Lock.class);
for (Map.Entry<String, List<LockType>> entry : lockData.getClassAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
componentConfiguration.setBeanLevelLockType(entry.getKey(), entry.getValue().get(0));
}
}
for (Map.Entry<Method, List<LockType>> entry : lockData.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
componentConfiguration.setLockType(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
}
}
final RuntimeAnnotationInformation<AccessTimeoutDetails> accessTimeout = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, AccessTimeout.class);
for (Map.Entry<String, List<AccessTimeoutDetails>> entry : accessTimeout.getClassAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
componentConfiguration.setBeanLevelAccessTimeout(entry.getKey(), entry.getValue().get(0));
}
}
for (Map.Entry<Method, List<AccessTimeoutDetails>> entry : accessTimeout.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
componentConfiguration.setAccessTimeout(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
}
}
}
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() == null) {
return;
}
SessionBeanMetaData sessionBeanMetaData = componentConfiguration.getDescriptorData();
if (sessionBeanMetaData instanceof SessionBean31MetaData) {
SessionBean31MetaData descriptor = (SessionBean31MetaData) sessionBeanMetaData;
//handle lock
if (descriptor.getLockType() != null) {
componentConfiguration.setBeanLevelLockType(componentConfiguration.getEJBClassName(), descriptor.getLockType());
}
//handle access timeout
if (descriptor.getAccessTimeout() != null) {
componentConfiguration.setBeanLevelAccessTimeout(componentConfiguration.getEJBClassName(), new AccessTimeoutDetails(descriptor.getAccessTimeout().getTimeout(), descriptor.getAccessTimeout().getUnit()));
}
final ConcurrentMethodsMetaData methods = descriptor.getConcurrentMethods();
if (methods != null) {
for (final ConcurrentMethodMetaData method : methods) {
final Method realMethod = resolveMethod(deploymentReflectionIndex, componentClass, componentClass, method.getMethod());
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(realMethod);
if (method.getLockType() != null) {
componentConfiguration.setLockType(method.getLockType(), methodIdentifier);
}
if (method.getAccessTimeout() != null) {
componentConfiguration.setAccessTimeout(new AccessTimeoutDetails(method.getAccessTimeout().getTimeout(), method.getAccessTimeout().getUnit()), methodIdentifier);
}
}
}
}
}
private Method resolveMethod(final DeploymentReflectionIndex index, final Class<?> currentClass, final Class<?> componentClass, final NamedMethodMetaData methodData) throws DeploymentUnitProcessingException {
if (currentClass == null) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
}
final ClassReflectionIndex classIndex = index.getClassIndex(currentClass);
if (methodData.getMethodParams() == null) {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
if (methods.isEmpty()) {
return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
} else if (methods.size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), currentClass.getName());
}
return methods.iterator().next();
} else {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
for (final Method method : methods) {
boolean match = true;
for (int i = 0; i < method.getParameterCount(); ++i) {
if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
match = false;
break;
}
}
if (match) {
return method;
}
}
}
return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
}
}
| 8,443 | 51.123457 | 277 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/TimerMethodMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.ejb.Schedule;
import jakarta.ejb.ScheduleExpression;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timeout;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.timerservice.spi.AutoTimer;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.common.IScheduleTarget;
import org.jboss.metadata.ejb.common.ITimeoutTarget;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
import org.jboss.metadata.ejb.spec.ScheduleMetaData;
import org.jboss.metadata.ejb.spec.TimerMetaData;
/**
* Deployment unit processor that merges the annotation information with the information in the deployment descriptor
*
* @author Stuart Douglas
*/
public class TimerMethodMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public TimerMethodMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final RuntimeAnnotationInformation<AutoTimer> scheduleAnnotationData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Schedule.class);
final Set<Method> timerAnnotationData = MethodAnnotationAggregator.runtimeAnnotationPresent(componentClass, applicationClasses, deploymentReflectionIndex, Timeout.class);
final Method timeoutMethod;
if (timerAnnotationData.size() > 1) {
throw EjbLogger.ROOT_LOGGER.componentClassHasMultipleTimeoutAnnotations(componentClass);
} else if (timerAnnotationData.size() == 1) {
timeoutMethod = timerAnnotationData.iterator().next();
} else {
timeoutMethod = null;
}
description.setTimeoutMethod(timeoutMethod);
//now for the schedule methods
for (Map.Entry<Method, List<AutoTimer>> entry : scheduleAnnotationData.getMethodAnnotations().entrySet()) {
for (AutoTimer timer : entry.getValue()) {
description.addScheduleMethod(entry.getKey(), timer);
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final EnterpriseBeanMetaData descriptorData = description.getDescriptorData();
if (descriptorData != null
&& (description.isSession() || description.isMessageDriven())) {
assert descriptorData instanceof ITimeoutTarget : descriptorData + " is not an ITimeoutTarget";
ITimeoutTarget target = (ITimeoutTarget) descriptorData;
if (target.getTimeoutMethod() != null) {
parseTimeoutMethod(target, description, componentClass, deploymentReflectionIndex);
}
parseScheduleMethods(descriptorData, description, componentClass, deploymentReflectionIndex);
}
//now check to see if the class implemented TimedObject
//if so, this will take precedence over annotations
//or the method specified in the deployment descriptor
if (TimedObject.class.isAssignableFrom(componentClass)) {
Class<?> c = componentClass;
while (c != null && c != Object.class) {
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
//TimedObject takes precedence
Method method = index.getMethod(Void.TYPE, "ejbTimeout", jakarta.ejb.Timer.class);
if (method != null) {
final Method otherMethod = description.getTimeoutMethod();
if (otherMethod != null && !otherMethod.equals(method)) {
throw EjbLogger.ROOT_LOGGER.invalidEjbEntityTimeout("3.1 18.2.5.3", componentClass);
}
description.setTimeoutMethod(method);
break;
}
c = c.getSuperclass();
}
}
}
private void parseScheduleMethods(final EnterpriseBeanMetaData beanMetaData, final EJBComponentDescription sessionBean, final Class<?> componentClass, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException {
if (beanMetaData instanceof IScheduleTarget) {
IScheduleTarget md = (IScheduleTarget) beanMetaData;
if (md.getTimers() != null) {
for (final TimerMetaData timer : md.getTimers()) {
AutoTimer autoTimer = new AutoTimer();
autoTimer.getTimerConfig().setInfo(timer.getInfo());
autoTimer.getTimerConfig().setPersistent(timer.isPersistent());
final ScheduleExpression scheduleExpression = autoTimer.getScheduleExpression();
final ScheduleMetaData schedule = timer.getSchedule();
if (schedule != null) {
scheduleExpression.dayOfMonth(schedule.getDayOfMonth());
scheduleExpression.dayOfWeek(schedule.getDayOfWeek());
scheduleExpression.hour(schedule.getHour());
scheduleExpression.minute(schedule.getMinute());
scheduleExpression.month(schedule.getMonth());
scheduleExpression.second(schedule.getSecond());
scheduleExpression.year(schedule.getYear());
}
if (timer.getEnd() != null) {
scheduleExpression.end(timer.getEnd().getTime());
}
if (timer.getStart() != null) {
scheduleExpression.start(timer.getStart().getTime());
}
scheduleExpression.timezone(timer.getTimezone());
sessionBean.addScheduleMethod(MethodResolutionUtils.resolveMethod(timer.getTimeoutMethod(), componentClass, deploymentReflectionIndex), autoTimer);
}
}
}
}
private void parseTimeoutMethod(final ITimeoutTarget beanMetaData, final EJBComponentDescription sessionBean, final Class<?> componentClass, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException {
//resolve timeout methods
final NamedMethodMetaData methodData = beanMetaData.getTimeoutMethod();
sessionBean.setTimeoutMethod(MethodResolutionUtils.resolveMethod(methodData, componentClass, deploymentReflectionIndex));
}
}
| 8,670 | 50.613095 | 296 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/ResourceAdaptorMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.resourceadapterbinding.metadata.EJBBoundResourceAdapterBindingMetaData;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
/**
* Handles the {@link org.jboss.ejb3.annotation.ResourceAdapter} annotation merging
*
* @author Stuart DouglasrunAs
*/
public class ResourceAdaptorMergingProcessor extends AbstractMergingProcessor<MessageDrivenComponentDescription> {
public ResourceAdaptorMergingProcessor() {
super(MessageDrivenComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final MessageDrivenComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<ResourceAdapter, String> resourceAdapter = clazz.getAnnotationInformation(ResourceAdapter.class);
if (resourceAdapter == null || resourceAdapter.getClassLevelAnnotations().isEmpty()) {
return;
}
final String configuredAdapterName = resourceAdapter.getClassLevelAnnotations().get(0);
final String adapterName = addEarPrefixIfRelativeName(configuredAdapterName, deploymentUnit, componentClass);
componentConfiguration.setResourceAdapterName(adapterName);
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final MessageDrivenComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final String ejbName = componentConfiguration.getEJBName();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null) {
return;
}
final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
if (assemblyDescriptor == null) {
return;
}
final List<EJBBoundResourceAdapterBindingMetaData> resourceAdapterBindingDataList = assemblyDescriptor.getAny(EJBBoundResourceAdapterBindingMetaData.class);
String configuredAdapterName = null;
if (resourceAdapterBindingDataList != null) {
for (EJBBoundResourceAdapterBindingMetaData resourceAdapterBindingData: resourceAdapterBindingDataList) {
if ("*".equals(resourceAdapterBindingData.getEjbName()) && configuredAdapterName == null) {
configuredAdapterName = resourceAdapterBindingData.getResourceAdapterName();
} else if (ejbName.equals(resourceAdapterBindingData.getEjbName())) {
configuredAdapterName = resourceAdapterBindingData.getResourceAdapterName();
}
}
}
if (configuredAdapterName != null) {
final String adapterName = addEarPrefixIfRelativeName(configuredAdapterName,deploymentUnit,componentClass);
componentConfiguration.setResourceAdapterName(adapterName);
}
}
// adds ear prefix to configured adapter name if it is specified in relative form
private String addEarPrefixIfRelativeName(final String configuredName, final DeploymentUnit deploymentUnit,
final Class<?> componentClass) throws DeploymentUnitProcessingException {
if (!configuredName.startsWith("#")) {
return configuredName;
}
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent == null) {
throw EjbLogger.ROOT_LOGGER.relativeResourceAdapterNameInStandaloneModule(deploymentUnit.getName(),
componentClass.getName(), configuredName);
}
return new StringBuilder().append(parent.getName()).append(configuredName).toString();
}
}
| 5,937 | 50.634783 | 317 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/StatelessSessionBeanPoolMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ejb3.component.stateless.StatelessComponentDescription;
/**
* Sets up the stateless bean component description with the pool name configured for the bean via the {@link org.jboss.ejb3.annotation.Pool}
* annotation and/or the deployment descriptor
*
* @author Jaikiran Pai
*/
public class StatelessSessionBeanPoolMergingProcessor extends AbstractPoolMergingProcessor<StatelessComponentDescription> {
public StatelessSessionBeanPoolMergingProcessor() {
super(StatelessComponentDescription.class);
}
@Override
protected void setPoolName(final StatelessComponentDescription componentDescription, final String poolName) {
componentDescription.setPoolConfigName(poolName);
}
}
| 1,818 | 39.422222 | 141 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/DeclareRolesMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.javaee.spec.SecurityRoleRefMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleRefsMetaData;
import jakarta.annotation.security.DeclareRoles;
/**
* Merging process for @DeclareRoles
*
* @author Stuart Douglas
*/
public class DeclareRolesMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public DeclareRolesMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<DeclareRoles, String[]> declareRoles = clazz.getAnnotationInformation(DeclareRoles.class);
if (declareRoles == null) {
return;
}
if (!declareRoles.getClassLevelAnnotations().isEmpty()) {
description.addDeclaredRoles(declareRoles.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
if (description.getDescriptorData() == null) {
return;
}
final SecurityRoleRefsMetaData roleRefs = description.getDescriptorData().getSecurityRoleRefs();
if (roleRefs != null) {
for(SecurityRoleRefMetaData ref : roleRefs) {
description.addDeclaredRoles(ref.getRoleName());
}
}
}
}
| 3,526 | 44.805195 | 296 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/ClusteredSingletonMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.clustering.EJBBoundClusteringMetaData;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.ClusteredSingleton;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import java.util.List;
/**
* Handles ClusteredSingleton merging.
*
* @author Flavia Rainone
*/
public class ClusteredSingletonMergingProcessor extends AbstractMergingProcessor<MessageDrivenComponentDescription> {
public ClusteredSingletonMergingProcessor() {
super(MessageDrivenComponentDescription.class);
}
@Override
protected void handleAnnotations(DeploymentUnit deploymentUnit, EEApplicationClasses applicationClasses,
DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass,
MessageDrivenComponentDescription componentDescription) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<ClusteredSingleton, Boolean> clustering = clazz.getAnnotationInformation(ClusteredSingleton.class);
if (clustering == null || clustering.getClassLevelAnnotations().isEmpty()) {
return;
}
componentDescription.setClusteredSingleton(true);
}
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit,
DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass,
MessageDrivenComponentDescription componentDescription) throws DeploymentUnitProcessingException {
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
Boolean allBeansClusteredSingleton = null;
if (ejbJarMetaData != null) {
final AssemblyDescriptorMetaData assemblyMetadata = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyMetadata != null) {
final List<EJBBoundClusteringMetaData> clusteringMetaDatas = assemblyMetadata.getAny(EJBBoundClusteringMetaData.class);
if (clusteringMetaDatas != null) {
for (final EJBBoundClusteringMetaData clusteringMetaData : clusteringMetaDatas) {
if ("*".equals(clusteringMetaData.getEjbName())) {
allBeansClusteredSingleton = clusteringMetaData.isClusteredSingleton();
} else if (componentDescription.getComponentName().equals(clusteringMetaData.getEjbName())) {
componentDescription.setClusteredSingleton(clusteringMetaData.isClusteredSingleton());
return;
}
}
}
}
}
if (allBeansClusteredSingleton != null && allBeansClusteredSingleton) {
componentDescription.setClusteredSingleton(true);
}
}
}
| 4,682 | 48.294737 | 140 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/MessageDrivenBeanPoolMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
/**
* Sets up the component description for a MDB with the pool name configured via {@link org.jboss.ejb3.annotation.Pool}
* annotation and/or the deployment descriptor
*
* @author Jaikiran Pai
*/
public class MessageDrivenBeanPoolMergingProcessor extends AbstractPoolMergingProcessor<MessageDrivenComponentDescription> {
public MessageDrivenBeanPoolMergingProcessor() {
super(MessageDrivenComponentDescription.class);
}
@Override
protected void setPoolName(final MessageDrivenComponentDescription componentDescription, final String poolName) {
componentDescription.setPoolConfigName(poolName);
}
}
| 1,809 | 40.136364 | 124 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/SessionSynchronizationMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import jakarta.ejb.AfterBegin;
import jakarta.ejb.AfterCompletion;
import jakarta.ejb.BeforeCompletion;
import jakarta.ejb.SessionSynchronization;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
/**
* Merging processor that handles session synchronization callback methods
*
* @author Stuart Douglas
*/
public class SessionSynchronizationMergingProcessor extends AbstractMergingProcessor<StatefulComponentDescription> {
public SessionSynchronizationMergingProcessor() {
super(StatefulComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription description) throws DeploymentUnitProcessingException {
if (SessionSynchronization.class.isAssignableFrom(componentClass)) {
//handled in handleDeploymentDescriptor
return;
}
RuntimeAnnotationInformation<Boolean> afterBegin = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, AfterBegin.class);
if (afterBegin.getMethodAnnotations().size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleAnnotationsOnBean("@AfterBegin", description.getEJBClassName());
} else if (!afterBegin.getMethodAnnotations().isEmpty()) {
Map.Entry<Method, List<Boolean>> entry = afterBegin.getMethodAnnotations().entrySet().iterator().next();
description.setAfterBegin(entry.getKey());
}
RuntimeAnnotationInformation<Boolean> afterComp = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, AfterCompletion.class);
if (afterComp.getMethodAnnotations().size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleAnnotationsOnBean("@AfterCompletion", description.getEJBClassName());
} else if (!afterComp.getMethodAnnotations().isEmpty()) {
Map.Entry<Method, List<Boolean>> entry = afterComp.getMethodAnnotations().entrySet().iterator().next();
description.setAfterCompletion(entry.getKey());
}
RuntimeAnnotationInformation<Boolean> beforeComp = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, BeforeCompletion.class);
if (beforeComp.getMethodAnnotations().size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleAnnotationsOnBean("@BeforeCompletion", description.getEJBClassName());
} else if (!beforeComp.getMethodAnnotations().isEmpty()) {
Map.Entry<Method, List<Boolean>> entry = beforeComp.getMethodAnnotations().entrySet().iterator().next();
description.setBeforeCompletion(entry.getKey());
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription description) throws DeploymentUnitProcessingException {
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
//if we implement SessionSynchronization we can ignore any DD information
if (SessionSynchronization.class.isAssignableFrom(componentClass)) {
final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(SessionSynchronization.class);
description.setAfterBegin(classIndex.getMethod(void.class, "afterBegin"));
description.setAfterCompletion(classIndex.getMethod(void.class, "afterCompletion", boolean.class));
description.setBeforeCompletion(classIndex.getMethod(void.class,"beforeCompletion"));
return;
}
SessionBeanMetaData data = description.getDescriptorData();
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData metaData = (SessionBean31MetaData) data;
if (metaData.getAfterBeginMethod() != null)
description.setAfterBegin(MethodResolutionUtils.resolveMethod(metaData.getAfterBeginMethod(), componentClass,reflectionIndex));
if (metaData.getAfterCompletionMethod() != null)
description.setAfterCompletion(MethodResolutionUtils.resolveMethod(metaData.getAfterCompletionMethod(), componentClass,reflectionIndex));
if (metaData.getBeforeCompletionMethod() != null)
description.setBeforeCompletion(MethodResolutionUtils.resolveMethod(metaData.getBeforeCompletionMethod(), componentClass,reflectionIndex));
}
}
}
| 6,663 | 55.474576 | 301 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/SessionBeanMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import jakarta.ejb.SessionBean;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.component.session.SessionBeanSetSessionContextMethodInvocationInterceptor;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
/**
* Processor that handles the {@link jakarta.ejb.SessionBean} interface
*
* @author Stuart Douglas
*/
public class SessionBeanMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
public SessionBeanMergingProcessor() {
super(SessionBeanComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
if (SessionBean.class.isAssignableFrom(componentClass)) {
// add the setSessionContext(SessionContext) method invocation interceptor for session bean implementing the jakarta.ejb.SessionContext
// interface
description.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
if (SessionBean.class.isAssignableFrom(configuration.getComponentClass())) {
configuration.addPostConstructInterceptor(SessionBeanSetSessionContextMethodInvocationInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.EJB_SET_CONTEXT_METHOD_INVOCATION_INTERCEPTOR);
}
}
});
//now lifecycle callbacks
final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove");
final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate");
final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate");
boolean ejbActivate = false, ejbPassivate = false, ejbRemove = false;
Class<?> c = componentClass;
while (c != null && c != Object.class) {
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(c);
if(!ejbActivate) {
final Method method = index.getMethod(ejbActivateIdentifier);
if(method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPostActivate(ejbActivateIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbActivate = true;
}
}
if(!ejbPassivate) {
final Method method = index.getMethod(ejbPassivateIdentifier);
if(method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPrePassivate(ejbPassivateIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbPassivate = true;
}
}
if(!ejbRemove) {
final Method method = index.getMethod(ejbRemoveIdentifier);
if(method != null) {
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
builder.setPreDestroy(ejbRemoveIdentifier);
description.addInterceptorMethodOverride(c.getName(), builder.build());
ejbRemove = true;
}
}
c = c.getSuperclass();
}
}
}
}
| 6,210 | 50.330579 | 304 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/MdbDeliveryMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription;
import org.jboss.as.ejb3.deliveryactive.metadata.EJBBoundMdbDeliveryMetaData;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.DeliveryActive;
import org.jboss.ejb3.annotation.DeliveryGroup;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
/**
* Handles the {@link org.jboss.ejb3.annotation.DeliveryActive} and {@link org.jboss.ejb3.annotation.DeliveryGroup} annotation merging
*
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2013 Red Hat inc.
* @author Flavia Rainone
*/
public class MdbDeliveryMergingProcessor extends AbstractMergingProcessor<MessageDrivenComponentDescription> {
public MdbDeliveryMergingProcessor() {
super(MessageDrivenComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final MessageDrivenComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<DeliveryActive, Boolean> deliveryActive = clazz.getAnnotationInformation(DeliveryActive.class);
if (deliveryActive != null
&& !deliveryActive.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setDeliveryActive(deliveryActive.getClassLevelAnnotations().get(0));
}
final ClassAnnotationInformation<DeliveryGroup, String> deliveryGroup = clazz.getAnnotationInformation(DeliveryGroup.class);
if (deliveryGroup != null) {
List<String> deliveryGroups = deliveryGroup.getClassLevelAnnotations();
if (!deliveryGroups.isEmpty()) {
componentConfiguration.setDeliveryGroup(deliveryGroups.toArray(new String[deliveryGroups.size()]));
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final MessageDrivenComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final String ejbName = componentConfiguration.getEJBName();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null) {
return;
}
final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
if (assemblyDescriptor == null) {
return;
}
Boolean deliveryActive = null;
String[] deliveryGroups = null;
final List<EJBBoundMdbDeliveryMetaData> deliveryMetaDataList = assemblyDescriptor.getAny(EJBBoundMdbDeliveryMetaData.class);
if (deliveryMetaDataList != null) {
for (EJBBoundMdbDeliveryMetaData deliveryMetaData : deliveryMetaDataList) {
if ("*".equals(deliveryMetaData.getEjbName())) {
// do not overwrite if deliveryActive is not null
if (deliveryActive == null)
deliveryActive = deliveryMetaData.isDeliveryActive();
deliveryGroups = mergeDeliveryGroups(deliveryGroups, deliveryMetaData.getDeliveryGroups());
} else if (ejbName.equals(deliveryMetaData.getEjbName())) {
deliveryActive = deliveryMetaData.isDeliveryActive();
deliveryGroups = mergeDeliveryGroups(deliveryGroups, deliveryMetaData.getDeliveryGroups());
}
}
}
// delivery group configuration has precedence over deliveryActive
if (deliveryGroups != null && deliveryGroups.length > 0) {
componentConfiguration.setDeliveryGroup(deliveryGroups);
}
else if (deliveryActive != null) {
componentConfiguration.setDeliveryActive(deliveryActive);
}
}
private final String[] mergeDeliveryGroups(String[] deliveryGroups1, String[] deliveryGroups2) {
if (deliveryGroups1 == null)
return deliveryGroups2;
if (deliveryGroups2 == null)
return deliveryGroups1;
final List<String> deliveryGroupList = new ArrayList(deliveryGroups1.length + deliveryGroups2.length);
Collections.addAll(deliveryGroupList, deliveryGroups1);
Collections.addAll(deliveryGroupList, deliveryGroups2);
return deliveryGroupList.toArray(new String[deliveryGroupList.size()]);
}
}
| 6,471 | 49.170543 | 317 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/StartupMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.singleton.SingletonComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import jakarta.ejb.Startup;
/**
* Handles {@link Startup}
* @author Stuart Douglas
*/
public class StartupMergingProcessor extends AbstractMergingProcessor<SingletonComponentDescription> {
public StartupMergingProcessor() {
super(SingletonComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SingletonComponentDescription description) throws DeploymentUnitProcessingException {
EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
if (clazz != null) {
final ClassAnnotationInformation<Startup, Object> data = clazz.getAnnotationInformation(Startup.class);
if (data != null
&& !data.getClassLevelAnnotations().isEmpty()) {
description.initOnStartup();
description.getModuleDescription().registerStartupBean();
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SingletonComponentDescription description) throws DeploymentUnitProcessingException {
if (!description.isInitOnStartup()) {
SessionBeanMetaData data = description.getDescriptorData();
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData singletonBeanMetaData = (SessionBean31MetaData) data;
Boolean initOnStartup = singletonBeanMetaData.isInitOnStartup();
if (initOnStartup != null && initOnStartup) {
description.initOnStartup();
description.getModuleDescription().registerStartupBean();
}
}
} // else skip. This is already marked as InitOnStartup by @Startup annotation.
}
}
| 3,687 | 48.837838 | 302 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/ApplicationExceptionMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import java.util.Map;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions;
import org.jboss.as.ejb3.deployment.ApplicationExceptions;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.tx.ApplicationExceptionDetails;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.EjbDeploymentMarker;
import org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData;
import org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.modules.Module;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
/**
* @author Stuart Douglas
*/
public class ApplicationExceptionMergingProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
final List<DeploymentUnit> accessibleSubDeployments = deploymentUnit.getAttachment(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ApplicationExceptions applicationExceptions = new ApplicationExceptions();
for (DeploymentUnit unit : accessibleSubDeployments) {
//we want to get the details for classes from all sub deployments we have access to
final ApplicationExceptionDescriptions exceptionDescriptions = unit.getAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS);
if (exceptionDescriptions != null) {
for (Map.Entry<String, org.jboss.as.ejb3.tx.ApplicationExceptionDetails> exception : exceptionDescriptions.getApplicationExceptions().entrySet()) {
try {
final Class<?> index = ClassLoadingUtils.loadClass(exception.getKey(), module);
applicationExceptions.addApplicationException(index, exception.getValue());
} catch (ClassNotFoundException e) {
ROOT_LOGGER.debug("Could not load application exception class", e);
}
}
}
}
//now add the exceptions from the assembly descriptor
EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData != null) {
// process assembly-descriptor stuff
AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
// process application-exception(s)
ApplicationExceptionsMetaData ddAppExceptions = assemblyDescriptor.getApplicationExceptions();
if (ddAppExceptions != null && !ddAppExceptions.isEmpty()) {
for (ApplicationExceptionMetaData applicationException : ddAppExceptions) {
String exceptionClassName = applicationException.getExceptionClass();
try {
final Class<?> index = ClassLoadingUtils.loadClass(exceptionClassName, module);
boolean rollback = applicationException.isRollback();
// by default inherited is true
boolean inherited = applicationException.isInherited() == null ? true : applicationException.isInherited();
// add the application exception to the ejb jar description
applicationExceptions.addApplicationException(index, new ApplicationExceptionDetails(exceptionClassName, inherited, rollback));
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadAppExceptionClassInEjbJarXml(exceptionClassName, e);
}
}
}
}
}
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DETAILS, applicationExceptions);
}
}
| 5,768 | 53.424528 | 163 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/AsynchronousMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import jakarta.ejb.Asynchronous;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.DependencyConfigurator;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.ViewConfiguration;
import org.jboss.as.ee.component.ViewConfigurator;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.interceptors.AsyncFutureInterceptorFactory;
import org.jboss.as.ejb3.component.interceptors.LogDiagnosticContextRecoveryInterceptor;
import org.jboss.as.ejb3.component.interceptors.LogDiagnosticContextStorageInterceptor;
import org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.ejb3.security.SecurityDomainInterceptorFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndexUtil;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.metadata.ejb.spec.AsyncMethodMetaData;
import org.jboss.metadata.ejb.spec.AsyncMethodsMetaData;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* Merging processor that handles EJB async methods, and adds a configurator to configure any that are found.
*
* @author Stuart Douglas
*/
public class AsynchronousMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
final ServiceName asynchronousThreadPoolService;
public AsynchronousMergingProcessor(final ServiceName asynchronousThreadPoolService) {
super(SessionBeanComponentDescription.class);
this.asynchronousThreadPoolService = asynchronousThreadPoolService;
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
final RuntimeAnnotationInformation<Boolean> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Asynchronous.class);
for (final Map.Entry<String, List<Boolean>> entry : data.getClassAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
description.addAsynchronousClass(entry.getKey());
}
}
for (final Map.Entry<Method, List<Boolean>> entry : data.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(entry.getKey()));
}
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
final SessionBeanMetaData data = description.getDescriptorData();
final boolean elytronSecurityDomain = description.getSecurityDomainServiceName() != null;
if (data instanceof SessionBean31MetaData) {
final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
if (async != null) {
for (AsyncMethodMetaData method : async) {
final Collection<Method> methods = MethodResolutionUtils.resolveMethods(method.getMethodName(),
method.getMethodParams(), componentClass, deploymentReflectionIndex);
for (final Method m : methods) {
description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
}
}
}
}
if (!description.getAsynchronousClasses().isEmpty() ||
!description.getAsynchronousMethods().isEmpty()) {
//setup a dependency on the executor service
description.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final SessionBeanComponentCreateService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(asynchronousThreadPoolService, ExecutorService.class, service.getAsyncExecutorService());
}
});
}
});
for (final ViewDescription view : description.getViews()) {
final EJBViewDescription ejbView = (EJBViewDescription) view;
ejbView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
//we need the component method to get the correct declaring class
final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method);
if (componentMethod != null) {
if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
addAsyncInterceptor(configuration, method, elytronSecurityDomain);
configuration.addAsyncMethod(method);
} else {
MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
if (componentDescription.getAsynchronousMethods().contains(id)) {
addAsyncInterceptor(configuration, method, elytronSecurityDomain);
configuration.addAsyncMethod(method);
}
}
}
}
}
});
}
}
}
private static void addAsyncInterceptor(final ViewConfiguration configuration, final Method method, final boolean isSecurityDomainKnown) throws DeploymentUnitProcessingException {
if (method.getReturnType().equals(void.class) || method.getReturnType().equals(Future.class)) {
configuration.addClientInterceptor(method, LogDiagnosticContextStorageInterceptor.getFactory(), InterceptorOrder.Client.LOCAL_ASYNC_LOG_SAVE);
if (isSecurityDomainKnown) {
// Make sure the security domain is available in the private data of the InterceptorContext
configuration.addClientInterceptor(method, SecurityDomainInterceptorFactory.INSTANCE, InterceptorOrder.Client.LOCAL_ASYNC_SECURITY_CONTEXT);
}
configuration.addClientInterceptor(method, AsyncFutureInterceptorFactory.INSTANCE, InterceptorOrder.Client.LOCAL_ASYNC_INVOCATION);
configuration.addClientInterceptor(method, LogDiagnosticContextRecoveryInterceptor.getFactory(), InterceptorOrder.Client.LOCAL_ASYNC_LOG_RESTORE);
} else {
throw EjbLogger.ROOT_LOGGER.wrongReturnTypeForAsyncMethod(method);
}
}
}
| 10,345 | 57.784091 | 304 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/TransactionManagementMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
/**
* @author Stuart Douglas
*/
public class TransactionManagementMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public TransactionManagementMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
ClassAnnotationInformation<TransactionManagement, TransactionManagementType> management = clazz.getAnnotationInformation(TransactionManagement.class);
if (management == null) {
return;
}
if (!management.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setTransactionManagementType(management.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EnterpriseBeanMetaData beanMetaData = componentConfiguration.getDescriptorData();
if(componentConfiguration.isEntity() || beanMetaData == null) {
return;
}
final TransactionManagementType type = componentConfiguration.getDescriptorData().getTransactionType();
if(type != null) {
componentConfiguration.setTransactionManagementType(type);
}
}
}
| 3,589 | 48.178082 | 307 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/SecurityDomainMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ee.structure.Attachments;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
/**
* @author Stuart Douglas
*/
public class SecurityDomainMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public SecurityDomainMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<SecurityDomain, String> securityDomain = clazz.getAnnotationInformation(SecurityDomain.class);
if (securityDomain == null) {
return;
}
if (!securityDomain.getClassLevelAnnotations().isEmpty()) {
if (ROOT_LOGGER.isDebugEnabled()) {
ROOT_LOGGER.debug("Jakarta Enterprise Beans " + description.getEJBName() + " is part of security domain " + securityDomain.getClassLevelAnnotations().get(0));
}
description.setDefinedSecurityDomain(securityDomain.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
String securityDomain = getJBossAppSecurityDomain(deploymentUnit);
String globalSecurityDomain = null;
final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData != null) {
final AssemblyDescriptorMetaData assemblyMetadata = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyMetadata != null) {
final List<EJBBoundSecurityMetaData> securityMetaDatas = assemblyMetadata.getAny(EJBBoundSecurityMetaData.class);
if (securityMetaDatas != null) {
for (final EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
if (securityMetaData.getEjbName().equals(description.getComponentName())) {
securityDomain = securityMetaData.getSecurityDomain();
break;
}
// check global security domain
if (securityMetaData.getEjbName().equals("*")) {
globalSecurityDomain = securityMetaData.getSecurityDomain();
continue;
}
}
}
}
}
if (securityDomain != null)
description.setDefinedSecurityDomain(securityDomain);
else if (globalSecurityDomain != null)
description.setDefinedSecurityDomain(globalSecurityDomain);
}
/**
* Try to obtain the security domain configured in jboss-app.xml at the ear level if available
*
* @param deploymentUnit
* @return
*/
private String getJBossAppSecurityDomain(final DeploymentUnit deploymentUnit) {
String securityDomain = null;
DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
final EarMetaData jbossAppMetaData = parent.getAttachment(Attachments.EAR_METADATA);
if (jbossAppMetaData instanceof JBossAppMetaData) {
securityDomain = ((JBossAppMetaData) jbossAppMetaData).getSecurityDomain();
}
}
return securityDomain;
}
}
| 5,938 | 48.082645 | 296 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/RunAsMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import jakarta.annotation.security.RunAs;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.spec.SecurityIdentityMetaData;
import org.jboss.metadata.javaee.spec.RunAsMetaData;
/**
* Handles the {@link jakarta.annotation.security.RunAs} annotation merging
*
* @author Stuart Douglas
*/
public class RunAsMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
private static final String DEFAULT_RUN_AS_PRINCIPAL = "anonymous";
public RunAsMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses,
final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass,
final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
// we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<RunAs, String> runAs = clazz.getAnnotationInformation(RunAs.class);
final ClassAnnotationInformation<RunAsPrincipal, String> runAsPrincipal = clazz
.getAnnotationInformation(RunAsPrincipal.class);
if (runAs == null) {
if(runAsPrincipal != null) {
EjbLogger.DEPLOYMENT_LOGGER.missingRunAsAnnotation(componentClass.getName());
}
return;
}
if (!runAs.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setRunAs(runAs.getClassLevelAnnotations().get(0));
}
String principal = DEFAULT_RUN_AS_PRINCIPAL;
if (runAsPrincipal != null
&& !runAsPrincipal.getClassLevelAnnotations().isEmpty()) {
principal = runAsPrincipal.getClassLevelAnnotations().get(0);
}
componentConfiguration.setRunAsPrincipal(principal);
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit,
final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass,
final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() != null) {
final SecurityIdentityMetaData identity = componentConfiguration.getDescriptorData().getSecurityIdentity();
if (identity != null) {
final RunAsMetaData runAs = identity.getRunAs();
if (runAs != null) {
final String role = runAs.getRoleName();
if (role != null && !role.trim().isEmpty()) {
componentConfiguration.setRunAs(role.trim());
}
}
}
}
if (componentConfiguration.getRunAs() != null) {
String principal = null;
String globalRunAsPrincipal = null;
EjbJarMetaData jbossMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (jbossMetaData != null && jbossMetaData.getAssemblyDescriptor() != null) {
List<EJBBoundSecurityMetaData> securityMetaDatas = jbossMetaData.getAssemblyDescriptor().getAny(EJBBoundSecurityMetaData.class);
if (securityMetaDatas != null) {
for (EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
if (securityMetaData.getEjbName().equals(componentConfiguration.getComponentName())) {
principal = securityMetaData.getRunAsPrincipal();
break;
}
// check global run-as principal
if (securityMetaData.getEjbName().equals("*")) {
globalRunAsPrincipal = securityMetaData.getRunAsPrincipal();
continue;
}
}
}
if (principal != null)
componentConfiguration.setRunAsPrincipal(principal);
else if (globalRunAsPrincipal != null)
componentConfiguration.setRunAsPrincipal(globalRunAsPrincipal);
else {
// we only set the run-as-principal to default, if it's not already set (via annotation) on the component
if (componentConfiguration.getRunAsPrincipal() == null) {
componentConfiguration.setRunAsPrincipal(DEFAULT_RUN_AS_PRINCIPAL);
}
}
}
}
}
} | 6,723 | 48.441176 | 144 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/AbstractMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.Collection;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
import org.jboss.modules.Module;
/**
* Superclass for the Jakarta Enterprise Beans metadata merging processors
*
* @author Stuart Douglas
*/
public abstract class AbstractMergingProcessor<T extends EJBComponentDescription> implements DeploymentUnitProcessor {
private final Class<T> typeParam;
public AbstractMergingProcessor(final Class<T> typeParam) {
this.typeParam = typeParam;
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final Collection<ComponentDescription> componentConfigurations = eeModuleDescription.getComponentDescriptions();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
if (componentConfigurations == null || componentConfigurations.isEmpty()) {
return;
}
for (ComponentDescription componentConfiguration : componentConfigurations) {
if (typeParam.isAssignableFrom(componentConfiguration.getClass())) {
try {
processComponentConfig(deploymentUnit, applicationClasses, module, deploymentReflectionIndex, (T) componentConfiguration);
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.failToMergeData(componentConfiguration.getComponentName(), e);
}
}
}
}
private void processComponentConfig(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final T description) throws DeploymentUnitProcessingException {
final Class<?> componentClass;
try {
componentClass = module.getClassLoader().loadClass(description.getEJBClassName());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadEjbClass(description.getEJBClassName(), e);
}
if (!MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
handleAnnotations(deploymentUnit, applicationClasses, deploymentReflectionIndex, componentClass, description);
}
handleDeploymentDescriptor(deploymentUnit, deploymentReflectionIndex, componentClass, description);
}
/**
* Handle annotations relating to the component that have been found in the deployment. Will not be called if the deployment is metadata complete.
*/
protected abstract void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final T description) throws DeploymentUnitProcessingException;
/**
* Handle the deployment descriptor
*/
protected abstract void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final T description) throws DeploymentUnitProcessingException;
protected MethodInterfaceType getMethodIntf(final MethodInterfaceType viewType, final MethodInterfaceType defaultMethodIntf) {
return viewType == null ? defaultMethodIntf : viewType;
}
protected String[] getMethodParams(MethodParametersMetaData methodParametersMetaData) {
if (methodParametersMetaData == null) {
return null;
}
return methodParametersMetaData.toArray(new String[methodParametersMetaData.size()]);
}
}
| 5,948 | 49.846154 | 282 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/AbstractPoolMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.List;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.deployment.EjbDeploymentAttachmentKeys;
import org.jboss.as.ejb3.pool.EJBBoundPoolMetaData;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.ejb3.annotation.Pool;
import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
/**
* Sets up the Jakarta Enterprise Beans component description with the pool name configured via the {@link org.jboss.ejb3.annotation.Pool}
* annotation and/or the deployment descriptor, for an Jakarta Enterprise Beans
*
* @author Jaikiran Pai
*/
public abstract class AbstractPoolMergingProcessor<T extends EJBComponentDescription> extends AbstractMergingProcessor<T> {
public AbstractPoolMergingProcessor(Class<T> descriptionType) {
super(descriptionType);
}
@Override
protected void handleAnnotations(DeploymentUnit deploymentUnit, EEApplicationClasses applicationClasses, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, T description) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
final ClassAnnotationInformation<Pool, String> pool = clazz.getAnnotationInformation(Pool.class);
if (pool == null) {
return;
}
if (!pool.getClassLevelAnnotations().isEmpty()) {
final String poolName = pool.getClassLevelAnnotations().get(0);
if (poolName == null || poolName.trim().isEmpty()) {
throw EjbLogger.ROOT_LOGGER.poolNameCannotBeEmptyString(description.getEJBName());
}
this.setPoolName(description, poolName);
}
}
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, T description) throws DeploymentUnitProcessingException {
final String ejbName = description.getEJBName();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null) {
return;
}
final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
if (assemblyDescriptor == null) {
return;
}
// get the pool metadata
final List<EJBBoundPoolMetaData> pools = assemblyDescriptor.getAny(EJBBoundPoolMetaData.class);
String poolName = null;
if (pools != null) {
for (final EJBBoundPoolMetaData poolMetaData : pools) {
// if this applies for all Jakarta Enterprise Beans and if there isn't a pool name already explicitly specified
// for the specific bean (i.e. via an ejb-name match)
if ("*".equals(poolMetaData.getEjbName()) && poolName == null) {
poolName = poolMetaData.getPoolName();
} else if (ejbName.equals(poolMetaData.getEjbName())) {
poolName = poolMetaData.getPoolName();
}
}
}
if (poolName != null) {
this.setPoolName(description, poolName);
}
}
/**
* Set the pool name for the component
*
* @param componentDescription The component description
* @param poolName The pool name
*/
protected abstract void setPoolName(final T componentDescription, final String poolName);
}
| 5,162 | 44.690265 | 244 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/ConcurrencyManagementMergingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
/**
* @author Stuart Douglas
*/
public class ConcurrencyManagementMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
public ConcurrencyManagementMergingProcessor() {
super(SessionBeanComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
//we only care about annotations on the bean class itself
if (clazz == null) {
return;
}
ClassAnnotationInformation<ConcurrencyManagement, ConcurrencyManagementType> management = clazz.getAnnotationInformation(ConcurrencyManagement.class);
if (management == null) {
return;
}
if (!management.getClassLevelAnnotations().isEmpty()) {
componentConfiguration.setConcurrencyManagementType(management.getClassLevelAnnotations().get(0));
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() == null) {
return;
}
SessionBeanMetaData data = componentConfiguration.getDescriptorData();
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData descriptor = (SessionBean31MetaData) data;
final ConcurrencyManagementType type = descriptor.getConcurrencyManagementType();
if (type != null) {
componentConfiguration.setConcurrencyManagementType(type);
}
}
}
}
| 3,804 | 48.415584 | 315 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/EjbDependsOnMergingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.merging;
import java.util.Set;
import jakarta.ejb.DependsOn;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEApplicationDescription;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.singleton.SingletonComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
/**
* @author Stuart Douglas
* @author James R. Perkins Jr. (jrp)
*/
public class EjbDependsOnMergingProcessor extends AbstractMergingProcessor<EJBComponentDescription> {
public EjbDependsOnMergingProcessor() {
super(EJBComponentDescription.class);
}
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final EEModuleClassDescription classDescription = applicationClasses.getClassByName(componentClass.getName());
if (classDescription == null) {
return;
}
final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_DESCRIPTION);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
//we ony care about annotations on the actual class
final ClassAnnotationInformation<DependsOn, String[]> dependsOnClassAnnotationInformation = classDescription.getAnnotationInformation(DependsOn.class);
if (dependsOnClassAnnotationInformation != null
&& !dependsOnClassAnnotationInformation.getClassLevelAnnotations().isEmpty()) {
final String[] annotationValues = dependsOnClassAnnotationInformation.getClassLevelAnnotations().get(0);
setupDependencies(description, applicationDescription, deploymentRoot, annotationValues);
}
}
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_DESCRIPTION);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
if (description.getDescriptorData() instanceof SessionBean31MetaData) {
SessionBean31MetaData metaData = (SessionBean31MetaData) description.getDescriptorData();
if (metaData.getDependsOn() != null) {
setupDependencies(description, applicationDescription, deploymentRoot, metaData.getDependsOn());
}
}
}
private void setupDependencies(final EJBComponentDescription description, final EEApplicationDescription applicationDescription, final ResourceRoot deploymentRoot, final String[] annotationValues) throws DeploymentUnitProcessingException {
for (final String annotationValue : annotationValues) {
final Set<ComponentDescription> components = applicationDescription.getComponents(annotationValue, deploymentRoot.getRoot());
if (components.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.failToFindEjbRefByDependsOn(annotationValue, description.getComponentClassName());
} else if (components.size() != 1) {
throw EjbLogger.ROOT_LOGGER.failToCallEjbRefByDependsOn(annotationValue, description.getComponentClassName(), components);
}
final ComponentDescription component = components.iterator().next();
description.addDependency(component.getStartServiceName());
if (description instanceof SingletonComponentDescription) {
((SingletonComponentDescription)description).getDependsOn().add(component.getStartServiceName());
if (ROOT_LOGGER.isDebugEnabled()) {
ROOT_LOGGER.debugf(description.getEJBName() + " bean is dependent on " + component.getComponentName());
}
}
}
}
}
| 5,986 | 52.455357 | 296 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/DeclareRolesAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import jakarta.annotation.security.DeclareRoles;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.metadata.property.PropertyReplacer;
/**
* @author Stuart Douglas
*/
public class DeclareRolesAnnotationInformationFactory extends ClassAnnotationInformationFactory<DeclareRoles,String[] >{
protected DeclareRolesAnnotationInformationFactory() {
super(DeclareRoles.class, null);
}
@Override
protected String[] fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
String[] values = annotationInstance.value().asStringArray();
for (int i = 0; i < values.length; i++) {
values[i] = propertyReplacer.replaceProperties(values[i]);
}
return values;
}
}
| 1,927 | 39.166667 | 125 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/LocalHomeAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import jakarta.ejb.LocalHome;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
/**
* Processes the {@link jakarta.ejb.LocalHome} annotation on a session bean
*
* @author Stuart Douglas
*/
public class LocalHomeAnnotationInformationFactory extends ClassAnnotationInformationFactory<LocalHome, String> {
protected LocalHomeAnnotationInformationFactory() {
super(LocalHome.class, null);
}
@Override
protected String fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
AnnotationValue value = annotationInstance.value();
return value.asClass().toString();
}
}
| 1,892 | 38.4375 | 123 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/TimerServiceAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import jakarta.ejb.Timeout;
import org.jboss.as.ee.component.deployers.BooleanAnnotationInformationFactory;
import org.jboss.as.ee.metadata.AbstractEEAnnotationProcessor;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
/**
* Processes EJB annotations and attaches them to the {@link org.jboss.as.ee.component.EEModuleClassDescription}
*
* @author Stuart Douglas
*/
public class TimerServiceAnnotationProcessor extends AbstractEEAnnotationProcessor {
final List<ClassAnnotationInformationFactory> factories;
public TimerServiceAnnotationProcessor() {
final List<ClassAnnotationInformationFactory> factories = new ArrayList<ClassAnnotationInformationFactory>();
factories.add(new BooleanAnnotationInformationFactory<Timeout>(Timeout.class));
factories.add(new ScheduleAnnotationInformationFactory());
this.factories = Collections.unmodifiableList(factories);
}
@Override
protected List<ClassAnnotationInformationFactory> annotationInformationFactories() {
return factories;
}
}
| 2,228 | 38.803571 | 117 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/RemoveAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
import jakarta.ejb.Remove;
/**
* Processes the {@link jakarta.ejb.Remove}
*
* @author Stuart Douglas
*/
public class RemoveAnnotationInformationFactory extends ClassAnnotationInformationFactory<Remove, Boolean> {
protected RemoveAnnotationInformationFactory() {
super(Remove.class, null);
}
@Override
protected Boolean fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
AnnotationValue value = annotationInstance.value("retainIfException");
if(value == null) {
return false;
}
return value.asBoolean();
}
}
| 1,921 | 36.686275 | 124 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/StatefulTimeoutAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
import jakarta.ejb.StatefulTimeout;
import java.util.concurrent.TimeUnit;
/**
* @author Stuart Douglas
*/
public class StatefulTimeoutAnnotationInformationFactory extends ClassAnnotationInformationFactory<StatefulTimeout, StatefulTimeoutInfo> {
protected StatefulTimeoutAnnotationInformationFactory() {
super(StatefulTimeout.class, null);
}
@Override
protected StatefulTimeoutInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final long value = annotationInstance.value().asLong();
final AnnotationValue unitValue = annotationInstance.value("unit");
final TimeUnit unit;
if (unitValue != null) {
unit = TimeUnit.valueOf(unitValue.asEnum());
} else {
unit = TimeUnit.MINUTES;
}
return new StatefulTimeoutInfo(value, unit);
}
}
| 2,245 | 39.836364 | 138 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/TransactionTimeoutAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import java.util.concurrent.TimeUnit;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.ejb3.annotation.TransactionTimeout;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
public class TransactionTimeoutAnnotationInformationFactory extends ClassAnnotationInformationFactory<TransactionTimeout, Integer> {
protected TransactionTimeoutAnnotationInformationFactory() {
super(TransactionTimeout.class, null);
}
@Override
protected Integer fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final long timeout = annotationInstance.value().asLong();
AnnotationValue unitAnnVal = annotationInstance.value("unit");
final TimeUnit unit = unitAnnVal != null ? TimeUnit.valueOf(unitAnnVal.asEnum()) : TimeUnit.SECONDS;
return (int) unit.toSeconds(timeout);
}
} | 2,077 | 45.177778 | 132 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/SecurityDomainAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.metadata.property.PropertyReplacer;
/**
* Processes the {@link org.jboss.ejb3.annotation.SecurityDomain} annotation on a session bean
*
* @author Stuart Douglas
*/
public class SecurityDomainAnnotationInformationFactory extends ClassAnnotationInformationFactory<SecurityDomain, String> {
protected SecurityDomainAnnotationInformationFactory() {
super(SecurityDomain.class, null);
}
@Override
protected String fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
return propertyReplacer.replaceProperties(annotationInstance.value().asString());
}
}
| 1,895 | 41.133333 | 123 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/ResourceAdaptorAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.metadata.property.PropertyReplacer;
/**
* Processes the {@link org.jboss.ejb3.annotation.ResourceAdapter} annotation
*
* @author Stuart Douglas
*/
public class ResourceAdaptorAnnotationInformationFactory extends ClassAnnotationInformationFactory<org.jboss.ejb3.annotation.ResourceAdapter, String> {
protected ResourceAdaptorAnnotationInformationFactory() {
super(org.jboss.ejb3.annotation.ResourceAdapter.class, null);
}
@Override
protected String fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
String resourceAdapterValue = annotationInstance.value().asString();
return propertyReplacer.replaceProperties(resourceAdapterValue);
}
}
| 1,945 | 42.244444 | 151 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/TransactionManagementAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
/**
* Processes the {@link jakarta.ejb.TransactionManagementType} annotation on a session bean
*
* @author Stuart Douglas
*/
public class TransactionManagementAnnotationInformationFactory extends ClassAnnotationInformationFactory<TransactionManagement, TransactionManagementType> {
protected TransactionManagementAnnotationInformationFactory() {
super(TransactionManagement.class, null);
}
@Override
protected TransactionManagementType fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final AnnotationValue value = annotationInstance.value();
if(value == null) {
return TransactionManagementType.CONTAINER;
}
return TransactionManagementType.valueOf(value.asEnum());
}
}
| 2,175 | 40.846154 | 156 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/ConcurrencyManagementAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
/**
* Processes the {@link jakarta.ejb.ConcurrencyManagement} annotation on a session bean
*
* @author Stuart Douglas
*/
public class ConcurrencyManagementAnnotationInformationFactory extends ClassAnnotationInformationFactory<ConcurrencyManagement, ConcurrencyManagementType> {
protected ConcurrencyManagementAnnotationInformationFactory() {
super(ConcurrencyManagement.class, null);
}
@Override
protected ConcurrencyManagementType fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final AnnotationValue value = annotationInstance.value();
if(value == null) {
return ConcurrencyManagementType.CONTAINER;
}
return ConcurrencyManagementType.valueOf(value.asEnum());
}
}
| 2,171 | 40.769231 | 156 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/CacheAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.as.ejb3.cache.CacheInfo;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.metadata.property.PropertyReplacer;
/**
* @author Paul Ferraro
*/
public class CacheAnnotationInformationFactory extends ClassAnnotationInformationFactory<Cache, CacheInfo> {
protected CacheAnnotationInformationFactory() {
super(Cache.class, null);
}
@Override
protected CacheInfo fromAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) {
String value = annotationInstance.value().asString();
return new CacheInfo(propertyReplacer.replaceProperties(value));
}
}
| 1,831 | 39.711111 | 114 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/ClusteredSingletonAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.ejb3.annotation.ClusteredSingleton;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.metadata.property.PropertyReplacer;
/**
* Processes the {@link ClusteredSingleton} annotation
*
* @author Flavia Rainone
*/
public class ClusteredSingletonAnnotationInformationFactory extends ClassAnnotationInformationFactory<ClusteredSingleton, Boolean> {
protected ClusteredSingletonAnnotationInformationFactory() {
super(ClusteredSingleton.class, null);
}
@Override
protected Boolean fromAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) {
return Boolean.TRUE;
}
}
| 1,804 | 39.111111 | 132 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/InitAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import jakarta.ejb.Init;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
/**
* @author Stuart Douglas
*/
public class InitAnnotationInformationFactory extends ClassAnnotationInformationFactory<Init, String> {
protected InitAnnotationInformationFactory() {
super(Init.class, null);
}
@Override
protected String fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
AnnotationValue value = annotationInstance.value();
if (value == null) {
return null;
}
return propertyReplacer.replaceProperties(value.asString());
}
}
| 1,878 | 37.346939 | 123 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/ScheduleAnnotationInformationFactory.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import jakarta.ejb.Schedule;
import jakarta.ejb.Schedules;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.timerservice.spi.AutoTimer;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.metadata.property.PropertyReplacer;
/**
* {@link org.jboss.as.ee.metadata.ClassAnnotationInformation} for Schedule annotation
*
* @author Stuart Douglas
*/
public class ScheduleAnnotationInformationFactory extends ClassAnnotationInformationFactory<Schedule, AutoTimer> {
public ScheduleAnnotationInformationFactory() {
super(Schedule.class, Schedules.class);
}
@Override
protected AutoTimer fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
final AutoTimer timer = new AutoTimer();
for (AnnotationValue av : annotationInstance.values()) {
switch (ScheduleValues.valueOf(av.name())) {
case dayOfMonth:
timer.getScheduleExpression().dayOfMonth(propertyReplacer.replaceProperties(av.asString()));
break;
case dayOfWeek:
timer.getScheduleExpression().dayOfWeek(propertyReplacer.replaceProperties(av.asString()));
break;
case hour:
timer.getScheduleExpression().hour(propertyReplacer.replaceProperties(av.asString()));
break;
case info:
timer.getTimerConfig().setInfo(propertyReplacer.replaceProperties(av.asString()));
break;
case minute:
timer.getScheduleExpression().minute(propertyReplacer.replaceProperties(av.asString()));
break;
case month:
timer.getScheduleExpression().month(propertyReplacer.replaceProperties(av.asString()));
break;
case persistent:
timer.getTimerConfig().setPersistent(av.asBoolean());
break;
case second:
timer.getScheduleExpression().second(propertyReplacer.replaceProperties(av.asString()));
break;
case timezone:
timer.getScheduleExpression().timezone(propertyReplacer.replaceProperties(av.asString()));
break;
case year:
timer.getScheduleExpression().year(propertyReplacer.replaceProperties(av.asString()));
break;
default:
throw EjbLogger.ROOT_LOGGER.invalidScheduleValue(av.name(), av.value().toString());
}
}
return timer;
}
/**
* Attribute names of {@code jakarta.ejb.Schedule} annotation.
* Enum instance names must match {@code Schedule} annotation field names.
*/
private enum ScheduleValues {
dayOfMonth,
dayOfWeek,
hour,
info,
minute,
month,
persistent,
second,
timezone,
year
}
}
| 4,270 | 39.67619 | 126 | java |
null | wildfly-main/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/annotation/EjbAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.deployment.processors.annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.ejb.AfterBegin;
import jakarta.ejb.AfterCompletion;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.BeforeCompletion;
import jakarta.ejb.Startup;
import org.jboss.as.ee.component.deployers.BooleanAnnotationInformationFactory;
import org.jboss.as.ee.metadata.AbstractEEAnnotationProcessor;
import org.jboss.as.ee.metadata.ClassAnnotationInformationFactory;
/**
* Processes Jakarta Enterprise Beans annotations and attaches them to the {@link org.jboss.as.ee.component.EEModuleClassDescription}
*
* @author Stuart Douglas
*/
public class EjbAnnotationProcessor extends AbstractEEAnnotationProcessor {
final List<ClassAnnotationInformationFactory> factories;
public EjbAnnotationProcessor() {
final List<ClassAnnotationInformationFactory> factories = new ArrayList<ClassAnnotationInformationFactory>();
factories.add(new LockAnnotationInformationFactory());
factories.add(new ConcurrencyManagementAnnotationInformationFactory());
factories.add(new AccessTimeoutAnnotationInformationFactory());
factories.add(new TransactionAttributeAnnotationInformationFactory());
factories.add(new TransactionTimeoutAnnotationInformationFactory());
factories.add(new TransactionManagementAnnotationInformationFactory());
factories.add(new RemoveAnnotationInformationFactory());
factories.add(new BooleanAnnotationInformationFactory<Startup>(Startup.class));
factories.add(new StatefulTimeoutAnnotationInformationFactory());
factories.add(new BooleanAnnotationInformationFactory<Asynchronous>(Asynchronous.class));
factories.add(new DependsOnAnnotationInformationFactory());
factories.add(new ResourceAdaptorAnnotationInformationFactory());
factories.add(new DeliveryActiveAnnotationInformationFactory());
factories.add(new DeliveryGroupAnnotationInformationFactory());
factories.add(new InitAnnotationInformationFactory());
// pool
factories.add(new PoolAnnotationInformationFactory());
//session synchronization
factories.add(new BooleanAnnotationInformationFactory<AfterBegin>(AfterBegin.class));
factories.add(new BooleanAnnotationInformationFactory<BeforeCompletion>(BeforeCompletion.class));
factories.add(new BooleanAnnotationInformationFactory<AfterCompletion>(AfterCompletion.class));
//security annotations
factories.add(new RunAsAnnotationInformationFactory());
factories.add(new RunAsPrincipalAnnotationInformationFactory());
factories.add(new SecurityDomainAnnotationInformationFactory());
factories.add(new DeclareRolesAnnotationInformationFactory());
factories.add(new RolesAllowedAnnotationInformationFactory());
factories.add(new BooleanAnnotationInformationFactory<DenyAll>(DenyAll.class));
factories.add(new BooleanAnnotationInformationFactory<PermitAll>(PermitAll.class));
//view annotations
factories.add(new LocalHomeAnnotationInformationFactory());
factories.add(new RemoteHomeAnnotationInformationFactory());
// clustering/cache annotations
factories.add(new ClusteredAnnotationInformationFactory());
factories.add(new CacheAnnotationInformationFactory());
factories.add(new ClusteredSingletonAnnotationInformationFactory());
this.factories = Collections.unmodifiableList(factories);
}
@Override
protected List<ClassAnnotationInformationFactory> annotationInformationFactories() {
return factories;
}
}
| 4,837 | 45.519231 | 133 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.