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.ant;
    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.asyrinx.joey.gen.model.rdb.xml.XmlToRdb;
    18  import org.xml.sax.SAXException;
    19
    20  /***
    21   * @author takeshi
    22   */
    23  public class DatabasesLoaderImpl implements DatabasesLoader {
    24
    25      /***
    26       *
    27       */
    28      public DatabasesLoaderImpl(XmlToRdb xmlToRdb) {
    29          super();
    30          this.xmlToRdb = xmlToRdb;
    31      }
    32
    33      private final XmlToRdb xmlToRdb;
    34
    35      public Databases load(List filesets, Project project) throws IOException, SAXException {
    36          final Databases databases = new Databases();
    37          // Deal with the filesets.
    38          for (int i = 0; i < filesets.size(); i++) {
    39              final FileSet fs = (FileSet) filesets.get(i);
    40              final File srcDir = fs.getDir(project);
    41              final DirectoryScanner ds = fs.getDirectoryScanner(project);
    42              final String[] dataModelFiles = ds.getIncludedFiles();
    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          return xmlToRdb.load(filename);
    54      }
    55
    56  }