PageRenderTime 44ms CodeModel.GetById 33ms app.highlight 9ms RepoModel.GetById 1ms 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
23package org.jboss.as.ee.naming;
24
25import org.jboss.as.ee.component.EEModuleDescription;
26import org.jboss.as.naming.ServiceBasedNamingStore;
27import org.jboss.as.naming.ValueManagedReferenceFactory;
28import org.jboss.as.naming.deployment.ContextNames;
29import org.jboss.as.naming.service.BinderService;
30import org.jboss.as.naming.service.NamingStoreService;
31import org.jboss.as.server.deployment.DeploymentPhaseContext;
32import org.jboss.as.server.deployment.DeploymentUnit;
33import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
34import org.jboss.as.server.deployment.DeploymentUnitProcessor;
35import org.jboss.msc.service.ServiceName;
36import org.jboss.msc.service.ServiceTarget;
37import org.jboss.msc.value.Values;
38
39/**
40 * Deployment processor that deploys a naming context for the current application.
41 *
42 * @author John E. Bailey
43 */
44public class ApplicationContextProcessor implements DeploymentUnitProcessor {
45
46    /**
47     * Add a ContextService for this module.
48     *
49     * @param phaseContext the deployment unit context
50     * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
51     */
52    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
53        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
54        if (deploymentUnit.getParent() != null) {
55            return;
56        }
57        EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
58
59        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
60
61        final ServiceName applicationContextServiceName = ContextNames.contextServiceNameOfApplication(moduleDescription.getApplicationName());
62        final NamingStoreService contextService = new NamingStoreService();
63        serviceTarget.addService(applicationContextServiceName, contextService).install();
64
65        final BinderService applicationNameBinder = new BinderService("AppName");
66        serviceTarget.addService(applicationContextServiceName.append("AppName"), applicationNameBinder)
67                .addDependency(applicationContextServiceName, ServiceBasedNamingStore.class, applicationNameBinder.getNamingStoreInjector())
68                .addInjection(applicationNameBinder.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(moduleDescription.getApplicationName())))
69                .install();
70
71        deploymentUnit.putAttachment(Attachments.APPLICATION_CONTEXT_CONFIG, applicationContextServiceName);
72    }
73
74    public void undeploy(DeploymentUnit context) {
75
76    }
77}