View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2004/12/12 14:59:03
    6    */
    7   package org.asyrinx.joey.gen.model.rdb.xml;
    8
    9   import java.io.File;
    10  import java.io.IOException;
    11  import java.util.List;
    12
    13  import org.apache.tools.ant.DirectoryScanner;
    14  import org.apache.tools.ant.Project;
    15  import org.apache.tools.ant.types.FileSet;
    16  import org.asyrinx.joey.gen.model.rdb.Databases;
    17  import org.xml.sax.SAXException;
    18
    19  /***
    20   * @author takeshi
    21   */
    22  public class DatabasesLoaderImpl implements DatabasesLoader {
    23
    24      /***
    25       *
    26       */
    27      public DatabasesLoaderImpl(XmlToRdb xmlToRdb) {
    28          super();
    29          this.xmlToRdb = xmlToRdb;
    30      }
    31
    32      private final XmlToRdb xmlToRdb;
    33
    34      public Databases load(List filesets, Project project) throws IOException, SAXException {
    35          final Databases databases = new Databases();
    36          // Deal with the filesets.
    37          for (int i = 0; i < filesets.size(); i++) {
    38              final FileSet fs = (FileSet) filesets.get(i);
    39              final DirectoryScanner ds = fs.getDirectoryScanner(project);
    40              final File srcDir = fs.getDir(project);
    41              final String[] dataModelFiles = ds.getIncludedFiles();
    42              // Make a transaction for each file
    43              for (int j = 0; j < dataModelFiles.length; j++) {
    44                  final File f = new File(srcDir, dataModelFiles[j]);
    45                  final Databases loaded = loadModelXmlFile(f.toString());
    46                  databases.appendDatabases(loaded);
    47              }
    48          }
    49          return databases;
    50      }
    51
    52      protected Databases loadModelXmlFile(String filename) throws IOException, SAXException {
    53          //final XmlToRdbImpl xmlToRdb = new XmlToRdbImpl();
    54          //xmlToRdb.setDebug("true".equals(getContextProperties().getString("schemaDebug")));
    55          return xmlToRdb.load(filename);
    56      }
    57
    58  }