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/ee/src/main/java/org/jboss/as/ee/subsystem/EeCapabilities.java | /*
* Copyright 2019 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.ee.subsystem;
import org.jboss.as.controller.capability.RuntimeCapability;
/**
* The capabilities provided by and required by this subsystem.
*
* @author Yeray Borges
*/
public final class EeCapabilities {
private static final String CAPABILITY_BASE = "org.wildfly.ee.";
static final String PATH_MANAGER_CAPABILITY = "org.wildfly.management.path-manager";
public static final String EE_GLOBAL_DIRECTORY_CAPABILITY_NAME = CAPABILITY_BASE + "global-directory";
public static final RuntimeCapability<Void> EE_GLOBAL_DIRECTORY_CAPABILITY = RuntimeCapability
.Builder.of(EE_GLOBAL_DIRECTORY_CAPABILITY_NAME, true, GlobalDirectoryService.class)
.addRequirements(PATH_MANAGER_CAPABILITY)
.build();
public static final String LEGACY_JACC_CAPABILITY = "org.wildfly.legacy-security.jacc";
public static final String ELYTRON_JACC_CAPABILITY = "org.wildfly.security.jacc-policy";
}
| 1,559 | 35.27907 | 106 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/InjectedEENamespaceContextSelector.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.ee.naming;
import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.NamingException;
import org.jboss.as.naming.NamingStore;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.DelegatingSupplier;
/**
* A simple EE-style namespace context selector which uses injected services for the contexts.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class InjectedEENamespaceContextSelector extends NamespaceContextSelector {
private static final CompositeName EMPTY_NAME = new CompositeName();
private final DelegatingSupplier<NamingStore> jbossContext = new DelegatingSupplier<>();
private final DelegatingSupplier<NamingStore> globalContext = new DelegatingSupplier<>();
private final DelegatingSupplier<NamingStore> appContext = new DelegatingSupplier<>();
private final DelegatingSupplier<NamingStore> moduleContext = new DelegatingSupplier<>();
private final DelegatingSupplier<NamingStore> compContext = new DelegatingSupplier<>();
private final DelegatingSupplier<NamingStore> exportedContext = new DelegatingSupplier<>();
public InjectedEENamespaceContextSelector() {
}
public DelegatingSupplier<NamingStore> getAppContextSupplier() {
return appContext;
}
public DelegatingSupplier<NamingStore> getModuleContextSupplier() {
return moduleContext;
}
public DelegatingSupplier<NamingStore> getCompContextSupplier() {
return compContext;
}
public DelegatingSupplier<NamingStore> getJbossContextSupplier() {
return jbossContext;
}
public DelegatingSupplier<NamingStore> getGlobalContextSupplier() {
return globalContext;
}
public DelegatingSupplier<NamingStore> getExportedContextSupplier() {
return exportedContext;
}
private NamingStore getNamingStore(final String identifier) {
if (identifier.equals("jboss")) {
return jbossContext.get();
} else if (identifier.equals("global")) {
return globalContext.get();
} else if (identifier.equals("app")) {
return appContext.get();
} else if (identifier.equals("module")) {
return moduleContext.get();
} else if (identifier.equals("comp")) {
return compContext.get();
} else if (identifier.equals("jboss/exported")) {
return exportedContext.get();
} else {
return null;
}
}
public Context getContext(final String identifier) {
NamingStore namingStore = getNamingStore(identifier);
if (namingStore != null) {
try {
return (Context) namingStore.lookup(EMPTY_NAME);
} catch (NamingException e) {
throw new IllegalStateException(e);
}
} else {
return null;
}
}
}
| 4,049 | 36.850467 | 95 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/JavaNamespaceSetup.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.ee.naming;
import org.jboss.as.naming.WritableServiceBasedNamingStore;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.SetupAction;
import org.jboss.msc.service.ServiceName;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
/**
* Sets and restores the <code>java:</code> contexts
*
* @author Stuart Douglas
*
*/
public class JavaNamespaceSetup implements SetupAction {
private final NamespaceContextSelector namespaceSelector;
private final ServiceName deploymentUnitServiceName;
public JavaNamespaceSetup(final NamespaceContextSelector namespaceSelector, final ServiceName deploymentUnitServiceName) {
this.namespaceSelector = namespaceSelector;
this.deploymentUnitServiceName = deploymentUnitServiceName;
}
@Override
public int priority() {
return 1000;
}
@Override
public Set<ServiceName> dependencies() {
return Collections.emptySet();
}
@Override
public void setup(Map<String, Object> properties) {
NamespaceContextSelector.pushCurrentSelector(namespaceSelector);
WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
}
@Override
public void teardown(Map<String, Object> properties) {
NamespaceContextSelector.popCurrentSelector();
WritableServiceBasedNamingStore.popOwner();
}
}
| 2,463 | 33.222222 | 126 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/ContextInjectionSource.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.ee.naming;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.naming.ContextManagedReferenceFactory;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.logging.NamingLogger;
import org.jboss.as.naming.NamingStore;
import org.jboss.as.naming.deployment.ContextNames;
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;
import org.jboss.msc.service.ServiceName;
/**
*
* Injection source that can be used to bind a potentially empty context
*
* @author Stuart Douglas
*/
public class ContextInjectionSource extends InjectionSource {
private final String name;
private final String fullName;
public ContextInjectionSource(final String name, String fullName) {
this.name = name;
this.fullName = fullName;
}
@Override
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final ContextManagedReferenceFactory managedReferenceFactory = new ContextManagedReferenceFactory(name);
final ServiceName contextServiceName;
if(fullName.startsWith("java:app")) {
contextServiceName = ContextNames.contextServiceNameOfApplication(resolutionContext.getApplicationName());
} else if (fullName.startsWith("java:module") || (fullName.startsWith("java:comp") && resolutionContext.isCompUsesModule())) {
contextServiceName = ContextNames.contextServiceNameOfModule(resolutionContext.getApplicationName(), resolutionContext.getModuleName());
} else if(fullName.startsWith("java:comp")) {
contextServiceName = ContextNames.contextServiceNameOfComponent(resolutionContext.getApplicationName(), resolutionContext.getModuleName(), resolutionContext.getComponentName());
} else {
throw NamingLogger.ROOT_LOGGER.invalidNameForContextBinding(fullName);
}
serviceBuilder.addDependency(contextServiceName, NamingStore.class, managedReferenceFactory.getNamingStoreInjectedValue());
injector.inject(managedReferenceFactory);
}
}
| 3,418 | 47.842857 | 251 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/Attachments.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.ee.naming;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.msc.service.ServiceName;
/**
* EE related attachments.
*
* @author John Bailey
*/
public class Attachments {
public static final AttachmentKey<ServiceName> APPLICATION_CONTEXT_CONFIG = AttachmentKey.create(ServiceName.class);
public static final AttachmentKey<ServiceName> MODULE_CONTEXT_CONFIG = AttachmentKey.create(ServiceName.class);
public static final AttachmentKey<JavaNamespaceSetup> JAVA_NAMESPACE_SETUP_ACTION = AttachmentKey.create(JavaNamespaceSetup.class);
}
| 1,618 | 39.475 | 135 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/ModuleContextProcessor.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.ee.naming;
import static org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION;
import static org.jboss.as.ee.naming.Attachments.MODULE_CONTEXT_CONFIG;
import static org.jboss.as.server.deployment.Attachments.SETUP_ACTIONS;
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.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.naming.service.NamingStoreService;
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.ServiceName;
import org.jboss.msc.service.ServiceTarget;
/**
* Deployment processor that deploys a naming context for the current module.
*
* @author John E. Bailey
* @author Eduardo Martins
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class ModuleContextProcessor implements DeploymentUnitProcessor {
/**
* Add a ContextService for this module.
*
* @param phaseContext the deployment unit context
* @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
*/
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(moduleDescription.getApplicationName(), moduleDescription.getModuleName());
final NamingStoreService contextService = new NamingStoreService(true);
serviceTarget.addService(moduleContextServiceName, contextService).install();
final ServiceName moduleNameServiceName = moduleContextServiceName.append("ModuleName");
final BinderService moduleNameBinder = new BinderService("ModuleName");
moduleNameBinder.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(moduleDescription.getModuleName()));
serviceTarget.addService(moduleNameServiceName, moduleNameBinder)
.addDependency(moduleContextServiceName, ServiceBasedNamingStore.class, moduleNameBinder.getNamingStoreInjector())
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, moduleNameServiceName);
deploymentUnit.putAttachment(MODULE_CONTEXT_CONFIG, moduleContextServiceName);
final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
phaseContext.requires(appContextServiceName, selector.getAppContextSupplier());
phaseContext.requires(moduleContextServiceName, selector.getModuleContextSupplier());
phaseContext.requires(moduleContextServiceName, selector.getCompContextSupplier());
phaseContext.requires(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, selector.getJbossContextSupplier());
phaseContext.requires(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, selector.getExportedContextSupplier());
phaseContext.requires(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, selector.getGlobalContextSupplier());
moduleDescription.setNamespaceContextSelector(selector);
// add the arquillian setup action, so the module namespace is available in arquillian tests
final JavaNamespaceSetup setupAction = new JavaNamespaceSetup(selector, deploymentUnit.getServiceName());
deploymentUnit.addToAttachmentList(SETUP_ACTIONS, setupAction);
deploymentUnit.addToAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS, setupAction);
deploymentUnit.putAttachment(Attachments.JAVA_NAMESPACE_SETUP_ACTION, setupAction);
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
JavaNamespaceSetup action = deploymentUnit.removeAttachment(Attachments.JAVA_NAMESPACE_SETUP_ACTION);
if (action != null) {
deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS).remove(action);
deploymentUnit.getAttachmentList(SETUP_ACTIONS).remove(action);
}
deploymentUnit.removeAttachment(MODULE_CONTEXT_CONFIG);
}
}
| 6,002 | 53.572727 | 168 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/InApplicationClientBindingProcessor.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.ee.naming;
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.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.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.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
/**
* Processor responsible for binding java:comp/InAppClientContainer
*
* @author Stuart Douglas
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class InApplicationClientBindingProcessor implements DeploymentUnitProcessor {
private final boolean appclient;
public InApplicationClientBindingProcessor(final boolean appclient) {
this.appclient = appclient;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if(moduleDescription == null) {
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());
bindServices(deploymentUnit, serviceTarget, moduleContextServiceName);
}
for(ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if(component.getNamingMode() == ComponentNamingMode.CREATE) {
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(),moduleDescription.getModuleName(),component.getComponentName());
bindServices(deploymentUnit, serviceTarget, compContextServiceName);
}
}
}
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
BinderService inAppClientContainerService = new BinderService("InAppClientContainer");
final ServiceName inAppClientServiceName = contextServiceName.append("InAppClientContainer");
inAppClientContainerService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(appclient));
serviceTarget.addService(inAppClientServiceName, inAppClientContainerService)
.addDependency(contextServiceName, ServiceBasedNamingStore.class, inAppClientContainerService.getNamingStoreInjector())
.install();
final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(inAppClientServiceName);
}
}
| 5,029 | 49.3 | 205 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/ApplicationContextProcessor.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.ee.naming;
import org.jboss.as.ee.component.EEModuleDescription;
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.naming.service.NamingStoreService;
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.ServiceName;
import org.jboss.msc.service.ServiceTarget;
/**
* Deployment processor that deploys a naming context for the current application.
*
* @author John E. Bailey
* @author Eduardo Martins
*/
public class ApplicationContextProcessor implements DeploymentUnitProcessor {
/**
* Add a ContextService for this module.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.getParent() != null) {
return;
}
EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName applicationContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
final NamingStoreService contextService = new NamingStoreService(true);
serviceTarget.addService(applicationContextServiceName, contextService).install();
final ServiceName appNameServiceName = applicationContextServiceName.append("AppName");
final BinderService applicationNameBinder = new BinderService("AppName");
applicationNameBinder.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(moduleDescription.getApplicationName()));
serviceTarget.addService(appNameServiceName, applicationNameBinder)
.addDependency(applicationContextServiceName, ServiceBasedNamingStore.class, applicationNameBinder.getNamingStoreInjector())
.install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, appNameServiceName);
deploymentUnit.putAttachment(Attachments.APPLICATION_CONTEXT_CONFIG, applicationContextServiceName);
}
public void undeploy(DeploymentUnit deploymentUnit) {
deploymentUnit.removeAttachment(Attachments.APPLICATION_CONTEXT_CONFIG);
}
}
| 3,859 | 49.789474 | 143 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/naming/InstanceNameBindingProcessor.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.ee.naming;
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.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.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.ServiceBasedNamingStore;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.BinderService;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentService;
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.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
/**
* Processor responsible for binding java:comp/InstanceName
*
* @author Stuart Douglas
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class InstanceNameBindingProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if(moduleDescription == null) {
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());
bindServices(deploymentUnit, serviceTarget, moduleContextServiceName);
}
for(ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if(component.getNamingMode() == ComponentNamingMode.CREATE) {
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(moduleDescription.getApplicationName(),moduleDescription.getModuleName(),component.getComponentName());
bindServices(deploymentUnit, serviceTarget, compContextServiceName);
}
}
}
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName");
final BinderService instanceNameService = new BinderService("InstanceName");
serviceTarget.addService(instanceNameServiceName, instanceNameService)
.addDependency(contextServiceName, ServiceBasedNamingStore.class, instanceNameService.getNamingStoreInjector())
.addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, new Injector<ServerEnvironment>() {
@Override
public void inject(final ServerEnvironment serverEnvironment) throws InjectionException {
instanceNameService.getManagedObjectInjector().inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
final String nodeName = serverEnvironment.getNodeName();
return nodeName == null ? "" : nodeName;
}
};
}
});
}
@Override
public void uninject() {
instanceNameService.getManagedObjectInjector().uninject();
}
})
.install();
final Map<ServiceName, Set<ServiceName>> jndiComponentDependencies = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPONENT_JNDI_DEPENDENCIES);
Set<ServiceName> jndiDependencies = jndiComponentDependencies.get(contextServiceName);
if (jndiDependencies == null) {
jndiComponentDependencies.put(contextServiceName, jndiDependencies = new HashSet<>());
}
jndiDependencies.add(instanceNameServiceName);
}
}
| 6,183 | 48.079365 | 205 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/processors/ManagedBeanSubDeploymentMarkingProcessor.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.ee.managedbean.processors;
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.SubDeploymentMarker;
import org.jboss.as.server.deployment.module.ModuleRootMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import jakarta.annotation.ManagedBean;
import java.util.List;
/**
* Processor that only runs for ear deployments where no application.xml is provided. It examines jars in the ear to determine
* sub-deployments containing {@link ManagedBean managed beans}.
*
* @author Jaikiran Pai
*/
public class ManagedBeanSubDeploymentMarkingProcessor implements DeploymentUnitProcessor {
private static final DotName MANAGED_BEAN = DotName.createSimple(ManagedBean.class.getName());
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
List<ResourceRoot> potentialSubDeployments = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : potentialSubDeployments) {
if (ModuleRootMarker.isModuleRoot(resourceRoot)) {
// module roots cannot be managed bean jars
continue;
}
final Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null
&& !index.getAnnotations(MANAGED_BEAN).isEmpty()) {
// this is a managed bean deployment
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
}
}
}
}
| 3,248 | 42.905405 | 126 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/processors/ManagedBeanAnnotationProcessor.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.ee.managedbean.processors;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;
import jakarta.annotation.ManagedBean;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.ComponentConfiguration;
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.deployers.EEResourceReferenceProcessorRegistry;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription;
import org.jboss.as.ee.managedbean.component.ManagedBeanCreateInterceptor;
import org.jboss.as.ee.managedbean.component.ManagedBeanResourceReferenceProcessor;
import org.jboss.as.ee.structure.EJBAnnotationPropertyReplacement;
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.invocation.AccessCheckingInterceptor;
import org.jboss.invocation.ContextClassLoaderInterceptor;
import org.jboss.invocation.ImmediateInterceptorFactory;
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.property.PropertyReplacer;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* Deployment unit processor responsible for scanning a deployment to find classes with {@code jakarta.annotation.ManagedBean} annotations.
* Note: This processor only supports JSR-316 compliant managed beans. So it will not handle complimentary spec additions (ex. Jakarta Enterprise Beans).
*
* @author John E. Bailey
*/
public class ManagedBeanAnnotationProcessor implements DeploymentUnitProcessor {
static final DotName MANAGED_BEAN_ANNOTATION_NAME = DotName.createSimple(ManagedBean.class.getName());
/**
* Check the deployment annotation index for all classes with the @ManagedBean annotation. For each class with the
* annotation, collect all the required information to create a managed bean instance, and attach it to the context.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
if(compositeIndex == null) {
return;
}
final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
if (instances == null || instances.isEmpty()) {
return;
}
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
if (!(target instanceof ClassInfo)) {
throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target);
}
final ClassInfo classInfo = (ClassInfo) target;
// skip if it's not a valid managed bean class
if (!assertManagedBeanClassValidity(classInfo)) {
continue;
}
final String beanClassName = classInfo.name().toString();
// Get the managed bean name from the annotation
final AnnotationValue nameValue = instance.value();
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString());
final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
// Add the view
ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
viewDescription.getConfigurators().addFirst(new ViewConfigurator() {
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
// Add MB association interceptors
configuration.addClientPostConstructInterceptor(ManagedBeanCreateInterceptor.FACTORY, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
configuration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
}
});
viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
componentDescription.getViews().add(viewDescription);
moduleDescription.addComponent(componentDescription);
// register an EEResourceReferenceProcessor which can process @Resource references to this managed bean.
registry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
}
}
/**
* Returns true if the passed <code>managedBeanClass</code> meets the requirements set by the Managed bean spec about
* bean implementation classes. The passed <code>managedBeanClass</code> must not be an interface and must not be final or abstract.
* If it passes these requirements then this method returns true. Else it returns false.
*
* @param managedBeanClass The session bean class
* @return
*/
private static boolean assertManagedBeanClassValidity(final ClassInfo managedBeanClass) {
final short flags = managedBeanClass.flags();
final String className = managedBeanClass.name().toString();
// must *not* be an interface
if (Modifier.isInterface(flags)) {
ROOT_LOGGER.invalidManagedBeanInterface("MB.2.1.1", className);
return false;
}
// bean class must *not* be abstract or final
if (Modifier.isAbstract(flags) || Modifier.isFinal(flags)) {
ROOT_LOGGER.invalidManagedBeanAbstractOrFinal("MB.2.1.1", className);
return false;
}
// valid class
return true;
}
}
| 8,526 | 54.012903 | 245 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/processors/JavaEEDependencyProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2021, 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.ee.managedbean.processors;
import static org.jboss.as.ee.subsystem.EeSubsystemRootResource.GLASSFISH_EL;
import static org.jboss.as.ee.subsystem.EeSubsystemRootResource.JSON_API;
import static org.jboss.as.ee.subsystem.EeSubsystemRootResource.WILDFLY_NAMING;
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.jboss.modules.filter.PathFilters;
/**
* Deployment processor which adds the Jakarta EE APIs to EE deployments
* <p/>
*
* @author John E. Bailey
* @author Jason T. Greene
* @author Stuart Douglas
*/
public class JavaEEDependencyProcessor implements DeploymentUnitProcessor {
private static String JBOSS_INVOCATION_ID = "org.jboss.invocation";
private static String JBOSS_AS_EE = "org.jboss.as.ee";
private static final String[] JAVA_EE_API_MODULES = {
"jakarta.annotation.api",
"jakarta.enterprise.concurrent.api",
"jakarta.interceptor.api",
JSON_API,
"jakarta.json.bind.api",
"jakarta.resource.api",
"javax.rmi.api",
"jakarta.xml.bind.api",
GLASSFISH_EL,
"org.glassfish.javax.enterprise.concurrent"
};
/**
* Add the EE APIs as a dependency to all deployments
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final ModuleLoader moduleLoader = Module.getBootModuleLoader();
//add jboss-invocation classes needed by the proxies
ModuleDependency invocation = new ModuleDependency(moduleLoader, JBOSS_INVOCATION_ID, false, false, false, false);
invocation.addImportFilter(PathFilters.is("org/jboss/invocation/proxy/classloading"), true);
invocation.addImportFilter(PathFilters.acceptAll(), false);
moduleSpecification.addSystemDependency(invocation);
ModuleDependency ee = new ModuleDependency(moduleLoader, JBOSS_AS_EE, false, false, false, false);
ee.addImportFilter(PathFilters.is("org/jboss/as/ee/component/serialization"), true);
ee.addImportFilter(PathFilters.is("org/jboss/as/ee/concurrent"), true);
ee.addImportFilter(PathFilters.is("org/jboss/as/ee/concurrent/handle"), true);
ee.addImportFilter(PathFilters.acceptAll(), false);
moduleSpecification.addSystemDependency(ee);
// add dep for naming permission
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, WILDFLY_NAMING, false, false, false, false));
//we always add all Jakarta EE API modules, as the platform spec requires them to always be available
//we do not just add the javaee.api module, as this breaks excludes
for (final String moduleIdentifier : JAVA_EE_API_MODULES) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, true, false, true, false));
}
}
}
| 4,712 | 44.757282 | 132 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/component/ManagedBeanCreateInterceptor.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.ee.managedbean.component;
import org.jboss.as.ee.component.Component;
import org.jboss.as.ee.component.ComponentClientInstance;
import org.jboss.as.ee.component.ComponentInstance;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ManagedBeanCreateInterceptor implements Interceptor {
public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new ManagedBeanCreateInterceptor());
public Object processInvocation(final InterceptorContext context) throws Exception {
final ComponentClientInstance instance = context.getPrivateData(ComponentClientInstance.class);
final Component component = context.getPrivateData(Component.class);
final ComponentInstance componentInstance = component.createInstance();
boolean ok = false;
try {
context.putPrivateData(ComponentInstance.class, componentInstance);
instance.setViewInstanceData(ComponentInstance.class, componentInstance);
final Object result = context.proceed();
ok = true;
return result;
} finally {
context.putPrivateData(ComponentInstance.class, null);
if (! ok) {
componentInstance.destroy();
instance.setViewInstanceData(ComponentInstance.class, null);
}
}
}
}
| 2,622 | 42.716667 | 121 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/component/ManagedBeanComponentDescription.java | package org.jboss.as.ee.managedbean.component;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.msc.service.ServiceName;
/**
* Component descriptor for {@link jakarta.annotation.ManagedBean} managed beans.
*
* This is only here so that other interested processors can tell if a given component is a managed bean,
* it does not add anything to the component description.
*
* @author Stuart Douglas
*/
public class ManagedBeanComponentDescription extends ComponentDescription {
/**
* Construct a new instance.
*
* @param componentName the component name
* @param componentClassName the component instance class name
* @param moduleDescription the EE module description
* @param deploymentUnitServiceName the service name of the DU containing this component
*/
public ManagedBeanComponentDescription(final String componentName, final String componentClassName, final EEModuleDescription moduleDescription, final ServiceName deploymentUnitServiceName) {
super(componentName, componentClassName, moduleDescription, deploymentUnitServiceName);
}
}
| 1,210 | 42.25 | 195 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/managedbean/component/ManagedBeanResourceReferenceProcessor.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.ee.managedbean.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.ComponentTypeInjectionSource;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* User: jpai
*/
public class ManagedBeanResourceReferenceProcessor implements EEResourceReferenceProcessor {
private final String managedBeanClassName;
public ManagedBeanResourceReferenceProcessor(final String managedBeanClassName) {
if (managedBeanClassName == null || managedBeanClassName.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.nullOrEmptyManagedBeanClassName();
}
this.managedBeanClassName = managedBeanClassName;
}
@Override
public String getResourceReferenceType() {
return this.managedBeanClassName;
}
@Override
public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
ROOT_LOGGER.debugf("Processing @Resource of type: %s", this.managedBeanClassName);
// ComponentType binding source for managed beans
final InjectionSource bindingSource = new ComponentTypeInjectionSource(this.managedBeanClassName);
return bindingSource;
}
}
| 2,442 | 39.716667 | 106 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/weld/InjectionTargetDefiningAnnotations.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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ee.weld;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.AttachmentList;
import org.jboss.jandex.DotName;
/**
* @author Stuart Douglas
*/
public class InjectionTargetDefiningAnnotations {
/**
* A set of injection target defining annotations. These are annotations that are not enough to cause weld to activate,
* however if weld is activated these will be turned into beans.
*/
public static final AttachmentKey<AttachmentList<DotName>> INJECTION_TARGET_DEFINING_ANNOTATIONS = AttachmentKey.createList(DotName.class);
private InjectionTargetDefiningAnnotations() {
}
}
| 1,695 | 36.688889 | 143 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/utils/InjectionUtils.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.ee.utils;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Locale;
/**
* Utility class for injection framework.
*
* @author <a href="mailto:[email protected]">Richard Opalka</a>
* @author Eduardo Martins
*/
public final class InjectionUtils {
private InjectionUtils() {
// forbidden instantiation
}
public static AccessibleObject getInjectionTarget(final String injectionTargetClassName, final String injectionTargetName, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException {
final Class<?> injectionTargetClass;
try {
injectionTargetClass = classLoader.loadClass(injectionTargetClassName);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, injectionTargetClassName);
}
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(injectionTargetClass);
String methodName = "set" + injectionTargetName.substring(0, 1).toUpperCase(Locale.ENGLISH) + injectionTargetName.substring(1);
boolean methodFound = false;
Method method = null;
Field field = null;
Class<?> current = injectionTargetClass;
while (current != Object.class && current != null && !methodFound) {
final Collection<Method> methods = index.getAllMethods(methodName);
for (Method m : methods) {
if (m.getParameterCount() == 1) {
if (m.isBridge() || m.isSynthetic()) {
continue;
}
if (methodFound) {
throw EeLogger.ROOT_LOGGER.multipleSetterMethodsFound(injectionTargetName, injectionTargetClassName);
}
methodFound = true;
method = m;
}
}
current = current.getSuperclass();
}
if (method == null) {
current = injectionTargetClass;
while (current != Object.class && current != null && field == null) {
field = index.getField(injectionTargetName);
if (field != null) {
break;
}
current = current.getSuperclass();
}
}
if (field == null && method == null) {
throw EeLogger.ROOT_LOGGER.cannotResolveInjectionPoint(injectionTargetName, injectionTargetClassName);
}
return field != null ? field : method;
}
}
| 3,967 | 40.768421 | 259 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/utils/ClassLoadingUtils.java | package org.jboss.as.ee.utils;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.modules.Module;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* @author Stuart Douglas
*/
public class ClassLoadingUtils {
public static Class<?> loadClass(final String className, final DeploymentUnit du) throws ClassNotFoundException {
return loadClass(className, du.getAttachment(Attachments.MODULE));
}
public static Class<?> loadClass(final String className, final Module module) throws ClassNotFoundException {
final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
return Class.forName(className, false, module.getClassLoader());
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
}
private ClassLoadingUtils() {
}
}
| 1,069 | 33.516129 | 117 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/utils/DescriptorUtils.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.ee.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import org.jboss.as.ee.logging.EeLogger;
/**
* Utility class for working with method descriptors
*
* @author Stuart Douglas
*/
public class DescriptorUtils {
private static final Map<Class<?>, String> primitives;
static {
Map<Class<?>, String> p = new IdentityHashMap<Class<?>, String>();
p.put(void.class, "V");
p.put(byte.class, "B");
p.put(char.class, "C");
p.put(double.class, "D");
p.put(float.class, "F");
p.put(int.class, "I");
p.put(long.class, "J");
p.put(short.class, "S");
p.put(boolean.class, "Z");
primitives = Collections.unmodifiableMap(p);
}
/**
* Changes a class name to the internal form suitable for use in a descriptor string.
* <p/>
* e.g. java.lang.String => Ljava/lang/String;
*/
public static String makeDescriptor(String className) {
String repl = className.replace(".", "/");
return 'L' + repl + ';';
}
public static String makeDescriptor(Class<?> c) {
String primitive = primitives.get(c);
if(primitive != null) {
return primitive;
}else if (c.isArray()) {
return c.getName().replace(".", "/");
} else {
return makeDescriptor(c.getName());
}
}
public static String makeDescriptor(Constructor<?> c) {
StringBuilder desc = new StringBuilder("(");
for (Class<?> p : c.getParameterTypes()) {
desc.append(DescriptorUtils.makeDescriptor(p));
}
desc.append(")");
desc.append("V");
return desc.toString();
}
/**
* returns an array of String representations of the parameter types. Primitives are returned as their native
* representations, while classes are returned in the internal descriptor form e.g. Ljava/lang/Integer;
*/
public static String[] parameterDescriptors(String methodDescriptor) {
int i = 1; // char 0 is a '('
List<String> ret = new ArrayList<String>();
int arrayStart = -1;
while (methodDescriptor.charAt(i) != ')') {
String type = null;
if (methodDescriptor.charAt(i) == '[') {
if (arrayStart == -1) {
arrayStart = i;
}
} else {
if (methodDescriptor.charAt(i) == 'L') {
int start = i;
i++;
while (methodDescriptor.charAt(i) != ';') {
++i;
}
if (arrayStart == -1) {
type = methodDescriptor.substring(start, i);
} else {
type = methodDescriptor.substring(arrayStart, i);
}
} else {
if (arrayStart == -1) {
type = methodDescriptor.charAt(i) + "";
} else {
type = methodDescriptor.substring(arrayStart, i + 1);
}
}
arrayStart = -1;
ret.add(type);
}
++i;
}
String[] r = new String[ret.size()];
for (int j = 0; j < ret.size(); ++j) {
r[j] = ret.get(j);
}
return r;
}
public static String[] parameterDescriptors(Method m) {
return parameterDescriptors(m.getParameterTypes());
}
public static String[] parameterDescriptors(Class<?>[] parameters) {
String[] ret = new String[parameters.length];
for (int i = 0; i < ret.length; ++i) {
ret[i] = DescriptorUtils.makeDescriptor(parameters[i]);
}
return ret;
}
public static String returnType(String methodDescriptor) {
return methodDescriptor.substring(methodDescriptor.lastIndexOf(')') + 1);
}
/**
* returns true if the descriptor represents a primitive type
*/
public static boolean isPrimitive(String descriptor) {
if (descriptor.length() == 1) {
return true;
}
return false;
}
public static String methodDescriptor(Method m) {
StringBuilder desc = new StringBuilder("(");
for (Class<?> p : m.getParameterTypes()) {
desc.append(DescriptorUtils.makeDescriptor(p));
}
desc.append(")");
desc.append(DescriptorUtils.makeDescriptor(m.getReturnType()));
return desc.toString();
}
public static String methodDescriptor(String[] parameters, String returnType) {
StringBuilder desc = new StringBuilder("(");
for (String p : parameters) {
desc.append(p);
}
desc.append(")");
desc.append(returnType);
return desc.toString();
}
/**
* performs basic validation on a descriptor
*/
public static String validateDescriptor(String descriptor) {
if (descriptor.length() == 0) {
throw EeLogger.ROOT_LOGGER.cannotBeEmpty("descriptors");
}
if (descriptor.length() > 1) {
if (descriptor.startsWith("L")) {
if (!descriptor.endsWith(";")) {
throw EeLogger.ROOT_LOGGER.invalidDescriptor(descriptor);
}
} else if (descriptor.startsWith("[")) {
} else {
throw EeLogger.ROOT_LOGGER.invalidDescriptor(descriptor);
}
} else {
char type = descriptor.charAt(0);
switch (type) {
case 'I':
case 'Z':
case 'S':
case 'B':
case 'F':
case 'D':
case 'V':
case 'J':
case 'C':
break;
default:
throw EeLogger.ROOT_LOGGER.invalidDescriptor(descriptor);
}
}
return descriptor;
}
}
| 7,233 | 32.183486 | 113 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/resource/definition/ResourceDefinitionAnnotationProcessor.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.ee.resource.definition;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.structure.EJBAnnotationPropertyReplacement;
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.metadata.property.PropertyReplacer;
import java.util.List;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* The foundation to create processors wrt deployment of classes annotated with EE Resource Definitions, as defined by EE.5.18.
*
* @author Eduardo Martins
*/
public abstract class ResourceDefinitionAnnotationProcessor implements DeploymentUnitProcessor {
/**
* Retrieves the annotation's dot name.
* @return
*/
protected abstract DotName getAnnotationDotName();
/**
* Retrieves the annotation collection's dot name.
* @return
*/
protected abstract DotName getAnnotationCollectionDotName();
/**
* Processes an annotation instance.
* @param annotationInstance the annotation instance
* @param propertyReplacer the property replacer which the processor may use to resolve annotation element values
* @return a resource definition injection source
* @throws DeploymentUnitProcessingException
*/
protected abstract ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException;
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
return;
}
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index == null) {
return;
}
final PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
final DotName annotationName = getAnnotationDotName();
for (AnnotationInstance annotationInstance : index.getAnnotations(annotationName)) {
final List<BindingConfiguration> bindingConfigurations = getAnnotatedClassBindingConfigurations(moduleDescription, annotationInstance);
final ResourceDefinitionInjectionSource injectionSource = processAnnotation(annotationInstance, propertyReplacer);
bindingConfigurations.add(new BindingConfiguration(injectionSource.getJndiName(),injectionSource));
}
final DotName collectionAnnotationName = getAnnotationCollectionDotName();
if (collectionAnnotationName != null) {
for (AnnotationInstance annotationInstance : index.getAnnotations(collectionAnnotationName)) {
final AnnotationInstance[] nestedAnnotationInstances = annotationInstance.value().asNestedArray();
if (nestedAnnotationInstances != null && nestedAnnotationInstances.length > 0) {
final List<BindingConfiguration> bindingConfigurations = getAnnotatedClassBindingConfigurations(moduleDescription, annotationInstance);
for (AnnotationInstance nestedAnnotationInstance : nestedAnnotationInstances) {
final ResourceDefinitionInjectionSource injectionSource = processAnnotation(nestedAnnotationInstance, propertyReplacer);
bindingConfigurations.add(new BindingConfiguration(injectionSource.getJndiName(),injectionSource));
}
}
}
}
}
private List<BindingConfiguration> getAnnotatedClassBindingConfigurations(EEModuleDescription moduleDescription, AnnotationInstance annotationInstance) throws DeploymentUnitProcessingException {
final AnnotationTarget target = annotationInstance.target();
if (!(target instanceof ClassInfo)) {
throw ROOT_LOGGER.classOnlyAnnotation(annotationInstance.toString(), target);
}
final ClassInfo classInfo = (ClassInfo) target;
return moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString()).getBindingConfigurations();
}
/**
* Utility class to help handle resource definition annotation elements
*/
public static class AnnotationElement {
public static final String NAME = "name";
public static final String PROPERTIES = "properties";
public static boolean asOptionalBoolean(final AnnotationInstance annotation, String property) {
AnnotationValue value = annotation.value(property);
return value == null ? true : value.asBoolean();
}
public static int asOptionalInt(AnnotationInstance annotation, String string) {
AnnotationValue value = annotation.value(string);
return value == null ? -1 : value.asInt();
}
public static int asOptionalInt(AnnotationInstance annotation, String property, int defaultValue) {
AnnotationValue value = annotation.value(property);
return value == null ? defaultValue : value.asInt();
}
public static String asOptionalString(AnnotationInstance annotation, String property) {
return asOptionalString(annotation, property, "", null);
}
public static String asOptionalString(AnnotationInstance annotation, String property, String defaultValue) {
return asOptionalString(annotation, property, defaultValue, null);
}
public static String asOptionalString(AnnotationInstance annotation, String property, PropertyReplacer propertyReplacer) {
return asOptionalString(annotation, property, "", propertyReplacer);
}
public static String asOptionalString(AnnotationInstance annotation, String property, String defaultValue, PropertyReplacer propertyReplacer) {
AnnotationValue value = annotation.value(property);
if (value == null) {
return defaultValue;
} else {
String valueString = value.asString();
if (valueString.isEmpty()) {
return defaultValue;
} else {
return propertyReplacer != null ? propertyReplacer.replaceProperties(valueString) : valueString;
}
}
}
public static String[] asOptionalStringArray(AnnotationInstance annotation, String property) {
AnnotationValue value = annotation.value(property);
return value == null ? new String[0] : value.asStringArray();
}
public static String asRequiredString(AnnotationInstance annotationInstance, String attributeName) {
return asRequiredString(annotationInstance, attributeName, null);
}
public static String asRequiredString(AnnotationInstance annotationInstance, final String attributeName, PropertyReplacer propertyReplacer) {
final AnnotationValue nameValue = annotationInstance.value(attributeName);
if (nameValue == null) {
throw ROOT_LOGGER.annotationAttributeMissing(annotationInstance.name().toString(), attributeName);
}
final String nameValueAsString = nameValue.asString();
if (nameValueAsString.isEmpty()) {
throw ROOT_LOGGER.annotationAttributeMissing(annotationInstance.name().toString(), attributeName);
}
return propertyReplacer != null ? propertyReplacer.replaceProperties(nameValueAsString) : nameValueAsString;
}
}
}
| 9,342 | 49.231183 | 198 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/resource/definition/ResourceDefinitionInjectionSource.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.ee.resource.definition;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.metadata.javaee.spec.PropertiesMetaData;
import org.jboss.metadata.javaee.spec.PropertyMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import java.util.HashMap;
import java.util.Map;
/**
* The abstract InjectionSource for EE Resource Definitions.
* @author Eduardo Martins
*/
public abstract class ResourceDefinitionInjectionSource extends InjectionSource {
protected final String jndiName;
protected final Map<String, String> properties = new HashMap<>();
public ResourceDefinitionInjectionSource(final String jndiName) {
if (jndiName.startsWith("java:")) {
this.jndiName = jndiName;
} else {
this.jndiName = "java:comp/env/" + jndiName;
}
}
public String getJndiName() {
return jndiName;
}
protected String uniqueName(ResolutionContext context) {
final StringBuilder name = new StringBuilder();
name.append(context.getApplicationName() + "_");
name.append(context.getModuleName() + "_");
if (context.getComponentName() != null) {
name.append(context.getComponentName() + "_");
}
name.append(jndiName);
return name.toString();
}
/**
* Add the specified properties.
* @param annotationProperties an array of propertyName = propertyValue strings
*/
public void addProperties(final String[] annotationProperties) {
addProperties(annotationProperties, null);
}
/**
* Add the specified properties.
* @param annotationProperties an array of propertyName = propertyValue strings
* @param propertyReplacer if not null all property names and values will be processed by the replacer.
*/
public void addProperties(final String[] annotationProperties, final PropertyReplacer propertyReplacer) {
if (annotationProperties != null) {
for (String annotationProperty : annotationProperties) {
if (propertyReplacer != null) {
annotationProperty = propertyReplacer.replaceProperties(annotationProperty);
}
final int index = annotationProperty.indexOf('=');
String propertyName;
String propertyValue;
if (index != -1) {
propertyName = annotationProperty.substring(0, index);
propertyValue = annotationProperty.length() > index ? annotationProperty.substring(index + 1) : "";
} else {
propertyName = annotationProperty;
propertyValue = "";
}
this.properties.put(propertyName, propertyValue);
}
}
}
/**
* Add the specified properties.
* @param descriptorProperties the metadata properties to add
*/
public void addProperties(final PropertiesMetaData descriptorProperties) {
if (descriptorProperties != null) {
for (PropertyMetaData descriptorProperty : descriptorProperties) {
this.properties.put(descriptorProperty.getName(), descriptorProperty.getValue());
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceDefinitionInjectionSource that = (ResourceDefinitionInjectionSource) o;
if (!jndiName.equals(that.jndiName)) return false;
if (!properties.equals(that.properties)) return false;
return true;
}
@Override
public int hashCode() {
int result = jndiName.hashCode();
result = 31 * result + properties.hashCode();
return result;
}
}
| 4,863 | 36.705426 | 119 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/resource/definition/ResourceDefinitionDescriptorProcessor.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.ee.resource.definition;
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.ResourceInjectionTarget;
import org.jboss.as.ee.component.deployers.AbstractDeploymentDescriptorBindingsProcessor;
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.RemoteEnvironment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Foundation for resource definition deployment descriptor processors.
*
* @author Eduardo Martins
*/
public abstract class ResourceDefinitionDescriptorProcessor extends AbstractDeploymentDescriptorBindingsProcessor {
@Override
protected List<BindingConfiguration> processDescriptorEntries(final DeploymentUnit deploymentUnit, final DeploymentDescriptorEnvironment environment, final ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
final ResourceDefinitionInjectionSources injectionSources = new ResourceDefinitionInjectionSources();
processEnvironment(environment.getEnvironment(), injectionSources);
if (injectionSources.bindingConfigurations != null) {
return injectionSources.bindingConfigurations;
} else {
return Collections.emptyList();
}
}
protected abstract void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException;
public static class ResourceDefinitionInjectionSources {
private List<BindingConfiguration> bindingConfigurations;
public void addResourceDefinitionInjectionSource(ResourceDefinitionInjectionSource injectionSource) {
if (bindingConfigurations == null) {
bindingConfigurations = new ArrayList<>();
}
bindingConfigurations.add(new BindingConfiguration(injectionSource.getJndiName(), injectionSource));
}
}
}
| 3,520 | 47.232877 | 437 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/AnnotationMetadata.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.ee.metadata;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Map;
/**
* Represents a piece of component metadata
*
* @author Stuart Douglas
*/
public class AnnotationMetadata<T> {
private final T componentDefault;
private final Map<Method, T> methodOverrides;
public AnnotationMetadata(final T componentDefault, final Map<Method, T> methodOverrides) {
this.componentDefault = componentDefault;
this.methodOverrides = Collections.unmodifiableMap(methodOverrides);
}
public T getComponentDefault() {
return componentDefault;
}
public Map<Method, T> getMethodOverrides() {
return methodOverrides;
}
}
| 1,742 | 32.519231 | 95 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/MetadataCompleteMarker.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.ee.metadata;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentUnit;
/**
* Marker class used to set/get the metadata-complete status of the deployment.
*
* @author Stuart Douglas
*/
public class MetadataCompleteMarker {
private static final AttachmentKey<Boolean> KEY = AttachmentKey.create(Boolean.class);
public static void setMetadataComplete(final DeploymentUnit deploymentUnit, final boolean value) {
deploymentUnit.putAttachment(KEY, value);
}
public static boolean isMetadataComplete(final DeploymentUnit deploymentUnit) {
final Boolean marker = deploymentUnit.getAttachment(KEY);
return marker != null && marker;
}
private MetadataCompleteMarker() {
}
}
| 1,812 | 36.770833 | 102 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/AbstractEEAnnotationProcessor.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.ee.metadata;
import java.util.List;
import java.util.Map;
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.structure.EJBAnnotationPropertyReplacement;
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.metadata.property.PropertyReplacer;
/**
* Superclass for EE annotation processors that attach their information to the EEClassDescription via {@link ClassAnnotationInformation}
*
* @author Stuart Douglas
*/
public abstract class AbstractEEAnnotationProcessor implements DeploymentUnitProcessor {
public final void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
if (index == null || eeModuleDescription == null) {
return;
}
final List<ClassAnnotationInformationFactory> factories = annotationInformationFactories();
for (final ClassAnnotationInformationFactory factory : factories) {
final Map<String, ClassAnnotationInformation<?, ?>> data = factory.createAnnotationInformation(index, propertyReplacer);
for (Map.Entry<String, ClassAnnotationInformation<?, ?>> entry : data.entrySet()) {
EEModuleClassDescription clazz = eeModuleDescription.addOrGetLocalClassDescription(entry.getKey());
clazz.addAnnotationInformation(entry.getValue());
}
}
afterAnnotationsProcessed(phaseContext, deploymentUnit);
}
/**
* Method that can be overridden to do any additional processing
* @param phaseContext The phase context
* @param deploymentUnit The deployment unit
*/
protected void afterAnnotationsProcessed(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit) {
}
/**
*
* @return The annotation information factories
*/
protected abstract List<ClassAnnotationInformationFactory> annotationInformationFactories();
}
| 3,787 | 45.765432 | 137 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/MethodAnnotationAggregator.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.ee.metadata;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Class which can turn a pre-runtime description of annotations into a runtime description.
* <p/>
* This correctly handles overridden methods, so the annotations on overridden methods will not show up in the result
*
* @author Stuart Douglas
*/
public class MethodAnnotationAggregator {
public static <A extends Annotation, T> RuntimeAnnotationInformation<T> runtimeAnnotationInformation(final Class<?> componentClass, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex index, final Class<A> annotationType) {
final HashSet<MethodIdentifier> methodIdentifiers = new HashSet<MethodIdentifier>();
final Map<Method, List<T>> methods = new HashMap<Method, List<T>>();
final Map<String, List<T>> classAnnotations = new HashMap<String, List<T>>();
Class<?> c = componentClass;
while (c != null && c != Object.class) {
final ClassReflectionIndex classIndex = index.getClassIndex(c);
final EEModuleClassDescription description = applicationClasses.getClassByName(c.getName());
if (description != null) {
ClassAnnotationInformation<A, T> annotationData = description.getAnnotationInformation(annotationType);
if (annotationData != null) {
if (!annotationData.getClassLevelAnnotations().isEmpty()) {
classAnnotations.put(c.getName(), annotationData.getClassLevelAnnotations());
}
for (Map.Entry<MethodIdentifier, List<T>> entry : annotationData.getMethodLevelAnnotations().entrySet()) {
final Method method = classIndex.getMethod(entry.getKey());
if (method != null) {
//we do not have to worry about private methods being overridden
if (Modifier.isPrivate(method.getModifiers()) || !methodIdentifiers.contains(entry.getKey())) {
methods.put(method, entry.getValue());
}
} else {
//this should not happen
//but if it does, we give some info
throw EeLogger.ROOT_LOGGER.cannotResolveMethod(entry.getKey(), c, entry.getValue());
}
}
}
}
//we store all the method identifiers
//so we can check if a method is overriden
for (Method method : (Iterable<Method>)classIndex.getMethods()) {
//we do not have to worry about private methods being overridden
if (!Modifier.isPrivate(method.getModifiers())) {
methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
}
}
c = c.getSuperclass();
}
return new RuntimeAnnotationInformation<T>(classAnnotations, methods);
}
public static <A extends Annotation, T> Set<Method> runtimeAnnotationPresent(final Class<?> componentClass, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex index, final Class<A> annotationType) {
RuntimeAnnotationInformation<Object> result = runtimeAnnotationInformation(componentClass, applicationClasses, index, annotationType);
return result.getMethodAnnotations().keySet();
}
}
| 5,064 | 46.783019 | 254 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/ClassAnnotationInformation.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.ee.metadata;
import org.jboss.invocation.proxy.MethodIdentifier;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Class level information about the annotations present on a particular class.
*
* @param <A> The annotation type
* @param <T> The data type that is used to store the annotation information internally
* @author Stuart Douglas
*/
public final class ClassAnnotationInformation<A extends Annotation, T> {
private final Class<A> annotationType;
private final List<T> classLevelAnnotations;
private final Map<MethodIdentifier, List<T>> methodLevelAnnotations;
private final Map<String, List<T>> fieldLevelAnnotations;
ClassAnnotationInformation(final Class<A> annotationType, final List<T> classLevelAnnotations, final Map<MethodIdentifier, List<T>> methodLevelAnnotations, final Map<String, List<T>> fieldLevelAnnotations) {
this.annotationType = annotationType;
this.classLevelAnnotations = Collections.unmodifiableList(classLevelAnnotations);
this.methodLevelAnnotations = Collections.unmodifiableMap(methodLevelAnnotations);
this.fieldLevelAnnotations = Collections.unmodifiableMap(fieldLevelAnnotations);
}
public Class<A> getAnnotationType() {
return annotationType;
}
public List<T> getClassLevelAnnotations() {
return classLevelAnnotations;
}
public Map<String, List<T>> getFieldLevelAnnotations() {
return fieldLevelAnnotations;
}
public Map<MethodIdentifier, List<T>> getMethodLevelAnnotations() {
return methodLevelAnnotations;
}
}
| 2,694 | 38.632353 | 211 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/EJBClientDescriptorMetaData.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.ee.metadata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Metadata for configurations contained in jboss-ejb-client.xml descriptor
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
public class EJBClientDescriptorMetaData {
private Boolean excludeLocalReceiver;
private Boolean localReceiverPassByValue;
private long invocationTimeout;
private String deploymentNodeSelector;
private String profile;
private int defaultCompression = -1;
private final Map<String, RemotingReceiverConfiguration> remotingReceiverConfigurations = new HashMap<String, RemotingReceiverConfiguration>();
private final List<HttpConnectionConfiguration> httpConnectionConfigurations = new ArrayList<>();
private final Set<ClusterConfig> clusterConfigs = new HashSet<ClusterConfig>();
/**
* Adds an outbound connection reference used by a remoting receiver in the client context represented
* by this {@link EJBClientDescriptorMetaData}
*
* @param outboundConnectionRef The name of the outbound connection. Cannot be null or empty string.
*/
public RemotingReceiverConfiguration addRemotingReceiverConnectionRef(final String outboundConnectionRef) {
if (outboundConnectionRef == null || outboundConnectionRef.trim().isEmpty()) {
throw new IllegalArgumentException("Cannot add a remoting receiver which references a null/empty outbound connection");
}
final RemotingReceiverConfiguration remotingReceiverConfiguration = new RemotingReceiverConfiguration(outboundConnectionRef);
this.remotingReceiverConfigurations.put(outboundConnectionRef, remotingReceiverConfiguration);
return remotingReceiverConfiguration;
}
/**
* Adds an HTTP connection
* by this {@link EJBClientDescriptorMetaData}
*
* @param uri The uri of the HTTP outbound connection. Cannot be null or empty string.
*/
public HttpConnectionConfiguration addHttpConnectionRef(final String uri) {
if (uri == null || uri.trim().isEmpty()) {
throw new IllegalArgumentException("Cannot add a HTTP connection which references a null/empty URI");
}
final HttpConnectionConfiguration httpConnectionConfiguration = new HttpConnectionConfiguration(uri);
this.httpConnectionConfigurations.add(httpConnectionConfiguration);
return httpConnectionConfiguration;
}
/**
* Returns a collection of outbound connection references that are used by the remoting receivers
* configured in the client context of this {@link EJBClientDescriptorMetaData}
*
* @return
*/
public Collection<RemotingReceiverConfiguration> getRemotingReceiverConfigurations() {
return this.remotingReceiverConfigurations.values();
}
public List<HttpConnectionConfiguration> getHttpConnectionConfigurations() {
return httpConnectionConfigurations;
}
/**
* Set the pass-by-value semantics for the local receiver belonging to the Jakarta Enterprise Beans client context
* represented by this metadata
*
* @param passByValue True if pass-by-value. False otherwise.
*/
public void setLocalReceiverPassByValue(final Boolean passByValue) {
this.localReceiverPassByValue = passByValue;
}
/**
* If pass-by-value semantics for the local Jakarta Enterprise Beans receiver has been explicitly set, then returns that value.
* Else returns null.
*
* @return
*/
public Boolean isLocalReceiverPassByValue() {
return this.localReceiverPassByValue;
}
/**
* Exclude/include the local receiver in the Jakarta Enterprise Beans client context represented by this metadata.
*
* @param excludeLocalReceiver True if local receiver has to be excluded in the Jakarta Enterprise Beans client context. False otherwise.
*/
public void setExcludeLocalReceiver(final Boolean excludeLocalReceiver) {
this.excludeLocalReceiver = excludeLocalReceiver;
}
/**
* Returns true if the local receiver is disabled in the Jakarta Enterprise Beans client context represented by this metadata.
* Else returns false.
*
* @return
*/
public Boolean isLocalReceiverExcluded() {
return this.excludeLocalReceiver;
}
public Collection<ClusterConfig> getClusterConfigs() {
return Collections.unmodifiableSet(this.clusterConfigs);
}
public ClusterConfig newClusterConfig(final String clusterName) {
final ClusterConfig clusterConfig = new ClusterConfig(clusterName);
this.clusterConfigs.add(clusterConfig);
return clusterConfig;
}
public long getInvocationTimeout() {
return this.invocationTimeout;
}
public void setInvocationTimeout(final long invocationTimeout) {
this.invocationTimeout = invocationTimeout;
}
public String getDeploymentNodeSelector() {
return this.deploymentNodeSelector;
}
public void setDeploymentNodeSelector(final String selector) {
this.deploymentNodeSelector = selector;
}
public String getProfile() {
return this.profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public int getDefaultCompression() {
return defaultCompression;
}
public void setDefaultCompression(int defaultCompression) {
this.defaultCompression = defaultCompression;
}
public class ClusterConfig extends CommonConnectionConfig {
private final String clusterName;
private final Set<ClusterNodeConfig> nodes = new HashSet<ClusterNodeConfig>();
private long maxAllowedConnectedNodes;
private String nodeSelector;
ClusterConfig(final String clusterName) {
this.clusterName = clusterName;
}
public ClusterNodeConfig newClusterNode(final String nodeName) {
final ClusterNodeConfig node = new ClusterNodeConfig(nodeName);
this.nodes.add(node);
return node;
}
public Collection<ClusterNodeConfig> getClusterNodeConfigs() {
return Collections.unmodifiableSet(this.nodes);
}
public String getClusterName() {
return this.clusterName;
}
public long getMaxAllowedConnectedNodes() {
return this.maxAllowedConnectedNodes;
}
public void setMaxAllowedConnectedNodes(final long maxAllowedConnectedNodes) {
this.maxAllowedConnectedNodes = maxAllowedConnectedNodes;
}
public void setNodeSelector(final String nodeSelector) {
this.nodeSelector = nodeSelector;
}
public String getNodeSelector() {
return this.nodeSelector;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClusterConfig that = (ClusterConfig) o;
if (!clusterName.equals(that.clusterName)) return false;
return true;
}
@Override
public int hashCode() {
return clusterName.hashCode();
}
}
public class ClusterNodeConfig extends CommonConnectionConfig {
private final String nodeName;
ClusterNodeConfig(final String nodeName) {
this.nodeName = nodeName;
}
public String getNodeName() {
return this.nodeName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClusterNodeConfig that = (ClusterNodeConfig) o;
if (!nodeName.equals(that.nodeName)) return false;
return true;
}
@Override
public int hashCode() {
return nodeName.hashCode();
}
}
private class CommonConnectionConfig {
private Properties connectionOptions;
private Properties channelCreationOptions;
private long connectTimeout;
public void setConnectionOptions(final Properties connectionOptions) {
this.connectionOptions = connectionOptions;
}
public void setChannelCreationOptions(final Properties channelCreationOptions) {
this.channelCreationOptions = channelCreationOptions;
}
public long getConnectTimeout() {
return this.connectTimeout;
}
public void setConnectTimeout(final long timeout) {
this.connectTimeout = timeout;
}
public Properties getConnectionOptions() {
return this.connectionOptions;
}
public Properties getChannelCreationOptions() {
return this.channelCreationOptions;
}
}
public class RemotingReceiverConfiguration {
private final String outboundConnectionRef;
private Properties channelCreationOptions;
private long connectionTimeout;
RemotingReceiverConfiguration(final String outboundConnectionRef) {
this.outboundConnectionRef = outboundConnectionRef;
}
/**
* Sets the channel creation options for this remoting receiver configuration
*
* @param channelCreationOpts The channel creation options
*/
public void setChannelCreationOptions(final Properties channelCreationOpts) {
this.channelCreationOptions = channelCreationOpts;
}
public Properties getChannelCreationOptions() {
return this.channelCreationOptions;
}
public void setConnectionTimeout(final long timeout) {
this.connectionTimeout = timeout;
}
public long getConnectionTimeout() {
return this.connectionTimeout;
}
public String getOutboundConnectionRef() {
return this.outboundConnectionRef;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RemotingReceiverConfiguration that = (RemotingReceiverConfiguration) o;
if (outboundConnectionRef != null ? !outboundConnectionRef.equals(that.outboundConnectionRef) : that.outboundConnectionRef != null)
return false;
return true;
}
@Override
public int hashCode() {
return outboundConnectionRef != null ? outboundConnectionRef.hashCode() : 0;
}
}
public static final class HttpConnectionConfiguration {
private final String uri;
HttpConnectionConfiguration(final String uri) {
this.uri = uri;
}
public String getUri() {
return uri;
}
}
}
| 12,215 | 32.377049 | 147 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/ClassAnnotationInformationFactory.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.ee.metadata;
import org.jboss.as.ee.logging.EeLogger;
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.FieldInfo;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.MethodParameterInfo;
import org.jboss.metadata.property.PropertyReplacer;
import java.lang.annotation.Annotation;
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;
/**
* Abstract factory that can produce a {@link ClassAnnotationInformation}
*
* @author Stuart Douglas
*/
public abstract class ClassAnnotationInformationFactory<A extends Annotation, T> {
private final Class<A> annotationType;
private final Class<?> multiAnnotationType;
private final DotName annotationDotName;
private final DotName multiAnnotationDotName;
protected ClassAnnotationInformationFactory(final Class<A> annotationType, final Class<?> multiAnnotationType) {
this.annotationType = annotationType;
this.annotationDotName = DotName.createSimple(annotationType.getName());
this.multiAnnotationType = multiAnnotationType;
if (multiAnnotationType != null) {
this.multiAnnotationDotName = DotName.createSimple(multiAnnotationType.getName());
} else {
this.multiAnnotationDotName = null;
}
}
public Map<String, ClassAnnotationInformation<A, T>> createAnnotationInformation(final CompositeIndex index, final PropertyReplacer propertyReplacer) {
final List<TargetAnnotation> annotations = new ArrayList<TargetAnnotation>();
if (multiAnnotationDotName != null) {
for (AnnotationInstance multiInstance : index.getAnnotations(multiAnnotationDotName)) {
annotations.addAll(fromMultiAnnotation(multiInstance));
}
}
final List<AnnotationInstance> simpleAnnotations = index.getAnnotations(annotationDotName);
if (simpleAnnotations != null) {
for(AnnotationInstance annotation : simpleAnnotations) {
annotations.add(new TargetAnnotation(annotation, annotation.target()));
}
}
final Map<DotName, List<TargetAnnotation>> classLevel = new HashMap<DotName, List<TargetAnnotation>>();
final Map<DotName, List<TargetAnnotation>> methodLevel = new HashMap<DotName, List<TargetAnnotation>>();
final Map<DotName, List<TargetAnnotation>> fieldLevel = new HashMap<DotName, List<TargetAnnotation>>();
for (TargetAnnotation instance : annotations) {
final DotName targetClass = getAnnotationClass(instance.target()).name();
if (instance.target() instanceof ClassInfo) {
List<TargetAnnotation> data = classLevel.get(targetClass);
if (data == null) classLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof MethodInfo) {
List<TargetAnnotation> data = methodLevel.get(targetClass);
if (data == null) methodLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof FieldInfo) {
List<TargetAnnotation> data = fieldLevel.get(targetClass);
if (data == null) fieldLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof MethodParameterInfo) {
//ignore for now
} else {
throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(instance.target());
}
}
final Map<String, ClassAnnotationInformation<A, T>> ret = new HashMap<String, ClassAnnotationInformation<A, T>>();
final Set<DotName> allClasses = new HashSet<DotName>(classLevel.keySet());
allClasses.addAll(methodLevel.keySet());
allClasses.addAll(fieldLevel.keySet());
for (DotName clazz : allClasses) {
final List<TargetAnnotation> classAnnotations = classLevel.get(clazz);
final List<T> classData;
if (classAnnotations == null) {
classData = Collections.emptyList();
} else {
classData = new ArrayList<T>(classAnnotations.size());
for (TargetAnnotation instance : classAnnotations) {
classData.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
final List<TargetAnnotation> fieldAnnotations = fieldLevel.get(clazz);
final Map<String, List<T>> fieldData;
//field level annotations
if (fieldAnnotations == null) {
fieldData = Collections.emptyMap();
} else {
fieldData = new HashMap<String, List<T>>();
for (TargetAnnotation instance : fieldAnnotations) {
final String name = ((FieldInfo) instance.target()).name();
List<T> data = fieldData.get(name);
if (data == null) {
fieldData.put(name, data = new ArrayList<T>(1));
}
data.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
final List<TargetAnnotation> methodAnnotations = methodLevel.get(clazz);
final Map<MethodIdentifier, List<T>> methodData;
//method level annotations
if (methodAnnotations == null) {
methodData = Collections.emptyMap();
} else {
methodData = new HashMap<MethodIdentifier, List<T>>();
for (TargetAnnotation instance : methodAnnotations) {
final MethodIdentifier identifier = getMethodIdentifier(instance.target());
List<T> data = methodData.get(identifier);
if (data == null) {
methodData.put(identifier, data = new ArrayList<T>(1));
}
data.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
ClassAnnotationInformation<A, T> information = new ClassAnnotationInformation<A, T>(annotationType, classData, methodData, fieldData);
ret.put(clazz.toString(), information);
}
return ret;
}
private ClassInfo getAnnotationClass(final AnnotationTarget annotationTarget) {
if (annotationTarget instanceof ClassInfo) {
return (ClassInfo) annotationTarget;
} else if (annotationTarget instanceof MethodInfo) {
return ((MethodInfo) annotationTarget).declaringClass();
} else if (annotationTarget instanceof FieldInfo) {
return ((FieldInfo) annotationTarget).declaringClass();
} else if (annotationTarget instanceof MethodParameterInfo) {
return ((MethodParameterInfo) annotationTarget).method().declaringClass();
} else {
throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(annotationTarget);
}
}
protected abstract T fromAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer);
protected List<TargetAnnotation> fromMultiAnnotation(AnnotationInstance multiAnnotationInstance) {
List<TargetAnnotation> instances = new ArrayList<TargetAnnotation>();
final AnnotationInstance[] values = multiAnnotationInstance.value().asNestedArray();
for(AnnotationInstance value : values) {
instances.add(new TargetAnnotation(value, multiAnnotationInstance.target()));
}
return instances;
}
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) {
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final String[] args = new String[methodInfo.args().length];
for (int i = 0; i < methodInfo.args().length; i++) {
args[i] = methodInfo.args()[i].name().toString();
}
return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args);
}
public Class<A> getAnnotationType() {
return annotationType;
}
public Class<?> getMultiAnnotationType() {
return multiAnnotationType;
}
private static final class TargetAnnotation {
private final AnnotationInstance instance;
private final AnnotationTarget target;
TargetAnnotation(final AnnotationInstance instance, final AnnotationTarget target) {
this.instance = instance;
this.target = target;
}
public AnnotationInstance instance() {
return instance;
}
public AnnotationTarget target() {
return target;
}
}
}
| 10,227 | 43.086207 | 155 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/RuntimeAnnotationInformation.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.ee.metadata;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Runtime metadata about the annotations that are present on a particular class
*
* @author Stuart Douglas
*/
public class RuntimeAnnotationInformation<T> {
private final Map<String, List<T>> classAnnotations;
private final Map<Method, List<T>> methodAnnotations;
public RuntimeAnnotationInformation(final Map<String, List<T>> classAnnotations, final Map<Method, List<T>> methodAnnotations) {
this.classAnnotations = Collections.unmodifiableMap(classAnnotations);
this.methodAnnotations = Collections.unmodifiableMap(methodAnnotations);
}
public Map<String, List<T>> getClassAnnotations() {
return classAnnotations;
}
public Map<Method, List<T>> getMethodAnnotations() {
return methodAnnotations;
}
}
| 1,937 | 36.269231 | 132 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/property/Attachments.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.ee.metadata.property;
import java.util.Properties;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.metadata.property.PropertyReplacer;
/**
* @author John Bailey
*/
public class Attachments {
public static final AttachmentKey<Properties> DEPLOYMENT_PROPERTIES = AttachmentKey.create(Properties.class);
public static final AttachmentKey<PropertyReplacer> FINAL_PROPERTY_REPLACER = AttachmentKey.create(PropertyReplacer.class);
}
| 1,507 | 39.756757 | 127 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/property/PropertyResolverProcessor.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.ee.metadata.property;
import java.util.function.Function;
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.property.PropertyReplacer;
/**
* @author John Bailey
*/
public class PropertyResolverProcessor implements DeploymentUnitProcessor {
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final PropertyReplacer propertyReplacer = deploymentUnit.getAttachment(Attachments.FINAL_PROPERTY_REPLACER);
//We pass a function basically to be used by wildfly-core which does not the dependencies used to instantiate a PropertyReplacer
final Function<String, String> functionExpand = (value) -> propertyReplacer.replaceProperties(value);
// setup the expression expand function for spec descriptors, if property expansion is enabled for them. If it does not exist, then by default we assume they are enabled.
final Boolean specDescriptorPropReplacement = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT);
if (specDescriptorPropReplacement == null || specDescriptorPropReplacement) {
deploymentUnit.putAttachment(org.jboss.as.server.deployment.Attachments.SPEC_DESCRIPTOR_EXPR_EXPAND_FUNCTION, functionExpand);
}
// setup the expression expand function for JBoss/WildFly descriptors, if property expansion is enabled for them
final Boolean jbossDescriptorPropReplacement = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT);
if (jbossDescriptorPropReplacement == null || jbossDescriptorPropReplacement) {
deploymentUnit.putAttachment(org.jboss.as.server.deployment.Attachments.WFLY_DESCRIPTOR_EXPR_EXPAND_FUNCTION, functionExpand);
}
}
public void undeploy(DeploymentUnit deploymentUnit) {
deploymentUnit.removeAttachment(Attachments.FINAL_PROPERTY_REPLACER);
deploymentUnit.removeAttachment(org.jboss.as.server.deployment.Attachments.SPEC_DESCRIPTOR_EXPR_EXPAND_FUNCTION);
deploymentUnit.removeAttachment(org.jboss.as.server.deployment.Attachments.WFLY_DESCRIPTOR_EXPR_EXPAND_FUNCTION);
}
}
| 3,563 | 55.571429 | 178 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/property/DeploymentPropertyResolverProcessor.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.ee.metadata.property;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Function;
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.property.CompositePropertyResolver;
import org.jboss.metadata.property.PropertiesPropertyResolver;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.metadata.property.PropertyReplacers;
import org.jboss.metadata.property.SimpleExpressionResolver;
import org.jboss.metadata.property.SystemPropertyResolver;
/**
* @author John Bailey
*/
public class DeploymentPropertyResolverProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
DeploymentUnit current = deploymentUnit;
final List<SimpleExpressionResolver> propertyResolvers = new ArrayList<>();
final List<Function<String, String>> functions = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_EXPRESSION_RESOLVERS);
if (functions != null) {
for (Function<String, String> funct : functions) {
propertyResolvers.add(expressionContent -> {
String input = "${" + expressionContent + "}";
String resolved = funct.apply(input);
return resolved == null ? null : new SimpleExpressionResolver.ResolutionResult(resolved, false);
});
}
}
do {
final Properties deploymentProperties = current.getAttachment(Attachments.DEPLOYMENT_PROPERTIES);
if (deploymentProperties != null) {
propertyResolvers.add(new PropertiesPropertyResolver(deploymentProperties));
}
current = current.getParent();
} while (current != null);
propertyResolvers.add(SystemPropertyResolver.INSTANCE);
final PropertyReplacer propertyReplacer = PropertyReplacers.resolvingExpressionReplacer(new CompositePropertyResolver(propertyResolvers.toArray(SimpleExpressionResolver[]::new)));
deploymentUnit.putAttachment(Attachments.FINAL_PROPERTY_REPLACER, propertyReplacer);
}
}
| 3,553 | 47.684932 | 187 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/metadata/property/DeploymentPropertiesProcessor.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.ee.metadata.property;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.jboss.as.ee.logging.EeLogger;
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.ResourceRoot;
import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
/**
* @author John Bailey
*/
public class DeploymentPropertiesProcessor implements DeploymentUnitProcessor {
private static final String DEPLOYMENT_PROPERTIES = "META-INF/jboss.properties";
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if(deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_PROPERTIES)) {
return;
}
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentFile = deploymentRoot.getRoot();
final VirtualFile propertiesFile = deploymentFile.getChild(DEPLOYMENT_PROPERTIES);
if (!propertiesFile.exists()) {
return;
}
Properties properties = new Properties();
InputStream propertyFileStream = null;
try {
propertyFileStream = propertiesFile.openStream();
properties.load(propertyFileStream);
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToLoadJbossProperties(e);
} finally {
VFSUtils.safeClose(propertyFileStream);
}
deploymentUnit.putAttachment(Attachments.DEPLOYMENT_PROPERTIES, properties);
}
}
| 2,928 | 40.842857 | 133 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentStartService.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.ee.component;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
/**
* Service wrapper for a {@link Component} which starts and stops the component instance.
*
* @author John Bailey
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ComponentStartService implements Service<Component> {
private final InjectedValue<BasicComponent> component = new InjectedValue<BasicComponent>();
private final InjectedValue<ExecutorService> executor = new InjectedValue<ExecutorService>();
/**
* {@inheritDoc}
*/
public void start(final StartContext context) throws StartException {
final Runnable task = new Runnable() {
@Override
public void run() {
try {
getValue().start();
context.complete();
} catch (Throwable e) {
context.failed(new StartException(e));
}
}
};
try {
executor.getValue().submit(task);
} catch (RejectedExecutionException e) {
task.run();
} finally {
context.asynchronous();
}
}
/**
* {@inheritDoc}
*/
public void stop(final StopContext context) {
final Runnable task = new Runnable() {
@Override
public void run() {
try {
getValue().stop();
} finally {
context.complete();
}
}
};
try {
executor.getValue().submit(task);
} catch (RejectedExecutionException e) {
task.run();
} finally {
context.asynchronous();
}
}
/**
* {@inheritDoc}
*/
public BasicComponent getValue() throws IllegalStateException, IllegalArgumentException {
return component.getValue();
}
/**
* Get the component injector.
*
* @return the component injector
*/
public Injector<BasicComponent> getComponentInjector() {
return component;
}
public InjectedValue<ExecutorService> getExecutorInjector() {
return executor;
}
}
| 3,567 | 30.575221 | 97 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEDefaultResourceJndiNames.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.ee.component;
/**
* The jndi names for the default EE bindings.
* @author Eduardo Martins
*/
public class EEDefaultResourceJndiNames {
private volatile String contextService;
private volatile String dataSource;
private volatile String jmsConnectionFactory;
private volatile String managedExecutorService;
private volatile String managedScheduledExecutorService;
private volatile String managedThreadFactory;
public String getContextService() {
return contextService;
}
public void setContextService(String contextService) {
this.contextService = contextService;
}
public String getDataSource() {
return dataSource;
}
public void setDataSource(String dataSource) {
this.dataSource = dataSource;
}
public String getJmsConnectionFactory() {
return jmsConnectionFactory;
}
public void setJmsConnectionFactory(String jmsConnectionFactory) {
this.jmsConnectionFactory = jmsConnectionFactory;
}
public String getManagedExecutorService() {
return managedExecutorService;
}
public void setManagedExecutorService(String managedExecutorService) {
this.managedExecutorService = managedExecutorService;
}
public String getManagedScheduledExecutorService() {
return managedScheduledExecutorService;
}
public void setManagedScheduledExecutorService(String managedScheduledExecutorService) {
this.managedScheduledExecutorService = managedScheduledExecutorService;
}
public String getManagedThreadFactory() {
return managedThreadFactory;
}
public void setManagedThreadFactory(String managedThreadFactory) {
this.managedThreadFactory = managedThreadFactory;
}
}
| 2,814 | 32.117647 | 92 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/DeploymentDescriptorEnvironment.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.ee.component;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
/**
* The environment as read from a deployment descriptor
*
* @author Stuart Douglas
*/
public class DeploymentDescriptorEnvironment {
private final String defaultContext;
private final RemoteEnvironment environment;
public DeploymentDescriptorEnvironment(String defaultContext, RemoteEnvironment environment) {
this.defaultContext = defaultContext;
this.environment = environment;
}
public String getDefaultContext() {
return defaultContext;
}
public RemoteEnvironment getEnvironment() {
return environment;
}
}
| 1,704 | 33.1 | 98 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/BasicComponentInstance.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.ee.component;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InvocationType;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* An abstract base component instance.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class BasicComponentInstance implements ComponentInstance {
private static final long serialVersionUID = -8099216228976950066L;
public static final Object INSTANCE_KEY = BasicComponentInstanceKey.class;
private final BasicComponent component;
private final Interceptor preDestroy;
@SuppressWarnings("unused")
private volatile int done;
private static final AtomicIntegerFieldUpdater<BasicComponentInstance> doneUpdater = AtomicIntegerFieldUpdater.newUpdater(BasicComponentInstance.class, "done");
private transient Map<Method, Interceptor> methodMap;
private Map<Object, Object> instanceData = new HashMap<Object, Object>();
private volatile boolean constructionFinished = false;
/**
* Construct a new instance.
*
* @param component the component
*/
protected BasicComponentInstance(final BasicComponent component, final Interceptor preDestroyInterceptor, final Map<Method, Interceptor> methodInterceptors) {
// Associated component
this.component = component;
this.preDestroy = preDestroyInterceptor;
this.methodMap = Collections.unmodifiableMap(methodInterceptors);
}
/**
* {@inheritDoc}
*/
public Component getComponent() {
return component;
}
/**
* {@inheritDoc}
*/
public Object getInstance() {
ManagedReference managedReference = (ManagedReference) getInstanceData(INSTANCE_KEY);
if(managedReference == null) {
//can happen if around construct chain returns null
return null;
}
return managedReference.getInstance();
}
/**
* {@inheritDoc}
*/
public Interceptor getInterceptor(final Method method) throws IllegalStateException {
Interceptor interceptor = methodMap.get(method);
if (interceptor == null) {
throw EeLogger.ROOT_LOGGER.methodNotFound(method);
}
return interceptor;
}
/**
* {@inheritDoc}
*/
public Collection<Method> allowedMethods() {
return methodMap.keySet();
}
/**
* {@inheritDoc}
*/
public final void destroy() {
if (doneUpdater.compareAndSet(this, 0, 1)) try {
preDestroy();
final Object instance = getInstance();
if (instance != null) {
final InterceptorContext interceptorContext = prepareInterceptorContext();
interceptorContext.setTarget(instance);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.PRE_DESTROY);
preDestroy.processInvocation(interceptorContext);
}
} catch (Exception e) {
ROOT_LOGGER.componentDestroyFailure(e, this);
} finally {
component.finishDestroy();
}
}
@Override
public Object getInstanceData(Object key) {
return instanceData.get(key);
}
@Override
public void setInstanceData(Object key, Object value) {
if(constructionFinished) {
throw EeLogger.ROOT_LOGGER.instanceDataCanOnlyBeSetDuringConstruction();
}
instanceData.put(key, value);
}
public void constructionFinished() {
this.constructionFinished = true;
}
/**
* Method that sub classes can use to override destroy logic.
*
*/
protected void preDestroy() {
}
protected InterceptorContext prepareInterceptorContext() {
final InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.putPrivateData(Component.class, component);
interceptorContext.putPrivateData(ComponentInstance.class, this);
interceptorContext.setContextData(new HashMap<String, Object>());
return interceptorContext;
}
private static class BasicComponentInstanceKey implements Serializable {
}
}
| 5,624 | 31.894737 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentConfiguration.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.ee.component;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.OrderedItemContainer;
import org.jboss.as.ee.concurrent.ConcurrentContext;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.service.Service;
/**
* The construction parameter set passed in to an abstract component.
* <p/>
* <h4>Interceptors</h4>
*
* NOTE: References in this file to Interceptors refer to the Jakarta Interceptors unless otherwise noted.
*
* The interceptor factories provided herein are assembled from the component's EE module class as well as the EE
* module classes of the declared interceptor classes for this component by way of a configurator.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class ComponentConfiguration {
private final ComponentDescription componentDescription;
// Core component config
private final ClassReflectionIndex classIndex;
private final ModuleLoader moduleLoader;
private final ClassLoader moduleClassLoader;
private final ConcurrentContext concurrentContext;
private ComponentCreateServiceFactory componentCreateServiceFactory = ComponentCreateServiceFactory.BASIC;
// Interceptor config
private final OrderedItemContainer<List<InterceptorFactory>> aroundConstructInterceptors = new OrderedItemContainer<>();
private final OrderedItemContainer<List<InterceptorFactory>> postConstructInterceptors = new OrderedItemContainer<>();
private final OrderedItemContainer<List<InterceptorFactory>> preDestroyInterceptors = new OrderedItemContainer<>();
private final OrderedItemContainer<List<InterceptorFactory>> prePassivateInterceptors = new OrderedItemContainer<>();
private final OrderedItemContainer<List<InterceptorFactory>> postActivateInterceptors = new OrderedItemContainer<>();
private final Map<Method, OrderedItemContainer<List<InterceptorFactory>>> componentInterceptors = new IdentityHashMap<>();
//TODO: move this into an Jakarta Enterprise Beans specific configuration
private final Map<Method, OrderedItemContainer<InterceptorFactory>> timeoutInterceptors = new IdentityHashMap<>();
// Component instance management
private ComponentFactory instanceFactory;
private final List<DependencyConfigurator<? extends Service<Component>>> createDependencies = new ArrayList<DependencyConfigurator<? extends Service<Component>>>();
private final List<DependencyConfigurator<ComponentStartService>> startDependencies = new ArrayList<DependencyConfigurator<ComponentStartService>>();
// Views
private final List<ViewConfiguration> views = new ArrayList<ViewConfiguration>();
private InterceptorFactory namespaceContextInterceptorFactory;
private NamespaceContextSelector namespaceContextSelector;
private final Set<Object> interceptorContextKeys = new HashSet<Object>();
/**
* Contains a set of all lifecycle methods defined by the bean
*/
private final Set<Method> lifecycleMethods = new HashSet<>();
public ComponentConfiguration(final ComponentDescription componentDescription, final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
this.componentDescription = componentDescription;
this.classIndex = classIndex;
this.moduleClassLoader = moduleClassLoader;
this.moduleLoader = moduleLoader;
this.concurrentContext = new ConcurrentContext();
}
/**
* Get the component description.
*
* @return the component description
*/
public ComponentDescription getComponentDescription() {
return componentDescription;
}
/**
* Get the component class.
*
* @return the component class
*/
public Class<?> getComponentClass() {
return classIndex.getIndexedClass();
}
/**
* Get the component name.
*
* @return the component name
*/
public String getComponentName() {
return componentDescription.getComponentName();
}
/**
* Get the set of currently known component methods. This is an identity set.
*
* @return the set of methods
*/
public Set<Method> getDefinedComponentMethods() {
return classIndex.getClassMethods();
}
/**
* Gets the interceptor list for a given method. This should not be called until
* all interceptors have been added.
*
* @param method the component method
* @return the deque
*/
public List<InterceptorFactory> getComponentInterceptors(Method method) {
Map<Method, OrderedItemContainer<List<InterceptorFactory>>> map = componentInterceptors;
OrderedItemContainer<List<InterceptorFactory>> interceptors = map.get(method);
if (interceptors == null) {
return Collections.emptyList();
}
List<List<InterceptorFactory>> sortedItems = interceptors.getSortedItems();
List<InterceptorFactory> ret = new ArrayList<>();
for(List<InterceptorFactory> item : sortedItems) {
ret.addAll(item);
}
return ret;
}
/**
* Gets the around timeout interceptor list for a given method. This should not be called until
* all interceptors have been added.
*
* @param method the component method
* @return the deque
*/
public List<InterceptorFactory> getAroundTimeoutInterceptors(Method method) {
Map<Method, OrderedItemContainer<InterceptorFactory>> map = timeoutInterceptors;
OrderedItemContainer<InterceptorFactory> interceptors = map.get(method);
if (interceptors == null) {
return Collections.emptyList();
}
return interceptors.getSortedItems();
}
/**
* Adds an interceptor factory to every method on the component.
*
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
* @param publicOnly If true then then interceptor is only added to public methods
*/
public void addComponentInterceptor(InterceptorFactory factory, int priority, boolean publicOnly) {
addComponentInterceptors(Collections.singletonList(factory), priority, publicOnly);
}
/**
* Adds an interceptor factory to every method on the component.
*
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
* @param publicOnly If true then then interceptor is only added to public methods
*/
public void addComponentInterceptors(List<InterceptorFactory> factory, int priority, boolean publicOnly) {
for (Method method : (Iterable<Method>)classIndex.getClassMethods()) {
if (publicOnly && !Modifier.isPublic(method.getModifiers())) {
continue;
}
OrderedItemContainer<List<InterceptorFactory>> interceptors = componentInterceptors.get(method);
if (interceptors == null) {
componentInterceptors.put(method, interceptors = new OrderedItemContainer<List<InterceptorFactory>>());
}
interceptors.add(factory, priority);
}
}
/**
* Adds an interceptor factory to a given method. The method parameter *must* be retrived from either the
* {@link org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex} or from {@link #getDefinedComponentMethods()},
* as the methods are stored in an identity hash map
*
* @param method The method to add the interceptor to
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
*/
public void addComponentInterceptor(Method method, InterceptorFactory factory, int priority) {
addComponentInterceptors(method, Collections.singletonList(factory), priority);
}
/**
* Adds an interceptor factory to a given method. The method parameter *must* be retrived from either the
* {@link org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex} or from {@link #getDefinedComponentMethods()},
* as the methods are stored in an identity hash map
*
* @param method The method to add the interceptor to
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
*/
public void addComponentInterceptors(Method method, List<InterceptorFactory> factory, int priority) {
OrderedItemContainer<List<InterceptorFactory>> interceptors = componentInterceptors.get(method);
if (interceptors == null) {
componentInterceptors.put(method, interceptors = new OrderedItemContainer<List<InterceptorFactory>>());
}
interceptors.add(factory, priority);
}
/**
* Adds a timeout interceptor factory to every method on the component.
*
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
*/
public void addTimeoutViewInterceptor(InterceptorFactory factory, int priority) {
for (Method method : (Iterable<Method>)classIndex.getClassMethods()) {
OrderedItemContainer<InterceptorFactory> interceptors = timeoutInterceptors.get(method);
if (interceptors == null) {
timeoutInterceptors.put(method, interceptors = new OrderedItemContainer<InterceptorFactory>());
}
interceptors.add(factory, priority);
}
}
/**
* Adds a timeout interceptor factory to every method on the component.
*
* @param method The method to add it to
* @param factory The interceptor factory to add
* @param priority The interceptors relative order
*/
public void addTimeoutViewInterceptor(final Method method, InterceptorFactory factory, int priority) {
OrderedItemContainer<InterceptorFactory> interceptors = timeoutInterceptors.get(method);
if (interceptors == null) {
timeoutInterceptors.put(method, interceptors = new OrderedItemContainer<InterceptorFactory>());
}
interceptors.add(factory, priority);
}
/**
* Get the create dependencies list.
*
* @return the create dependencies list
*/
public List<DependencyConfigurator<? extends Service<Component>>> getCreateDependencies() {
return createDependencies;
}
/**
* Get the start dependencies list.
*
* @return the start dependencies list
*/
public List<DependencyConfigurator<ComponentStartService>> getStartDependencies() {
return startDependencies;
}
/**
* Get the list of views for this component.
*
* @return the list of views
*/
public List<ViewConfiguration> getViews() {
return views;
}
/**
* Get the around-construct interceptors.
* <p/>
* This method should only be called after all interceptors have been added
*
* @return the sorted interceptors
*/
public List<InterceptorFactory> getAroundConstructInterceptors() {
List<List<InterceptorFactory>> sortedItems = aroundConstructInterceptors.getSortedItems();
List<InterceptorFactory> interceptorFactories = new ArrayList<>();
for(List<InterceptorFactory> i : sortedItems) {
interceptorFactories.addAll(i);
}
return interceptorFactories;
}
/**
* Adds an around-construct interceptor
*
* @param factories The interceptors to add
* @param priority The priority
*/
public void addAroundConstructInterceptors(List<InterceptorFactory> factories, int priority) {
aroundConstructInterceptors.add(factories, priority);
}
/**
* Adds an around-construct interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addAroundConstructInterceptor(InterceptorFactory interceptorFactory, int priority) {
aroundConstructInterceptors.add(Collections.singletonList(interceptorFactory), priority);
}
/**
* Get the post-construct interceptors.
* <p/>
* This method should only be called after all interceptors have been added
*
* @return the sorted interceptors
*/
public List<InterceptorFactory> getPostConstructInterceptors() {
List<List<InterceptorFactory>> sortedItems = postConstructInterceptors.getSortedItems();
List<InterceptorFactory> interceptorFactories = new ArrayList<>();
for(List<InterceptorFactory> i : sortedItems) {
interceptorFactories.addAll(i);
}
return interceptorFactories;
}
/**
* Adds a post construct interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addPostConstructInterceptors(List<InterceptorFactory> interceptorFactory, int priority) {
postConstructInterceptors.add(interceptorFactory, priority);
}
/**
* Adds a post construct interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addPostConstructInterceptor(InterceptorFactory interceptorFactory, int priority) {
postConstructInterceptors.add(Collections.singletonList(interceptorFactory), priority);
}
/**
* Get the pre-destroy interceptors.
* <p/>
* This method should only be called after all interceptors have been added
*
* @return the sorted interceptor
*/
public List<InterceptorFactory> getPreDestroyInterceptors() {
List<List<InterceptorFactory>> sortedItems = preDestroyInterceptors.getSortedItems();
List<InterceptorFactory> interceptorFactories = new ArrayList<>();
for(List<InterceptorFactory> i : sortedItems) {
interceptorFactories.addAll(i);
}
return interceptorFactories;
}
/**
* Adds a pre destroy interceptor
*
* @param factories The interceptor factory to add
* @param priority The factories priority
*/
public void addPreDestroyInterceptors(List<InterceptorFactory> factories, int priority) {
preDestroyInterceptors.add(factories, priority);
}
/**
* Adds a pre destroy interceptor
*
* @param interceptorFactory The interceptor factory to add
* @param priority The factories priority
*/
public void addPreDestroyInterceptor(InterceptorFactory interceptorFactory, int priority) {
preDestroyInterceptors.add(Collections.singletonList(interceptorFactory), priority);
}
/**
* Get the pre-passivate interceptors.
* <p/>
* This method should only be called after all interceptors have been added
*
* @return the sorted interceptors
*/
public List<InterceptorFactory> getPrePassivateInterceptors() {
List<List<InterceptorFactory>> sortedItems = prePassivateInterceptors.getSortedItems();
List<InterceptorFactory> interceptorFactories = new ArrayList<>();
for(List<InterceptorFactory> i : sortedItems) {
interceptorFactories.addAll(i);
}
return interceptorFactories;
}
/**
* Adds a pre passivate interceptor
*
* @param factories The interceptor to add
* @param priority The priority
*/
public void addPrePassivateInterceptors(List<InterceptorFactory> factories, int priority) {
prePassivateInterceptors.add(factories, priority);
}
/**
* Adds a pre passivate interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addPrePassivateInterceptor(InterceptorFactory interceptorFactory, int priority) {
prePassivateInterceptors.add(Collections.singletonList(interceptorFactory), priority);
}
/**
* Get the post-activate interceptors.
* <p/>
* This method should only be called after all interceptors have been added
*
* @return the sorted interceptors
*/
public List<InterceptorFactory> getPostActivateInterceptors() {
List<List<InterceptorFactory>> sortedItems = postActivateInterceptors.getSortedItems();
List<InterceptorFactory> interceptorFactories = new ArrayList<>();
for(List<InterceptorFactory> i : sortedItems) {
interceptorFactories.addAll(i);
}
return interceptorFactories;
}
/**
* Adds a post activate interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addPostActivateInterceptors(List<InterceptorFactory> interceptorFactory, int priority) {
postActivateInterceptors.add(interceptorFactory, priority);
}
/**
* Adds a post activate interceptor
*
* @param interceptorFactory The interceptor to add
* @param priority The priority
*/
public void addPostActivateInterceptor(InterceptorFactory interceptorFactory, int priority) {
postActivateInterceptors.add(Collections.singletonList(interceptorFactory), priority);
}
/**
* Get the application name.
*
* @return the application name
*/
public String getApplicationName() {
return componentDescription.getApplicationName();
}
/**
* Get the module name.
*
* @return the module name
*/
public String getModuleName() {
return componentDescription.getModuleName();
}
/**
* Get the instance factory for this component.
*
* @return the instance factory
*/
public ComponentFactory getInstanceFactory() {
return instanceFactory;
}
/**
* Set the instance factory for this component.
*
* @param instanceFactory the instance factory
*/
public void setInstanceFactory(final ComponentFactory instanceFactory) {
this.instanceFactory = instanceFactory;
}
public ClassReflectionIndex getClassIndex() {
return classIndex;
}
/**
* Get the component create service factory for this component.
*
* @return the component create service factory
*/
public ComponentCreateServiceFactory getComponentCreateServiceFactory() {
return componentCreateServiceFactory;
}
/**
* Set the component create service factory for this component.
*
* @param componentCreateServiceFactory the component create service factory
*/
public void setComponentCreateServiceFactory(final ComponentCreateServiceFactory componentCreateServiceFactory) {
if (componentCreateServiceFactory == null) {
throw EeLogger.ROOT_LOGGER.nullVar("componentCreateServiceFactory", "component", getComponentName());
}
this.componentCreateServiceFactory = componentCreateServiceFactory;
}
public String toString() {
return getClass().getName() + "[name=" + componentDescription.getComponentName() + " class=" + componentDescription.getComponentClassName() + "]";
}
public InterceptorFactory getNamespaceContextInterceptorFactory() {
return namespaceContextInterceptorFactory;
}
public void setNamespaceContextInterceptorFactory(InterceptorFactory interceptorFactory) {
this.namespaceContextInterceptorFactory = interceptorFactory;
}
public ClassLoader getModuleClassLoader() {
return moduleClassLoader;
}
public ModuleLoader getModuleLoader() {
return moduleLoader;
}
/**
* @return The components namespace context selector, if any
*/
public NamespaceContextSelector getNamespaceContextSelector() {
return namespaceContextSelector;
}
public void setNamespaceContextSelector(final NamespaceContextSelector namespaceContextSelector) {
this.namespaceContextSelector = namespaceContextSelector;
}
public Set<Object> getInterceptorContextKeys() {
return interceptorContextKeys;
}
public ConcurrentContext getConcurrentContext() {
return concurrentContext;
}
/**
* Adds a lifecycle method to the lifecycle methods set
*
* @param method The lifecycle method
*/
public void addLifecycleMethod(Method method) {
lifecycleMethods.add(method);
}
/**
* Returns a set of all lifecycle methods defined on the bean
*
* @return All lifecycle methods defined on the component class and its superclasses
*/
public Set<Method> getLifecycleMethods() {
return Collections.unmodifiableSet(lifecycleMethods);
}
}
| 22,282 | 36.576728 | 193 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/AbstractComponentConfigurator.java | package org.jboss.as.ee.component;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
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.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.invocation.Interceptors;
import org.jboss.msc.value.InjectedValue;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* @author Stuart Douglas
*/
public class AbstractComponentConfigurator {
/**
* The weaved interceptor factory results in a lot of runtime allocations, and should not be used
* @param interceptorFactories The interceptor factories
* @return
*/
@Deprecated
protected static InterceptorFactory weaved(final Collection<InterceptorFactory> interceptorFactories) {
if(interceptorFactories == null) {
return null;
}
return new InterceptorFactory() {
@Override
public Interceptor create(InterceptorFactoryContext context) {
final Interceptor[] interceptors = new Interceptor[interceptorFactories.size()];
final Iterator<InterceptorFactory> factories = interceptorFactories.iterator();
for (int i = 0; i < interceptors.length; i++) {
interceptors[i] = factories.next().create(context);
}
return Interceptors.getWeavedInterceptor(interceptors);
}
};
}
/**
* Sets up all resource injections for a class. This takes into account injections that have been specified in the module and component deployment descriptors
* <p/>
* Note that this does not take superclasses into consideration, only injections on the current class
*
* @param clazz The class or superclass to perform injection for
* @param actualClass The actual component or interceptor class
* @param classDescription The class description, may be null
* @param moduleDescription The module description
* @param description The component description
* @param configuration The component configuration
* @param context The phase context
* @param injectors The list of injectors for the current component
* @param instanceKey The key that identifies the instance to inject in the interceptor context
* @param uninjectors The list of uninjections for the current component
* @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
*
*/
protected void mergeInjectionsForClass(final Class<?> clazz, final Class<?> actualClass, final EEModuleClassDescription classDescription, final EEModuleDescription moduleDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final ComponentDescription description, final ComponentConfiguration configuration, final DeploymentPhaseContext context, final Deque<InterceptorFactory> injectors, final Object instanceKey, final Deque<InterceptorFactory> uninjectors, boolean metadataComplete) throws DeploymentUnitProcessingException {
final Map<InjectionTarget, ResourceInjectionConfiguration> mergedInjections = new HashMap<InjectionTarget, ResourceInjectionConfiguration>();
if (classDescription != null && !metadataComplete) {
mergedInjections.putAll(classDescription.getInjectionConfigurations());
}
mergedInjections.putAll(moduleDescription.getResourceInjections(clazz.getName()));
mergedInjections.putAll(description.getResourceInjections(clazz.getName()));
for (final ResourceInjectionConfiguration injectionConfiguration : mergedInjections.values()) {
if(!moduleDescription.isAppClient() && injectionConfiguration.getTarget().isStatic(context.getDeploymentUnit())) {
ROOT_LOGGER.debugf("Injection for a member with static modifier is only acceptable on application clients, ignoring injection for target %s",injectionConfiguration.getTarget());
continue;
}
if(injectionConfiguration.getTarget() instanceof MethodInjectionTarget) {
//we need to make sure that if this is a method injection it has not been overriden
final MethodInjectionTarget mt = (MethodInjectionTarget)injectionConfiguration.getTarget();
Method method = mt.getMethod(deploymentReflectionIndex, clazz);
if(!isNotOverriden(clazz, method, actualClass, deploymentReflectionIndex)) {
continue;
}
}
final Object valueContextKey = new Object();
final InjectedValue<ManagedReferenceFactory> managedReferenceFactoryValue = new InjectedValue<ManagedReferenceFactory>();
configuration.getStartDependencies().add(new ComponentDescription.InjectedConfigurator(injectionConfiguration, configuration, context, managedReferenceFactoryValue));
injectors.addFirst(injectionConfiguration.getTarget().createInjectionInterceptorFactory(instanceKey, valueContextKey, managedReferenceFactoryValue, context.getDeploymentUnit(), injectionConfiguration.isOptional()));
uninjectors.addLast(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(valueContextKey)));
}
}
protected boolean isNotOverriden(final Class<?> clazz, final Method method, final Class<?> actualClass, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException {
return Modifier.isPrivate(method.getModifiers()) || ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, actualClass, method).getDeclaringClass() == clazz;
}
}
| 6,249 | 58.52381 | 550 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewDescription.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.ee.component;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndexUtil;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.Interceptors;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.invocation.proxy.ProxyFactory;
import org.jboss.msc.service.ServiceName;
import static java.lang.reflect.Modifier.ABSTRACT;
import static java.lang.reflect.Modifier.PUBLIC;
import static java.lang.reflect.Modifier.STATIC;
import static org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX;
/**
* A description of a view.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class ViewDescription {
//JVM bridge method flag
public static final int BRIDGE = 0x0040;
private final String viewClassName;
private final ComponentDescription componentDescription;
private final List<String> viewNameParts = new ArrayList<String>();
private final Set<String> bindingNames = new HashSet<String>();
private final Deque<ViewConfigurator> configurators = new ArrayDeque<ViewConfigurator>();
private boolean serializable;
private boolean useWriteReplace;
private final String markupClassName;
/**
* Construct a new instance.
*
* @param componentDescription the associated component description
* @param viewClassName the view class name
*/
public ViewDescription(final ComponentDescription componentDescription, final String viewClassName) {
this(componentDescription, viewClassName, true);
}
/**
* Construct a new instance.
*
* @param componentDescription the associated component description
* @param viewClassName the view class name
* @param defaultConfiguratorRequired
*/
public ViewDescription(final ComponentDescription componentDescription, final String viewClassName, final boolean defaultConfiguratorRequired) {
this(componentDescription, viewClassName, defaultConfiguratorRequired, null);
}
public ViewDescription(final ComponentDescription componentDescription, final String viewClassName, final boolean defaultConfiguratorRequired, final String markupClassName) {
this.componentDescription = componentDescription;
this.viewClassName = viewClassName;
if (defaultConfiguratorRequired) {
configurators.addFirst(DefaultConfigurator.INSTANCE);
}
configurators.addFirst(ViewBindingConfigurator.INSTANCE);
this.markupClassName = markupClassName;
}
/**
* Get the view's class name.
*
* @return the class name
*/
public String getViewClassName() {
return viewClassName;
}
/**
* Get the associated component description.
*
* @return the component description
*/
public ComponentDescription getComponentDescription() {
return componentDescription;
}
/**
* Get the strings to append to the view base name. The view base name is the component base name
* followed by {@code "VIEW"} followed by these strings.
*
* @return the list of strings
*/
public List<String> getViewNameParts() {
return viewNameParts;
}
/**
* Get the service name for this view.
*
* @return the service name
*/
public ServiceName getServiceName() {
//TODO: need to set viewNameParts somewhere
if (!viewNameParts.isEmpty()) {
return componentDescription.getServiceName().append("VIEW").append(viewNameParts.toArray(new String[viewNameParts.size()]));
} else {
return componentDescription.getServiceName().append("VIEW").append(viewClassName);
}
}
/**
* Creates view configuration. Allows for extensibility in EE sub components.
*
* @param viewClass view class
* @param componentConfiguration component config
* @param proxyFactory proxy factory
* @return new view configuration
*/
public ViewConfiguration createViewConfiguration(final Class<?> viewClass, final ComponentConfiguration componentConfiguration, final ProxyFactory<?> proxyFactory) {
return new ViewConfiguration(viewClass, componentConfiguration, getServiceName(), proxyFactory);
}
/**
* Get the set of binding names for this view.
*
* @return the set of binding names
*/
public Set<String> getBindingNames() {
return bindingNames;
}
/**
* Get the configurators for this view.
*
* @return the configurators
*/
public Deque<ViewConfigurator> getConfigurators() {
return configurators;
}
/**
* Create the injection source
*
* @param serviceName The view service name
* @param viewClassLoader The view class loader
* @param appclient appclient environment
*/
protected InjectionSource createInjectionSource(final ServiceName serviceName, Supplier<ClassLoader> viewClassLoader, boolean appclient) {
return new ViewBindingInjectionSource(serviceName);
}
public static final ImmediateInterceptorFactory CLIENT_DISPATCHER_INTERCEPTOR_FACTORY = new ImmediateInterceptorFactory(new Interceptor() {
public Object processInvocation(final InterceptorContext context) throws Exception {
ComponentView view = context.getPrivateData(ComponentView.class);
return view.invoke(context);
}
});
private static class DefaultConfigurator implements ViewConfigurator {
public static final DefaultConfigurator INSTANCE = new DefaultConfigurator();
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
// Create method indexes
final DeploymentReflectionIndex reflectionIndex = context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
for (final Method method : methods) {
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
Method componentMethod = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);
if (componentMethod == null && method.getDeclaringClass().isInterface() && (method.getModifiers() & (ABSTRACT | PUBLIC | STATIC)) == PUBLIC) {
// no component method and the interface method is defaulted, so we really do want to invoke on the interface method
componentMethod = method;
}
if (componentMethod != null) {
if ((BRIDGE & componentMethod.getModifiers()) != 0) {
Method other = findRealMethodForBridgeMethod(componentMethod, componentConfiguration, reflectionIndex, methodIdentifier);
//try and find the non-bridge method to delegate to
if(other != null) {
componentMethod = other;
}
}
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
configuration.addClientInterceptor(method, CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.getViewToComponentMethodMap().put(method, componentMethod);
}
}
configuration.addClientPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addClientPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
}
private Method findRealMethodForBridgeMethod(final Method componentMethod, final ComponentConfiguration componentConfiguration, final DeploymentReflectionIndex reflectionIndex, final MethodIdentifier methodIdentifier) {
final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(componentMethod.getDeclaringClass()); //the non-bridge method will be on the same class as the bridge method
final Collection<Method> methods = classIndex.getAllMethods(componentMethod.getName(), componentMethod.getParameterCount());
for(final Method method : methods) {
if (((BRIDGE & method.getModifiers()) == 0)
&& componentMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
boolean ok = true;
for (int i = 0; i < method.getParameterCount(); ++i) {
if (!componentMethod.getParameterTypes()[i].isAssignableFrom(method.getParameterTypes()[i])) {
ok = false;
break;
}
}
if (ok) {
return method;
}
}
}
return null;
}
}
private static class ViewBindingConfigurator implements ViewConfigurator {
public static final ViewBindingConfigurator INSTANCE = new ViewBindingConfigurator();
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
boolean appclient = context.getDeploymentUnit().getAttachment(Attachments.EE_MODULE_DESCRIPTION).isAppClient();
// Create view bindings
final List<BindingConfiguration> bindingConfigurations = configuration.getBindingConfigurations();
for (String bindingName : description.getBindingNames()) {
bindingConfigurations.add(new BindingConfiguration(bindingName, description.createInjectionSource(description.getServiceName(), () -> componentConfiguration.getModuleClassLoader(), appclient)));
}
}
}
public boolean isSerializable() {
return serializable;
}
public void setSerializable(final boolean serializable) {
this.serializable = serializable;
}
public boolean isUseWriteReplace() {
return useWriteReplace;
}
public void setUseWriteReplace(final boolean useWriteReplace) {
this.useWriteReplace = useWriteReplace;
}
@Override
public String toString() {
return "View of type " + viewClassName + " for " + componentDescription;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final ViewDescription that = (ViewDescription) o;
//compare the component description based on ==
if (componentDescription != that.componentDescription)
return false;
if (viewClassName != null ? !viewClassName.equals(that.viewClassName) : that.viewClassName != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = viewClassName != null ? viewClassName.hashCode() : 0;
result = 31 * result + (componentDescription != null ? componentDescription.hashCode() : 0);
return result;
}
public String getMarkupClassName() {
return markupClassName;
}
public boolean requiresSuperclassInProxy() {
return true;
}
}
| 13,703 | 41.559006 | 237 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/InterceptorEnvironment.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.ee.component;
import java.util.ArrayList;
import java.util.List;
/**
* Class that represents the environment entries of an interceptor, defined in the interceptors section
* of ejb-jar.xml.
*
*
*
* @author Stuart Douglas
*/
public class InterceptorEnvironment implements ResourceInjectionTarget {
private final DeploymentDescriptorEnvironment deploymentDescriptorEnvironment;
private final List<ResourceInjectionConfiguration> resourceInjections = new ArrayList<ResourceInjectionConfiguration>();
private final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
public InterceptorEnvironment(final DeploymentDescriptorEnvironment deploymentDescriptorEnvironment) {
this.deploymentDescriptorEnvironment = deploymentDescriptorEnvironment;
}
public List<BindingConfiguration> getBindingConfigurations() {
return bindingConfigurations;
}
public void addResourceInjection(final ResourceInjectionConfiguration injection) {
resourceInjections.add(injection);
}
public List<ResourceInjectionConfiguration> getResourceInjections() {
return resourceInjections;
}
public DeploymentDescriptorEnvironment getDeploymentDescriptorEnvironment() {
return deploymentDescriptorEnvironment;
}
}
| 2,366 | 37.177419 | 124 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/LookupInjectionSource.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.ee.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ImmediateManagedReference;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* A binding which gets its value from another JNDI binding.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class LookupInjectionSource extends InjectionSource {
private static final String SLASH = "/";
// the schemes of supported URLs
private static final Set<String> URL_SCHEMES;
static {
Set<String> set = new HashSet<String>();
set.add("http");
set.add("https");
set.add("ftp");
set.add("file");
set.add("jar");
URL_SCHEMES = Collections.unmodifiableSet(set);
}
private final String lookupName;
private final boolean optional;
public LookupInjectionSource(final String lookupName) {
this(lookupName,false);
}
public LookupInjectionSource(final String lookupName, final boolean optional) {
if (lookupName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("lookupName");
}
this.lookupName = lookupName;
this.optional = optional;
}
/**
* {@inheritDoc}
*/
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
final String applicationName = resolutionContext.getApplicationName();
final String moduleName = resolutionContext.getModuleName();
final String componentName = resolutionContext.getComponentName();
final boolean compUsesModule = resolutionContext.isCompUsesModule();
final String scheme = org.jboss.as.naming.InitialContext.getURLScheme(lookupName);
if (scheme == null) {
String sanitizedLookupName = sanitizeLookupName(lookupName);
// relative name, build absolute name and setup normal lookup injection
if (componentName != null && !compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:comp/env/" + sanitizedLookupName)
.setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else if (compUsesModule) {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/env/" + sanitizedLookupName)
.setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:jboss/env/" + sanitizedLookupName)
.setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
if (scheme.equals("java")) {
// an absolute java name, setup normal lookup injection
if (compUsesModule && lookupName.startsWith("java:comp/")) {
// switch "comp" with "module"
ContextNames.bindInfoFor(applicationName, moduleName, componentName, "java:module/" + lookupName.substring(10))
.setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
} else {
ContextNames.bindInfoFor(applicationName, moduleName, componentName, lookupName)
.setupLookupInjection(serviceBuilder, injector, phaseContext.getDeploymentUnit(), optional);
}
} else {
// an absolute non java name
final ManagedReferenceFactory managedReferenceFactory;
if (URL_SCHEMES.contains(scheme)) {
// a Jakarta EE Standard Resource Manager Connection Factory for URLs, using lookup to define value of URL, inject factory that creates URL instances
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new URL(lookupName));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
};
} else {
// lookup for a non java jndi resource, inject factory which does a true jndi lookup
managedReferenceFactory = new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
try {
return new ImmediateManagedReference(new InitialContext().lookup(lookupName));
} catch (NamingException e) {
EeLogger.ROOT_LOGGER.tracef(e, "failed to lookup %s", lookupName);
return null;
}
}
};
}
injector.inject(managedReferenceFactory);
}
}
}
private String sanitizeLookupName(String lookupName) {
int slashIndex = lookupName.indexOf(SLASH);
if (slashIndex == 0) {
EeLogger.ROOT_LOGGER.invalidNamePrefix(lookupName);
return lookupName.substring(1);
}
return lookupName;
}
public boolean equals(Object configuration) {
if (configuration instanceof LookupInjectionSource) {
LookupInjectionSource lookup = (LookupInjectionSource) configuration;
return lookupName.equals(lookup.lookupName);
}
return false;
}
public int hashCode() {
return lookupName.hashCode();
}
public String toString() {
return "lookup (" + lookupName + ")";
}
}
| 7,616 | 42.775862 | 210 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ReflectiveClassIntrospector.java | package org.jboss.as.ee.component;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.jboss.as.naming.ConstructorManagedReferenceFactory;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
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.wildfly.security.manager.WildFlySecurityManager;
/**
* @author Stuart Douglas
*/
public class ReflectiveClassIntrospector implements EEClassIntrospector, Service<EEClassIntrospector> {
public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("ee", "reflectiveClassIntrospector");
public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION = new RuntimePermission("accessDeclaredMembers");
/**
* Constructs a new instance.
*
* @throws SecurityException if the security manager is present and the runtime {@code accessDeclaredMembers}
* access
* is not granted
*/
public ReflectiveClassIntrospector() {
// If security manager is enabled check the permissions that would normally be checked in
// Class.getDeclaredConstructor()
if (WildFlySecurityManager.isChecking()) {
SecurityManager s = System.getSecurityManager();
s.checkPermission(CHECK_MEMBER_ACCESS_PERMISSION);
}
}
@Override
public ManagedReferenceFactory createFactory(final Class<?> clazz) {
if (WildFlySecurityManager.isChecking()) {
// Execute in a privileged block for executions, such as Jakarta Server Pages, that do not copy the security
// context/protection domains onto class loaders. The permission check is done on the constructor.
return AccessController.doPrivileged(new PrivilegedAction<ManagedReferenceFactory>() {
@Override
public ManagedReferenceFactory run() {
try {
return new ConstructorManagedReferenceFactory(clazz.getDeclaredConstructor());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
});
} else {
try {
return new ConstructorManagedReferenceFactory(clazz.getDeclaredConstructor());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
@Override
public ManagedReference createInstance(Object instance) {
return null;
}
@Override
public ManagedReference getInstance(Object instance) {
return null;
}
@Override
public void start(StartContext startContext) throws StartException {
}
@Override
public void stop(StopContext stopContext) {
}
@Override
public EEClassIntrospector getValue() throws IllegalStateException, IllegalArgumentException {
return this;
}
}
| 3,169 | 35.436782 | 122 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/FixedInjectionSource.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.ee.component;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
/**
* An injection of a fixed value.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class FixedInjectionSource extends InjectionSource {
private final Object value;
private final ManagedReferenceFactory managedReferenceFactory;
/**
* Construct a new instance.
*
* @param factory The managed reference factory to inject
* @param value the value to use for equality comparison
*/
public FixedInjectionSource(final ManagedReferenceFactory factory, final Object value) {
managedReferenceFactory = factory;
this.value = value;
}
/**
* {@inheritDoc}
*/
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
injector.inject(managedReferenceFactory);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof FixedInjectionSource == false) {
return false;
}
FixedInjectionSource other = (FixedInjectionSource) obj;
return this.equalTo(other);
}
private boolean equalTo(final FixedInjectionSource configuration) {
return configuration != null && value.equals(configuration.value);
}
public int hashCode() {
return value.hashCode();
}
}
| 2,743 | 34.636364 | 210 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentView.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.ee.component;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.InterceptorContext;
/**
* A component view.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface ComponentView {
/**
* Create the component view instance.
*
* @return the component view instance
*/
ManagedReference createInstance() throws Exception;
/**
* Create the component view instance using the additional context data
*
* @param contextData Additional context data used in the view creation
* @return the component view instance
*/
ManagedReference createInstance(Map<Object, Object> contextData) throws Exception;
/**
* Invoke on the component view interceptor chain.
* TODO: fully document the semantics of this method
*
* @param interceptorContext The context of the invocation
* @return The result of the invocation
*/
Object invoke(final InterceptorContext interceptorContext) throws Exception;
/**
* Get the associated component.
*
* @return the component
*/
Component getComponent();
/**
*
* @return The proxy class used in the view
*/
Class<?> getProxyClass();
/**
*
* @return The class of the view
*/
Class<?> getViewClass();
/**
*
* @return All methods that the view supports
*/
Set<Method> getViewMethods();
/**
* Gets a view method based on name and descriptor
* @param name the method name
* @param descriptor The method descriptor in JVM format
* @return The method that corresponds to the given name and descriptor
* @throws IllegalArgumentException If the method cannot be found
*/
Method getMethod(final String name, final String descriptor);
/**
* Provides a mechanism to attach arbitrary data to the component view
* @param clazz The class of attachment
* @return The data, or null if it is not present
*/
<T> T getPrivateData(Class<T> clazz);
boolean isAsynchronous(final Method method);
}
| 3,249 | 29.092593 | 86 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentCreateServiceFactory.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.ee.component;
/**
* A factory for component creation which allows component behavior customization.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface ComponentCreateServiceFactory {
/**
* Construct a new component creation service from the given configuration.
*
* @param configuration the configuration
* @return the create service
*/
BasicComponentCreateService constructService(ComponentConfiguration configuration);
/**
* The default, basic component create service factory.
*/
ComponentCreateServiceFactory BASIC = new ComponentCreateServiceFactory() {
public BasicComponentCreateService constructService(final ComponentConfiguration configuration) {
return new BasicComponentCreateService(configuration);
}
};
}
| 1,894 | 37.673469 | 105 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EnvEntryInjectionSource.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.ee.component;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.ValueManagedReferenceFactory;
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;
/**
* A description of an env-entry.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class EnvEntryInjectionSource extends InjectionSource {
private final Object value;
/**
* Construct a new instance.
*
* @param value the immediate value of the env entry.
*/
public EnvEntryInjectionSource(final Object value) {
this.value = value;
}
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
injector.inject(new ValueManagedReferenceFactory(value));
}
public boolean equals(final Object injectionSource) {
return injectionSource instanceof EnvEntryInjectionSource && equalTo((EnvEntryInjectionSource) injectionSource);
}
private boolean equalTo(final EnvEntryInjectionSource injectionSource) {
return injectionSource != null && value.equals(injectionSource.value);
}
public int hashCode() {
return value.hashCode();
}
}
| 2,554 | 38.307692 | 251 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewConfigurator.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.ee.component;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
/**
* A configurator for views. Each configurator is run in the order it appears on the component description.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface ViewConfigurator {
/**
* Apply this configurator to the given configuration.
*
* @param context the deployment phase context
* @param componentConfiguration the completed component configuration
* @param description the completed view description
* @param configuration the view configuration to build on to
* @throws DeploymentUnitProcessingException if configuration fails
*/
void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException;
}
| 2,030 | 43.152174 | 201 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ManagedReferenceMethodInterceptor.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.ee.component;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.Interceptors;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
final class ManagedReferenceMethodInterceptor implements Interceptor {
private final Object contextKey;
private final Method method;
ManagedReferenceMethodInterceptor(final Object contextKey, final Method method) {
this.contextKey = contextKey;
this.method = method;
}
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
final ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(contextKey);
final Object instance = reference.getInstance();
try {
return method.invoke(instance, context.getParameters());
} catch (IllegalAccessException e) {
final IllegalAccessError n = new IllegalAccessError(e.getMessage());
n.setStackTrace(e.getStackTrace());
throw n;
} catch (InvocationTargetException e) {
throw Interceptors.rethrow(e.getCause());
}
}
}
| 2,425 | 37.507937 | 138 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ResourceInjectionTarget.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.ee.component;
/**
* Represents an object that has a descriptor based JNDI environment.
*
* @author Stuart Douglas
*/
public interface ResourceInjectionTarget {
void addResourceInjection(final ResourceInjectionConfiguration injection);
}
| 1,293 | 35.971429 | 78 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/Attachments.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.ee.component;
import java.util.Set;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry;
import org.jboss.as.ee.component.deployers.MessageDestinationInjectionSource;
import org.jboss.as.ee.component.deployers.StartupCountdown;
import org.jboss.as.ee.concurrent.ConcurrentContextSetupAction;
import org.jboss.as.ee.concurrent.handle.ContextHandleFactory;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.AttachmentList;
import org.jboss.as.server.deployment.SetupAction;
import org.jboss.msc.service.ServiceName;
/**
* @author John Bailey
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class Attachments {
public static final AttachmentKey<EEApplicationDescription> EE_APPLICATION_DESCRIPTION = AttachmentKey.create(EEApplicationDescription.class);
public static final AttachmentKey<EEApplicationClasses> EE_APPLICATION_CLASSES_DESCRIPTION = AttachmentKey.create(EEApplicationClasses.class);
public static final AttachmentKey<EEModuleDescription> EE_MODULE_DESCRIPTION = AttachmentKey.create(EEModuleDescription.class);
public static final AttachmentKey<EEModuleConfiguration> EE_MODULE_CONFIGURATION = AttachmentKey.create(EEModuleConfiguration.class);
public static final AttachmentKey<DeploymentDescriptorEnvironment> MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT = AttachmentKey.create(DeploymentDescriptorEnvironment.class);
/**
* Components that failed during install. This will allow some optional components to be ignored.
*/
public static final AttachmentKey<Set<ServiceName>> FAILED_COMPONENTS = AttachmentKey.create(Set.class);
/**
* A list of actions that should be performed for every web invocation
*/
public static final AttachmentKey<AttachmentList<SetupAction>> WEB_SETUP_ACTIONS = AttachmentKey.createList(SetupAction.class);
/**
* A list of actions that should be performed for other non-web EE threads. At the moment this is ejb timer, remote, async invocations, and the app client.
*/
public static final AttachmentKey<AttachmentList<SetupAction>> OTHER_EE_SETUP_ACTIONS = AttachmentKey.createList(SetupAction.class);
/**
* Additional (remote) components that can be resolved but are not installed.
*/
public static final AttachmentKey<AttachmentList<ComponentDescription>> ADDITIONAL_RESOLVABLE_COMPONENTS = AttachmentKey.createList(ComponentDescription.class);
/**
* Unlike the EE spec which says application name is the name of the top level deployment (even if it is just
* a jar and not an ear), the Jakarta Enterprise Beans spec semantics (for JNDI) expect that the application name is the
* .ear name (or any configured value in application.xml). Absence of the .ear is expected to mean
* there's no application name. This attachement key, provides the application name which is follows the
* Jakarta Enterprise Beans spec semantics.
*/
public static final AttachmentKey<String> EAR_APPLICATION_NAME = AttachmentKey.create(String.class);
/**
* Any message destinations that need to be resolved.
*/
public static final AttachmentKey<AttachmentList<MessageDestinationInjectionSource>> MESSAGE_DESTINATIONS = AttachmentKey.createList(MessageDestinationInjectionSource.class);
public static final AttachmentKey<EEResourceReferenceProcessorRegistry> RESOURCE_REFERENCE_PROCESSOR_REGISTRY = AttachmentKey.create(EEResourceReferenceProcessorRegistry.class);
public static final AttachmentKey<StartupCountdown> STARTUP_COUNTDOWN = AttachmentKey.create(StartupCountdown.class);
public static final AttachmentKey<ComponentRegistry> COMPONENT_REGISTRY = AttachmentKey.create(ComponentRegistry.class);
public static final AttachmentKey<AttachmentList<ContextHandleFactory>> ADDITIONAL_FACTORIES = AttachmentKey.createList(ContextHandleFactory.class);
public static final AttachmentKey<ConcurrentContextSetupAction> CONCURRENT_CONTEXT_SETUP_ACTION = AttachmentKey.create(ConcurrentContextSetupAction.class);
}
| 5,157 | 52.175258 | 181 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewBindingInjectionSource.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.ee.component;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ViewBindingInjectionSource extends InjectionSource {
private final ServiceName serviceName;
public ViewBindingInjectionSource(final ServiceName serviceName) {
this.serviceName = serviceName;
}
/** {@inheritDoc} */
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) {
serviceBuilder.addDependency(serviceName, ComponentView.class, new ViewManagedReferenceFactory.Injector(injector));
}
public boolean equals(final Object injectionSource) {
return injectionSource instanceof ViewBindingInjectionSource && equalTo((ViewBindingInjectionSource) injectionSource);
}
private boolean equalTo(final ViewBindingInjectionSource configuration) {
return configuration != null && serviceName.equals(configuration.serviceName);
}
public int hashCode() {
return serviceName.hashCode();
}
}
| 2,421 | 39.366667 | 210 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/BindingConfiguration.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.ee.component;
import org.jboss.as.ee.logging.EeLogger;
/**
* A binding into JNDI. This class contains the mechanism to construct the binding service. In particular
* it represents <b>only</b> the description of the binding; it does not represent injection or any other parameters
* of a JNDI resource.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class BindingConfiguration {
private final String name;
private final InjectionSource source;
/**
* Construct a new instance.
*
* @param name the binding name
* @param source The source which will be used to resolve a value to be bound in the JNDI
* @throws IllegalArgumentException If either of the passed <code>name</code> or <code>source</code> is null
*/
public BindingConfiguration(final String name, final InjectionSource source) {
if (name == null) {
throw EeLogger.ROOT_LOGGER.nullName("binding");
}
if (source == null) {
throw EeLogger.ROOT_LOGGER.nullVar("source","binding", "");
}
this.name = name;
this.source = source;
}
/**
* The name into which this binding should be made. The meaning of relative names depends on where this
* binding description is used. For component bindings, relative names are generally relative to {@code java:comp/env}.
*
* @return the name into which this binding should be made
*/
public String getName() {
return name;
}
/**
* Get the source for this binding.
*
* @return the binding's injection source
*/
public InjectionSource getSource() {
return source;
}
public boolean equals(Object other) {
if (!(other instanceof BindingConfiguration))
return false;
BindingConfiguration config = (BindingConfiguration)other;
return name.equals(config.name) && source.equals(config.source);
}
public int hashCode() {
return name.hashCode() * 31 + source.hashCode();
}
}
| 3,127 | 34.146067 | 124 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/NamespaceConfigurator.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.ee.component;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.naming.InjectedEENamespaceContextSelector;
import org.jboss.as.naming.NamingStore;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DelegatingSupplier;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* A configurator which adds interceptors to the component which establish the naming context. The interceptor is
* added to the beginning of each chain.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class NamespaceConfigurator implements ComponentConfigurator {
/** {@inheritDoc} */
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final ComponentNamingMode namingMode = description.getNamingMode();
final String applicationName = configuration.getApplicationName();
final String moduleName = configuration.getModuleName();
final String compName = configuration.getComponentName();
final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(applicationName);
final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(applicationName, moduleName);
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(applicationName, moduleName, compName);
final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
final DelegatingSupplier<NamingStore> appSupplier = selector.getAppContextSupplier();
final DelegatingSupplier<NamingStore> moduleSupplier = selector.getModuleContextSupplier();
final DelegatingSupplier<NamingStore> compSupplier = selector.getCompContextSupplier();
final DelegatingSupplier<NamingStore> jbossSupplier = selector.getJbossContextSupplier();
final DelegatingSupplier<NamingStore> globalSupplier = selector.getGlobalContextSupplier();
final DelegatingSupplier<NamingStore> exportedSupplier = selector.getExportedContextSupplier();
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) {
appSupplier.set(serviceBuilder.requires(appContextServiceName));
moduleSupplier.set(serviceBuilder.requires(moduleContextServiceName));
if (namingMode == ComponentNamingMode.CREATE) {
compSupplier.set(serviceBuilder.requires(compContextServiceName));
} else if(namingMode == ComponentNamingMode.USE_MODULE) {
compSupplier.set(serviceBuilder.requires(moduleContextServiceName));
}
globalSupplier.set(serviceBuilder.requires(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME));
jbossSupplier.set(serviceBuilder.requires(ContextNames.JBOSS_CONTEXT_SERVICE_NAME));
exportedSupplier.set(serviceBuilder.requires(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME));
}
});
final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new NamespaceContextInterceptor(selector, context.getDeploymentUnit().getServiceName()));
configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.JNDI_NAMESPACE_INTERCEPTOR);
configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.JNDI_NAMESPACE_INTERCEPTOR);
if(description.isPassivationApplicable()) {
configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
}
configuration.setNamespaceContextInterceptorFactory(interceptorFactory);
configuration.setNamespaceContextSelector(selector);
}
}
| 5,609 | 62.033708 | 190 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewConfiguration.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.ee.component;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.component.interceptors.OrderedItemContainer;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.proxy.ProxyFactory;
import org.jboss.msc.service.ServiceName;
/**
* A configuration of a component view.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author Stuart Douglas
*/
public class ViewConfiguration {
private final ComponentConfiguration componentConfiguration;
private final ServiceName viewServiceName;
private final Map<Method, OrderedItemContainer<InterceptorFactory>> viewInterceptors = new IdentityHashMap<Method, OrderedItemContainer<InterceptorFactory>>();
private final Map<Method, OrderedItemContainer<InterceptorFactory>> clientInterceptors = new IdentityHashMap<Method, OrderedItemContainer<InterceptorFactory>>();
private final OrderedItemContainer<InterceptorFactory> clientPostConstructInterceptors = new OrderedItemContainer<InterceptorFactory>();
private final OrderedItemContainer<InterceptorFactory> clientPreDestroyInterceptors = new OrderedItemContainer<InterceptorFactory>();
private final ProxyFactory<?> proxyFactory;
private final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
private final Class<?> viewClass;
private final Set<Method> asyncMethods = new HashSet<Method>();
private final Map<Class<?>, Object> privateData = new HashMap<Class<?>, Object>();
private final List<DependencyConfigurator<ViewService>> dependencies = new ArrayList<DependencyConfigurator<ViewService>>();
private final Map<Method, Method> viewToComponentMethodMap = new HashMap<>();
private ViewInstanceFactory viewInstanceFactory;
/**
* Construct a new instance.
*
* @param viewClass the view class
* @param componentConfiguration the associated component configuration
* @param viewServiceName the service name of this view
* @param proxyFactory the proxy factory to use to locally construct client proxy instances
*/
public ViewConfiguration(final Class<?> viewClass, final ComponentConfiguration componentConfiguration, final ServiceName viewServiceName, final ProxyFactory<?> proxyFactory) {
this.componentConfiguration = componentConfiguration;
this.viewServiceName = viewServiceName;
this.proxyFactory = proxyFactory;
this.viewClass = viewClass;
}
/**
* Get the component configuration for this view.
*
* @return the component configuration
*/
public ComponentConfiguration getComponentConfiguration() {
return componentConfiguration;
}
/**
* Get the view service name for this view.
*
* @return the view service name
*/
public ServiceName getViewServiceName() {
return viewServiceName;
}
/**
* Get the view interceptors for a method. These interceptors are run sequentially on the "server side" of an
* invocation. The interceptor factories are used every time a new view instance is constructed, called with a
* new factory context each time. The factory may return the same interceptor instance or a new interceptor
* instance as appropriate.
*
* @param method the method to look up
* @return the interceptors for this method
*/
public List<InterceptorFactory> getViewInterceptors(Method method) {
OrderedItemContainer<InterceptorFactory> container = viewInterceptors.get(method);
if (container == null) {
return Collections.emptyList();
}
return container.getSortedItems();
}
/**
* Adds an interceptor factory to all methods of a view
*
* @param interceptorFactory The factory to add
* @param priority The interceptor order
*/
public void addViewInterceptor(InterceptorFactory interceptorFactory, int priority) {
for (Method method : proxyFactory.getCachedMethods()) {
addViewInterceptor(method, interceptorFactory, priority);
}
}
/**
* Adds a view interceptor to the given method
*
* @param method The method to add
* @param interceptorFactory The interceptor factory
* @param priority The priority
*/
public void addViewInterceptor(Method method, InterceptorFactory interceptorFactory, int priority) {
OrderedItemContainer<InterceptorFactory> container = viewInterceptors.get(method);
if (container == null) {
viewInterceptors.put(method, container = new OrderedItemContainer<InterceptorFactory>());
}
container.add(interceptorFactory, priority);
}
/**
* Get the client interceptors for a method. These interceptors are run sequentially on the "client side" of an
* invocation. The interceptor factories are used every time a new client proxy instance is constructed, called with a
* new factory context each time. The factory may return the same interceptor instance or a new interceptor
* instance as appropriate.
*
* @param method the method to look up
* @return the interceptors for this method
*/
public List<InterceptorFactory> getClientInterceptors(Method method) {
OrderedItemContainer<InterceptorFactory> container = clientInterceptors.get(method);
if (container == null) {
return Collections.emptyList();
}
return container.getSortedItems();
}
/**
* Adds a client interceptor factory to all methods of a view
*
* @param interceptorFactory The factory to add
* @param priority The interceptor order
*/
public void addClientInterceptor(InterceptorFactory interceptorFactory, int priority) {
for (Method method : proxyFactory.getCachedMethods()) {
addClientInterceptor(method, interceptorFactory, priority);
}
}
/**
* Adds a client interceptor to the given method
*
* @param method The method to add
* @param interceptorFactory The interceptor factory
* @param priority The priority
*/
public void addClientInterceptor(Method method, InterceptorFactory interceptorFactory, int priority) {
OrderedItemContainer<InterceptorFactory> container = clientInterceptors.get(method);
if (container == null) {
clientInterceptors.put(method, container = new OrderedItemContainer<InterceptorFactory>());
}
container.add(interceptorFactory, priority);
}
/**
* Get the post-construct interceptors for client proxy instances.
* <p/>
* This method should only be called after all interceptors have been added.
*
* @return the interceptors
*/
public List<InterceptorFactory> getClientPostConstructInterceptors() {
return clientPostConstructInterceptors.getSortedItems();
}
/**
* Adds a client post construct interceptor
*
* @param interceptorFactory The interceptor
* @param priority The interceptor order
*/
public void addClientPostConstructInterceptor(final InterceptorFactory interceptorFactory, final int priority) {
clientPostConstructInterceptors.add(interceptorFactory, priority);
}
/**
* Get the pre-destroy interceptors for client proxy instances.
* <p/>
* This method should only be called after all interceptors have been added.
*
* @return the interceptors
*/
public List<InterceptorFactory> getClientPreDestroyInterceptors() {
return clientPreDestroyInterceptors.getSortedItems();
}
/**
* Adds a client pre-destroy interceptor
*
* @param interceptorFactory The interceptor
* @param priority The interceptor order
*/
public void addClientPreDestroyInterceptor(final InterceptorFactory interceptorFactory, final int priority) {
clientPreDestroyInterceptors.add(interceptorFactory, priority);
}
/**
* Get the client proxy factory to use to construct proxy instances.
*
* @return the proxy factory
*/
public ProxyFactory<?> getProxyFactory() {
return proxyFactory;
}
/**
* Get the binding configurations for this view.
*
* @return the binding configurations
*/
public List<BindingConfiguration> getBindingConfigurations() {
return bindingConfigurations;
}
/**
* Get the view class.
*
* @return the view class
*/
public Class<?> getViewClass() {
return viewClass;
}
/**
* Gets all async methods for the view
* @return The async methods
*/
public Set<Method> getAsyncMethods() {
return Collections.unmodifiableSet(asyncMethods);
}
/**
* Marks a method on the view as asynchronous
*
* @param method The method
*/
public void addAsyncMethod(Method method) {
this.asyncMethods.add(method);
}
public ViewInstanceFactory getViewInstanceFactory() {
return viewInstanceFactory;
}
/**
*
* @param viewInstanceFactory The instance factory that is used to create the view instances
*/
public void setViewInstanceFactory(final ViewInstanceFactory viewInstanceFactory) {
this.viewInstanceFactory = viewInstanceFactory;
}
/**
* Attaches arbitrary private data to this view instance
*
* @param type The type of data
* @param data The data
*/
public <T> void putPrivateData(final Class<T> type, T data ) {
privateData.put(type, data);
}
/**
* retrieves private data
*/
public Map<Class<?>, Object> getPrivateData() {
return privateData;
}
public List<DependencyConfigurator<ViewService>> getDependencies() {
return dependencies;
}
public Map<Method, Method> getViewToComponentMethodMap() {
return viewToComponentMethodMap;
}
}
| 11,355 | 36.111111 | 180 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ClassDescriptionTraversal.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.ee.component;
import java.util.ArrayList;
import java.util.List;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
/**
* throwaway utility class for traversing a class configuration from most general superclass down
*/
public abstract class ClassDescriptionTraversal {
final Class<?> clazz;
final EEApplicationClasses applicationClasses;
public ClassDescriptionTraversal(final Class<?> clazz, final EEApplicationClasses applicationClasses) {
this.clazz = clazz;
this.applicationClasses = applicationClasses;
}
public void run() throws DeploymentUnitProcessingException {
Class<?> clazz = this.clazz;
final List<EEModuleClassDescription> queue = new ArrayList<EEModuleClassDescription>();
final List<Class<?>> classQueue = new ArrayList<Class<?>>();
while (clazz != null && clazz != Object.class) {
final EEModuleClassDescription configuration = applicationClasses.getClassByName(clazz.getName());
queue.add(configuration);
classQueue.add(clazz);
clazz = clazz.getSuperclass();
}
for (int i = queue.size() - 1; i >= 0; --i) {
final EEModuleClassDescription config = queue.get(i);
if(config != null) {
handle(classQueue.get(i), config);
} else {
handle(classQueue.get(i), null);
}
}
}
protected abstract void handle(final Class<?> clazz, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException;
}
| 2,625 | 40.68254 | 147 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEModuleClassDescription.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.ee.component;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
/**
* The description of a (possibly annotated) class in an EE module.
*
* This class must be thread safe as it may be used by sub deployments at the same time
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class EEModuleClassDescription {
private final String className;
private boolean invalid;
private StringBuilder invalidMessageBuilder;
private final Map<Class<? extends Annotation>, ClassAnnotationInformation<?,?>> annotationInformation = Collections.synchronizedMap(new HashMap<Class<? extends Annotation>, ClassAnnotationInformation<?, ?>>());
private InterceptorClassDescription interceptorClassDescription = InterceptorClassDescription.EMPTY_INSTANCE;
private final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
private final Map<InjectionTarget, ResourceInjectionConfiguration> injectionConfigurations = new HashMap<InjectionTarget, ResourceInjectionConfiguration>();
public EEModuleClassDescription(final String className) {
this.className = className;
}
/**
* Get the class name of this EE module class.
*
* @return the class name
*/
public String getClassName() {
return className;
}
public InterceptorClassDescription getInterceptorClassDescription() {
return interceptorClassDescription;
}
public void setInterceptorClassDescription(final InterceptorClassDescription interceptorClassDescription) {
if(interceptorClassDescription == null) {
throw EeLogger.ROOT_LOGGER.nullVar("interceptorClassDescription", "module class", className);
}
this.interceptorClassDescription = interceptorClassDescription;
}
/**
* Get the binding configurations for this EE module class.
*
* @return the binding configurations
*/
public List<BindingConfiguration> getBindingConfigurations() {
return bindingConfigurations;
}
/**
* Get the resource injection configurations for this EE module class.
*
* @return the resource injection configuration
*/
public Map<InjectionTarget, ResourceInjectionConfiguration> getInjectionConfigurations() {
return injectionConfigurations;
}
public void addResourceInjection(final ResourceInjectionConfiguration injection) {
injectionConfigurations.put(injection.getTarget(), injection);
}
public void addAnnotationInformation(ClassAnnotationInformation annotationInformation) {
this.annotationInformation.put(annotationInformation.getAnnotationType(), annotationInformation);
}
public <A extends Annotation, T> ClassAnnotationInformation<A, T> getAnnotationInformation(Class<A> annotationType) {
return (ClassAnnotationInformation<A, T>) this.annotationInformation.get(annotationType);
}
public synchronized void setInvalid(String message) {
if(!invalid) {
invalid = true;
invalidMessageBuilder = new StringBuilder();
} else {
invalidMessageBuilder.append('\n');
}
invalidMessageBuilder.append(message);
}
public synchronized boolean isInvalid() {
return invalid;
}
public String getInvalidMessage() {
if(invalidMessageBuilder == null) {
return "";
}
return invalidMessageBuilder.toString();
}
}
| 4,846 | 36 | 214 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentFactory.java | package org.jboss.as.ee.component;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.InterceptorContext;
/**
* @author Stuart Douglas
*/
public interface ComponentFactory {
ManagedReference create(final InterceptorContext context);
}
| 267 | 18.142857 | 62 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentConfigurator.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.ee.component;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
/**
* A configurator for components. Each configurator is run in the order it appears on the component description.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface ComponentConfigurator {
/**
* Apply this configurator to the given component configuration.
*
* @param context the deployment phase context
* @param description the completed component description
* @param configuration the component configuration to build on to
* @throws DeploymentUnitProcessingException if configuration fails
*/
void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException;
}
| 1,948 | 42.311111 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/FieldInjectionTarget.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.ee.component;
import static org.jboss.as.server.deployment.Attachments.MODULE;
import static org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ManagedReferenceFactory;
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.InterceptorFactory;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleClassLoader;
import org.jboss.msc.value.Value;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author Eduardo Martins
*/
public final class FieldInjectionTarget extends InjectionTarget {
/**
*
* @param className
* @param name
* @param fieldType
*/
public FieldInjectionTarget(final String className, final String name, final String fieldType) {
super(className, name, fieldType);
}
@Override
public boolean isStatic(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
return Modifier.isStatic(getField(deploymentUnit).getModifiers());
}
public InterceptorFactory createInjectionInterceptorFactory(final Object targetContextKey, final Object valueContextKey, final Value<ManagedReferenceFactory> factoryValue, final DeploymentUnit deploymentUnit, final boolean optional) throws DeploymentUnitProcessingException {
return new ManagedReferenceFieldInjectionInterceptorFactory(targetContextKey, valueContextKey, factoryValue, getField(deploymentUnit), optional);
}
private Field getField(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final String name = getName();
final String className = getClassName();
final Module module = deploymentUnit.getAttachment(MODULE);
final ModuleClassLoader classLoader = module.getClassLoader();
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
final ClassReflectionIndex classIndex;
try {
classIndex = reflectionIndex.getClassIndex(Class.forName(className, false, classLoader));
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException(e);
}
final Field field = classIndex.getField(name);
if (field == null) {
throw EeLogger.ROOT_LOGGER.fieldNotFound(name);
}
return field;
}
}
| 3,745 | 42.057471 | 279 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentNamingMode.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.ee.component;
/**
* A component's naming context operation mode.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public enum ComponentNamingMode {
/**
* No component namespace is available.
*/
NONE,
/**
* Use the module's namespace for the component namespace.
*/
USE_MODULE,
/**
* Create a new namespace for this component.
*/
CREATE,
}
| 1,468 | 32.386364 | 70 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/MethodInjectionTarget.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.ee.component;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Iterator;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.utils.ClassLoadingUtils;
import org.jboss.as.naming.ManagedReferenceFactory;
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.ClassReflectionIndexUtil;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.msc.value.Value;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author Eduardo Martins
*/
public final class MethodInjectionTarget extends InjectionTarget {
public MethodInjectionTarget(final String className, final String name, final String paramType) {
super(className, name, paramType);
}
@Override
public boolean isStatic(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
return Modifier.isStatic(getMethod(deploymentUnit).getModifiers());
}
public InterceptorFactory createInjectionInterceptorFactory(final Object targetContextKey, final Object valueContextKey, final Value<ManagedReferenceFactory> factoryValue, final DeploymentUnit deploymentUnit, final boolean optional) throws DeploymentUnitProcessingException {
return new ManagedReferenceMethodInjectionInterceptorFactory(targetContextKey, valueContextKey, factoryValue, getMethod(deploymentUnit), optional);
}
public Method getMethod(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final String name = getName();
final String className = getClassName();
final String paramType = getDeclaredValueClassName();
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
final Class<?> clazz;
try {
clazz = ClassLoadingUtils.loadClass(className, deploymentUnit);
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException(e);
}
Method method = getMethod(reflectionIndex, clazz);
return method;
}
public Method getMethod(final DeploymentReflectionIndex reflectionIndex, final Class<?> clazz) throws DeploymentUnitProcessingException {
final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz);
Collection<Method> methods = null;
final String paramType = getDeclaredValueClassName();
final String name = getName();
final String className = getClassName();
if (paramType != null) {
// find the methods with the specific name and the param types
methods = ClassReflectionIndexUtil.findMethods(reflectionIndex, classIndex, name, paramType);
}
// either paramType is not set, or we may need to find autoboxing methods
// e.g. setMyBoolean(boolean) for a Boolean
if (methods == null || methods.isEmpty()) {
// find all the methods with the specific name and which accept just 1 parameter.
methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1);
}
Iterator<Method> iterator = methods.iterator();
if (!iterator.hasNext()) {
throw EeLogger.ROOT_LOGGER.methodNotFound(name, paramType, className);
}
Method method = iterator.next();
if (iterator.hasNext()) {
throw EeLogger.ROOT_LOGGER.multipleMethodsFound(name, paramType, className);
}
return method;
}
}
| 4,893 | 46.514563 | 279 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ManagedReferenceLifecycleMethodInterceptor.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.ee.component;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.Interceptors;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
final class ManagedReferenceLifecycleMethodInterceptor implements Interceptor {
private final Object contextKey;
private final Method method;
private final boolean changeMethod;
private final boolean lifecycleMethod;
private final boolean withContext;
/**
* This is equivalent to calling <code>ManagedReferenceLifecycleMethodInterceptorFactory(Object, java.lang.reflect.Method, boolean, false)</code>
*
* @param contextKey
* @param method The method for which the interceptor has to be created
* @param changeMethod True if during the interceptor processing, the {@link org.jboss.invocation.InterceptorContext#getMethod()}
* is expected to return the passed <code>method</code>
*/
ManagedReferenceLifecycleMethodInterceptor(final Object contextKey, final Method method, final boolean changeMethod) {
this(contextKey, method, changeMethod, false);
}
/**
* @param contextKey
* @param method The method for which the interceptor has to be created
* @param changeMethod True if during the interceptor processing, the {@link org.jboss.invocation.InterceptorContext#getMethod()}
* is expected to return the passed <code>method</code>
* @param lifecycleMethod If the passed <code>method</code> is a lifecycle callback method. False otherwise
*/
ManagedReferenceLifecycleMethodInterceptor(final Object contextKey, final Method method, final boolean changeMethod, final boolean lifecycleMethod) {
this.contextKey = contextKey;
this.method = method;
this.changeMethod = changeMethod;
this.lifecycleMethod = lifecycleMethod;
withContext = method.getParameterCount() == 1;
}
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
final ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(contextKey);
final Object instance = reference.getInstance();
try {
final Method method = this.method;
if (withContext) {
final Method oldMethod = context.getMethod();
try {
if (this.lifecycleMethod) {
// because InvocationContext#getMethod() is expected to return null for lifecycle methods
context.setMethod(null);
return method.invoke(instance, context.getInvocationContext());
} else if (this.changeMethod) {
context.setMethod(method);
return method.invoke(instance, context.getInvocationContext());
} else {
return method.invoke(instance, context.getInvocationContext());
}
} finally {
// reset any changed method on the interceptor context
context.setMethod(oldMethod);
}
} else {
method.invoke(instance);
return context.proceed();
}
} catch (IllegalAccessException e) {
final IllegalAccessError n = new IllegalAccessError(e.getMessage());
n.setStackTrace(e.getStackTrace());
throw n;
} catch (InvocationTargetException e) {
throw Interceptors.rethrow(e.getCause());
}
}
}
| 4,917 | 44.119266 | 153 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ConstructorComponentFactory.java | package org.jboss.as.ee.component;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.InterceptorContext;
/**
* @author Stuart Douglas
*/
public class ConstructorComponentFactory implements ComponentFactory {
private final Constructor<?> constructor;
public ConstructorComponentFactory(final Constructor<?> constructor) {
this.constructor = constructor;
}
@Override
public ManagedReference create(final InterceptorContext context) {
try {
Object instance = constructor.newInstance();
return new ConstructorManagedReference(instance);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static final class ConstructorManagedReference implements ManagedReference, Serializable {
private final Object value;
private ConstructorManagedReference(final Object value) {
this.value = value;
}
@Override
public void release() {
}
@Override
public Object getInstance() {
return value;
}
}
}
| 1,313 | 25.28 | 102 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentCreateException.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.ee.component;
/**
* An exception relating to a problem with the creation of an EE component.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class ComponentCreateException extends Exception {
private static final long serialVersionUID = 4525122726559539936L;
/**
* Constructs a {@code ComponentCreateException} with no detail message. The cause is not initialized, and may
* subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
*/
public ComponentCreateException() {
super((String) null);
}
/**
* Constructs a {@code ComponentCreateException} with the specified detail message. The cause is not initialized,
* and may subsequently be initialized by a call to {@link #initCause(Throwable) initCause}.
*
* @param msg the detail message
*/
public ComponentCreateException(final String msg) {
super(msg);
}
/**
* Constructs a {@code ComponentCreateException} with the specified cause. The detail message is set to:
* <pre>(cause == null ? null : cause.toString())</pre>
* (which typically contains the class and detail message of {@code cause}).
*
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
*/
public ComponentCreateException(final Throwable cause) {
super(cause);
}
/**
* Constructs a {@code ComponentCreateException} with the specified detail message and cause.
*
* @param msg the detail message
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
*/
public ComponentCreateException(final String msg, final Throwable cause) {
super(msg, cause);
}
}
| 2,840 | 37.917808 | 117 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewInstanceFactory.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.ee.component;
import java.util.Map;
import org.jboss.as.naming.ManagedReference;
/**
* Factory that can be used to customize a views proxy creation
*
* TODO: this needs to be thought through a bit more
*
* @author Stuart Douglas
*/
public interface ViewInstanceFactory {
ManagedReference createViewInstance(ComponentView componentView, final Map<Object, Object> contextData) throws Exception;
}
| 1,447 | 35.2 | 125 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEModuleDescription.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.ee.component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.concurrent.ConcurrentContext;
import org.jboss.as.ee.naming.InjectedEENamespaceContextSelector;
import org.jboss.msc.service.ServiceName;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class EEModuleDescription implements ResourceInjectionTarget {
private final String applicationName;
private volatile String moduleName;
private final String earApplicationName;
//distinct name defaults to the empty string
private volatile String distinctName = "";
private final Map<String, ComponentDescription> componentsByName = new HashMap<String, ComponentDescription>();
private final Map<String, List<ComponentDescription>> componentsByClassName = new HashMap<String, List<ComponentDescription>>();
private final Map<String, EEModuleClassDescription> classDescriptions = new HashMap<String, EEModuleClassDescription>();
private final Map<String, InterceptorClassDescription> interceptorClassOverrides = new HashMap<String, InterceptorClassDescription>();
/**
* Additional interceptor environment that was defined in the deployment descriptor <interceptors/> element.
*/
private final Map<String, InterceptorEnvironment> interceptorEnvironment = new HashMap<String, InterceptorEnvironment>();
/**
* A map of message destinations names to their resolved JNDI name
*/
private final Map<String, String> messageDestinations = new HashMap<String, String>();
private InjectedEENamespaceContextSelector namespaceContextSelector;
// Module Bindings
private final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
//injections that have been set in the components deployment descriptor
private final Map<String, Map<InjectionTarget, ResourceInjectionConfiguration>> resourceInjections = new HashMap<String, Map<InjectionTarget, ResourceInjectionConfiguration>>();
private final boolean appClient;
private ServiceName defaultClassIntrospectorServiceName = ReflectiveClassIntrospector.SERVICE_NAME;
private final ConcurrentContext concurrentContext;
private final EEDefaultResourceJndiNames defaultResourceJndiNames;
/**
* The default security domain for the module.
*/
private String defaultSecurityDomain;
/**
* The number of registered startup beans.
*/
private int startupBeansCount;
/**
* Construct a new instance.
*
* @param applicationName the application name (which is same as the module name if the .ear is absent)
* @param moduleName the module name
* @param earApplicationName The application name (which is null if the .ear is absent)
* @param appClient indicates if the process type is an app client
*/
public EEModuleDescription(final String applicationName, final String moduleName, final String earApplicationName, final boolean appClient) {
this.applicationName = applicationName;
this.moduleName = moduleName;
this.earApplicationName = earApplicationName;
this.appClient = appClient;
this.concurrentContext = new ConcurrentContext();
this.defaultResourceJndiNames = new EEDefaultResourceJndiNames();
}
/**
* Adds or retrieves an existing EEModuleClassDescription for the local module. This method should only be used
* for classes that reside within the current deployment unit, usually by annotation scanners that are attaching annotation
* information.
* <p/>
* This
*
* @param className The class name
* @return The new or existing {@link EEModuleClassDescription}
*/
public EEModuleClassDescription addOrGetLocalClassDescription(final String className) {
if (className == null) {
throw EeLogger.ROOT_LOGGER.nullVar("className", "module", moduleName);
}
EEModuleClassDescription ret = classDescriptions.get(className);
if (ret == null) {
classDescriptions.put(className, ret = new EEModuleClassDescription(className));
}
return ret;
}
/**
* Returns a class that is local to this module
*
* @param className The class
* @return The description, or null if not found
*/
EEModuleClassDescription getClassDescription(final String className) {
return classDescriptions.get(className);
}
/**
* Returns all class descriptions in this module
*
* @return All class descriptions
*/
public Collection<EEModuleClassDescription> getClassDescriptions() {
return classDescriptions.values();
}
public ServiceName getDefaultClassIntrospectorServiceName() {
return defaultClassIntrospectorServiceName;
}
public void setDefaultClassIntrospectorServiceName(ServiceName defaultClassIntrospectorServiceName) {
this.defaultClassIntrospectorServiceName = defaultClassIntrospectorServiceName;
}
/**
* Add a component to this module.
*
* @param description the component description
*/
public void addComponent(ComponentDescription description) {
final String componentName = description.getComponentName();
final String componentClassName = description.getComponentClassName();
if (componentName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("componentName", "module", moduleName);
}
if (componentClassName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("componentClassName","module", moduleName);
}
if (componentsByName.containsKey(componentName)) {
ComponentDescription existingComponent = componentsByName.get(componentName);
throw EeLogger.ROOT_LOGGER.componentAlreadyDefined(componentName, componentClassName,
existingComponent.getComponentClassName());
}
componentsByName.put(componentName, description);
List<ComponentDescription> list = componentsByClassName.get(componentClassName);
if (list == null) {
componentsByClassName.put(componentClassName, list = new ArrayList<ComponentDescription>(1));
}
list.add(description);
}
public void removeComponent(final String componentName, final String componentClassName) {
componentsByName.remove(componentName);
componentsByClassName.remove(componentClassName);
}
/**
* Returns the application name which can be the same as the module name, in the absence of a .ear top level
* deployment
*
* @return
* @see {@link #getEarApplicationName()}
*/
public String getApplicationName() {
//if no application name is set just return the module name
//this means that if the module name is changed the application name
//will change as well
if(applicationName == null) {
return moduleName;
}
return applicationName;
}
public String getModuleName() {
return moduleName;
}
public boolean hasComponent(final String name) {
return componentsByName.containsKey(name);
}
/**
* @return true if the process type is an app client
*/
public boolean isAppClient() {
return appClient;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public ComponentDescription getComponentByName(String name) {
return componentsByName.get(name);
}
public List<ComponentDescription> getComponentsByClassName(String className) {
final List<ComponentDescription> ret = componentsByClassName.get(className);
return ret == null ? Collections.<ComponentDescription>emptyList() : ret;
}
public Collection<ComponentDescription> getComponentDescriptions() {
return componentsByName.values();
}
public InjectedEENamespaceContextSelector getNamespaceContextSelector() {
return namespaceContextSelector;
}
public void setNamespaceContextSelector(InjectedEENamespaceContextSelector namespaceContextSelector) {
this.namespaceContextSelector = namespaceContextSelector;
}
public String getDistinctName() {
return distinctName;
}
public void setDistinctName(String distinctName) {
if (distinctName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("distinctName", "module", moduleName);
}
this.distinctName = distinctName;
}
/**
* Unlike the {@link #getApplicationName()} which follows the Jakarta EE spec semantics i.e. application name is the
* name of the top level deployment (even if it is just a jar and not an ear), this method returns the
* application name which follows the Jakarta Enterprise Beans spec semantics i.e. the application name is the
* .ear name or any configured value in application.xml. This method returns null in the absence of a .ear
*
* @return
*/
public String getEarApplicationName() {
return this.earApplicationName;
}
/**
* Get module level interceptor method overrides that are set up in ejb-jar.xml
*
* @param className The class name
* @return The overrides, or null if no overrides have been set up
*/
public InterceptorClassDescription getInterceptorClassOverride(final String className) {
return interceptorClassOverrides.get(className);
}
/**
* Adds a module level interceptor class override, it is merged with any existing overrides if they exist
*
* @param className The class name
* @param override The override
*/
public void addInterceptorMethodOverride(final String className, final InterceptorClassDescription override) {
interceptorClassOverrides.put(className, InterceptorClassDescription.merge(interceptorClassOverrides.get(className), override));
}
public List<BindingConfiguration> getBindingConfigurations() {
return bindingConfigurations;
}
public void addResourceInjection(final ResourceInjectionConfiguration injection) {
String className = injection.getTarget().getClassName();
Map<InjectionTarget, ResourceInjectionConfiguration> map = resourceInjections.get(className);
if (map == null) {
resourceInjections.put(className, map = new HashMap<InjectionTarget, ResourceInjectionConfiguration>());
}
map.put(injection.getTarget(), injection);
}
public Map<InjectionTarget, ResourceInjectionConfiguration> getResourceInjections(final String className) {
Map<InjectionTarget, ResourceInjectionConfiguration> injections = resourceInjections.get(className);
if (injections == null) {
return Collections.emptyMap();
} else {
return Collections.unmodifiableMap(injections);
}
}
public void addMessageDestination(final String name, final String jndiName) {
messageDestinations.put(name, jndiName);
}
public Map<String, String> getMessageDestinations() {
return Collections.unmodifiableMap(messageDestinations);
}
public void addInterceptorEnvironment(final String interceptorClassName, final InterceptorEnvironment env) {
interceptorEnvironment.put(interceptorClassName, env);
}
public Map<String, InterceptorEnvironment> getInterceptorEnvironment() {
return interceptorEnvironment;
}
public ConcurrentContext getConcurrentContext() {
return concurrentContext;
}
public EEDefaultResourceJndiNames getDefaultResourceJndiNames() {
return defaultResourceJndiNames;
}
public String getDefaultSecurityDomain() {
return defaultSecurityDomain;
}
public void setDefaultSecurityDomain(String defaultSecurityDomain) {
this.defaultSecurityDomain = defaultSecurityDomain;
}
public int getStartupBeansCount() {
return this.startupBeansCount;
}
public int registerStartupBean() {
return ++this.startupBeansCount;
}
}
| 13,465 | 37.919075 | 181 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/DefaultComponentConfigurator.java | package org.jboss.as.ee.component;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Set;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.component.interceptors.UserInterceptorFactory;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
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.ContextClassLoaderInterceptor;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.Interceptors;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.modules.Module;
import static org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX;
/**
* @author Stuart Douglas
*/
class DefaultComponentConfigurator extends AbstractComponentConfigurator implements ComponentConfigurator {
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final boolean metadataComplete = MetadataCompleteMarker.isMetadataComplete(deploymentUnit);
// Module stuff
final Deque<InterceptorFactory> injectors = new ArrayDeque<>();
final Deque<InterceptorFactory> uninjectors = new ArrayDeque<>();
final Deque<InterceptorFactory> destructors = new ArrayDeque<>();
final List<InterceptorFactory> componentUserAroundInvoke = new ArrayList<>();
final List<InterceptorFactory> componentUserAroundTimeout;
final List<InterceptorFactory> userPostConstruct = new ArrayList<>();
final List<InterceptorFactory> userPreDestroy = new ArrayList<>();
final List<InterceptorFactory> componentUserPrePassivate;
final List<InterceptorFactory> componentUserPostActivate;
final Set<MethodIdentifier> timeoutMethods = description.getTimerMethods();
if (description.isTimerServiceRequired()) {
componentUserAroundTimeout = new ArrayList<>();
} else {
componentUserAroundTimeout = null;
}
if (description.isPassivationApplicable()) {
componentUserPrePassivate = new ArrayList<>();
componentUserPostActivate = new ArrayList<>();
} else {
componentUserPrePassivate = null;
componentUserPostActivate = null;
}
destructors.add(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(BasicComponentInstance.INSTANCE_KEY)));
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
public void handle(Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
mergeInjectionsForClass(clazz, configuration.getComponentClass(), classDescription, moduleDescription, deploymentReflectionIndex, description, configuration, context, injectors, BasicComponentInstance.INSTANCE_KEY, uninjectors, metadataComplete);
}
}.run();
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
final InterceptorClassDescription interceptorConfig = InterceptorClassDescription.merge(ComponentDescription.mergeInterceptorConfig(clazz, classDescription, description, metadataComplete), moduleDescription.getInterceptorClassOverride(clazz.getName()));
handleClassMethod(clazz, interceptorConfig.getAroundInvoke(), componentUserAroundInvoke, false, false, configuration);
if (description.isTimerServiceRequired()) {
handleClassMethod(clazz, interceptorConfig.getAroundTimeout(), componentUserAroundTimeout, false, false, configuration);
}
if (!description.isIgnoreLifecycleInterceptors()) {
handleClassMethod(clazz, interceptorConfig.getPostConstruct(), userPostConstruct, true, true, configuration);
handleClassMethod(clazz, interceptorConfig.getPreDestroy(), userPreDestroy, true, true, configuration);
if (description.isPassivationApplicable()) {
handleClassMethod(clazz, interceptorConfig.getPrePassivate(), componentUserPrePassivate, false, true, configuration);
handleClassMethod(clazz, interceptorConfig.getPostActivate(), componentUserPostActivate, false, true, configuration);
}
}
}
private void handleClassMethod(final Class<?> clazz, final MethodIdentifier methodIdentifier, final List<InterceptorFactory> interceptors, boolean changeMethod, boolean lifecycleMethod, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
if (methodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier);
if (isNotOverriden(clazz, method, configuration.getComponentClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new ManagedReferenceLifecycleMethodInterceptor(BasicComponentInstance.INSTANCE_KEY, method, changeMethod, lifecycleMethod));
interceptors.add(interceptorFactory);
if(lifecycleMethod) {
configuration.addLifecycleMethod(method);
}
}
}
}
}.run();
final ClassLoader classLoader = module.getClassLoader();
final InterceptorFactory tcclInterceptor = new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader));
if (!injectors.isEmpty()) {
configuration.addPostConstructInterceptors(new ArrayList<>(injectors), InterceptorOrder.ComponentPostConstruct.COMPONENT_RESOURCE_INJECTION_INTERCEPTORS);
}
// Apply post-construct
if (!userPostConstruct.isEmpty()) {
configuration.addPostConstructInterceptors(userPostConstruct, InterceptorOrder.ComponentPostConstruct.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addPostConstructInterceptor(tcclInterceptor, InterceptorOrder.ComponentPostConstruct.TCCL_INTERCEPTOR);
// Apply pre-destroy
if (!uninjectors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(uninjectors), InterceptorOrder.ComponentPreDestroy.COMPONENT_UNINJECTION_INTERCEPTORS);
}
if (!destructors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(destructors), InterceptorOrder.ComponentPreDestroy.COMPONENT_DESTRUCTION_INTERCEPTORS);
}
if (!userPreDestroy.isEmpty()) {
configuration.addPreDestroyInterceptors(userPreDestroy, InterceptorOrder.ComponentPreDestroy.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPreDestroy.TERMINAL_INTERCEPTOR);
configuration.addPreDestroyInterceptor(tcclInterceptor, InterceptorOrder.ComponentPreDestroy.TCCL_INTERCEPTOR);
if (description.isPassivationApplicable()) {
if (!componentUserPrePassivate.isEmpty()) {
configuration.addPrePassivateInterceptors(componentUserPrePassivate, InterceptorOrder.ComponentPassivation.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPrePassivateInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPassivation.TERMINAL_INTERCEPTOR);
configuration.addPrePassivateInterceptor(tcclInterceptor, InterceptorOrder.ComponentPassivation.TCCL_INTERCEPTOR);
if (!componentUserPostActivate.isEmpty()) {
configuration.addPostActivateInterceptors(componentUserPostActivate, InterceptorOrder.ComponentPassivation.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPostActivateInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPassivation.TERMINAL_INTERCEPTOR);
configuration.addPostActivateInterceptor(tcclInterceptor, InterceptorOrder.ComponentPassivation.TCCL_INTERCEPTOR);
}
// @AroundInvoke interceptors
if (description.isIntercepted()) {
for (final Method method : configuration.getDefinedComponentMethods()) {
//now add the interceptor that initializes and the interceptor that actually invokes to the end of the interceptor chain
configuration.addComponentInterceptor(method, Interceptors.getInitialInterceptorFactory(), InterceptorOrder.Component.INITIAL_INTERCEPTOR);
configuration.addComponentInterceptor(method, new ImmediateInterceptorFactory(new ManagedReferenceMethodInterceptor(BasicComponentInstance.INSTANCE_KEY, method)), InterceptorOrder.Component.TERMINAL_INTERCEPTOR);
final MethodIdentifier identifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
// first add the default interceptors (if not excluded) to the deque
final boolean requiresTimerChain = description.isTimerServiceRequired() && timeoutMethods.contains(identifier);
if(requiresTimerChain) {
configuration.addComponentInterceptor(method, new UserInterceptorFactory(weaved(componentUserAroundInvoke), weaved(componentUserAroundTimeout)), InterceptorOrder.Component.COMPONENT_USER_INTERCEPTORS);
} else {
configuration.addComponentInterceptors(method, componentUserAroundInvoke, InterceptorOrder.Component.COMPONENT_USER_INTERCEPTORS);
}
}
}
}
}
| 11,238 | 60.081522 | 278 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewManagedReferenceFactory.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.ee.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ContextListManagedReferenceFactory;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.msc.inject.InjectionException;
/**
* A managed reference factory for a component view.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ViewManagedReferenceFactory implements ContextListManagedReferenceFactory {
private final ComponentView view;
/**
* Construct a new instance.
*
* @param view the component view
*/
public ViewManagedReferenceFactory(final ComponentView view) {
this.view = view;
}
@Override
public String getInstanceClassName() {
return view.getComponent().getComponentClass().getName();
}
/** {@inheritDoc} */
public ManagedReference getReference() {
try {
return view.createInstance();
} catch (Exception e) {
throw EeLogger.ROOT_LOGGER.componentViewConstructionFailure(e);
}
}
/**
* The bridge injector for binding views into JNDI. Injects a {@link ComponentView}
* wrapped as a {@link ManagedReferenceFactory}.
*/
public static class Injector implements org.jboss.msc.inject.Injector<ComponentView> {
private final org.jboss.msc.inject.Injector<ManagedReferenceFactory> referenceFactoryInjector;
/**
* Construct a new instance.
*
* @param referenceFactoryInjector the injector from the binder service
*/
public Injector(final org.jboss.msc.inject.Injector<ManagedReferenceFactory> referenceFactoryInjector) {
this.referenceFactoryInjector = referenceFactoryInjector;
}
/** {@inheritDoc} */
public void inject(final ComponentView value) throws InjectionException {
referenceFactoryInjector.inject(new ViewManagedReferenceFactory(value));
}
/** {@inheritDoc} */
public void uninject() {
referenceFactoryInjector.uninject();
}
}
}
| 3,189 | 34.444444 | 112 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/InjectionTarget.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.ee.component;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.msc.value.Value;
/**
* An injection target field or method in a class.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author Eduardo Martins
*/
public abstract class InjectionTarget {
private final String className;
private final String name;
private final String declaredValueClassName;
/**
*
* @param className The class to inject into
* @param name The target name
* @param declaredValueClassName The type of injection
*/
protected InjectionTarget(final String className, final String name, final String declaredValueClassName) {
this.className = className;
this.name = name;
this.declaredValueClassName = declaredValueClassName;
}
/**
* Get the name of the target property.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Get the name of the target class.
*
* @return the class name
*/
public String getClassName() {
return className;
}
/**
* Get the class name of the field or the parameter type declared for the target method.
*
* @return the class name
*/
public String getDeclaredValueClassName() {
return declaredValueClassName;
}
/**
* Get an interceptor factory which will carry out injection into this target.
*
*
* @param targetContextKey the interceptor context key for the target
* @param valueContextKey the interceptor context key for the value
* @param factoryValue the value to inject
* @param deploymentUnit the deployment unit
* @param optional If this is an optional injection
* @return the interceptor factory
* @throws DeploymentUnitProcessingException
* if an error occurs
*/
public abstract InterceptorFactory createInjectionInterceptorFactory(final Object targetContextKey, final Object valueContextKey, final Value<ManagedReferenceFactory> factoryValue, final DeploymentUnit deploymentUnit, final boolean optional) throws DeploymentUnitProcessingException;
/**
* Indicates if the target has the staic modifier.
*
* @param deploymentUnit the deployment unit
* @return true
* @throws DeploymentUnitProcessingException if an error occurs
*/
public abstract boolean isStatic(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException;
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final InjectionTarget that = (InjectionTarget) o;
if (className != null ? !className.equals(that.className) : that.className != null) return false;
if (declaredValueClassName != null ? !declaredValueClassName.equals(that.declaredValueClassName) : that.declaredValueClassName != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
return true;
}
@Override
public int hashCode() {
int result = className != null ? className.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (declaredValueClassName != null ? declaredValueClassName.hashCode() : 0);
return result;
}
@Override
public String toString() {
return new StringBuilder("InjectionTarget[className=").append(className).append(",name=").append(name).append(",declaredValueClassName=").append(declaredValueClassName).append("]").toString();
}
}
| 4,937 | 36.409091 | 287 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/DependencyConfigurator.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.ee.component;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
/**
* A configurator for a service dependency.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @param <T> the type of the service that is being configured
*/
public interface DependencyConfigurator<T extends Service> {
/**
* Configure the dependency on the service builder.
*
* @param serviceBuilder the service builder
* @param service
*/
void configureDependency(ServiceBuilder<?> serviceBuilder, final T service) throws DeploymentUnitProcessingException;
}
| 1,741 | 37.711111 | 121 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentClientInstance.java | package org.jboss.as.ee.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.invocation.InterceptorContext;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Class that represents an instance of a component client. It should only be referenced from client
* post construct interceptors.
*
* This stores all the context data for the client, such as the SFSB session ID etc.
*
* Previously this was achieved using stateful interceptor chains. This information can only be set during view
* construction for thread safety reasons. If mutable data is required then a mutable and thread safe structure should
* be inserted into the map at construction time.
*
* The class is only used at component creation time, after that the information that is contains is attached to the
* private data of the interceptor context.
*
* @author Stuart Douglas
*/
public class ComponentClientInstance implements Serializable {
private final Map<Object, Object> contextInformation = new HashMap<Object, Object>();
private volatile boolean constructionComplete = false;
public Object getViewInstanceData(final Object key) {
return contextInformation.get(key);
}
public void setViewInstanceData(final Object key, final Object data) {
if(constructionComplete) {
throw EeLogger.ROOT_LOGGER.instanceDataCanOnlyBeSetDuringConstruction();
}
contextInformation.put(key, data);
}
void prepareInterceptorContext(InterceptorContext interceptorContext){
for(Map.Entry<Object, Object> entry : contextInformation.entrySet()) {
interceptorContext.putPrivateData(entry.getKey(), entry.getValue());
}
}
void constructionComplete() {
constructionComplete = true;
}
}
| 1,820 | 34.019231 | 118 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEApplicationClasses.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.ee.component;
import java.util.List;
/**
* Allows a deployment to get old of class descriptions from all sub deployments it has access to.
*
* This maintains a list of all {@link EEModuleDescription}s that this sub deployment has access to,
* in the same order they appear in the dependencies list.
*
* @author Stuart Douglas
*/
public final class EEApplicationClasses {
//TODO: should we build a map of the available classes
private final List<EEModuleDescription> availableModules;
public EEApplicationClasses(final List<EEModuleDescription> availableModules) {
this.availableModules = availableModules;
}
/**
* Look for a class description in all available modules.
* @param name The class to lookup
* @return
*/
public EEModuleClassDescription getClassByName(String name) {
for(EEModuleDescription module : availableModules) {
final EEModuleClassDescription desc = module.getClassDescription(name);
if(desc != null) {
return desc;
}
}
return null;
}
}
| 2,146 | 34.783333 | 100 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ViewService.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.ee.component;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.utils.DescriptorUtils;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.Interceptors;
import org.jboss.invocation.SimpleInterceptorFactoryContext;
import org.jboss.invocation.proxy.ProxyFactory;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
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.manager.WildFlySecurityManager;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ViewService implements Service<ComponentView> {
private final InjectedValue<Component> componentInjector = new InjectedValue<Component>();
private final Map<Method, InterceptorFactory> viewInterceptorFactories;
private final Map<Method, InterceptorFactory> clientInterceptorFactories;
private final InterceptorFactory clientPostConstruct;
private final InterceptorFactory clientPreDestroy;
private final ProxyFactory<?> proxyFactory;
private final Class<?> viewClass;
private final Set<Method> asyncMethods;
private final ViewInstanceFactory viewInstanceFactory;
private final Map<Class<?>, Object> privateData;
private volatile ComponentView view;
private volatile Interceptor clientPostConstructInterceptor;
private volatile Interceptor clientPreDestroyInterceptor;
private volatile Map<Method, Interceptor> clientInterceptors;
public ViewService(final ViewConfiguration viewConfiguration) {
viewClass = viewConfiguration.getViewClass();
final ProxyFactory<?> proxyFactory = viewConfiguration.getProxyFactory();
this.proxyFactory = proxyFactory;
final List<Method> methods = proxyFactory.getCachedMethods();
final int methodCount = methods.size();
clientPostConstruct = Interceptors.getChainedInterceptorFactory(viewConfiguration.getClientPostConstructInterceptors());
clientPreDestroy = Interceptors.getChainedInterceptorFactory(viewConfiguration.getClientPreDestroyInterceptors());
final IdentityHashMap<Method, InterceptorFactory> viewInterceptorFactories = new IdentityHashMap<Method, InterceptorFactory>(methodCount);
final IdentityHashMap<Method, InterceptorFactory> clientInterceptorFactories = new IdentityHashMap<Method, InterceptorFactory>(methodCount);
for (final Method method : methods) {
if (method.getName().equals("finalize") && method.getParameterCount() == 0) {
viewInterceptorFactories.put(method, Interceptors.getTerminalInterceptorFactory());
} else {
viewInterceptorFactories.put(method, Interceptors.getChainedInterceptorFactory(viewConfiguration.getViewInterceptors(method)));
clientInterceptorFactories.put(method, Interceptors.getChainedInterceptorFactory(viewConfiguration.getClientInterceptors(method)));
}
}
this.viewInterceptorFactories = viewInterceptorFactories;
this.clientInterceptorFactories = clientInterceptorFactories;
this.asyncMethods = viewConfiguration.getAsyncMethods();
if (viewConfiguration.getViewInstanceFactory() == null) {
viewInstanceFactory = new DefaultViewInstanceFactory();
} else {
viewInstanceFactory = viewConfiguration.getViewInstanceFactory();
}
if(viewConfiguration.getPrivateData().isEmpty()) {
privateData = Collections.emptyMap();
} else {
privateData = viewConfiguration.getPrivateData();
}
}
public void start(final StartContext context) throws StartException {
// Construct the view
View view = new View(privateData);
view.initializeInterceptors();
this.view = view;
final SimpleInterceptorFactoryContext factoryContext = new SimpleInterceptorFactoryContext();
final Component component = view.getComponent();
factoryContext.getContextData().put(Component.class, component);
factoryContext.getContextData().put(ComponentView.class, view);
clientPostConstructInterceptor = clientPostConstruct.create(factoryContext);
clientPreDestroyInterceptor = clientPreDestroy.create(factoryContext);
final Map<Method, InterceptorFactory> clientInterceptorFactories = ViewService.this.clientInterceptorFactories;
clientInterceptors = new IdentityHashMap<Method, Interceptor>(clientInterceptorFactories.size());
for (Map.Entry<Method, InterceptorFactory> entry : clientInterceptorFactories.entrySet()) {
clientInterceptors.put(entry.getKey(), entry.getValue().create(factoryContext));
}
}
public void stop(final StopContext context) {
view = null;
}
public Injector<Component> getComponentInjector() {
return componentInjector;
}
public ComponentView getValue() throws IllegalStateException, IllegalArgumentException {
return view;
}
class View implements ComponentView {
private final Component component;
private final Map<Method, Interceptor> viewInterceptors;
private final Map<MethodDescription, Method> methods;
private final Map<Class<?>, Object> privateData;
View(final Map<Class<?>, Object> privateData) {
this.privateData = privateData;
component = componentInjector.getValue();
//we need to build the view interceptor chain
this.viewInterceptors = new IdentityHashMap<Method, Interceptor>();
this.methods = new HashMap<MethodDescription, Method>();
}
void initializeInterceptors() {
final SimpleInterceptorFactoryContext factoryContext = new SimpleInterceptorFactoryContext();
final Map<Method, InterceptorFactory> viewInterceptorFactories = ViewService.this.viewInterceptorFactories;
factoryContext.getContextData().put(Component.class, component);
//we don't have this code in the constructor so we avoid passing around
//a half constructed instance
factoryContext.getContextData().put(ComponentView.class, this);
for (Map.Entry<Method, InterceptorFactory> entry : viewInterceptorFactories.entrySet()) {
Method method = entry.getKey();
viewInterceptors.put(method, entry.getValue().create(factoryContext));
methods.put(new MethodDescription(method.getName(), DescriptorUtils.methodDescriptor(method)), method);
}
}
public ManagedReference createInstance() throws Exception {
return createInstance(Collections.<Object, Object>emptyMap());
}
public ManagedReference createInstance(Map<Object, Object> contextData) throws Exception {
// view instance creation can lead to instantiating application component classes (like the MDB implementation class
// or even the Jakarta Enterprise Beans implementation class of a no-interface view exposing bean). Such class initialization needs to
// have the TCCL set to the component/application's classloader. @see https://issues.jboss.org/browse/WFLY-3989
final ClassLoader oldTCCL = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(component.getComponentClass());
return viewInstanceFactory.createViewInstance(this, contextData);
} finally {
// reset the TCCL
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTCCL);
}
}
@Override
public Object invoke(InterceptorContext interceptorContext) throws Exception {
if(component instanceof BasicComponent) {
((BasicComponent) component).waitForComponentStart();
}
final Method method = interceptorContext.getMethod();
final Interceptor interceptor = viewInterceptors.get(method);
return interceptor.processInvocation(interceptorContext);
}
public Component getComponent() {
return component;
}
@Override
public Class<?> getProxyClass() {
return proxyFactory.defineClass();
}
@Override
public Class<?> getViewClass() {
return viewClass;
}
@Override
public Set<Method> getViewMethods() {
return viewInterceptors.keySet();
}
@Override
public Method getMethod(final String name, final String descriptor) {
Method method = this.methods.get(new MethodDescription(name, descriptor));
if (method == null) {
throw EeLogger.ROOT_LOGGER.viewMethodNotFound(name, descriptor, viewClass, component.getComponentClass());
}
return method;
}
@Override
public <T> T getPrivateData(final Class<T> clazz) {
return (T) privateData.get(clazz);
}
@Override
public boolean isAsynchronous(final Method method) {
return asyncMethods.contains(method);
}
@Override
public String toString() {
return "Component view " + viewClass + " for component "
+ component.getComponentClass();
}
private final class MethodDescription {
private final String name;
private final String descriptor;
public MethodDescription(final String name, final String descriptor) {
this.name = name;
this.descriptor = descriptor;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final MethodDescription that = (MethodDescription) o;
if (!descriptor.equals(that.descriptor)) return false;
if (!name.equals(that.name)) return false;
return true;
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + descriptor.hashCode();
return result;
}
}
}
private class DefaultViewInstanceFactory implements ViewInstanceFactory {
public ManagedReference createViewInstance(final ComponentView componentView, final Map<Object, Object> contextData) throws Exception {
final Object proxy;
final Component component = componentView.getComponent();
final ComponentClientInstance instance = new ComponentClientInstance();
try {
proxy = proxyFactory.newInstance(new ProxyInvocationHandler(clientInterceptors, instance, componentView));
} catch (InstantiationException e) {
InstantiationError error = new InstantiationError(e.getMessage());
Throwable cause = e.getCause();
if (cause != null) error.initCause(cause);
throw error;
} catch (IllegalAccessException e) {
IllegalAccessError error = new IllegalAccessError(e.getMessage());
Throwable cause = e.getCause();
if (cause != null) error.initCause(cause);
throw error;
}
InterceptorContext context = new InterceptorContext();
context.putPrivateData(ComponentView.class, componentView);
context.putPrivateData(Component.class, component);
context.putPrivateData(ComponentClientInstance.class, instance);
context.setContextData(new HashMap<String, Object>());
for(Map.Entry<Object, Object> entry : contextData.entrySet()) {
context.putPrivateData(entry.getKey(), entry.getValue());
}
clientPostConstructInterceptor.processInvocation(context);
instance.constructionComplete();
return new ManagedReference() {
@Override
public void release() {
try {
InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.putPrivateData(ComponentView.class, componentView);
interceptorContext.putPrivateData(Component.class, component);
clientPreDestroyInterceptor.processInvocation(interceptorContext);
} catch (Exception e) {
ROOT_LOGGER.preDestroyInterceptorFailure(e, component.getComponentClass());
}
}
@Override
public Object getInstance() {
return proxy;
}
};
}
}
}
| 14,578 | 43.045317 | 148 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ManagedReferenceReleaseInterceptor.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.ee.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
/**
* An interceptor which releases a managed reference.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
class ManagedReferenceReleaseInterceptor implements Interceptor {
private final Object contextKey;
/**
* Construct a new instance.
*
* @param contextKey the context key
*/
ManagedReferenceReleaseInterceptor(final Object contextKey) {
if (contextKey == null) {
throw EeLogger.ROOT_LOGGER.nullVar("contextKey");
}
this.contextKey = contextKey;
}
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
try {
return context.proceed();
} finally {
final ManagedReference managedReference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(contextKey);
if (managedReference != null) {
managedReference.release();
}
}
}
}
| 2,258 | 33.753846 | 149 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentInstanceInterceptorFactory.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.ee.component;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import java.util.Map;
/**
* A factory to create interceptors per ComponentInstance instance.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public abstract class ComponentInstanceInterceptorFactory implements InterceptorFactory {
private final Object KEY = new Object();
@Override
public final Interceptor create(InterceptorFactoryContext context) {
final Map<Object, Object> contextData = context.getContextData();
Interceptor interceptor = (Interceptor) contextData.get(KEY);
if (interceptor == null) {
final Component component = (Component) context.getContextData().get(Component.class);
contextData.put(KEY, interceptor = create(component, context));
}
return interceptor;
}
protected abstract Interceptor create(Component component, InterceptorFactoryContext context);
}
| 2,098 | 40.156863 | 98 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/BasicComponent.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.ee.component;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InvocationType;
import org.jboss.as.naming.ImmediateManagedReference;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.invocation.SimpleInterceptorFactoryContext;
import org.jboss.msc.service.ServiceName;
/**
* A basic component implementation.
*
* @author John Bailey
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public class BasicComponent implements Component {
private final String componentName;
private final Class<?> componentClass;
private final InterceptorFactory postConstruct;
private final InterceptorFactory preDestroy;
private final Map<Method, InterceptorFactory> interceptorFactoryMap;
private final NamespaceContextSelector namespaceContextSelector;
private final ServiceName createServiceName;
private volatile boolean gate;
private final AtomicBoolean stopping = new AtomicBoolean();
private Interceptor postConstructInterceptor;
private Interceptor preDestroyInterceptor;
private Map<Method, Interceptor> interceptorInstanceMap;
/**
* Construct a new instance.
*
* @param createService the create service which created this component
*/
public BasicComponent(final BasicComponentCreateService createService) {
componentName = createService.getComponentName();
componentClass = createService.getComponentClass();
postConstruct = createService.getPostConstruct();
preDestroy = createService.getPreDestroy();
interceptorFactoryMap = createService.getComponentInterceptors();
namespaceContextSelector = createService.getNamespaceContextSelector();
createServiceName = createService.getServiceName();
}
/**
* {@inheritDoc}
*/
public ComponentInstance createInstance() {
BasicComponentInstance instance = constructComponentInstance(null, true);
return instance;
}
/**
* Wraps an existing object instance in a ComponentInstance, and run the post construct interceptor chain on it.
*
* @param instance The instance to wrap
* @return The new ComponentInstance
*/
public ComponentInstance createInstance(Object instance) {
BasicComponentInstance obj = constructComponentInstance(new ImmediateManagedReference(instance), true);
obj.constructionFinished();
return obj;
}
@Override
public ComponentInstance getInstance(Object instance) {
BasicComponentInstance obj = constructComponentInstance(new ImmediateManagedReference(instance), false);
obj.constructionFinished();
return obj;
}
public void waitForComponentStart() {
if (!gate) {
EeLogger.ROOT_LOGGER.tracef("Waiting for component %s (%s)", componentName, componentClass);
// Block until successful start
synchronized (this) {
if (stopping.get()) {
throw EeLogger.ROOT_LOGGER.componentIsStopped();
}
while (!gate) {
// TODO: check for failure condition
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw EeLogger.ROOT_LOGGER.componentNotAvailable();
}
}
}
EeLogger.ROOT_LOGGER.tracef("Finished waiting for component %s (%s)", componentName, componentClass);
}
}
/**
* Construct the component instance. Upon return, the object instance should have injections and lifecycle
* invocations completed already.
*
*
* @param instance An instance to be wrapped, or null if a new instance should be created
* @return the component instance
*/
protected BasicComponentInstance constructComponentInstance(ManagedReference instance, boolean invokePostConstruct) {
return constructComponentInstance(instance, invokePostConstruct, Collections.emptyMap());
}
/**
* Construct the component instance. Upon return, the object instance should have injections and lifecycle
* invocations completed already.
*
*
* @param instance An instance to be wrapped, or null if a new instance should be created
* @return the component instance
*/
protected BasicComponentInstance constructComponentInstance(ManagedReference instance, boolean invokePostConstruct, final Map<Object, Object> context) {
waitForComponentStart();
// create the component instance
final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(preDestroyInterceptor, interceptorInstanceMap, context);
if(instance != null) {
basicComponentInstance.setInstanceData(BasicComponentInstance.INSTANCE_KEY, instance);
}
if (invokePostConstruct) {
// now invoke the postconstruct interceptors
final InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.putPrivateData(Component.class, this);
interceptorContext.putPrivateData(ComponentInstance.class, basicComponentInstance);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.POST_CONSTRUCT);
interceptorContext.setContextData(new HashMap<String, Object>());
try {
postConstructInterceptor.processInvocation(interceptorContext);
} catch (Exception e) {
throw EeLogger.ROOT_LOGGER.componentConstructionFailure(e);
}
}
componentInstanceCreated(basicComponentInstance);
// return the component instance
return basicComponentInstance;
}
/**
* Method that can be overridden to perform setup on the instance after it has been created
*
* @param basicComponentInstance The component instance
*
*/
protected void componentInstanceCreated(final BasicComponentInstance basicComponentInstance) {
}
/**
* Responsible for instantiating the {@link BasicComponentInstance}. This method is *not* responsible for
* handling the post construct activities like injection and lifecycle invocation. That is handled by
* {@link #constructComponentInstance(org.jboss.as.naming.ManagedReference, boolean)}.
* <p/>
*
* @return the component instance
*/
protected BasicComponentInstance instantiateComponentInstance(final Interceptor preDestroyInterceptor, final Map<Method, Interceptor> methodInterceptors, Map<Object, Object> context) {
// create and return the component instance
return new BasicComponentInstance(this, preDestroyInterceptor, methodInterceptors);
}
/**
* Get the class of this bean component.
*
* @return the class
*/
public Class<?> getComponentClass() {
return componentClass;
}
/**
* Get the name of this bean component.
*
* @return the component name
*/
public String getComponentName() {
return componentName;
}
public ServiceName getCreateServiceName() {
return createServiceName;
}
/**
* {@inheritDoc}
*/
public synchronized void start() {
init();
this.stopping.set(false);
gate = true;
notifyAll();
}
public synchronized void init() {
final InterceptorFactoryContext context = new SimpleInterceptorFactoryContext();
context.getContextData().put(Component.class, this);
createInterceptors(context);
}
protected void createInterceptors(InterceptorFactoryContext context) {
// Create the post-construct interceptors for the ComponentInstance
postConstructInterceptor = this.postConstruct.create(context);
// create the pre-destroy interceptors
preDestroyInterceptor = this.getPreDestroy().create(context);
final Map<Method, InterceptorFactory> interceptorFactoryMap = this.getInterceptorFactoryMap();
// This is an identity map. This means that only <b>certain</b> {@code Method} objects will
// match - specifically, they must equal the objects provided to the proxy.
final IdentityHashMap<Method, Interceptor> interceptorMap = new IdentityHashMap<Method, Interceptor>();
for (Map.Entry<Method, InterceptorFactory> entry : interceptorFactoryMap.entrySet()) {
interceptorMap.put(entry.getKey(), entry.getValue().create(context));
}
this.interceptorInstanceMap = interceptorMap;
}
/**
* {@inheritDoc}
*/
public void stop() {
if (stopping.compareAndSet(false, true)) {
synchronized (this) {
gate = false;
this.interceptorInstanceMap = null;
this.preDestroyInterceptor = null;
this.postConstructInterceptor = null;
}
//TODO: only run this if there is no instances
//TODO: trigger destruction of all component instances
//TODO: this has lots of potential for race conditions unless we are careful
//TODO: using stopContext.asynchronous() and then executing synchronously is pointless.
// Use org.jboss.as.server.Services#addServerExecutorDependency to inject an executor to do this async
}
}
Map<Method, InterceptorFactory> getInterceptorFactoryMap() {
return interceptorFactoryMap;
}
InterceptorFactory getPreDestroy() {
return preDestroy;
}
void finishDestroy() {
}
@Override
public String toString() {
return getClass().getSimpleName() + " " + componentName;
}
/**
* @return The components namespace context selector, or null if it does not have one
*/
@Override
public NamespaceContextSelector getNamespaceContextSelector() {
return namespaceContextSelector;
}
public static ServiceName serviceNameOf(final ServiceName deploymentUnitServiceName, final String componentName) {
return deploymentUnitServiceName.append("component").append(componentName);
}
}
| 11,812 | 37.604575 | 188 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentInstantiatorInterceptor.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.ee.component;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ManagedReference;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
/**
* An interceptor factory which gets an object instance from a managed resource. A reference to the resource will be
* attached to the given factory context key; the resource should be retained and passed to an instance of {@link
* ManagedReferenceReleaseInterceptor} which is run during destruction.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
class ComponentInstantiatorInterceptor implements Interceptor {
private final ComponentFactory componentFactory;
private final Object contextKey;
private final boolean setTarget;
/**
* Construct a new instance.
*
* @param componentFactory the managed reference factory to create from
* @param contextKey the context key
* @param setTarget
*/
public ComponentInstantiatorInterceptor(final ComponentFactory componentFactory, final Object contextKey, final boolean setTarget) {
this.setTarget = setTarget;
if (componentFactory == null) {
throw EeLogger.ROOT_LOGGER.nullVar("componentFactory");
}
if (contextKey == null) {
throw EeLogger.ROOT_LOGGER.nullVar("contextKey");
}
this.componentFactory = componentFactory;
this.contextKey = contextKey;
}
public Object processInvocation(final InterceptorContext context) throws Exception {
final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
final ManagedReference existing = (ManagedReference) componentInstance.getInstanceData(contextKey);
if (existing == null) {
final ManagedReference reference = componentFactory.create(context);
boolean ok = false;
try {
componentInstance.setInstanceData(contextKey, reference);
if (setTarget) {
context.setTarget(reference.getInstance());
}
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
reference.release();
componentInstance.setInstanceData(contextKey, reference);
}
}
} else {
return context.proceed();
}
}
}
| 3,545 | 38.842697 | 136 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentInstance.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.ee.component;
import org.jboss.invocation.Interceptor;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
/**
* An instance of a Jakarta EE component.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface ComponentInstance extends Serializable {
/**
* Get the component associated with this instance.
*
* @return the component
*/
Component getComponent();
/**
* Get the actual object instance. The object instance has all injections filled.
*
* @return the instance
*/
Object getInstance();
/**
* Get the instance interceptor (entry point) for the given method. This is the internal entry point for
* the component instance, which bypasses view interceptors.
*
* @param method the method
* @return the interceptor
* @throws IllegalStateException if the method does not exist
*/
Interceptor getInterceptor(Method method) throws IllegalStateException;
/**
* Get the list of allowed methods for this component instance. The handler will only accept invocations on
* these exact {@code Method} objects.
*
* @return the list of methods
*/
Collection<Method> allowedMethods();
/**
* Destroy this component instance. Implementations of this method must be idempotent, meaning that destroying
* a component instance more than one time has no additional effect.
*/
void destroy();
/**
* Gets some data that was attached to this component instance
*
* @param key The component data key
* @return The attached data
*/
Object getInstanceData(final Object key);
/**
* Attaches some data to this component instance. This should only be used during component construction.
*
* @param key The key to store the data
* @param value The data value
*/
void setInstanceData(final Object key, final Object value);
}
| 3,056 | 31.870968 | 115 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ManagedReferenceMethodInjectionInterceptorFactory.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.ee.component;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InvocationType;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.msc.value.Value;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
final class ManagedReferenceMethodInjectionInterceptorFactory implements InterceptorFactory {
private final Object targetContextKey;
private final Object valueContextKey;
private final Value<ManagedReferenceFactory> factoryValue;
private final Method method;
private final boolean optional;
ManagedReferenceMethodInjectionInterceptorFactory(final Object targetContextKey, final Object valueContextKey, final Value<ManagedReferenceFactory> factoryValue, final Method method, final boolean optional) {
this.targetContextKey = targetContextKey;
this.valueContextKey = valueContextKey;
this.factoryValue = factoryValue;
this.method = method;
this.optional = optional;
}
public Interceptor create(final InterceptorFactoryContext context) {
return new ManagedReferenceMethodInjectionInterceptor(targetContextKey, valueContextKey, factoryValue.getValue(), method, optional);
}
/**
* An interceptor which constructs and injects a managed reference into a setter method. The context key given
* for storing the reference should be passed to a {@link ManagedReferenceReleaseInterceptor} which is run during
* object destruction.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
static final class ManagedReferenceMethodInjectionInterceptor implements Interceptor {
private final Object targetKey;
private final Object valueKey;
private final ManagedReferenceFactory factory;
private final Method method;
private final boolean optional;
ManagedReferenceMethodInjectionInterceptor(final Object targetKey, final Object valueKey, final ManagedReferenceFactory factory, final Method method, final boolean optional) {
this.targetKey = targetKey;
this.factory = factory;
this.method = method;
this.optional = optional;
this.valueKey = valueKey;
}
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
Object target;
if (Modifier.isStatic(method.getModifiers())) {
target = null;
} else {
target = ((ManagedReference) componentInstance.getInstanceData(targetKey)).getInstance();
if (target == null) {
throw EeLogger.ROOT_LOGGER.injectionTargetNotFound();
}
}
ManagedReference reference = factory.getReference();
if (reference == null && optional) {
return context.proceed();
}
if (reference == null) {
throw EeLogger.ROOT_LOGGER.managedReferenceMethodWasNull(method);
}
boolean ok = false;
try {
componentInstance.setInstanceData(valueKey, reference);
final InvocationType invocationType = context.getPrivateData(InvocationType.class);
try {
context.putPrivateData(InvocationType.class, InvocationType.DEPENDENCY_INJECTION);
method.invoke(target, reference.getInstance());
} finally {
context.putPrivateData(InvocationType.class, invocationType);
}
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
componentInstance.setInstanceData(valueKey, null);
reference.release();
}
}
}
}
}
| 5,434 | 41.460938 | 212 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentDescription.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.ee.component;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
/**
* A description of a generic Jakarta EE component. The description is pre-classloading so it references everything by name.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class ComponentDescription implements ResourceInjectionTarget {
private static final DefaultComponentConfigurator DEFAULT_COMPONENT_CONFIGURATOR = new DefaultComponentConfigurator();
private static final DefaultInterceptorConfigurator DEFAULT_INTERCEPTOR_CONFIGURATOR = new DefaultInterceptorConfigurator();
private static final DefaultComponentViewConfigurator DEFAULT_COMPONENT_VIEW_CONFIGURATOR = new DefaultComponentViewConfigurator();
private final ServiceName serviceName;
private ServiceName contextServiceName;
private final String componentName;
private final String componentClassName;
private final EEModuleDescription moduleDescription;
private final Set<ViewDescription> views = new HashSet<ViewDescription>();
/**
* Interceptors methods that have been defined by the deployment descriptor
*/
private final Map<String, InterceptorClassDescription> interceptorClassOverrides = new HashMap<String, InterceptorClassDescription>();
private List<InterceptorDescription> classInterceptors = new ArrayList<InterceptorDescription>();
private List<InterceptorDescription> defaultInterceptors = new ArrayList<InterceptorDescription>();
private final Map<MethodIdentifier, List<InterceptorDescription>> methodInterceptors = new HashMap<MethodIdentifier, List<InterceptorDescription>>();
private final Set<MethodIdentifier> methodExcludeDefaultInterceptors = new HashSet<MethodIdentifier>();
private final Set<MethodIdentifier> methodExcludeClassInterceptors = new HashSet<MethodIdentifier>();
private Set<InterceptorDescription> allInterceptors;
private boolean excludeDefaultInterceptors = false;
private boolean ignoreLifecycleInterceptors = false;
private final Set<ServiceName> dependencies = new HashSet<ServiceName>();
private ComponentNamingMode namingMode = ComponentNamingMode.USE_MODULE;
private DeploymentDescriptorEnvironment deploymentDescriptorEnvironment;
// Bindings
private final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
//injections that have been set in the components deployment descriptor
private final Map<String, Map<InjectionTarget, ResourceInjectionConfiguration>> resourceInjections = new HashMap<String, Map<InjectionTarget, ResourceInjectionConfiguration>>();
private final Deque<ComponentConfigurator> configurators = new ArrayDeque<ComponentConfigurator>();
/**
* If this component is deployed in a bean deployment archive this stores the id of the BDA
*/
private String beanDeploymentArchiveId;
/**
* Construct a new instance.
*
* @param componentName the component name
* @param componentClassName the component instance class name
* @param moduleDescription the EE module description
* @param deploymentUnitServiceName the service name of the DU containing this component
*/
public ComponentDescription(final String componentName, final String componentClassName, final EEModuleDescription moduleDescription, final ServiceName deploymentUnitServiceName) {
this.moduleDescription = moduleDescription;
if (componentName == null) {
throw EeLogger.ROOT_LOGGER.nullName("component");
}
if (componentClassName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("componentClassName", "component", componentName);
}
if (moduleDescription == null) {
throw EeLogger.ROOT_LOGGER.nullVar("moduleDescription", "component", componentName);
}
if (deploymentUnitServiceName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("deploymentUnitServiceName", "component", componentName);
}
serviceName = BasicComponent.serviceNameOf(deploymentUnitServiceName, componentName);
this.componentName = componentName;
this.componentClassName = componentClassName;
configurators.addLast(DEFAULT_COMPONENT_CONFIGURATOR);
configurators.addLast(DEFAULT_INTERCEPTOR_CONFIGURATOR);
configurators.addLast(DEFAULT_COMPONENT_VIEW_CONFIGURATOR);
}
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
return new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
}
/**
* Get the component name.
*
* @return the component name
*/
public String getComponentName() {
return componentName;
}
/**
* Set context service name.
*
* @param contextServiceName
*/
public void setContextServiceName(final ServiceName contextServiceName) {
this.contextServiceName = contextServiceName;
}
/**
* Get the context service name.
*
* @return the context service name
*/
public ServiceName getContextServiceName() {
if (contextServiceName != null) return contextServiceName;
if (getNamingMode() == ComponentNamingMode.CREATE) {
return ContextNames.contextServiceNameOfComponent(getApplicationName(), getModuleName(), getComponentName());
} else if (getNamingMode() == ComponentNamingMode.USE_MODULE) {
return ContextNames.contextServiceNameOfModule(getApplicationName(), getModuleName());
} else {
throw new IllegalStateException();
}
}
/**
* Get the base service name for this component.
*
* @return the base service name
*/
public ServiceName getServiceName() {
return serviceName;
}
/**
* Get the service name of this components start service
*
* @return The start service name
*/
public ServiceName getStartServiceName() {
return serviceName.append("START");
}
/**
* Get the service name of this components create service
*
* @return The create service name
*/
public ServiceName getCreateServiceName() {
return serviceName.append("CREATE");
}
/**
* Get the component instance class name.
*
* @return the component class name
*/
public String getComponentClassName() {
return componentClassName;
}
/**
* Get the component's module name.
*
* @return the module name
*/
public String getModuleName() {
return moduleDescription.getModuleName();
}
/**
* Get the component's module's application name.
*
* @return the application name
*/
public String getApplicationName() {
return moduleDescription.getApplicationName();
}
/**
* Get the list of interceptor classes applied directly to class. These interceptors will have lifecycle methods invoked
*
* @return the interceptor classes
*/
public List<InterceptorDescription> getClassInterceptors() {
return classInterceptors;
}
/**
* Override the class interceptors with a new set of interceptors
*
* @param classInterceptors
*/
public void setClassInterceptors(List<InterceptorDescription> classInterceptors) {
this.classInterceptors = classInterceptors;
this.allInterceptors = null;
}
/**
* @return the components default interceptors
*/
public List<InterceptorDescription> getDefaultInterceptors() {
return defaultInterceptors;
}
public void setDefaultInterceptors(final List<InterceptorDescription> defaultInterceptors) {
allInterceptors = null;
this.defaultInterceptors = defaultInterceptors;
}
/**
* Returns a combined map of class and method level interceptors
*
* @return all interceptors on the class
*/
public Set<InterceptorDescription> getAllInterceptors() {
if (allInterceptors == null) {
allInterceptors = new HashSet<InterceptorDescription>();
allInterceptors.addAll(classInterceptors);
if (!excludeDefaultInterceptors) {
allInterceptors.addAll(defaultInterceptors);
}
for (List<InterceptorDescription> interceptors : methodInterceptors.values()) {
allInterceptors.addAll(interceptors);
}
}
return allInterceptors;
}
/**
* @return <code>true</code> if the <code>ExcludeDefaultInterceptors</code> annotation was applied to the class
*/
public boolean isExcludeDefaultInterceptors() {
return excludeDefaultInterceptors;
}
public void setExcludeDefaultInterceptors(boolean excludeDefaultInterceptors) {
allInterceptors = null;
this.excludeDefaultInterceptors = excludeDefaultInterceptors;
}
public boolean isIgnoreLifecycleInterceptors() {
return ignoreLifecycleInterceptors;
}
/**
* If this component should ignore lifecycle interceptors. This should generally only be set when they are going
* to be handled by an external framework such as Weld.
*
*/
public void setIgnoreLifecycleInterceptors(boolean ignoreLifecycleInterceptors) {
this.ignoreLifecycleInterceptors = ignoreLifecycleInterceptors;
}
/**
* @param method The method that has been annotated <code>@ExcludeDefaultInterceptors</code>
*/
public void excludeDefaultInterceptors(MethodIdentifier method) {
methodExcludeDefaultInterceptors.add(method);
}
public boolean isExcludeDefaultInterceptors(MethodIdentifier method) {
return methodExcludeDefaultInterceptors.contains(method);
}
/**
* @param method The method that has been annotated <code>@ExcludeClassInterceptors</code>
*/
public void excludeClassInterceptors(MethodIdentifier method) {
methodExcludeClassInterceptors.add(method);
}
public boolean isExcludeClassInterceptors(MethodIdentifier method) {
return methodExcludeClassInterceptors.contains(method);
}
/**
* Add a class level interceptor.
*
* @param description the interceptor class description
*/
public void addClassInterceptor(InterceptorDescription description) {
classInterceptors.add(description);
this.allInterceptors = null;
}
/**
* Returns the {@link InterceptorDescription} for the passed <code>interceptorClassName</code>, if such a class
* interceptor exists for this component description. Else returns null.
*
* @param interceptorClassName The fully qualified interceptor class name
* @return
*/
public InterceptorDescription getClassInterceptor(String interceptorClassName) {
for (InterceptorDescription interceptor : classInterceptors) {
if (interceptor.getInterceptorClassName().equals(interceptorClassName)) {
return interceptor;
}
}
return null;
}
/**
* Get the method interceptor configurations. The key is the method identifier, the value is
* the set of class names of interceptors to configure on that method.
*
* @return the method interceptor configurations
*/
public Map<MethodIdentifier, List<InterceptorDescription>> getMethodInterceptors() {
return methodInterceptors;
}
/**
* Add a method interceptor class name.
*
* @param method the method
* @param description the interceptor descriptor
*/
public void addMethodInterceptor(MethodIdentifier method, InterceptorDescription description) {
//we do not add method level interceptors to the set of interceptor classes,
//as their around invoke annotations
List<InterceptorDescription> interceptors = methodInterceptors.get(method);
if (interceptors == null) {
methodInterceptors.put(method, interceptors = new ArrayList<InterceptorDescription>());
}
final String name = description.getInterceptorClassName();
// add the interceptor class to the EEModuleDescription
interceptors.add(description);
this.allInterceptors = null;
}
/**
* Sets the method level interceptors for a method, and marks it as exclude class and default level interceptors.
* <p/>
* This is used to set the final interceptor order after it has been modifier by the deployment descriptor
*
* @param identifier the method identifier
* @param interceptorDescriptions The interceptors
*/
public void setMethodInterceptors(MethodIdentifier identifier, List<InterceptorDescription> interceptorDescriptions) {
methodInterceptors.put(identifier, interceptorDescriptions);
methodExcludeClassInterceptors.add(identifier);
methodExcludeDefaultInterceptors.add(identifier);
}
/**
* Adds an interceptor class method override, merging it with existing overrides (if any)
*
* @param className The class name
* @param override The method override
*/
public void addInterceptorMethodOverride(final String className, final InterceptorClassDescription override) {
interceptorClassOverrides.put(className, InterceptorClassDescription.merge(interceptorClassOverrides.get(className), override));
}
/**
* Get the naming mode of this component.
*
* @return the naming mode
*/
public ComponentNamingMode getNamingMode() {
return namingMode;
}
/**
* Set the naming mode of this component. May not be {@code null}.
*
* @param namingMode the naming mode
*/
public void setNamingMode(final ComponentNamingMode namingMode) {
if (namingMode == null) {
throw EeLogger.ROOT_LOGGER.nullVar("namingMode", "component", componentName);
}
this.namingMode = namingMode;
}
/**
* @return The module description for the component
*/
public EEModuleDescription getModuleDescription() {
return moduleDescription;
}
/**
* Add a dependency to this component. If the same dependency is added multiple times, only the first will
* take effect.
*
* @param serviceName the service name of the dependency
*/
public void addDependency(ServiceName serviceName) {
if (serviceName == null) {
throw EeLogger.ROOT_LOGGER.nullVar("serviceName", "component", componentName);
}
dependencies.add(serviceName);
}
/**
* Get the dependency set.
*
* @return the dependency set
*/
public Set<ServiceName> getDependencies() {
return dependencies;
}
public DeploymentDescriptorEnvironment getDeploymentDescriptorEnvironment() {
return deploymentDescriptorEnvironment;
}
public void setDeploymentDescriptorEnvironment(DeploymentDescriptorEnvironment deploymentDescriptorEnvironment) {
this.deploymentDescriptorEnvironment = deploymentDescriptorEnvironment;
}
/**
* Get the binding configurations for this component. This list contains bindings which are specific to the
* component.
*
* @return the binding configurations
*/
public List<BindingConfiguration> getBindingConfigurations() {
return bindingConfigurations;
}
/**
* Get the list of views which apply to this component.
*
* @return the list of views
*/
public Set<ViewDescription> getViews() {
return views;
}
/**
*
*
* @return true If this component type is eligible for a timer service
*/
public boolean isTimerServiceApplicable() {
return false;
}
/**
*
* @return <code>true</code> if this component has timeout methods and is eligible for a 'real' timer service
*/
public boolean isTimerServiceRequired() {
return isTimerServiceApplicable() && !getTimerMethods().isEmpty();
}
/**
*
* @return The set of all method identifiers for the timeout methods
*/
public Set<MethodIdentifier> getTimerMethods() {
return Collections.emptySet();
}
public boolean isPassivationApplicable() {
return false;
}
/**
* Get the configurators for this component.
*
* @return the configurators
*/
public Deque<ComponentConfigurator> getConfigurators() {
return configurators;
}
public boolean isIntercepted() {
return true;
}
/**
* @return <code>true</code> if errors should be ignored when installing this component
*/
public boolean isOptional() {
return false;
}
static class InjectedConfigurator implements DependencyConfigurator<ComponentStartService> {
private final ResourceInjectionConfiguration injectionConfiguration;
private final ComponentConfiguration configuration;
private final DeploymentPhaseContext context;
private final InjectedValue<ManagedReferenceFactory> managedReferenceFactoryValue;
InjectedConfigurator(final ResourceInjectionConfiguration injectionConfiguration, final ComponentConfiguration configuration, final DeploymentPhaseContext context, final InjectedValue<ManagedReferenceFactory> managedReferenceFactoryValue) {
this.injectionConfiguration = injectionConfiguration;
this.configuration = configuration;
this.context = context;
this.managedReferenceFactoryValue = managedReferenceFactoryValue;
}
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(
configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.USE_MODULE,
configuration.getComponentName(),
configuration.getModuleName(),
configuration.getApplicationName()
);
injectionConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, context, managedReferenceFactoryValue);
}
}
public String getBeanDeploymentArchiveId() {
return beanDeploymentArchiveId;
}
public void setBeanDeploymentArchiveId(final String beanDeploymentArchiveId) {
this.beanDeploymentArchiveId = beanDeploymentArchiveId;
}
public void addResourceInjection(final ResourceInjectionConfiguration injection) {
String className = injection.getTarget().getClassName();
Map<InjectionTarget, ResourceInjectionConfiguration> map = resourceInjections.get(className);
if (map == null) {
resourceInjections.put(className, map = new HashMap<InjectionTarget, ResourceInjectionConfiguration>());
}
map.put(injection.getTarget(), injection);
}
public Map<InjectionTarget, ResourceInjectionConfiguration> getResourceInjections(final String className) {
Map<InjectionTarget, ResourceInjectionConfiguration> injections = resourceInjections.get(className);
if (injections == null) {
return Collections.emptyMap();
} else {
return Collections.unmodifiableMap(injections);
}
}
/**
* If this method returns true then Weld will directly create the component instance,
* which will apply interceptors and decorators via sub classing.
*
* For most components this is not necessary.
*
* Also not that even though Jakarta Enterprise Beans's are intercepted, their interceptor is done through
* a different method that integrates with the existing Jakarta Enterprise Beans interceptor chain
*
*/
public boolean isCDIInterceptorEnabled() {
return false;
}
public static InterceptorClassDescription mergeInterceptorConfig(final Class<?> clazz, final EEModuleClassDescription classDescription, final ComponentDescription description, final boolean metadataComplete) {
final InterceptorClassDescription interceptorConfig;
if (classDescription != null && !metadataComplete) {
interceptorConfig = InterceptorClassDescription.merge(classDescription.getInterceptorClassDescription(), description.interceptorClassOverrides.get(clazz.getName()));
} else {
interceptorConfig = InterceptorClassDescription.merge(null, description.interceptorClassOverrides.get(clazz.getName()));
}
return interceptorConfig;
}
}
| 22,845 | 36.887231 | 248 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentRegistry.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.ee.component;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.value.InjectedValue;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Registry that can be used to create a fully injected class instance. If there is an appropriate component regiestered
* an instance of the component will be created. Otherwise the default class introspector will be used to create an instance.
* <p/>
* This can be problematic in theory, as it is possible to have multiple components for a single class, however it does
* not seem to be an issue in practice.
* <p/>
* This registry only contains simple component types that have at most 1 view
*
* @author Stuart Douglas
*/
public class ComponentRegistry {
private static ServiceName SERVICE_NAME = ServiceName.of("ee", "ComponentRegistry");
private final Map<Class<?>, ComponentManagedReferenceFactory> componentsByClass = new ConcurrentHashMap<Class<?>, ComponentManagedReferenceFactory>();
private final ServiceRegistry serviceRegistry;
private final InjectedValue<EEClassIntrospector> classIntrospectorInjectedValue = new InjectedValue<>();
public static ServiceName serviceName(final DeploymentUnit deploymentUnit) {
return deploymentUnit.getServiceName().append(SERVICE_NAME);
}
public ComponentRegistry(final ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
public void addComponent(final ComponentConfiguration componentConfiguration) {
if(componentConfiguration.getViews().size() < 2) {
if(componentConfiguration.getViews().isEmpty()) {
componentsByClass.put(componentConfiguration.getComponentClass(), new ComponentManagedReferenceFactory(componentConfiguration.getComponentDescription().getStartServiceName(), null));
} else {
componentsByClass.put(componentConfiguration.getComponentClass(), new ComponentManagedReferenceFactory(componentConfiguration.getComponentDescription().getStartServiceName(), componentConfiguration.getViews().get(0).getViewServiceName()));
}
}
}
public ManagedReferenceFactory createInstanceFactory(final Class<?> componentClass) {
return createInstanceFactory(componentClass, false);
}
public ManagedReferenceFactory createInstanceFactory(final Class<?> componentClass, final boolean optional) {
final ManagedReferenceFactory factory = componentsByClass.get(componentClass);
if (factory == null) {
EEClassIntrospector introspector = optional ? classIntrospectorInjectedValue.getOptionalValue() : classIntrospectorInjectedValue.getValue();
return introspector != null ? introspector.createFactory(componentClass) : null;
}
return factory;
}
public ManagedReference createInstance(final Object instance) {
final ComponentManagedReferenceFactory factory = componentsByClass.get(instance.getClass());
if (factory == null) {
return classIntrospectorInjectedValue.getValue().createInstance(instance);
}
return factory.createReference(instance);
}
public ManagedReference getInstance(final Object instance) {
final ComponentManagedReferenceFactory factory = componentsByClass.get(instance.getClass());
if (factory == null) {
return classIntrospectorInjectedValue.getValue().getInstance(instance);
}
return factory.getReference(instance);
}
public InjectedValue<EEClassIntrospector> getClassIntrospectorInjectedValue() {
return classIntrospectorInjectedValue;
}
private static class ComponentManagedReference implements ManagedReference {
private final ComponentInstance instance;
private boolean destroyed;
ComponentManagedReference(final ComponentInstance component) {
instance = component;
}
@Override
public synchronized void release() {
if (!destroyed) {
instance.destroy();
destroyed = true;
}
}
@Override
public Object getInstance() {
return instance.getInstance();
}
}
public class ComponentManagedReferenceFactory implements ManagedReferenceFactory {
private final ServiceName serviceName;
private final ServiceName viewServiceName;
private volatile ServiceController<Component> component;
private volatile ServiceController<ViewService.View> view;
private ComponentManagedReferenceFactory(final ServiceName serviceName, ServiceName viewServiceName) {
this.serviceName = serviceName;
this.viewServiceName = viewServiceName;
}
@Override
public ManagedReference getReference() {
if (component == null) {
synchronized (this) {
if (component == null) {
component = (ServiceController<Component>) serviceRegistry.getService(serviceName);
}
}
}
if (view == null && viewServiceName != null) {
synchronized (this) {
if (view == null) {
view = (ServiceController<ViewService.View>) serviceRegistry.getService(viewServiceName);
}
}
}
if (component == null) {
return null;
}
if(view == null) {
return new ComponentManagedReference(component.getValue().createInstance());
} else {
try {
return view.getValue().createInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public ManagedReference createReference(final Object instance) {
if (component == null) {
synchronized (this) {
if (component == null) {
component = (ServiceController<Component>) serviceRegistry.getService(serviceName);
}
}
}
if (component == null) {
return null;
}
return new ComponentManagedReference(component.getValue().createInstance(instance));
}
ManagedReference getReference(final Object instance) {
if (component == null) {
synchronized (this) {
if (component == null) {
component = (ServiceController<Component>) serviceRegistry.getService(serviceName);
}
}
}
if (component == null) {
return null;
}
return new ComponentManagedReference(component.getValue().getInstance(instance));
}
public ServiceName getServiceName() {
return serviceName;
}
}
}
| 8,339 | 39.485437 | 255 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEClassIntrospector.java | package org.jboss.as.ee.component;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
/**
*
*
* @author Stuart Douglas
*/
public interface EEClassIntrospector {
ManagedReferenceFactory createFactory(final Class<?> clazz);
/**
* Returns the managed reference of an new instance.
* @param instance an object instance
* @return a managed reference
*/
ManagedReference createInstance(Object instance);
/**
* Returns the managed reference of an existing instance.
* @param instance an object instance
* @return a managed reference
*/
ManagedReference getInstance(Object instance);
}
| 693 | 22.931034 | 64 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEApplicationDescription.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.ee.component;
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.vfs.VirtualFile;
/**
* @author John Bailey
*/
public class EEApplicationDescription {
//these are only written to by a single top level processor, so do not need to be synchronized
private final Map<String, List<ViewInformation>> componentsByViewName = new HashMap<String, List<ViewInformation>>();
private final Map<String, List<Description>> componentsByName = new HashMap<String, List<Description>>();
//this must be synchronized for writing
private final Map<String, List<MessageDestinationMapping>> messageDestinationJndiMapping = new HashMap<String, List<MessageDestinationMapping>>();
/**
* Add a component to this application.
*
* @param description the component description
* @param deploymentRoot
*/
public void addComponent(final ComponentDescription description, final VirtualFile deploymentRoot) {
for (final ViewDescription viewDescription : description.getViews()) {
List<ViewInformation> viewComponents = componentsByViewName.get(viewDescription.getViewClassName());
if (viewComponents == null) {
viewComponents = new ArrayList<ViewInformation>(1);
componentsByViewName.put(viewDescription.getViewClassName(), viewComponents);
}
viewComponents.add(new ViewInformation(viewDescription, deploymentRoot, description.getComponentName()));
}
List<Description> components = componentsByName.get(description.getComponentName());
if (components == null) {
componentsByName.put(description.getComponentName(), components = new ArrayList<Description>(1));
}
components.add(new Description(description, deploymentRoot));
}
/**
* Add a message destination to the application
*
* @param name The message destination name
* @param resolvedName The resolved JNDI name
* @param deploymentRoot The deployment root
*/
public void addMessageDestination(final String name, final String resolvedName, final VirtualFile deploymentRoot) {
List<MessageDestinationMapping> components = messageDestinationJndiMapping.get(name);
if (components == null) {
messageDestinationJndiMapping.put(name, components = new ArrayList<MessageDestinationMapping>(1));
}
components.add(new MessageDestinationMapping(resolvedName, deploymentRoot));
}
/**
* Get all views that have the given type in the application
*
* @param viewType The view type
* @return All views of the given type
*/
public Set<ViewDescription> getComponentsForViewName(final String viewType, final VirtualFile deploymentRoot) {
final List<ViewInformation> info = componentsByViewName.get(viewType);
if (info == null) {
return Collections.<ViewDescription>emptySet();
}
final Set<ViewDescription> ret = new HashSet<ViewDescription>();
final Set<ViewDescription> currentDep = new HashSet<ViewDescription>();
for (ViewInformation i : info) {
if (deploymentRoot.equals(i.deploymentRoot)) {
currentDep.add(i.viewDescription);
}
ret.add(i.viewDescription);
}
if(!currentDep.isEmpty()) {
return currentDep;
}
return ret;
}
/**
* Get all components in the application that have the given name
*
* @param componentName The name of the component
* @param deploymentRoot The deployment root of the component doing the lookup
* @return A set of all views for the given component name and type
*/
public Set<ComponentDescription> getComponents(final String componentName, final VirtualFile deploymentRoot) {
if (componentName.contains("#")) {
final String[] parts = componentName.split("#");
String path = parts[0];
if (!path.startsWith("../")) {
path = "../" + path;
}
final VirtualFile virtualPath = deploymentRoot.getChild(path);
final String name = parts[1];
final List<Description> info = componentsByName.get(name);
if (info == null) {
return Collections.emptySet();
}
final Set<ComponentDescription> ret = new HashSet<ComponentDescription>();
for (Description i : info) {
//now we need to check the path
if (virtualPath.equals(i.deploymentRoot)) {
ret.add(i.componentDescription);
}
}
return ret;
} else {
final List<Description> info = componentsByName.get(componentName);
if (info == null) {
return Collections.emptySet();
}
final Set<ComponentDescription> all = new HashSet<ComponentDescription>();
final Set<ComponentDescription> thisDeployment = new HashSet<ComponentDescription>();
for (Description i : info) {
all.add(i.componentDescription);
if (i.deploymentRoot.equals(deploymentRoot)) {
thisDeployment.add(i.componentDescription);
}
}
//if there are multiple e
if (all.size() > 1) {
return thisDeployment;
}
return all;
}
}
/**
* Get all views in the application that have the given name and view type
*
* @param componentName The name of the component
* @param viewName The view type
* @param deploymentRoot The deployment root of the component doing the lookup
* @return A set of all views for the given component name and type
*/
public Set<ViewDescription> getComponents(final String componentName, final String viewName, final VirtualFile deploymentRoot) {
final List<ViewInformation> info = componentsByViewName.get(viewName);
if (info == null) {
return Collections.<ViewDescription>emptySet();
}
if (componentName.contains("#")) {
final String[] parts = componentName.split("#");
String path = parts[0];
if (!path.startsWith("../")) {
path = "../" + path;
}
final VirtualFile virtualPath = deploymentRoot.getChild(path);
final String name = parts[1];
final Set<ViewDescription> ret = new HashSet<ViewDescription>();
for (ViewInformation i : info) {
if (i.beanName.equals(name)
// now we need to check the path
&& virtualPath.equals(i.deploymentRoot)) {
ret.add(i.viewDescription);
}
}
return ret;
} else {
final Set<ViewDescription> all = new HashSet<ViewDescription>();
final Set<ViewDescription> thisDeployment = new HashSet<ViewDescription>();
for (ViewInformation i : info) {
if (i.beanName.equals(componentName)) {
all.add(i.viewDescription);
if (i.deploymentRoot.equals(deploymentRoot)) {
thisDeployment.add(i.viewDescription);
}
}
}
if (all.size() > 1) {
return thisDeployment;
}
return all;
}
}
/**
* Resolves a message destination name into a JNDI name
*/
public Set<String> resolveMessageDestination(final String messageDestName, final VirtualFile deploymentRoot) {
if (messageDestName.contains("#")) {
final String[] parts = messageDestName.split("#");
String path = parts[0];
if (!path.startsWith("../")) {
path = "../" + path;
}
final VirtualFile virtualPath = deploymentRoot.getChild(path);
final String name = parts[1];
final Set<String> ret = new HashSet<String>();
final List<MessageDestinationMapping> data = messageDestinationJndiMapping.get(name);
if (data != null) {
for (final MessageDestinationMapping i : data) {
//now we need to check the path
if (virtualPath.equals(i.deploymentRoot)) {
ret.add(i.jndiName);
}
}
}
return ret;
} else {
final Set<String> all = new HashSet<String>();
final Set<String> thisDeployment = new HashSet<String>();
final List<MessageDestinationMapping> data = messageDestinationJndiMapping.get(messageDestName);
if (data != null) {
for (final MessageDestinationMapping i : data) {
all.add(i.jndiName);
if (i.deploymentRoot.equals(deploymentRoot)) {
thisDeployment.add(i.jndiName);
}
}
}
if (all.size() > 1) {
return thisDeployment;
}
return all;
}
}
private static class ViewInformation {
private final ViewDescription viewDescription;
private final VirtualFile deploymentRoot;
private final String beanName;
ViewInformation(final ViewDescription viewDescription, final VirtualFile deploymentRoot, final String beanName) {
this.viewDescription = viewDescription;
this.deploymentRoot = deploymentRoot;
this.beanName = beanName;
}
}
private static class Description {
private final ComponentDescription componentDescription;
private final VirtualFile deploymentRoot;
Description(final ComponentDescription componentDescription, final VirtualFile deploymentRoot) {
this.componentDescription = componentDescription;
this.deploymentRoot = deploymentRoot;
}
}
private static final class MessageDestinationMapping {
private final String jndiName;
private final VirtualFile deploymentRoot;
MessageDestinationMapping(final String jndiName, final VirtualFile deploymentRoot) {
this.jndiName = jndiName;
this.deploymentRoot = deploymentRoot;
}
}
}
| 11,683 | 40.432624 | 150 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/EEModuleConfiguration.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.ee.component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
/**
*
* TODO: do we still need this?
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class EEModuleConfiguration {
private final String applicationName;
private final String moduleName;
private final List<ComponentConfiguration> componentConfigurations;
public EEModuleConfiguration(EEModuleDescription description) throws DeploymentUnitProcessingException {
applicationName = description.getApplicationName();
moduleName = description.getModuleName();
this.componentConfigurations = new ArrayList<ComponentConfiguration>();
}
public String getApplicationName() {
return applicationName;
}
public String getModuleName() {
return moduleName;
}
public Collection<ComponentConfiguration> getComponentConfigurations() {
return Collections.unmodifiableList(componentConfigurations);
}
public void addComponentConfiguration(ComponentConfiguration configuration) {
componentConfigurations.add(configuration);
}
}
| 2,308 | 33.462687 | 108 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/BasicComponentCreateService.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.ee.component;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.IdentityHashMap;
import java.util.Map;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.Interceptors;
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;
/**
* A service for creating a component.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class BasicComponentCreateService implements Service<Component> {
private final ServiceName serviceName;
private final String componentName;
private final Class<?> componentClass;
private final InterceptorFactory postConstruct;
private final InterceptorFactory preDestroy;
private final Map<Method, InterceptorFactory> componentInterceptors;
private final NamespaceContextSelector namespaceContextSelector;
private BasicComponent component;
/**
* Construct a new instance.
*
* @param componentConfiguration the component configuration
*/
public BasicComponentCreateService(final ComponentConfiguration componentConfiguration) {
serviceName = componentConfiguration.getComponentDescription().getCreateServiceName();
componentName = componentConfiguration.getComponentName();
postConstruct = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPostConstructInterceptors());
preDestroy = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPreDestroyInterceptors());
final IdentityHashMap<Method, InterceptorFactory> componentInterceptors = new IdentityHashMap<Method, InterceptorFactory>();
for (Method method : componentConfiguration.getDefinedComponentMethods()) {
if(requiresInterceptors(method, componentConfiguration)) {
componentInterceptors.put(method, Interceptors.getChainedInterceptorFactory(componentConfiguration.getComponentInterceptors(method)));
}
}
componentClass = componentConfiguration.getComponentClass();
this.componentInterceptors = componentInterceptors;
this.namespaceContextSelector = componentConfiguration.getNamespaceContextSelector();
}
protected boolean requiresInterceptors(final Method method, final ComponentConfiguration componentConfiguration) {
return Modifier.isPublic(method.getModifiers()) && !Modifier.isFinal(method.getModifiers()) && componentConfiguration.getComponentDescription().isIntercepted();
}
/**
* {@inheritDoc}
*/
public synchronized void start(final StartContext context) throws StartException {
component = createComponent();
}
/**
* Create the component.
*
* @return the component instance
*/
protected BasicComponent createComponent() {
return new BasicComponent(this);
}
/**
* {@inheritDoc}
*/
public synchronized void stop(final StopContext context) {
component = null;
}
/**
* {@inheritDoc}
*/
public synchronized Component getValue() throws IllegalStateException, IllegalArgumentException {
Component component = this.component;
if (component == null) {
throw EeLogger.ROOT_LOGGER.serviceNotStarted();
}
return component;
}
/**
* Get the component name.
*
* @return the component name
*/
public String getComponentName() {
return componentName;
}
/**
* Get the post-construct interceptor factory.
*
* @return the post-construct interceptor factory
*/
public InterceptorFactory getPostConstruct() {
return postConstruct;
}
/**
* Get the pre-destroy interceptor factory.
*
* @return the pre-destroy interceptor factory
*/
public InterceptorFactory getPreDestroy() {
return preDestroy;
}
/**
* Get the component interceptor factory map.
*
* @return the component interceptor factories
*/
public Map<Method, InterceptorFactory> getComponentInterceptors() {
return componentInterceptors;
}
/**
* Get the component class.
*
* @return the component class
*/
public Class<?> getComponentClass() {
return componentClass;
}
/**
*
* @return the namespace context selector for the component, or null if it does not have one
*/
public NamespaceContextSelector getNamespaceContextSelector() {
return namespaceContextSelector;
}
public ServiceName getServiceName() {
return this.serviceName;
}
}
| 5,984 | 33.595376 | 168 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/DefaultInterceptorConfigurator.java | package org.jboss.as.ee.component;
import static org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.interceptors.InterceptorClassDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.component.interceptors.UserInterceptorFactory;
import org.jboss.as.ee.metadata.MetadataCompleteMarker;
import org.jboss.as.ee.utils.ClassLoadingUtils;
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.ClassReflectionIndexUtil;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.Interceptors;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.modules.Module;
/**
* @author Stuart Douglas
*/
class DefaultInterceptorConfigurator extends AbstractComponentConfigurator implements ComponentConfigurator {
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final boolean metadataComplete = MetadataCompleteMarker.isMetadataComplete(deploymentUnit);
// Module stuff
final Deque<InterceptorFactory> instantiators = new ArrayDeque<>();
final Deque<InterceptorFactory> injectors = new ArrayDeque<>();
final Deque<InterceptorFactory> uninjectors = new ArrayDeque<>();
final Deque<InterceptorFactory> destructors = new ArrayDeque<>();
final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<>();
final Map<String, List<InterceptorFactory>> userAroundConstructsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPrePassivatesByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPostActivatesByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPostConstructByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Map<String, List<InterceptorFactory>> userPreDestroyByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Set<MethodIdentifier> timeoutMethods = description.getTimerMethods();
if (description.isTimerServiceRequired()) {
userAroundTimeoutsByInterceptorClass = new HashMap<>();
} else {
userAroundTimeoutsByInterceptorClass = null;
}
if (description.isPassivationApplicable()) {
userPrePassivatesByInterceptorClass = new HashMap<>();
userPostActivatesByInterceptorClass = new HashMap<>();
} else {
userPrePassivatesByInterceptorClass = null;
userPostActivatesByInterceptorClass = null;
}
//the actual component creation interceptor
//this really belongs in DefaultComponentConfigurator, but all the other AroundConstruct chain is assembled here
final InterceptorFactory instantiator;
// Primary instance
final ComponentFactory instanceFactory = configuration.getInstanceFactory();
if (instanceFactory != null) {
instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(instanceFactory, BasicComponentInstance.INSTANCE_KEY, true));
} else {
final ClassReflectionIndex componentClassIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass());
//use the default constructor if no instanceFactory has been set
final Constructor<?> constructor = componentClassIndex.getConstructor(EMPTY_CLASS_ARRAY);
if (constructor == null) {
throw EeLogger.ROOT_LOGGER.defaultConstructorNotFound(configuration.getComponentClass());
}
instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(new ConstructorComponentFactory(constructor), BasicComponentInstance.INSTANCE_KEY, true));
}
//all interceptors with lifecycle callbacks, in the correct order
final List<InterceptorDescription> interceptorWithLifecycleCallbacks = new ArrayList<InterceptorDescription>();
if (!description.isExcludeDefaultInterceptors()) {
interceptorWithLifecycleCallbacks.addAll(description.getDefaultInterceptors());
}
interceptorWithLifecycleCallbacks.addAll(description.getClassInterceptors());
for (final InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
final String interceptorClassName = interceptorDescription.getInterceptorClassName();
final Class<?> interceptorClass;
try {
interceptorClass = ClassLoadingUtils.loadClass(interceptorClassName, module);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
}
final InterceptorEnvironment interceptorEnvironment = moduleDescription.getInterceptorEnvironment().get(interceptorClassName);
if (interceptorEnvironment != null) {
//if the interceptor has environment config we merge it into the components environment
description.getBindingConfigurations().addAll(interceptorEnvironment.getBindingConfigurations());
for (final ResourceInjectionConfiguration injection : interceptorEnvironment.getResourceInjections()) {
description.addResourceInjection(injection);
}
}
//we store the interceptor instance under the class key
final Object contextKey = interceptorClass;
configuration.getInterceptorContextKeys().add(contextKey);
final ClassReflectionIndex interceptorIndex = deploymentReflectionIndex.getClassIndex(interceptorClass);
final Constructor<?> constructor = interceptorIndex.getConstructor(EMPTY_CLASS_ARRAY);
if (constructor == null) {
throw EeLogger.ROOT_LOGGER.defaultConstructorNotFoundOnComponent(interceptorClassName, configuration.getComponentClass());
}
instantiators.addFirst(new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(new ConstructorComponentFactory(constructor), contextKey, false)));
destructors.addLast(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(contextKey)));
final boolean interceptorHasLifecycleCallbacks = interceptorWithLifecycleCallbacks.contains(interceptorDescription);
new ClassDescriptionTraversal(interceptorClass, applicationClasses) {
@Override
public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
mergeInjectionsForClass(clazz, interceptorClass, classDescription, moduleDescription, deploymentReflectionIndex, description, configuration, context, injectors, contextKey, uninjectors, metadataComplete);
final InterceptorClassDescription interceptorConfig;
if (classDescription != null && !metadataComplete) {
interceptorConfig = InterceptorClassDescription.merge(classDescription.getInterceptorClassDescription(), moduleDescription.getInterceptorClassOverride(clazz.getName()));
} else {
interceptorConfig = InterceptorClassDescription.merge(null, moduleDescription.getInterceptorClassOverride(clazz.getName()));
}
// Only class level interceptors are processed for postconstruct/predestroy methods.
// Method level interceptors aren't supposed to be processed for postconstruct/predestroy lifecycle
// methods, as per interceptors spec
if (interceptorHasLifecycleCallbacks && !description.isIgnoreLifecycleInterceptors()) {
final MethodIdentifier postConstructMethodIdentifier = interceptorConfig.getPostConstruct();
handleInterceptorClass(clazz, postConstructMethodIdentifier, userPostConstructByInterceptorClass, true, true);
final MethodIdentifier preDestroyMethodIdentifier = interceptorConfig.getPreDestroy();
handleInterceptorClass(clazz, preDestroyMethodIdentifier, userPreDestroyByInterceptorClass, true, true);
final MethodIdentifier aroundConstructMethodIdentifier = interceptorConfig.getAroundConstruct();
handleInterceptorClass(clazz, aroundConstructMethodIdentifier, userAroundConstructsByInterceptorClass, true, true);
}
final MethodIdentifier aroundInvokeMethodIdentifier = interceptorConfig.getAroundInvoke();
handleInterceptorClass(clazz, aroundInvokeMethodIdentifier, userAroundInvokesByInterceptorClass, false, false);
if (description.isTimerServiceRequired()) {
final MethodIdentifier aroundTimeoutMethodIdentifier = interceptorConfig.getAroundTimeout();
handleInterceptorClass(clazz, aroundTimeoutMethodIdentifier, userAroundTimeoutsByInterceptorClass, false, false);
}
if (description.isPassivationApplicable()) {
handleInterceptorClass(clazz, interceptorConfig.getPrePassivate(), userPrePassivatesByInterceptorClass, false, false);
handleInterceptorClass(clazz, interceptorConfig.getPostActivate(), userPostActivatesByInterceptorClass, false, false);
}
}
private void handleInterceptorClass(final Class<?> clazz, final MethodIdentifier methodIdentifier, final Map<String, List<InterceptorFactory>> classMap, final boolean changeMethod, final boolean lifecycleMethod) throws DeploymentUnitProcessingException {
if (methodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier);
if (isNotOverriden(clazz, method, interceptorClass, deploymentReflectionIndex)) {
final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new ManagedReferenceLifecycleMethodInterceptor(contextKey, method, changeMethod, lifecycleMethod));
List<InterceptorFactory> factories = classMap.get(interceptorClassName);
if (factories == null) {
classMap.put(interceptorClassName, factories = new ArrayList<InterceptorFactory>());
}
factories.add(interceptorFactory);
}
}
}
}.run();
}
final List<InterceptorFactory> userAroundConstruct = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> userPostConstruct = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> userPreDestroy = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> userPrePassivate = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> userPostActivate = new ArrayList<InterceptorFactory>();
//now add the lifecycle interceptors in the correct order
for (final InterceptorDescription interceptorClass : interceptorWithLifecycleCallbacks) {
if (userPostConstructByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPostConstruct.addAll(userPostConstructByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
if (userAroundConstructsByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userAroundConstruct.addAll(userAroundConstructsByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
if (userPreDestroyByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPreDestroy.addAll(userPreDestroyByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
if (description.isPassivationApplicable()) {
if (userPrePassivatesByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPrePassivate.addAll(userPrePassivatesByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
if (userPostActivatesByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
userPostActivate.addAll(userPostActivatesByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
}
}
}
// Apply post-construct
if (!injectors.isEmpty()) {
configuration.addPostConstructInterceptors(new ArrayList<>(injectors), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_RESOURCE_INJECTION_INTERCEPTORS);
}
if (!instantiators.isEmpty()) {
configuration.addPostConstructInterceptors(new ArrayList<>(instantiators), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_INSTANTIATION_INTERCEPTORS);
}
if (!userAroundConstruct.isEmpty()) {
configuration.addAroundConstructInterceptors(userAroundConstruct, InterceptorOrder.AroundConstruct.INTERCEPTOR_AROUND_CONSTRUCT);
}
configuration.addAroundConstructInterceptor(instantiator, InterceptorOrder.AroundConstruct.CONSTRUCT_COMPONENT);
configuration.addAroundConstructInterceptor(new ImmediateInterceptorFactory(Interceptors.getTerminalInterceptor()), InterceptorOrder.AroundConstruct.TERMINAL_INTERCEPTOR);
if(!configuration.getAroundConstructInterceptors().isEmpty()) {
configuration.addPostConstructInterceptor(new AroundConstructInterceptorFactory(Interceptors.getChainedInterceptorFactory(configuration.getAroundConstructInterceptors())), InterceptorOrder.ComponentPostConstruct.AROUND_CONSTRUCT_CHAIN);
}
if (!userPostConstruct.isEmpty()) {
configuration.addPostConstructInterceptors(userPostConstruct, InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_USER_INTERCEPTORS);
}
// Apply pre-destroy
if (!uninjectors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(uninjectors), InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_UNINJECTION_INTERCEPTORS);
}
if (!destructors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(destructors), InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_DESTRUCTION_INTERCEPTORS);
}
if (!userPreDestroy.isEmpty()) {
configuration.addPreDestroyInterceptors(userPreDestroy, InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_USER_INTERCEPTORS);
}
if (description.isPassivationApplicable()) {
if (!userPrePassivate.isEmpty()) {
configuration.addPrePassivateInterceptors(userPrePassivate, InterceptorOrder.ComponentPassivation.INTERCEPTOR_USER_INTERCEPTORS);
}
if (!userPostActivate.isEmpty()) {
configuration.addPostActivateInterceptors(userPostActivate, InterceptorOrder.ComponentPassivation.INTERCEPTOR_USER_INTERCEPTORS);
}
}
// @AroundInvoke interceptors
final List<InterceptorDescription> classInterceptors = description.getClassInterceptors();
final Map<MethodIdentifier, List<InterceptorDescription>> methodInterceptors = description.getMethodInterceptors();
if (description.isIntercepted()) {
for (final Method method : configuration.getDefinedComponentMethods()) {
//now add the interceptor that initializes and the interceptor that actually invokes to the end of the interceptor chain
final MethodIdentifier identifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
final List<InterceptorFactory> userAroundInvokes = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> userAroundTimeouts = new ArrayList<InterceptorFactory>();
// first add the default interceptors (if not excluded) to the deque
final boolean requiresTimerChain = description.isTimerServiceRequired() && timeoutMethods.contains(identifier);
if (!description.isExcludeDefaultInterceptors() && !description.isExcludeDefaultInterceptors(identifier)) {
for (InterceptorDescription interceptorDescription : description.getDefaultInterceptors()) {
String interceptorClassName = interceptorDescription.getInterceptorClassName();
List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokes != null) {
userAroundInvokes.addAll(aroundInvokes);
}
if (requiresTimerChain) {
List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeouts != null) {
userAroundTimeouts.addAll(aroundTimeouts);
}
}
}
}
// now add class level interceptors (if not excluded) to the deque
if (!description.isExcludeClassInterceptors(identifier)) {
for (InterceptorDescription interceptorDescription : classInterceptors) {
String interceptorClassName = interceptorDescription.getInterceptorClassName();
List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokes != null) {
userAroundInvokes.addAll(aroundInvokes);
}
if (requiresTimerChain) {
List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeouts != null) {
userAroundTimeouts.addAll(aroundTimeouts);
}
}
}
}
// now add method level interceptors for to the deque so that they are triggered after the class interceptors
List<InterceptorDescription> methodLevelInterceptors = methodInterceptors.get(identifier);
if (methodLevelInterceptors != null) {
for (InterceptorDescription methodLevelInterceptor : methodLevelInterceptors) {
String interceptorClassName = methodLevelInterceptor.getInterceptorClassName();
List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokes != null) {
userAroundInvokes.addAll(aroundInvokes);
}
if (requiresTimerChain) {
List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeouts != null) {
userAroundTimeouts.addAll(aroundTimeouts);
}
}
}
}
if(requiresTimerChain) {
configuration.addComponentInterceptor(method, new UserInterceptorFactory(weaved(userAroundInvokes), weaved(userAroundTimeouts)), InterceptorOrder.Component.INTERCEPTOR_USER_INTERCEPTORS);
} else {
configuration.addComponentInterceptors(method, userAroundInvokes, InterceptorOrder.Component.INTERCEPTOR_USER_INTERCEPTORS);
}
}
}
}
}
| 21,823 | 63.568047 | 270 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/InterceptorDescription.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.ee.component;
/**
* A description of an {@link jakarta.interceptor.Interceptor @Interceptor} annotation value or its equivalent
* deployment descriptor construct.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class InterceptorDescription {
private final String interceptorClassName;
public InterceptorDescription(final String interceptorClassName) {
this.interceptorClassName = interceptorClassName;
}
public String getInterceptorClassName() {
return interceptorClassName;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final InterceptorDescription that = (InterceptorDescription) o;
if (interceptorClassName != null ? !interceptorClassName.equals(that.interceptorClassName) : that.interceptorClassName != null)
return false;
return true;
}
@Override
public int hashCode() {
return interceptorClassName != null ? interceptorClassName.hashCode() : 0;
}
}
| 2,165 | 35.1 | 135 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/NamespaceViewConfigurator.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.ee.component;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
/**
* @author John Bailey
*/
public class NamespaceViewConfigurator implements ViewConfigurator {
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addViewInterceptor(componentConfiguration.getNamespaceContextInterceptorFactory(), InterceptorOrder.View.JNDI_NAMESPACE_INTERCEPTOR);
}
}
| 1,758 | 46.540541 | 233 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/Component.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.ee.component;
import org.jboss.as.naming.context.NamespaceContextSelector;
/**
* Common contract for an EE component. Implementations of this will be available as a service and can be used as the
* backing for a JNDI ObjectFactory reference.
*
* @author John Bailey
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public interface Component {
/**
* Start operation called when the Component is available.
*/
void start();
/**
* Stop operation called when the Component is no longer available.
*
*/
void stop();
/**
* Get the component's actual implementation class.
*
* @return the component class
*/
Class<?> getComponentClass();
/**
* Create a new instance of this component. This may be invoked by a component interceptor, a client interceptor,
* or in the course of creating a new client, or in the case of an "eager" singleton, at component start. This
* method will block until the component is available. If the component fails to start then a runtime exception
* will be thrown.
*
* @return the component instance
*/
ComponentInstance createInstance();
ComponentInstance createInstance(Object instance);
/**
* Returns a component instance for a pre-existing instance.
* @param instance the actual object instance
* @return a component instance
*/
ComponentInstance getInstance(Object instance);
NamespaceContextSelector getNamespaceContextSelector();
/**
* Checks whether the supplied {@link Throwable} is remotable meaning it can be safely sent to the client over the wire.
*/
default boolean isRemotable(Throwable throwable) {
return true;
}
void waitForComponentStart();
}
| 2,922 | 32.988372 | 124 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ProxyInvocationHandler.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.ee.component;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* An invocation handler for a component proxy.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ProxyInvocationHandler implements InvocationHandler {
private final Map<Method, Interceptor> interceptors;
private final ComponentView componentView;
private final ComponentClientInstance instance;
/**
* Construct a new instance.
*
* @param interceptors the interceptors map to use
* @param instance The view instane data
* @param componentView The component view
*/
public ProxyInvocationHandler(final Map<Method, Interceptor> interceptors, ComponentClientInstance instance, ComponentView componentView) {
this.interceptors = interceptors;
this.instance = instance;
this.componentView = componentView;
}
/** {@inheritDoc} */
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Interceptor interceptor = interceptors.get(method);
if (interceptor == null) {
throw new NoSuchMethodError(method.toString());
}
final InterceptorContext context = new InterceptorContext();
// special location for original proxy
context.putPrivateData(Object.class, proxy);
context.putPrivateData(Component.class, componentView.getComponent());
context.putPrivateData(ComponentView.class, componentView);
context.putPrivateData(SecurityDomain.class, WildFlySecurityManager.isChecking() ?
AccessController.doPrivileged((PrivilegedAction<SecurityDomain>) SecurityDomain::getCurrent) :
SecurityDomain.getCurrent());
instance.prepareInterceptorContext(context);
context.setParameters(args);
context.setMethod(method);
// setup the public context data
context.setContextData(new HashMap<String, Object>());
context.setBlockingCaller(true);
return interceptor.processInvocation(context);
}
}
| 3,503 | 40.714286 | 143 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentInterceptorFactory.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.ee.component;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
/**
* A factory to create interceptors that are tied to a component instance.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public abstract class ComponentInterceptorFactory implements InterceptorFactory {
@Override
public Interceptor create(InterceptorFactoryContext context) {
// TODO: a contract with AbstractComponentDescription
Component component = (Component) context.getContextData().get(Component.class);
return create(component, context);
}
protected abstract Interceptor create(Component component, InterceptorFactoryContext context);
}
| 1,824 | 41.44186 | 98 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/NamespaceContextInterceptor.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.ee.component;
import org.jboss.as.naming.WritableServiceBasedNamingStore;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.msc.service.ServiceName;
/**
* An interceptor which imposes the given namespace context selector.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class NamespaceContextInterceptor implements Interceptor {
private final NamespaceContextSelector selector;
private final ServiceName deploymentUnitServiceName;
public NamespaceContextInterceptor(final NamespaceContextSelector selector, final ServiceName deploymentUnitServiceName) {
this.selector = selector;
this.deploymentUnitServiceName = deploymentUnitServiceName;
}
public Object processInvocation(final InterceptorContext context) throws Exception {
NamespaceContextSelector.pushCurrentSelector(selector);
try {
WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
try {
return context.proceed();
} finally {
WritableServiceBasedNamingStore.popOwner();
}
} finally {
NamespaceContextSelector.popCurrentSelector();
}
}
}
| 2,387 | 39.474576 | 126 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/InjectionSource.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.ee.component;
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;
/**
* A configuration for an injection source.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public abstract class InjectionSource {
/**
* Get the value to use as the injection source. The value will be yield an injectable which is dereferenced once
* for every time the reference source is injected. The given binder service builder may be used to apply any
* dependencies for this binding (i.e. the source for the binding's value).
*
* @param resolutionContext the resolution context to use
* @param serviceBuilder the builder for the binder service
* @param phaseContext the deployment phase context
* @param injector the injector into which the value should be placed
* @throws DeploymentUnitProcessingException if an error occurs
*/
public abstract void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException;
/**
* A resolution context for the injection source.
*/
public static class ResolutionContext {
private final boolean compUsesModule;
private final String componentName;
private final String moduleName;
private final String applicationName;
public ResolutionContext(final boolean compUsesModule, final String componentName, final String moduleName, final String applicationName) {
this.compUsesModule = compUsesModule;
this.componentName = componentName;
this.moduleName = moduleName;
this.applicationName = applicationName;
}
/**
* Determine whether the resolution context has a combined "comp" and "module" namespace.
*
* @return {@code true} if "comp" is an alias for "module", {@code false} otherwise
*/
public boolean isCompUsesModule() {
return compUsesModule;
}
/**
* Get the current component name, or {@code null} if there is none.
*
* @return the current component name
*/
public String getComponentName() {
return componentName;
}
/**
* Get the current module name, or {@code null} if there is none.
*
* @return the current module name
*/
public String getModuleName() {
return moduleName;
}
/**
* Get the current application name, or {@code null} if there is none.
*
* @return the current application name
*/
public String getApplicationName() {
return applicationName;
}
}
}
| 4,093 | 38.747573 | 235 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ManagedReferenceFieldInjectionInterceptorFactory.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.ee.component;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.msc.value.Value;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
final class ManagedReferenceFieldInjectionInterceptorFactory implements InterceptorFactory {
private final Object targetContextKey;
private final Object valueContextKey;
private final Value<ManagedReferenceFactory> factoryValue;
private final Field field;
private final boolean optional;
ManagedReferenceFieldInjectionInterceptorFactory(final Object targetContextKey, final Object valueContextKey, final Value<ManagedReferenceFactory> factoryValue, final Field field, final boolean optional) {
this.targetContextKey = targetContextKey;
this.valueContextKey = valueContextKey;
this.factoryValue = factoryValue;
this.field = field;
this.optional = optional;
}
public Interceptor create(final InterceptorFactoryContext context) {
return new ManagedReferenceFieldInjectionInterceptor(targetContextKey, valueContextKey, factoryValue.getValue(), field, optional);
}
/**
* An interceptor which constructs and injects a managed reference into a field. The context key given
* for storing the reference should be passed to a {@link ManagedReferenceReleaseInterceptor} which is run during
* object destruction.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
static final class ManagedReferenceFieldInjectionInterceptor implements Interceptor {
private final Object targetKey;
private final ManagedReferenceFactory factory;
private final Field field;
private final boolean optional;
private final Object valueContextKey;
ManagedReferenceFieldInjectionInterceptor(final Object targetKey, final Object valueContextKey, final ManagedReferenceFactory factory, final Field field, final boolean optional) {
this.targetKey = targetKey;
this.factory = factory;
this.field = field;
this.optional = optional;
this.valueContextKey = valueContextKey;
}
/**
* {@inheritDoc}
*/
public Object processInvocation(final InterceptorContext context) throws Exception {
ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
Object target;
if (Modifier.isStatic(field.getModifiers())) {
target = null;
} else {
target = ((ManagedReference) componentInstance.getInstanceData(targetKey)).getInstance();
if (target == null) {
throw EeLogger.ROOT_LOGGER.injectionTargetNotFound();
}
}
final ManagedReference reference = factory.getReference();
if (reference == null && optional) {
return context.proceed();
} else if(reference == null) {
throw EeLogger.ROOT_LOGGER.managedReferenceWasNull(field);
}
boolean ok = false;
try {
componentInstance.setInstanceData(valueContextKey, reference);
Object injected = reference.getInstance();
try {
field.set(target, injected);
} catch (IllegalArgumentException e) {
throw EeLogger.ROOT_LOGGER.cannotSetField(field.getName(), injected.getClass(), injected.getClass().getClassLoader(), field.getType(), field.getType().getClassLoader());
}
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
componentInstance.setInstanceData(valueContextKey, null);
reference.release();
}
}
}
}
}
| 5,349 | 41.8 | 209 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentIsStoppedException.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2016, 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.ee.component;
/**
* Exception indicating that a component receiving a method call has stopped.
*
* @author Richard Achmatowicz
*/
public class ComponentIsStoppedException extends IllegalStateException {
private static final long serialVersionUID = 1L;
/**
* Constructs a <code>ComponentIsStoppedException</code> with no detail message.
*/
public ComponentIsStoppedException() {
}
/**
* Constructs a <code>ComponentIsStoppedException</code> with the specified
* detail message.
*
* @param message the detail message
*/
public ComponentIsStoppedException(String message) {
super(message);
}
}
| 1,715 | 33.32 | 84 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/DefaultComponentViewConfigurator.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.ee.component;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.serialization.WriteReplaceInterface;
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.ModuleClassFactory;
import org.jboss.as.server.deployment.reflect.ProxyMetadataSource;
import org.jboss.invocation.proxy.ProxyConfiguration;
import org.jboss.invocation.proxy.ProxyFactory;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* @author Stuart Douglas
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
class DefaultComponentViewConfigurator extends AbstractComponentConfigurator implements ComponentConfigurator {
private static final AtomicInteger PROXY_ID = new AtomicInteger(0);
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final ProxyMetadataSource proxyReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.PROXY_REFLECTION_INDEX);
//views
for (ViewDescription view : description.getViews()) {
Class<?> viewClass;
try {
viewClass = module.getClassLoader().loadClass(view.getViewClassName());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadViewClass(e, view.getViewClassName(), configuration);
}
final ViewConfiguration viewConfiguration;
final ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
if (viewClass.getName().startsWith("java.")) {
proxyConfiguration.setProxyName("org.jboss.proxy.java.lang." + viewClass.getSimpleName() + "$$$view" + PROXY_ID.incrementAndGet());
} else {
proxyConfiguration.setProxyName(viewClass.getName() + "$$$view" + PROXY_ID.incrementAndGet());
}
proxyConfiguration.setClassLoader(module.getClassLoader());
proxyConfiguration.setClassFactory(ModuleClassFactory.INSTANCE);
proxyConfiguration.setProtectionDomain(viewClass.getProtectionDomain());
proxyConfiguration.setMetadataSource(proxyReflectionIndex);
if (view.isSerializable()) {
proxyConfiguration.addAdditionalInterface(Serializable.class);
if (view.isUseWriteReplace()) {
proxyConfiguration.addAdditionalInterface(WriteReplaceInterface.class);
}
}
Class<?> markupClass;
try {
if (view.getMarkupClassName() != null) {
markupClass = module.getClassLoader().loadClass(view.getMarkupClassName());
proxyConfiguration.addAdditionalInterface(markupClass);
}
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadViewClass(e, view.getMarkupClassName(), configuration);
}
//we define it in the modules class loader to prevent permgen leaks
if (viewClass.isInterface()) {
final Class<?> componentClass = configuration.getComponentClass();
Constructor<?> defaultConstructor = null;
try {
defaultConstructor = componentClass.getConstructor();
} catch (Exception e) {
//ignore
}
proxyConfiguration.setSuperClass(!view.requiresSuperclassInProxy() || defaultConstructor == null ? Object.class : componentClass);
proxyConfiguration.addAdditionalInterface(viewClass);
viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
} else {
proxyConfiguration.setSuperClass(viewClass);
viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
}
for (final ViewConfigurator configurator : view.getConfigurators()) {
configurator.configure(context, configuration, view, viewConfiguration);
}
configuration.getViews().add(viewConfiguration);
}
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) {
for (ServiceName dependencyName : description.getDependencies()) {
serviceBuilder.requires(dependencyName);
}
}
});
}
}
| 6,309 | 49.887097 | 190 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/ComponentTypeInjectionSource.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.ee.component;
import java.util.Iterator;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
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.module.ResourceRoot;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import static org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION;
/**
* An injection source which injects a component based upon its type.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class ComponentTypeInjectionSource extends InjectionSource {
private final String typeName;
public ComponentTypeInjectionSource(final String typeName) {
this.typeName = typeName;
}
public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEApplicationDescription applicationDescription = deploymentUnit.getAttachment(EE_APPLICATION_DESCRIPTION);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final Set<ViewDescription> componentsForViewName = applicationDescription.getComponentsForViewName(typeName, deploymentRoot.getRoot());
final Iterator<ViewDescription> iterator = componentsForViewName.iterator();
if (!iterator.hasNext()) {
throw EeLogger.ROOT_LOGGER.componentNotFound(typeName);
}
final ViewDescription description = iterator.next();
if (iterator.hasNext()) {
throw EeLogger.ROOT_LOGGER.multipleComponentsFound(typeName);
}
//TODO: should ComponentView also be a managed reference factory?
serviceBuilder.addDependency(description.getServiceName(), ComponentView.class, new ViewManagedReferenceFactory.Injector(injector));
}
public boolean equals(final Object other) {
if (other instanceof ComponentTypeInjectionSource) {
return ((ComponentTypeInjectionSource) other).typeName.equals(typeName);
}
return false;
}
public int hashCode() {
return typeName.hashCode();
}
}
| 3,620 | 44.2625 | 251 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/component/AroundConstructInterceptorFactory.java | package org.jboss.as.ee.component;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
/**
* @author Stuart Douglas
*/
public class AroundConstructInterceptorFactory implements InterceptorFactory {
private final InterceptorFactory aroundConstrctChain;
public AroundConstructInterceptorFactory(final InterceptorFactory aroundConstrctChain) {
this.aroundConstrctChain = aroundConstrctChain;
}
@Override
public Interceptor create(final InterceptorFactoryContext context) {
final Interceptor aroundConstruct = aroundConstrctChain.create(context);
return new Interceptor() {
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
aroundConstruct.processInvocation(context);
context.setParameters(null);
return context.proceed();
}
};
}
}
| 1,061 | 31.181818 | 96 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.