KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > deployment > RARDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., 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.resource.deployment;
23
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.net.URL JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.resource.spi.XATerminator JavaDoc;
30 import javax.resource.spi.work.WorkManager JavaDoc;
31
32 import org.jboss.deployment.DeploymentException;
33 import org.jboss.deployment.DeploymentInfo;
34 import org.jboss.deployment.ObjectModelFactorySimpleSubDeployerSupport;
35 import org.jboss.resource.metadata.ConnectorMetaData;
36 import org.jboss.resource.metadata.JBossRAMetaData;
37 import org.jboss.resource.metadata.RARDeploymentMetaData;
38 import org.jboss.xb.binding.ObjectModelFactory;
39 import org.jboss.xb.binding.Unmarshaller;
40 import org.jboss.xb.binding.UnmarshallerFactory;
41
42 /**
43  * A resource adapter deployer
44  *
45  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
46  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
47  * @version $Revision: 46111 $
48  */

49 public class RARDeployer extends ObjectModelFactorySimpleSubDeployerSupport
50    implements RARDeployerMBean
51 {
52    
53    /** The JBOSS_RA_XML */
54    private static final String JavaDoc JBOSS_RA_XML = "META-INF/jboss-ra.xml";
55    
56    /** The work manager name */
57    protected ObjectName JavaDoc workManagerName;
58    
59    /** The work manager */
60    protected WorkManager JavaDoc workManager;
61
62    /** The xa terminator */
63    protected XATerminator JavaDoc xaTerminator;
64
65    /** The xa terminator name */
66    protected ObjectName JavaDoc xaTerminatorName;
67    
68    public RARDeployer()
69    {
70       setEnhancedSuffixes(new String JavaDoc[] { "250:.rar" });
71    }
72    
73    protected void parseMetaData(DeploymentInfo di, URL JavaDoc url) throws DeploymentException
74    {
75      
76       super.parseMetaData(di, url);
77       
78       InputStream JavaDoc is = di.localCl.getResourceAsStream(JBOSS_RA_XML);
79       RARDeploymentMetaData rdmd = new RARDeploymentMetaData();
80       rdmd.setConnectorMetaData((ConnectorMetaData)di.metaData);
81       di.metaData = rdmd;
82       
83       try
84       {
85          if(is != null)
86          {
87             
88             Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
89             ObjectModelFactory factory = getExtendedObjectModelFactory();
90             JBossRAMetaData ramd = (JBossRAMetaData)unmarshaller.unmarshal(is, factory, (Object JavaDoc)null);
91             rdmd.setRaXmlMetaData(ramd);
92             
93          }
94       
95       }
96       
97       catch (Throwable JavaDoc t)
98       {
99          
100          DeploymentException.rethrowAsDeploymentException("Error parsing meta data " + url, t);
101
102       }finally
103       {
104          try
105          {
106             if(is != null)
107             {
108                is.close();
109             }
110          }
111          catch (IOException JavaDoc e)
112          {
113          }
114       }
115       
116          
117    }
118    public String JavaDoc getExtension()
119    {
120       return ".rar";
121    }
122
123    public String JavaDoc getMetaDataURL()
124    {
125       return "META-INF/ra.xml";
126    }
127
128    public String JavaDoc getObjectName(DeploymentInfo di) throws DeploymentException
129    {
130       String JavaDoc name = di.shortName;
131       di = di.parent;
132       while (di != null)
133       {
134          name = di.shortName + "#" + name;
135          di = di.parent;
136       }
137       return "jboss.jca:service=RARDeployment,name='" + name + "'";
138    }
139
140    public String JavaDoc getDeploymentClass()
141    {
142       return RARDeployment.class.getName();
143    }
144
145    public ObjectModelFactory getObjectModelFactory()
146    {
147       return new ResourceAdapterObjectModelFactory();
148    }
149
150    public ObjectName JavaDoc getWorkManagerName()
151    {
152       return workManagerName;
153    }
154
155    public void setWorkManagerName(ObjectName JavaDoc workManagerName)
156    {
157       this.workManagerName = workManagerName;
158    }
159
160    public ObjectName JavaDoc getXATerminatorName()
161    {
162       return xaTerminatorName;
163    }
164
165    public void setXATerminatorName(ObjectName JavaDoc xaTerminatorName)
166    {
167       this.xaTerminatorName = xaTerminatorName;
168    }
169    
170    protected void startService() throws Exception JavaDoc
171    {
172       workManager = (WorkManager JavaDoc) server.getAttribute(workManagerName, "Instance");
173       xaTerminator = (XATerminator JavaDoc) server.getAttribute(xaTerminatorName, "XATerminator");
174       super.startService();
175    }
176
177    private ObjectModelFactory getExtendedObjectModelFactory()
178    {
179       return new JBossRAObjectModelFactory();
180    }
181 }
182
Popular Tags