Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 179   Methods: 4
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DDCreatorHelper.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights 
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.ejb;
 55   
 
 56   
 import java.io.File;
 57   
 import java.io.FileInputStream;
 58   
 import java.io.ObjectInputStream;
 59   
 import javax.ejb.deployment.DeploymentDescriptor;
 60   
 
 61   
 /**
 62   
  * A helper class which performs the actual work of the ddcreator task.
 63   
  *
 64   
  * This class is run with a classpath which includes the weblogic tools and the home and remote
 65   
  * interface class files referenced in the deployment descriptors being built.
 66   
  *
 67   
  * @author Conor MacNeill, Cortex ebusiness Pty Limited
 68   
  */
 69   
 public class DDCreatorHelper {
 70   
     /**
 71   
      * The root directory of the tree containing the textual deployment desciptors. 
 72   
      */
 73   
     private File descriptorDirectory;
 74   
     
 75   
     /**
 76   
      * The directory where generated serialised desployment descriptors are written.
 77   
      */
 78   
     private File generatedFilesDirectory;
 79   
 
 80   
     /**
 81   
      * The descriptor text files for which a serialised descriptor is to be created.
 82   
      */
 83   
     String[] descriptors; 
 84   
 
 85   
     /**
 86   
      * The main method.
 87   
      *
 88   
      * The main method creates an instance of the DDCreatorHelper, passing it the 
 89   
      * args which it then processes.
 90   
      */    
 91  0
     public static void main(String[] args) throws Exception {
 92  0
         DDCreatorHelper helper = new DDCreatorHelper(args);
 93  0
         helper.process();
 94   
     }
 95   
   
 96   
     /**
 97   
      * Initialise the helper with the command arguments.
 98   
      *
 99   
      */
 100  0
     private DDCreatorHelper(String[] args) {
 101  0
         int index = 0;
 102  0
         descriptorDirectory = new File(args[index++]);
 103  0
         generatedFilesDirectory = new File(args[index++]);
 104   
         
 105  0
         descriptors = new String[args.length - index];
 106  0
         for (int i = 0; index < args.length; ++i) {
 107  0
             descriptors[i] = args[index++];
 108   
         }
 109   
     }
 110   
     
 111   
     /**
 112   
      * Do the actual work.
 113   
      *
 114   
      * The work proceeds by examining each descriptor given. If the serialised
 115   
      * file does not exist or is older than the text description, the weblogic
 116   
      * DDCreator tool is invoked directly to build the serialised descriptor.
 117   
      */    
 118  0
     private void process() throws Exception {
 119  0
         for (int i = 0; i < descriptors.length; ++i) {
 120  0
             String descriptorName = descriptors[i];
 121  0
             File descriptorFile = new File(descriptorDirectory, descriptorName);
 122   
 
 123  0
             int extIndex = descriptorName.lastIndexOf(".");
 124  0
             String serName = null;
 125  0
             if (extIndex != -1) {
 126  0
                 serName = descriptorName.substring(0, extIndex) + ".ser";
 127   
             } else {
 128  0
                 serName = descriptorName + ".ser";
 129   
             }
 130  0
             File serFile = new File(generatedFilesDirectory, serName);
 131   
                 
 132   
             // do we need to regenerate the file
 133  0
             if (!serFile.exists() || serFile.lastModified() < descriptorFile.lastModified()
 134   
                 || regenerateSerializedFile(serFile)) {
 135   
                 
 136  0
                 String[] args = {"-noexit", 
 137   
                                  "-d", serFile.getParent(),
 138   
                                  "-outputfile", serFile.getName(),
 139   
                                  descriptorFile.getPath()};
 140  0
                 try {
 141  0
                     weblogic.ejb.utils.DDCreator.main(args);
 142   
                 } catch (Exception e) {
 143   
                     // there was an exception - run with no exit to get proper error
 144  0
                     String[] newArgs = {"-d", generatedFilesDirectory.getPath(),
 145   
                                  "-outputfile", serFile.getName(),
 146   
                                  descriptorFile.getPath()};
 147  0
                     weblogic.ejb.utils.DDCreator.main(newArgs);
 148   
                 }
 149   
             }
 150   
         }
 151   
     }
 152   
 
 153   
     /**
 154   
      * EJBC will fail if the serialized descriptor file does not match the bean classes.
 155   
      * You can test for this by trying to load the deployment descriptor.  If it fails,
 156   
      * the serialized file needs to be regenerated because the associated class files
 157   
      * don't match.
 158   
      */
 159  0
     private boolean regenerateSerializedFile(File serFile) {
 160  0
         try {
 161   
 
 162  0
             FileInputStream fis = new FileInputStream(serFile);
 163  0
             ObjectInputStream ois = new ObjectInputStream(fis);
 164  0
             DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject();
 165  0
             fis.close();
 166   
 
 167   
             // Since the descriptor read properly, everything should be o.k.
 168  0
             return false;
 169   
 
 170   
         } catch (Exception e) {
 171   
             
 172   
             // Weblogic will throw an error if the deployment descriptor does 
 173   
             // not match the class files.
 174  0
             return true;
 175   
 
 176   
         }
 177   
     }
 178   
 }
 179