KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > engine > MediaEngineDeployer


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.engine;
9
10 import java.io.File JavaDoc;
11 import java.net.URL JavaDoc;
12
13 import org.dom4j.DocumentException;
14 import org.dom4j.io.SAXReader;
15 import org.jboss.deployment.DeploymentException;
16 import org.jboss.deployment.DeploymentInfo;
17 import org.jboss.deployment.SubDeployer;
18 import org.jboss.deployment.SubDeployerSupport;
19
20 /**
21  * @version <tt>$Revision: 1.4 $</tt>
22  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
23  *
24  * @jmx:mbean extends="org.jboss.deployment.SubDeployerMBean"
25  */

26 public class MediaEngineDeployer
27    extends SubDeployerSupport
28    implements SubDeployer, MediaEngineDeployerMBean
29 {
30    public MediaEngineDeployer()
31    {
32    }
33
34    /**
35     * @see org.jboss.deployment.SubDeployerMBean#accepts(DeploymentInfo)
36     */

37    public boolean accepts(DeploymentInfo info)
38    {
39
40       String JavaDoc urlStr = info.url.toString();
41       return (urlStr.endsWith("-media.xml"));
42    }
43
44    protected boolean isDeployable(String JavaDoc name, URL JavaDoc url)
45    {
46       return (name.endsWith("-media.xml"));
47    }
48
49    public void init(DeploymentInfo di) throws DeploymentException
50    {
51       //default action on duplicate deployment is to ignore this one.
52
super.init(di);
53
54       boolean debug = log.isDebugEnabled();
55
56       try
57       {
58          if (di.watch == null)
59          {
60             // resolve the watch
61
if (di.url.getProtocol().equals("file"))
62             {
63                File JavaDoc file = new File JavaDoc(di.url.getFile());
64
65                // If not directory we watch the package
66
if (!file.isDirectory())
67                {
68                   di.watch = di.url;
69                }
70             }
71             else
72             {
73                // We watch the top only, no directory support
74
di.watch = di.url;
75             }
76          }
77          // Get the document if not already present
78
parseDocument(di);
79       }
80       catch (Exception JavaDoc e)
81       {
82          log.error("failed to parse media document: ", e);
83          throw new DeploymentException(e);
84       }
85    }
86
87    /**
88     * @param di
89     */

90    private void parseDocument(DeploymentInfo di)
91       throws DeploymentException, DocumentException
92    {
93       // Spy: Have a look at this:
94
/*if (di.getDocument() == null)
95       {
96          //DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
97          URL docURL = di.localUrl;
98          // Load jboss-service.xml from the jar or directory
99       
100          if (docURL == null)
101             throw new DeploymentException("Failed to initialize");
102       
103          SAXReader sr = new SAXReader();
104          di.setDocument(sr.read(docURL));
105       }
106       else
107       {
108          log.debug("Using existing deployment.document");
109       }*/

110
111    }
112
113    /* (non-Javadoc)
114     * @see org.jboss.deployment.SubDeployerMBean#create(org.jboss.deployment.DeploymentInfo)
115     */

116    public synchronized void create(DeploymentInfo di)
117       throws DeploymentException
118    {
119
120       super.create(di);
121       log.info("Deploying *-media.xml descriptor");
122    }
123
124    /* (non-Javadoc)
125     * @see org.jboss.deployment.SubDeployerMBean#start(org.jboss.deployment.DeploymentInfo)
126     */

127    public void start(DeploymentInfo di) throws DeploymentException
128    {
129       // Spy: Have a look at this:
130
/*super.start(di);
131       try
132       {
133          MediaXmlLoader.deployXML(
134             di.getW3CDocument(),
135             di.localUrl,
136             getServer());
137       }
138       catch (Exception ex)
139       {
140          ex.printStackTrace();
141          throw new DeploymentException(ex);
142       }
143       super.start(di);*/

144    }
145
146    /* (non-Javadoc)
147     * @see org.jboss.deployment.SubDeployerMBean#stop(org.jboss.deployment.DeploymentInfo)
148     */

149    public synchronized void stop(DeploymentInfo di) throws DeploymentException
150    {
151       // Spy: Have a look at this:
152
/*super.stop(di);
153       try
154       {
155          MediaXmlLoader.undeploy(di.getW3CDocument(), di.localUrl, getServer());
156       }
157       catch (Exception ex)
158       {
159          ex.printStackTrace();
160          throw new DeploymentException(ex);
161       }
162       super.start(di);*/

163    }
164 }
165
Popular Tags