~abone/+junk/schemaspy

« back to all changes in this revision

Viewing changes to src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java

  • Committer: johncurrier
  • Date: 2010-05-10 20:11:55 UTC
  • Revision ID: svn-v4:e86a8a9b-1e1f-0410-8769-81452b7583c3:trunk:575
Implementation of feature request #2999566 - provide verbose details of program flow

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import java.io.InputStream;
6
6
import java.util.ArrayList;
7
7
import java.util.List;
 
8
import java.util.logging.Logger;
8
9
import javax.xml.XMLConstants;
9
10
import javax.xml.parsers.DocumentBuilder;
10
11
import javax.xml.parsers.DocumentBuilderFactory;
23
24
import org.xml.sax.SAXException;
24
25
 
25
26
/**
 
27
 * Additional metadata about a schema as expressed in XML instead of from
 
28
 * the database.
 
29
 *
26
30
 * @author John Currier
27
31
 */
28
32
public class SchemaMeta {
29
33
    private final List<TableMeta> tables = new ArrayList<TableMeta>();
30
34
    private final String comments;
31
35
    private final File metaFile;
32
 
    
 
36
    private final Logger logger = Logger.getLogger(getClass().getName());
 
37
 
33
38
    public SchemaMeta(String xmlMeta, String dbName, String schema) throws InvalidConfigurationException {
34
39
        File meta = new File(xmlMeta);
35
40
        if (meta.isDirectory()) {
36
41
            String filename = (schema == null ? dbName : schema) + ".meta.xml";
37
42
            meta = new File(meta, filename);
38
 
            
 
43
 
39
44
            if (!meta.exists()) {
40
45
                if (Config.getInstance().isOneOfMultipleSchemas()) {
41
46
                    // don't force all of the "one of many" schemas to have metafiles
42
 
                    System.out.println("Meta directory \"" + xmlMeta + "\" should contain a file named \"" + filename + '\"');
 
47
                    logger.info("Meta directory \"" + xmlMeta + "\" should contain a file named \"" + filename + '\"');
43
48
                    comments = null;
44
49
                    metaFile = null;
45
50
                    return;
50
55
        } else if (!meta.exists()) {
51
56
            throw new InvalidConfigurationException("Specified meta file \"" + xmlMeta + "\" does not exist");
52
57
        }
53
 
        
 
58
 
54
59
        metaFile = meta;
55
 
        
 
60
 
56
61
        Document doc = parse(metaFile);
57
 
    
 
62
 
58
63
        NodeList commentsNodes = doc.getElementsByTagName("comments");
59
64
        if (commentsNodes != null && commentsNodes.getLength() > 0)
60
65
            comments = commentsNodes.item(0).getTextContent();
64
69
        NodeList tablesNodes = doc.getElementsByTagName("tables");
65
70
        if (tablesNodes != null) {
66
71
            NodeList tableNodes = ((Element)tablesNodes.item(0)).getElementsByTagName("table");
67
 
    
 
72
 
68
73
            for (int i = 0; i < tableNodes.getLength(); ++i) {
69
74
                Node tableNode = tableNodes.item(i);
70
75
                TableMeta tableMeta = new TableMeta(tableNode);
79
84
    public String getComments() {
80
85
        return comments;
81
86
    }
82
 
    
 
87
 
83
88
    public File getFile() {
84
89
        return metaFile;
85
90
    }
86
 
    
 
91
 
87
92
    public List<TableMeta> getTables() {
88
93
        return tables;
89
94
    }
90
 
    
 
95
 
91
96
    private void validate(Document document) throws SAXException, IOException {
92
97
        // create a SchemaFactory capable of understanding WXS schemas
93
98
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
103
108
        // validate the DOM tree
104
109
        validator.validate(new DOMSource(document));
105
110
    }
106
 
    
 
111
 
107
112
    private Document parse(File file) throws InvalidConfigurationException {
108
113
        DocumentBuilder docBuilder;
109
114
        Document doc = null;
111
116
        factory.setNamespaceAware(true);
112
117
        factory.setIgnoringElementContentWhitespace(true);
113
118
        factory.setIgnoringComments(true);
114
 
        
 
119
 
115
120
        try {
116
121
            docBuilder = factory.newDocumentBuilder();
117
122
        } catch (ParserConfigurationException exc) {