[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-cvs-commits
Subject:    [jboss-cvs] contrib/varia/src/main/org/jboss/varia/deployment/convertor JarTransformer.java WebLogic
From:       Alexey Loubyansky <loubyansky () users ! sourceforge ! net>
Date:       2004-01-31 21:34:19
Message-ID: E1An2kt-0000DV-9T () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

  User: loubyansky
  Date: 04/01/31 13:34:19

  Modified:    varia/src/main/org/jboss/varia/deployment/convertor Tag:
                        Branch_3_2 JarTransformer.java
                        WebLogicConvertor.java XslTransformer.java
  Log:
  hardcoded the target JBoss DD names instead of putting them into -output.properties \
files  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.4   +77 -90    \
contrib/varia/src/main/org/jboss/varia/deployment/convertor/JarTransformer.java  
  Index: JarTransformer.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/deployment/convertor/JarTransformer.java,v
  retrieving revision 1.4.2.3
  retrieving revision 1.4.2.4
  diff -u -r1.4.2.3 -r1.4.2.4
  --- JarTransformer.java	4 Nov 2003 15:15:25 -0000	1.4.2.3
  +++ JarTransformer.java	31 Jan 2004 21:34:18 -0000	1.4.2.4
  @@ -9,7 +9,6 @@
   import java.io.ByteArrayInputStream;

   import java.io.ByteArrayOutputStream;

   import java.io.File;

  -import java.io.FileFilter;

   import java.io.FileInputStream;

   import java.io.FileOutputStream;

   import java.io.InputStream;

  @@ -18,6 +17,7 @@
   import java.util.Properties;

   

   import org.jboss.logging.Logger;

  +import org.jboss.deployment.DeploymentException;

   

   import javax.xml.transform.dom.DOMSource;

   

  @@ -44,6 +44,7 @@
    *      Jar entry name

    *

    * @author <a href="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>

  + * @version $Revision: 1.4.2.4 $

    */

   public class JarTransformer

   {

  @@ -63,103 +64,89 @@
         File metaInf = new File(root, "META-INF");

         if(!metaInf.exists())

         {

  -         return;

  -         //throw new Exception("No META-INF directory found");

  +         throw new DeploymentException("No META-INF directory found");

         }

   

         // set path to ejb-jar.xml in xslParams

         File ejbjar = new File(metaInf, "ejb-jar.xml");

  -      if(ejbjar.exists())

  -         xslParams.setProperty("ejb-jar-xml", ejbjar.getAbsolutePath());

  -

  -      // list only xml files.

  -      // Note: returns null only if the path name isn't a directory

  -      // or I/O exception occured

  -      File[] files = metaInf.listFiles(

  -        new FileFilter()

  -        {

  -           public boolean accept(File file)

  -           {

  -              if( file.getName().endsWith( ".xml" )

  -                 && !file.isDirectory() )

  -                 return true;

  -              return false;

  -           }

  -        }

  -      );

  -

  -      log.debug("list XML files: " + java.util.Arrays.asList(files));

  -      for(int i = 0; i < files.length; i++)

  -      {

  -         File file = files[i];

  -

  -         // construct names for transformation resources

  -         String xmlName = file.getName();

  -         String xslName = xslParams.getProperty("resources_path")

  -                          + xmlName.substring(0, xmlName.length() - 3)

  -                          + "xsl";

  -         String propsName = xslParams.getProperty("resources_path")

  -                            + xmlName.substring(0, xmlName.length() - 4)

  -                            + "-output.properties";

  -

  -         // try to find XSL template and open InputStream on it

  -         InputStream templateIs = null;

  -         try

  -         {

  -            templateIs = JarTransformer.class.getClassLoader().

  -               getResource(xslName).openStream();

  -         }

  -         catch( Exception e )

  -         {

  -            log.debug("xsl template wasn't found for '" + xmlName + "'");

  -            continue;

  -         }

  -

  -         log.debug("Attempt to transform '" + xmlName + "' with '" + xslName + \
"'");

  -

  -         // try to load output properties

  -         Properties outputProps = loadProperties( propsName );

  -

  -         // transform Jar entry and write transformed data to result

  -         InputStream input = null;

  -         OutputStream output = null;

  -         try

  -         {

  -            // transformation closes the input stream, so read entry to byte[]

  -            input = new FileInputStream(file);

  -            byte[] bytes = readBytes(input);

  -            input.close();

  -            bytes = transformBytes(bytes, templateIs, outputProps, xslParams);

  -

  -            // Determine the new name for the transformed entry

  -            String entryname = null;

  -            if(outputProps != null)

  -               entryname = outputProps.getProperty("newname");

  -            if(entryname == null)

  -               entryname = file.getName();

  -

  -            output = new FileOutputStream(new File(root, entryname));

  -            writeBytes( output, bytes );

  -

  -            log.debug("Entry '" + file.getName() + "' transformed to '" + \
entryname + "'");

  -         }

  -         catch(Exception e)

  -         {

  -            log.debug("Exception while transforming entry '" + file.getName(), e);

  -         }

  -         finally

  -         {

  -            if(templateIs != null)

  -               try{ templateIs.close(); } catch(Exception e) {}

  -            if(input != null)

  -               try{ input.close(); } catch(Exception e) {}

  -            if(output != null)

  -               try{ output.close(); } catch(Exception e) {}

  -         }

  +      if(!ejbjar.exists())

  +      {

  +         throw new DeploymentException("ejb-jar.xml not found.");

         }

  +      xslParams.setProperty("ejb-jar-xml", ejbjar.getAbsolutePath());

  +

  +      File weblogicEjbJar = new File(metaInf, "weblogic-ejb-jar.xml");

  +      transformDD(xslParams, weblogicEjbJar, root, "META-INF/jboss.xml");

  +

  +      File weblogicCmp = new File(metaInf, "weblogic-cmp-rdbms-jar.xml");

  +      transformDD(xslParams, weblogicCmp, root, "META-INF/jbosscmp-jdbc.xml");

      }

   

      // Private static methods ------------------------------------------

  +

  +   private static void transformDD(Properties xslParams, File file, File root, \
String tgtName)

  +      throws DeploymentException

  +   {

  +      final String srcName = file.getName();

  +

  +      // construct names for transformation resources

  +      String xmlName = srcName;

  +      String xslName = xslParams.getProperty("resources_path")

  +                       + xmlName.substring(0, xmlName.length() - 3)

  +                       + "xsl";

  +      String propsName = xslParams.getProperty("resources_path")

  +                         + xmlName.substring(0, xmlName.length() - 4)

  +                         + "-output.properties";

  +

  +      // try to find XSL template and open InputStream on it

  +      InputStream templateIs = null;

  +      try

  +      {

  +         templateIs = JarTransformer.class.getClassLoader().

  +            getResource(xslName).openStream();

  +      }

  +      catch( Exception e )

  +      {

  +         log.debug("xsl template wasn't found for '" + xmlName + "'");

  +         return;

  +      }

  +

  +      log.debug("Attempt to transform '" + xmlName + "' with '" + xslName + "'");

  +

  +      // try to load output properties

  +      Properties outputProps = loadProperties( propsName );

  +

  +      // transform Jar entry and write transformed data to result

  +      InputStream input = null;

  +      OutputStream output = null;

  +      try

  +      {

  +         // transformation closes the input stream, so read entry to byte[]

  +         input = new FileInputStream(file);

  +         byte[] bytes = readBytes(input);

  +         input.close();

  +         bytes = transformBytes(bytes, templateIs, outputProps, xslParams);

  +

  +         output = new FileOutputStream(new File(root, tgtName));

  +         writeBytes( output, bytes );

  +

  +         log.debug("Entry '" + srcName + "' transformed to '" + tgtName + "'");

  +      }

  +      catch(Exception e)

  +      {

  +         log.debug("Exception while transforming entry '" + srcName, e);

  +      }

  +      finally

  +      {

  +         if(templateIs != null)

  +            try{ templateIs.close(); } catch(Exception e) {}

  +         if(input != null)

  +            try{ input.close(); } catch(Exception e) {}

  +         if(output != null)

  +            try{ output.close(); } catch(Exception e) {}

  +      }

  +   }

  +

      /**

       * Searches for, loads and returns properties from file

       * <code>propsName</code>

  
  
  
  1.4.2.5   +62 -52    \
contrib/varia/src/main/org/jboss/varia/deployment/convertor/WebLogicConvertor.java  
  Index: WebLogicConvertor.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/deployment/convertor/WebLogicConvertor.java,v
  retrieving revision 1.4.2.4
  retrieving revision 1.4.2.5
  diff -u -r1.4.2.4 -r1.4.2.5
  --- WebLogicConvertor.java	10 Nov 2003 05:42:30 -0000	1.4.2.4
  +++ WebLogicConvertor.java	31 Jan 2004 21:34:18 -0000	1.4.2.5
  @@ -43,7 +43,7 @@
    *
    * @author <a href="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>
    * @author <a href="mailto:andreas@jboss.org">Andreas Schaefer</a>
  - * @version $Revision: 1.4.2.4 $
  + * @version $Revision: 1.4.2.5 $
    *
    * <p><b>20020519 Andreas Schaefer:</b>
    * <ul>
  @@ -388,7 +388,7 @@
               outputProps,
               null
            );
  -         XslTransformer.domToFile(result, root, outputProps);
  +         XslTransformer.domToFile(result, new File(root, "META-INF/jboss.xml"), \
outputProps);  
            //
            // cmp-rdbms DDs
  @@ -402,66 +402,75 @@
   
            Document ejbJarDoc = builder.parse(ejbJarXml);
            NodeList entityList = ejbJarDoc.getElementsByTagName("entity");
  -         if(entityList.getLength() == 0)
  -         {
  -            log.error("NO ENTITIES IN EJB-JAR.XML!!!");
  -         }
  -
  -         Map params = new HashMap(2);
  -         params.put("ejb-jar-xml", ejbJarXml.getAbsolutePath());
   
  -         File weblogicCmpRdbmsJarXml = getDDFile(root, \
                "weblogic-cmp-rdbms-jar.xml", false);
  -         if(weblogicCmpRdbmsJarXml.exists())
  +         int entitiesTotal = entityList.getLength();
  +         if(entitiesTotal > 0)
            {
  -            log.debug("Transforming " + weblogicCmpRdbmsJarXml);
  +            int transformedTotal = 0;
   
  -            Node entity = entityList.item(0);
  -            String remote = getRemote(entity);
  -            params.put("remote", remote);
  +            Map params = new HashMap(2);
  +            params.put("ejb-jar-xml", ejbJarXml.getAbsolutePath());
   
  -            log.debug("remote: " + remote);
  -
  -            XslTransformer.transform(
  -               weblogicCmpRdbmsJarXml,
  -               "resources/5.1/weblogic-cmp-rdbms-jar.xsl",
  -               params,
  -               null,
  -               enterpriseBeans
  -            );
  -         }
  -         else
  -         {
  -            // no weblogic-cmp-rdbms-jar.xml -> look for files \
                <remote-interface>-cmp-rdbms.xml
  -            for(int entityInd = 0; entityInd < entityList.getLength(); \
++entityInd)  +            File weblogicCmpRdbmsJarXml = getDDFile(root, \
"weblogic-cmp-rdbms-jar.xml", false);  +            \
if(weblogicCmpRdbmsJarXml.exists())  {
  -               Node entity = entityList.item(entityInd);
  +               log.debug("Transforming " + weblogicCmpRdbmsJarXml);
  +
  +               Node entity = entityList.item(0);
                  String remote = getRemote(entity);
  -               int lastDot = remote.lastIndexOf('.');
  -               String shortRemote = (lastDot > -1 ? remote.substring(lastDot + 1) \
: remote);  +               params.put("remote", remote);
   
  -               String ddName = shortRemote + "-cmp-rdbms.xml";
  -               File ddFile = getDDFile(root, ddName, false);
  -               if(ddFile.exists())
  -               {
  -                  log.debug("processing " + ddFile.getName());
  -                  params.put("remote", remote);
  -                  XslTransformer.transform(
  -                     ddFile,
  -                     "resources/5.1/weblogic-cmp-rdbms-jar.xsl",
  -                     params,
  -                     null,
  -                     enterpriseBeans
  -                  );
  -               }
  -               else
  +               log.debug("remote: " + remote);
  +
  +               XslTransformer.transform(
  +                  weblogicCmpRdbmsJarXml,
  +                  "resources/5.1/weblogic-cmp-rdbms-jar.xsl",
  +                  params,
  +                  null,
  +                  enterpriseBeans
  +               );
  +
  +               transformedTotal = 1;
  +            }
  +            else
  +            {
  +               // no weblogic-cmp-rdbms-jar.xml -> look for files \
<remote-interface>-cmp-rdbms.xml  +               for(int entityInd = 0; entityInd < \
entityList.getLength(); ++entityInd)  {
  -                  log.warn("NO " + ddName + " was found.");
  +                  Node entity = entityList.item(entityInd);
  +                  String remote = getRemote(entity);
  +                  int lastDot = remote.lastIndexOf('.');
  +                  String shortRemote = (lastDot > -1 ? remote.substring(lastDot + \
1) : remote);  +
  +                  String ddName = shortRemote + "-cmp-rdbms.xml";
  +                  File ddFile = getDDFile(root, ddName, false);
  +                  if(ddFile.exists())
  +                  {
  +                     log.debug("processing " + ddFile.getName());
  +                     params.put("remote", remote);
  +                     XslTransformer.transform(
  +                        ddFile,
  +                        "resources/5.1/weblogic-cmp-rdbms-jar.xsl",
  +                        params,
  +                        null,
  +                        enterpriseBeans
  +                     );
  +
  +                     ++transformedTotal;
  +                  }
  +                  else
  +                  {
  +                     log.warn("NO " + ddName + " was found.");
  +                  }
                  }
               }
  -         }
   
  -         outputProps = \
                loadProperties("resources/5.1/weblogic-cmp-rdbms-jar-output.properties");
                
  -         XslTransformer.domToFile(doc, root, outputProps);
  +            if(transformedTotal > 0)
  +            {
  +               outputProps = \
loadProperties("resources/5.1/weblogic-cmp-rdbms-jar-output.properties");  +          \
XslTransformer.domToFile(doc, new File(root, "META-INF/jbosscmp-jdbc.xml"), \
outputProps);  +            }
  +         }
         }
   
         private String getRemote(Node entity)
  @@ -530,12 +539,13 @@
            "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB RDBMS Persistence//EN";
         private static final String WEBLOGIC_EJB_JAR_510 =
            "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN";
  -      private static final String SUN_EJB_20=
  +      private static final String SUN_EJB_20 =
            "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN";
         private static final String SUN_EJB_11 =
            "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";
   
         private static final Map DTD_BY_ID = new HashMap(3);
  +
         static
         {
            String base51 = "resources/5.1/";
  
  
  
  1.3.2.4   +2 -1      \
contrib/varia/src/main/org/jboss/varia/deployment/convertor/XslTransformer.java  
  Index: XslTransformer.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/deployment/convertor/XslTransformer.java,v
  retrieving revision 1.3.2.3
  retrieving revision 1.3.2.4
  diff -u -r1.3.2.3 -r1.3.2.4
  --- XslTransformer.java	4 Nov 2003 15:15:25 -0000	1.3.2.3
  +++ XslTransformer.java	31 Jan 2004 21:34:18 -0000	1.3.2.4
  @@ -40,6 +40,7 @@
    * XslTransformer is a utility class for XSL transformations.

    *

    * @author <a href="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>

  + * @version $Revision: 1.3.2.4 $

    */

   public class XslTransformer

   {

  @@ -100,7 +101,7 @@
         transformer.setOutputProperties(outputProps);

   

         Source src = new DOMSource(node);

  -      OutputStream out = new FileOutputStream(new File(dest, \
outputProps.getProperty("newname")));

  +      OutputStream out = new FileOutputStream(dest);

         try

         {

            transformer.transform(src, new StreamResult(out));

  
  
  


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic