PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ee/src/main/java/org/jboss/as/ee/naming/ApplicationContextProcessor.java

#
Java | 77 lines | 35 code | 10 blank | 32 comment | 2 complexity | a15e3ceff5f430275f828cb49854ac2b MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2010, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ee.naming;
  23. import org.jboss.as.ee.component.EEModuleDescription;
  24. import org.jboss.as.naming.ServiceBasedNamingStore;
  25. import org.jboss.as.naming.ValueManagedReferenceFactory;
  26. import org.jboss.as.naming.deployment.ContextNames;
  27. import org.jboss.as.naming.service.BinderService;
  28. import org.jboss.as.naming.service.NamingStoreService;
  29. import org.jboss.as.server.deployment.DeploymentPhaseContext;
  30. import org.jboss.as.server.deployment.DeploymentUnit;
  31. import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
  32. import org.jboss.as.server.deployment.DeploymentUnitProcessor;
  33. import org.jboss.msc.service.ServiceName;
  34. import org.jboss.msc.service.ServiceTarget;
  35. import org.jboss.msc.value.Values;
  36. /**
  37. * Deployment processor that deploys a naming context for the current application.
  38. *
  39. * @author John E. Bailey
  40. */
  41. public class ApplicationContextProcessor implements DeploymentUnitProcessor {
  42. /**
  43. * Add a ContextService for this module.
  44. *
  45. * @param phaseContext the deployment unit context
  46. * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
  47. */
  48. public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  49. final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  50. if (deploymentUnit.getParent() != null) {
  51. return;
  52. }
  53. EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
  54. final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
  55. final ServiceName applicationContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
  56. final NamingStoreService contextService = new NamingStoreService();
  57. serviceTarget.addService(applicationContextServiceName, contextService).install();
  58. final BinderService applicationNameBinder = new BinderService("AppName");
  59. serviceTarget.addService(applicationContextServiceName.append("AppName"), applicationNameBinder)
  60. .addDependency(applicationContextServiceName, ServiceBasedNamingStore.class, applicationNameBinder.getNamingStoreInjector())
  61. .addInjection(applicationNameBinder.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(moduleDescription.getApplicationName())))
  62. .install();
  63. deploymentUnit.putAttachment(Attachments.APPLICATION_CONTEXT_CONFIG, applicationContextServiceName);
  64. }
  65. public void undeploy(DeploymentUnit context) {
  66. }
  67. }