Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 113   Methods: 6
NCLOC: 84   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
ValidateTask.java 0% 0% 0% 0%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.ant;
 11   
 
 12   
 import java.io.File;
 13   
 import java.net.URL;
 14   
 import java.util.ArrayList;
 15   
 import java.util.Iterator;
 16   
 
 17   
 import org.apache.tools.ant.BuildException;
 18   
 import org.apache.tools.ant.DirectoryScanner;
 19   
 import org.apache.tools.ant.Task;
 20   
 import org.apache.tools.ant.types.FileSet;
 21   
 import org.jbind.xml.facade.JBindFacade;
 22   
 import org.jbind.xml.instance.builder.DataContext;
 23   
 import org.jbind.xml.instance.builder.IImplBuilder;
 24   
 import org.jbind.xml.msg.IConstraintViolations;
 25   
 import org.jbind.xml.msg.XmlMessages;
 26   
 import org.jbind.xml.schema.cmp.Schemas;
 27   
 import org.jbind.xml.schema.instantiation.ISchemaReader;
 28   
 
 29   
 public class ValidateTask extends Task {
 30   
 
 31   
   private File myFile = null;
 32   
   private String myUrl = null;
 33   
   private Boolean myIsXsd = null;
 34   
   private Boolean myUseSharedDataContext = Boolean.FALSE;
 35   
   private ArrayList myFileSets = new ArrayList();
 36   
 
 37  0
   public void setFile(File aFile) {
 38  0
     myFile = aFile;
 39   
   }
 40  0
   public void setUrl(String aUrl) {
 41  0
     myUrl = aUrl;
 42   
   }
 43  0
   public void setIsXsd(Boolean aBoolean) {
 44  0
     myIsXsd = aBoolean;
 45   
   }
 46   
 
 47  0
   public void addFileset(FileSet aFileSet) {
 48  0
     myFileSets.add(aFileSet);
 49   
   }
 50   
 
 51  0
   public void setUseSharedDataContext(Boolean aBoolean) {
 52  0
     myUseSharedDataContext = aBoolean;
 53   
   }
 54   
 
 55  0
   public void execute() throws BuildException {
 56  0
     IConstraintViolations violations = XmlMessages.constraintViolations();
 57   
 
 58  0
     try {
 59   
 
 60   
       // collect the URLs
 61   
 
 62  0
       ArrayList urls = new ArrayList();
 63  0
       if (null != myFile) {
 64  0
         urls.add(myFile.toURL());
 65   
       }
 66  0
       if (null != myUrl) {
 67  0
         urls.add(new URL(myUrl));
 68   
       }
 69   
 
 70  0
       for (Iterator i = myFileSets.iterator(); i.hasNext(); ) {
 71  0
         FileSet fs = (FileSet)i.next();
 72  0
         DirectoryScanner ds = fs.getDirectoryScanner(project);
 73  0
         File baseDir = ds.getBasedir();
 74  0
         String[] files = ds.getIncludedFiles();
 75  0
         for (int idx = 0; idx < files.length; idx++) {
 76  0
           File f = new File(baseDir, files[idx]);
 77  0
           urls.add(f.toURL());
 78   
         }
 79   
       }
 80   
 
 81  0
       DataContext dataContext = null;
 82  0
       if (myUseSharedDataContext.booleanValue()) {
 83  0
         dataContext = new DataContext(true);
 84   
       }
 85   
 
 86  0
       for (int i = 0; i < urls.size(); i++) {
 87  0
         IConstraintViolations v = XmlMessages.constraintViolations();
 88  0
         URL url = (URL)urls.get(i);
 89  0
         Schemas.getInstance().reset();
 90  0
         if (((myIsXsd != null) && myIsXsd.booleanValue()) || ((myIsXsd == null) && url.toString().endsWith(".xsd"))) {
 91  0
           ISchemaReader reader = JBindFacade.createSchemaReader();
 92  0
           reader.readSchema(url, true, null);
 93   
         } else {
 94  0
           IImplBuilder builder = JBindFacade.createImplBuilder(dataContext, true);
 95  0
           builder.buildDocument(url);
 96   
         }
 97  0
         if (!v.isEmpty()) {
 98  0
           violations.add(v);
 99   
         }
 100   
       }
 101   
 
 102   
     } catch (Exception e) {
 103  0
       throw new BuildException(e, location);
 104   
     }
 105   
 
 106  0
     if (!violations.isEmpty()) {
 107  0
       throw new BuildException(violations.output(null, false, false), location);
 108   
     }
 109   
 
 110   
   }
 111   
 
 112   
 }
 113