KickJava   Java API By Example, From Geeks To Geeks.

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


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.ApplicationClientDDObjectFactory;
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.Element JavaDoc;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
40  * @version $Revision: $
41  */

42 public class AppClientParsingDeployer extends ObjectModelFactoryDeployer<ApplicationClientDD>
43 {
44    private String JavaDoc appClientXmlPath = "application-client.xml";
45    
46    public AppClientParsingDeployer()
47    {
48       super(ApplicationClientDD.class);
49    }
50    
51    @Override JavaDoc
52    protected ObjectModelFactory getObjectModelFactory(ApplicationClientDD root)
53    {
54       return new ApplicationClientDDObjectFactory();
55    }
56
57    @Override JavaDoc
58    public void deploy(DeploymentUnit unit) throws DeploymentException
59    {
60       if (accepts(unit))
61          createMetaData(unit, appClientXmlPath, null);
62    }
63    
64    /**
65     * This method looks to the deployment for a META-INF/application-client.xml
66     * descriptor to identify a j2ee client jar.
67     */

68    private boolean accepts(DeploymentUnit unit) throws DeploymentException
69    {
70       boolean accepts = false;
71
72       // The jar must contain an META-INF/application-client.xml
73
VirtualFile dd = unit.getMetaDataFile(appClientXmlPath);
74       if (dd != null)
75       {
76          log.debug("Found application-client.xml file: " + unit.getName());
77          try
78          {
79             Element JavaDoc root = DOMUtils.parse(dd.openStream());
80             String JavaDoc namespaceURI = root.getNamespaceURI();
81             // Accept the J2EE5 namespace
82
accepts = "http://java.sun.com/xml/ns/javaee".equals(namespaceURI);
83             if (accepts == false)
84                log.debug("Ignore application-client.xml with namespace: " + namespaceURI);
85          }
86          catch (IOException JavaDoc ex)
87          {
88             DeploymentException.rethrowAsDeploymentException("Cannot parse " + appClientXmlPath, ex);
89          }
90       }
91
92       return accepts;
93    }
94 }
95
Popular Tags