KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > emb > EMBDeployer


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.emb;
9
10 import java.net.URL JavaDoc;
11
12 import org.dom4j.io.SAXReader;
13 import org.jboss.deployment.DeploymentException;
14 import org.jboss.deployment.DeploymentInfo;
15 import org.jboss.ejb.EJBDeployer;
16 import org.jboss.ejb.EJBDeployerMBean;
17 import org.jboss.media.engine.MediaXmlLoader;
18
19 /**
20  * @version <tt>$Revision: 1.3 $</tt>
21  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
22  * @jmx:mbean extends="org.jboss.ejb.EJBDeployerMBean"
23  */

24 public class EMBDeployer
25    extends EJBDeployer
26    implements EMBDeployerMBean, EJBDeployerMBean
27 {
28
29    public boolean accepts(DeploymentInfo di)
30    {
31       // To be accepted the deployment's root name must end in jar
32
String JavaDoc urlStr = di.url.getFile();
33       if (!urlStr.endsWith("jar") && !urlStr.endsWith("jar/"))
34       {
35          return false;
36       }
37
38       // jar must contain ejb-jar.xml and jboss-media.xml
39
boolean accepts = false;
40       try
41       {
42          URL JavaDoc dd = di.localCl.findResource("META-INF/ejb-jar.xml");
43          if (dd == null)
44          {
45             return false;
46          }
47
48          URL JavaDoc dm = di.localCl.findResource("META-INF/jboss-media.xml");
49          if (dm == null)
50          {
51             return false;
52          }
53
54          // If the DD url is not a subset of the urlStr then this is coming
55
// from a jar referenced by the deployment jar manifest and the
56
// this deployment jar it should not be treated as an ejb-jar
57
if (di.localUrl != null)
58          {
59             urlStr = di.localUrl.toString();
60          }
61
62          String JavaDoc ddStr = dd.toString();
63          if (ddStr.indexOf(urlStr) >= 0)
64          {
65             accepts = true;
66          }
67       }
68       catch (Exception JavaDoc ignore)
69       {
70       }
71
72       return accepts;
73    }
74
75    /* (non-Javadoc)
76     * @see org.jboss.deployment.SubDeployer#create(org.jboss.deployment.DeploymentInfo)
77     */

78    public synchronized void create(DeploymentInfo di)
79       throws DeploymentException
80    {
81       super.create(di);
82
83       try
84       {
85          // Spy: Have a look at this:
86
/*MediaXmlLoader.deployXML(
87             di.getW3CDocument(),
88             di.localUrl,
89             getServer());*/

90       }
91       catch (Exception JavaDoc e)
92       {
93          if (e instanceof DeploymentException)
94             throw (DeploymentException) e;
95          throw new DeploymentException("Failed to load metadata", e);
96       }
97    }
98
99    /* (non-Javadoc)
100     * @see org.jboss.deployment.SubDeployer#start(org.jboss.deployment.DeploymentInfo)
101     */

102    public synchronized void start(DeploymentInfo di) throws DeploymentException
103    {
104       // TODO Auto-generated method stub
105
super.start(di);
106    }
107
108    protected void parseDocument(DeploymentInfo di) throws Exception JavaDoc
109    {
110       // Spy: Have a look at this:
111
/*if (di.getDocument() == null)
112       {
113          //DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
114          URL docURL = di.localUrl;
115          // Load jboss-service.xml from the jar or directory
116          if (di.isXML == false)
117             docURL = di.localCl.findResource("META-INF/jboss-media.xml");
118          // Validate that the descriptor was found
119          if (docURL == null)
120             throw new DeploymentException("Failed to find META-INF/jboss-media.xml");
121
122          SAXReader sr = new SAXReader();
123          di.setDocument(sr.read(docURL));
124       }
125       else
126       {
127          log.debug("Using existing deployment.document");
128       }*/

129    }
130
131 }
Popular Tags