1 22 package org.jboss.varia.deployment.convertor; 23 24 import java.io.File ; 25 import java.util.Properties ; 26 import java.util.jar.JarFile ; 27 import java.net.URL ; 28 29 import javax.management.JMException ; 30 import javax.management.ObjectName ; 31 32 import org.jboss.deployment.DeploymentInfo; 33 import org.jboss.system.ServiceMBeanSupport; 34 35 36 52 public class WebLogicConvertor 53 extends ServiceMBeanSupport 54 implements Convertor, WebLogicConvertorMBean 55 { 56 58 private String deployerName; 59 60 61 private String wlVersion; 62 63 64 private String removeTable; 65 66 67 private String datasource; 68 69 70 private String datasourceMapping; 71 72 73 private Properties xslParams; 74 75 79 public String getDeployer() 80 { 81 return deployerName; 82 } 83 86 public void setDeployer( String name ) 87 { 88 if( deployerName != null && name!= null && deployerName != name ) 89 { 90 try 92 { 93 server.invoke( 94 new ObjectName ( deployerName ), 95 "removeConvertor", 96 new Object [] { this }, 97 new String [] { this.getClass().getName() } 98 ); 99 } 100 catch( JMException jme ) { } 101 } 102 if( name != null ) deployerName = name; 103 } 104 105 108 public String getWlVersion() 109 { 110 return wlVersion; 111 } 112 115 public void setWlVersion( String wlVersion ) 116 { 117 this.wlVersion = wlVersion; 118 } 119 120 123 public String getRemoveTable() 124 { 125 return removeTable; 126 } 127 130 public void setRemoveTable( String removeTable ) 131 { 132 this.removeTable = removeTable; 133 } 134 135 138 public String getDatasource() 139 { 140 return datasource; 141 } 142 145 public void setDatasource( String datasource ) 146 { 147 this.datasource = datasource; 148 } 149 150 153 public String getDatasourceMapping() 154 { 155 return datasourceMapping; 156 } 157 160 public void setDatasourceMapping( String datasourceMapping ) 161 { 162 this.datasourceMapping = datasourceMapping; 163 } 164 165 public void startService() 167 { 168 try 169 { 170 initXslParams(); 172 173 server.invoke( 174 new ObjectName (deployerName), 175 "addConvertor", 176 new Object [] { this }, 177 new String [] { Convertor.class.getName() } 178 ); 179 } 180 catch( JMException jme ) 181 { 182 log.error( "Caught exception during startService()", jme ); 183 } 184 } 185 186 public void stopService() 187 { 188 if(deployerName != null) 189 { 190 try { 192 server.invoke( 193 new ObjectName (deployerName), 194 "removeConvertor", 195 new Object [] { this }, 196 new String [] { this.getClass().getName() } 197 ); 198 } 199 catch( JMException jme ) 200 { 201 } 203 } 204 } 205 206 214 public boolean accepts(URL url) 215 { 216 String stringUrl = url.toString(); 217 JarFile jarFile = null; 218 boolean accepted = false; 219 try 220 { 221 jarFile = new JarFile (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 e) 229 { 230 log.debug("Couldn't create JarFile for " + url.getPath(), e); 231 return false; 232 } 233 234 return accepted; 235 } 236 237 244 public void convert(DeploymentInfo di, File path) 245 throws Exception 246 { 247 Properties xslParams = getXslParams(); 248 JarTransformer.transform(path, xslParams); 249 } 250 251 255 public Properties getXslParams() 256 { 257 if(xslParams == null) 258 { 259 log.warn("xmlParams should have been initialized!"); 260 xslParams = initXslParams(); 261 } 262 263 xslParams.setProperty("resources_path", "resources/" + wlVersion + "/"); 265 266 xslParams.setProperty("remove-table", removeTable); 268 269 xslParams.setProperty("datasource", datasource); 271 272 xslParams.setProperty("datasource-mapping", datasourceMapping); 274 275 return xslParams; 276 } 277 278 282 private Properties initXslParams() 283 { 284 xslParams = new Properties (); 285 286 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 287 288 URL url = cl.getResource( "standardjboss.xml" ); 290 if( url != null ) 291 xslParams.setProperty( "standardjboss", 292 new File ( url.getFile()).getAbsolutePath() ); 293 else log.debug( "standardjboss.xml not found." ); 294 295 url = cl.getResource( "standardjbosscmp-jdbc.xml" ); 297 if( url != null ) 298 xslParams.setProperty( "standardjbosscmp-jdbc", 299 new File ( 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 |