KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > JBossWebAppParsingDeployer


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * 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.deployment;
23
24 import org.jboss.deployers.plugins.deployers.helpers.AttachmentLocator;
25 import org.jboss.deployers.plugins.deployers.helpers.ObjectModelFactoryDeployer;
26 import org.jboss.deployers.spi.DeploymentException;
27 import org.jboss.deployers.spi.deployer.DeploymentUnit;
28 import org.jboss.metadata.WebMetaData;
29 import org.jboss.metadata.web.JBossWebMetaDataObjectFactory;
30 import org.jboss.xb.binding.ObjectModelFactory;
31
32 /**
33  * An ObjectModelFactoryDeployer for translating jboss-web.xml descriptors into
34  * WebMetaData instances.
35  *
36  * @author Scott.Stark@jboss.org
37  * @version $Revision:$
38  */

39 public class JBossWebAppParsingDeployer extends ObjectModelFactoryDeployer<WebMetaData>
40 {
41    private String JavaDoc webXmlPath = "jboss-web.xml";
42
43    public JBossWebAppParsingDeployer()
44    {
45       super(WebMetaData.class);
46       setRelativeOrder(PARSER_DEPLOYER+1);
47    }
48
49    /**
50     * Get the virtual file path for the jboss-web descriptor in the
51     * DeploymentContext.getMetaDataPath.
52     *
53     * @return the current virtual file path for the web-app descriptor
54     */

55    public String JavaDoc getWebXmlPath()
56    {
57       return webXmlPath;
58    }
59    /**
60     * Set the virtual file path for the jboss-web descriptor in the
61     * DeploymentContext.getMetaDataLocation. The standard path is jboss-web.xml
62     * to be found in the WEB-INF metdata path.
63     *
64     * @param webXmlPath - new virtual file path for the web-app descriptor
65     */

66    public void setWebXmlPath(String JavaDoc webXmlPath)
67    {
68       this.webXmlPath = webXmlPath;
69    }
70
71    /**
72     * Overriden to indicate we expect to run the parse even if an existing
73     * WebMetaData attachment is found.
74     * @return true.
75     */

76    @Override JavaDoc
77    protected boolean allowsReparse()
78    {
79       return true;
80    }
81
82    /**
83     * Return JBossWebMetaDataObjectFactory as our ObjectModelFactory.
84     * @return a new JBossWebMetaDataObjectFactory instance
85     */

86    @Override JavaDoc
87    protected ObjectModelFactory getObjectModelFactory(WebMetaData root)
88    {
89       return new JBossWebMetaDataObjectFactory(root);
90    }
91
92    /**
93     * Overriden to invoke createMetaData(unit, webXmlPath, null) to parse any
94     * webXmlPath descriptor into a WebMetaData instance.
95     */

96    @Override JavaDoc
97    public void deploy(DeploymentUnit unit) throws DeploymentException
98    {
99       log.debug("deploy, unit: "+unit);
100       createMetaData(unit, webXmlPath, null);
101       WebMetaData metaData = getMetaData(unit, WebMetaData.class.getName());
102       if( metaData == null )
103          return;
104
105       // Merge any settings from the ear level
106
J2eeApplicationMetaData earMetaData = AttachmentLocator.search(unit, J2eeApplicationMetaData.class);
107       if( earMetaData != null )
108       {
109          String JavaDoc path = unit.getRelativePath();
110          J2eeModuleMetaData webModule = earMetaData.getModule(path);
111          if( webModule != null )
112          {
113             // Check for a context-root setting
114
String JavaDoc contextRoot = metaData.getContextRoot();
115             if( contextRoot == null )
116             {
117                contextRoot = webModule.getWebContext();
118                metaData.setContextRoot(contextRoot);
119             }
120
121             // Add any alt-dd setting
122
metaData.setAltDDPath(webModule.getAlternativeDD());
123          }
124
125          // Merge security domain/roles
126
if( metaData.getSecurityDomain() == null )
127             metaData.setSecurityDomain(earMetaData.getSecurityDomain());
128          metaData.mergeSecurityRoles(earMetaData.getSecurityRoles());
129       }
130    }
131 }
132
Popular Tags