KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.deployers;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer;
30 import org.jboss.deployers.spi.DeploymentException;
31 import org.jboss.deployers.spi.deployer.DeploymentUnit;
32 import org.jboss.deployers.spi.structure.DeploymentContext;
33 import org.jboss.resource.metadata.ConnectorMetaData;
34 import org.jboss.system.metadata.ServiceAttributeMetaData;
35 import org.jboss.system.metadata.ServiceConstructorMetaData;
36 import org.jboss.system.metadata.ServiceInjectionValueMetaData;
37 import org.jboss.system.metadata.ServiceMetaData;
38
39 /**
40  * RARDeployer.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 1.1 $
44  */

45 public class RARDeployer extends AbstractSimpleRealDeployer<ConnectorMetaData>
46 {
47    /** The work manager name */
48    private String JavaDoc workManagerName;
49    
50    /** The xa terminator name */
51    private String JavaDoc xaTerminatorName;
52    
53    /**
54     * Create a new RARDeployer.
55     * Set the relative order to COMPONENT_DEPLOYER+1 by default
56     */

57    public RARDeployer()
58    {
59       super(ConnectorMetaData.class);
60       setRelativeOrder(COMPONENT_DEPLOYER+1);
61    }
62
63    /**
64     * Get the workManagerName.
65     *
66     * @return the workManagerName.
67     */

68    public String JavaDoc getWorkManagerName()
69    {
70       return workManagerName;
71    }
72
73    /**
74     * Set the workManagerName.
75     *
76     * @param workManagerName the workManagerName.
77     */

78    public void setWorkManagerName(String JavaDoc workManagerName)
79    {
80       this.workManagerName = workManagerName;
81    }
82
83    /**
84     * Get the XATerminatorName.
85     *
86     * @return the xaTerminatorName.
87     */

88    public String JavaDoc getXATerminatorName()
89    {
90       return xaTerminatorName;
91    }
92
93    /**
94     * Set the XATerminatorName.
95     *
96     * @param xaTerminatorName the xaTerminatorName.
97     */

98    public void setXATerminatorName(String JavaDoc xaTerminatorName)
99    {
100       this.xaTerminatorName = xaTerminatorName;
101    }
102
103    protected String JavaDoc getObjectName(DeploymentUnit unit, ConnectorMetaData cmd)
104    {
105       // TODO this is a hack
106
DeploymentContext ctx = unit.getDeploymentContext();
107       String JavaDoc name = ctx.getRoot().getName();
108       ctx = ctx.getParent();
109       while (ctx != null)
110       {
111          name = ctx.getRoot().getName() + "#" + name;
112          ctx = ctx.getParent();
113       }
114       return "jboss.jca:service=RARDeployment,name='" + name + "'";
115    }
116    
117    public void deploy(DeploymentUnit unit, ConnectorMetaData cmd) throws DeploymentException
118    {
119       try
120       {
121          ServiceMetaData rarDeployment = new ServiceMetaData();
122          String JavaDoc name = getObjectName(unit, cmd);
123          ObjectName JavaDoc objectName = new ObjectName JavaDoc(name);
124          rarDeployment.setObjectName(objectName);
125          rarDeployment.setCode(RARDeployment.class.getName());
126          ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
127          constructor.setSignature(new String JavaDoc[] { ConnectorMetaData.class.getName() });
128          constructor.setParameters(new Object JavaDoc[] { cmd });
129          rarDeployment.setConstructor(constructor);
130          
131          List JavaDoc<ServiceAttributeMetaData> attributes = new ArrayList JavaDoc<ServiceAttributeMetaData>();
132          ServiceAttributeMetaData attribute = null;
133          if (workManagerName != null)
134          {
135             attribute = new ServiceAttributeMetaData();
136             attribute.setName("WorkManager");
137             attribute.setValue(new ServiceInjectionValueMetaData(workManagerName));
138             attributes.add(attribute);
139          }
140          if (xaTerminatorName != null)
141          {
142             attribute = new ServiceAttributeMetaData();
143             attribute.setName("XATerminator");
144             attribute.setValue(new ServiceInjectionValueMetaData(xaTerminatorName, "XATerminator"));
145             attributes.add(attribute);
146          }
147          if (attributes.isEmpty() == false)
148             rarDeployment.setAttributes(attributes);
149
150          // TODO component
151
unit.addAttachment(ServiceMetaData.class, rarDeployment);
152       }
153       catch (Exception JavaDoc e)
154       {
155          throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e);
156       }
157    }
158
159    public void undeploy(DeploymentUnit unit, ConnectorMetaData cmd)
160    {
161    }
162 }
163
Popular Tags