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 File srcDir = fs.getDir(project);
    40              final DirectoryScanner ds = fs.getDirectoryScanner(project);
    41              final String[] dataModelFiles = ds.getIncludedFiles();
    42              for (int j = 0; j < dataModelFiles.length; j++) {
    43                  final File f = new File(srcDir, dataModelFiles[j]);
    44                  final Databases loaded = loadModelXmlFile(f.toString());
    45                  databases.appendDatabases(loaded);
    46              }
    47          }
    48          return databases;
    49      }
    50
    51      protected Databases loadModelXmlFile(String filename) throws IOException, SAXException {
    52          return xmlToRdb.load(filename);
    53      }
    54
    55  }