KickJava   Java API By Example, From Geeks To Geeks.

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


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.ApplicationMetaData;
29 import org.jboss.xb.binding.ObjectModelFactory;
30 import org.jboss.virtual.VirtualFile;
31 import org.jboss.virtual.VFS;
32 import org.jboss.system.server.ServerConfig;
33
34 /**
35  * An ObjectModelFactoryDeployer for translating jboss-web.xml descriptors into
36  * WebMetaData instances.
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision:$
40  */

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

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

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

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

88    @Override JavaDoc
89    protected ObjectModelFactory getObjectModelFactory(ApplicationMetaData root)
90    {
91       return new JBossEjbObjectFactory(root);
92    }
93
94    /**
95     * Overriden to invoke createMetaData(unit, jbossXmlPath, null) to parse any
96     * jbossXmlPath descriptor into a ApplicationMetaData instance.
97     */

98    @Override JavaDoc
99    public void deploy(DeploymentUnit unit) throws DeploymentException
100    {
101       // make sure it's there is ejb-jar.xml
102
// TODO: also make sure it's ejb2.x module (Wolf: added hack in parse)
103
VirtualFile ejbjar = unit.getMetaDataFile("ejb-jar.xml");
104       if (ejbjar == null)
105       {
106          return;
107       }
108
109       log.debug("deploy, unit: "+unit);
110       createMetaData(unit, jbossXmlPath, null);
111
112       ApplicationMetaData metaData = getMetaData(unit, ApplicationMetaData.class.getName());
113       if( metaData == null )
114          return;
115
116       // Merge any settings from the ear level
117
J2eeApplicationMetaData earMetaData = AttachmentLocator.search(unit, J2eeApplicationMetaData.class);
118       if( earMetaData != null )
119       {
120          // Merge security domain/roles
121
if( metaData.getSecurityDomain() == null )
122             metaData.setSecurityDomain(earMetaData.getSecurityDomain());
123          metaData.mergeSecurityRoles(earMetaData.getSecurityRoles());
124       }
125
126    }
127
128    protected ApplicationMetaData parse(DeploymentUnit unit,
129                                        String JavaDoc name,
130                                        ApplicationMetaData root)
131       throws Exception JavaDoc
132    {
133       // Wolf: hack to get to EJB3 deployer
134
if(root.getEjbVersion() > 2)
135          return null;
136       
137       String JavaDoc configPath = System.getProperty(ServerConfig.SERVER_CONFIG_URL);
138       java.net.URL JavaDoc configUrl = new java.net.URL JavaDoc(configPath);
139       VirtualFile stdJBoss = VFS.getVirtualFile(configUrl, "standardjboss.xml");
140       if(stdJBoss == null)
141       {
142          throw new DeploymentException("standardjboss.xml not found in config dir: " + configPath);
143       }
144
145       ApplicationMetaData result = parse(unit, stdJBoss, root);
146
147       // Try to find the metadata
148
VirtualFile file = unit.getMetaDataFile(name);
149       if (file == null)
150          return null;
151
152       result = parse(unit, file, root);
153       init(unit, result, file);
154       return result;
155    }
156 }
157
Popular Tags