KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > deployment > convertor > WebLogicConvertor


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.varia.deployment.convertor;
23
24 import java.io.File JavaDoc;
25 import java.util.Properties JavaDoc;
26 import java.util.jar.JarFile JavaDoc;
27 import java.net.URL JavaDoc;
28
29 import javax.management.JMException JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31
32 import org.jboss.deployment.DeploymentInfo;
33 import org.jboss.system.ServiceMBeanSupport;
34
35
36 /**
37  * Converts WebLogic applications.
38  *
39  * @author <a HREF="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>
40  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
41  * @version $Revision: 37459 $
42  *
43  * <p><b>20020519 Andreas Schaefer:</b>
44  * <ul>
45  * <li>Creation</li>
46  * </ul>
47  *
48  * @jmx.mbean
49  * name="jboss.system:service=Convertor,type=WebLogic"
50  * extends="org.jboss.system.ServiceMBean"
51  */

52 public class WebLogicConvertor
53    extends ServiceMBeanSupport
54    implements Convertor, WebLogicConvertorMBean
55 {
56    // Attributes ---------------------------------------
57
/** the deployer name this converter is registered with */
58    private String JavaDoc deployerName;
59
60    /** the version of xsl resources to apply */
61    private String JavaDoc wlVersion;
62
63    /** remove-table value */
64    private String JavaDoc removeTable;
65
66    /** datasource name that will be set up for converted bean */
67    private String JavaDoc datasource;
68
69    /** the datasource mapping for the datasource */
70    private String JavaDoc datasourceMapping;
71
72    /** xsl parameters used in transformations */
73    private Properties JavaDoc xslParams;
74
75    // WebLogicConverter implementation -----------------
76
/**
77     * @jmx.managed-attribute
78     */

79    public String JavaDoc getDeployer()
80    {
81       return deployerName;
82    }
83    /**
84     * @jmx.managed-attribute
85     */

86    public void setDeployer( String JavaDoc name )
87    {
88       if( deployerName != null && name!= null && deployerName != name )
89       {
90          // Remove deployer
91
try
92          {
93             server.invoke(
94                new ObjectName JavaDoc( deployerName ),
95                "removeConvertor",
96                new Object JavaDoc[] { this },
97                new String JavaDoc[] { this.getClass().getName() }
98             );
99          }
100          catch( JMException JavaDoc jme ) { }
101       }
102       if( name != null ) deployerName = name;
103    }
104
105    /**
106     * @jmx.managed-attribute
107     */

108    public String JavaDoc getWlVersion()
109    {
110       return wlVersion;
111    }
112    /**
113     * @jmx.managed-attribute
114     */

115    public void setWlVersion( String JavaDoc wlVersion )
116    {
117       this.wlVersion = wlVersion;
118    }
119
120    /**
121     * @jmx.managed-attribute
122     */

123    public String JavaDoc getRemoveTable()
124    {
125       return removeTable;
126    }
127    /**
128     * @jmx.managed-attribute
129     */

130    public void setRemoveTable( String JavaDoc removeTable )
131    {
132       this.removeTable = removeTable;
133    }
134
135    /**
136     * @jmx.managed-attribute
137     */

138    public String JavaDoc getDatasource()
139    {
140       return datasource;
141    }
142    /**
143     * @jmx.managed-attribute
144     */

145    public void setDatasource( String JavaDoc datasource )
146    {
147       this.datasource = datasource;
148    }
149
150    /**
151     * @jmx.managed-attribute
152     */

153    public String JavaDoc getDatasourceMapping()
154    {
155       return datasourceMapping;
156    }
157    /**
158     * @jmx.managed-attribute
159     */

160    public void setDatasourceMapping( String JavaDoc datasourceMapping )
161    {
162       this.datasourceMapping = datasourceMapping;
163    }
164
165    // ServiceMBeanSupport overridding ------------------
166
public void startService()
167    {
168       try
169       {
170          // init xsl params first
171
initXslParams();
172
173          server.invoke(
174             new ObjectName JavaDoc(deployerName),
175             "addConvertor",
176             new Object JavaDoc[] { this },
177             new String JavaDoc[] { Convertor.class.getName() }
178          );
179       }
180       catch( JMException JavaDoc jme )
181       {
182          log.error( "Caught exception during startService()", jme );
183       }
184    }
185
186    public void stopService()
187    {
188       if(deployerName != null)
189       {
190          // Remove deployer
191
try {
192             server.invoke(
193                new ObjectName JavaDoc(deployerName),
194                "removeConvertor",
195                new Object JavaDoc[] { this },
196                new String JavaDoc[] { this.getClass().getName() }
197             );
198          }
199          catch( JMException JavaDoc jme )
200          {
201             // Ingore
202
}
203       }
204    }
205
206    // Converter implementation ----------------------------------------
207
/**
208     * Checks if the deployment can be converted to a JBoss deployment
209     * by this converter.
210     *
211     * @param url The url of deployment to be converted
212     * @return true if this converter is able to convert
213     */

214    public boolean accepts(URL JavaDoc url)
215    {
216       String JavaDoc stringUrl = url.toString();
217       JarFile JavaDoc jarFile = null;
218       boolean accepted = false;
219       try
220       {
221          jarFile = new JarFile JavaDoc(url.getPath());
222          accepted = (jarFile.getEntry("META-INF/weblogic-ejb-jar.xml" ) != null)
223             && (stringUrl.endsWith(".wlar") || (stringUrl.endsWith(".wl")))
224          || stringUrl.endsWith(".war.wl")
225          || stringUrl.endsWith(".ear.wl") ;
226          jarFile.close();
227       }
228       catch(Exception JavaDoc e)
229       {
230          log.debug("Couldn't create JarFile for " + url.getPath(), e);
231          return false;
232       }
233
234       return accepted;
235    }
236
237    /**
238     * Converts the necessary files to make the given deployment deployable
239     * on JBoss
240     *
241     * @param di The deployment to be converted
242     * @param path Path of the extracted deployment
243     **/

244    public void convert(DeploymentInfo di, File JavaDoc path)
245       throws Exception JavaDoc
246    {
247       Properties JavaDoc xslParams = getXslParams();
248       JarTransformer.transform(path, xslParams);
249    }
250
251    // Public -------------------------------------------
252
/**
253     * Returns the XSL parameters
254     */

255    public Properties JavaDoc getXslParams()
256    {
257       if(xslParams == null)
258       {
259          log.warn("xmlParams should have been initialized!");
260          xslParams = initXslParams();
261       }
262
263       // xsl resources path
264
xslParams.setProperty("resources_path", "resources/" + wlVersion + "/");
265
266       // set remove-table
267
xslParams.setProperty("remove-table", removeTable);
268
269       // datasource
270
xslParams.setProperty("datasource", datasource);
271
272       // datasource-mapping
273
xslParams.setProperty("datasource-mapping", datasourceMapping);
274
275       return xslParams;
276    }
277
278    // Private -------------------------------------------------------
279
/**
280     * Initializes XSL parameters
281     */

282    private Properties JavaDoc initXslParams()
283    {
284       xslParams = new Properties JavaDoc();
285
286       ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
287
288       // path to standardjboss.xml
289
URL JavaDoc url = cl.getResource( "standardjboss.xml" );
290       if( url != null )
291          xslParams.setProperty( "standardjboss",
292             new File JavaDoc( url.getFile()).getAbsolutePath() );
293       else log.debug( "standardjboss.xml not found." );
294
295       // path to standardjbosscmp-jdbc.xml
296
url = cl.getResource( "standardjbosscmp-jdbc.xml" );
297       if( url != null )
298          xslParams.setProperty( "standardjbosscmp-jdbc",
299             new File JavaDoc( url.getFile()).getAbsolutePath() );
300       else log.debug( "standardjbosscmp-jdbc.xml not found." );
301
302       log.debug( "initialized xsl parameters: " + xslParams );
303
304       return xslParams;
305    }
306 }
307
Popular Tags