KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > deployers > JBossClientParsingDeployer


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, Red Hat Middleware LLC, and individual contributors as indicated
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.ejb3.deployers;
23
24 import java.io.IOException JavaDoc;
25
26 import org.jboss.deployers.plugins.deployers.helpers.ObjectModelFactoryDeployer;
27 import org.jboss.deployers.spi.DeploymentException;
28 import org.jboss.deployers.spi.deployer.DeploymentUnit;
29 import org.jboss.ejb3.metamodel.ApplicationClientDD;
30 import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory;
31 import org.jboss.util.xml.DOMUtils;
32 import org.jboss.virtual.VirtualFile;
33 import org.jboss.xb.binding.ObjectModelFactory;
34 import org.w3c.dom.DocumentType JavaDoc;
35 import org.w3c.dom.Element JavaDoc;
36
37 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
41  * @version $Revision: $
42  */

43 public class JBossClientParsingDeployer extends ObjectModelFactoryDeployer<ApplicationClientDD>
44 {
45    private String JavaDoc jbossClientXmlPath = "jboss-client.xml";
46    
47    /**
48     * Set the relative order to PARSER_DEPLOYER+1 by default
49     *
50     */

51    public JBossClientParsingDeployer()
52    {
53       super(ApplicationClientDD.class);
54       setRelativeOrder(PARSER_DEPLOYER + 1);
55    }
56    
57    @Override JavaDoc
58    protected boolean allowsReparse()
59    {
60       return true;
61    }
62    
63    @Override JavaDoc
64    protected ObjectModelFactory getObjectModelFactory(ApplicationClientDD root)
65    {
66       return new JBossClientDDObjectFactory(root);
67    }
68
69    @Override JavaDoc
70    public void deploy(DeploymentUnit unit) throws DeploymentException
71    {
72       if (accepts(unit))
73          createMetaData(unit, jbossClientXmlPath, null);
74    }
75
76    /**
77     * This method looks to the deployment for a META-INF/application-client.xml
78     * descriptor to identify a j2ee client jar.
79     */

80    private boolean accepts(DeploymentUnit unit) throws DeploymentException
81    {
82       boolean accepts = false;
83
84       // The jar must contain an META-INF/application-client.xml
85
VirtualFile dd = unit.getMetaDataFile(jbossClientXmlPath);
86       if (dd != null)
87       {
88          log.debug("Found application-client.xml file: " + unit.getName());
89          try
90          {
91             Element JavaDoc root = DOMUtils.parse(dd.openStream());
92             DocumentType JavaDoc doctype = root.getOwnerDocument().getDoctype();
93             String JavaDoc publicId = (doctype != null ? doctype.getPublicId() : null);
94             // Accept the JBoss5 publicId
95
accepts = "-//JBoss//DTD Application Client 5.0//EN".equals(publicId);
96             if (accepts == false)
97                log.debug("Ignore jboss-client.xml with publicId: " + publicId);
98          }
99          catch (IOException JavaDoc ex)
100          {
101             DeploymentException.rethrowAsDeploymentException("Cannot parse " + jbossClientXmlPath, ex);
102          }
103       }
104
105       return accepts;
106    }
107 }
108
Popular Tags