Skip to content

Commit

Permalink
Give warning messages for unknown XML metadata attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Aug 22, 2008
1 parent f51ce42 commit 167718f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/net/sourceforge/schemaspy/model/xml/ForeignKeyMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,27 @@ public class ForeignKeyMeta {

ForeignKeyMeta(Node foreignKeyNode) {
NamedNodeMap attribs = foreignKeyNode.getAttributes();
Node node = attribs.getNamedItem("table");
if (node == null)
throw new IllegalStateException("XML foreignKey definition requires 'table' attribute");
tableName = node.getNodeValue();
attribs.removeNamedItem("table");
node = attribs.getNamedItem("column");
if (node == null)
throw new IllegalStateException("XML foreignKey definition requires 'column' attribute");
columnName = node.getNodeValue();
attribs.removeNamedItem("column");
node = attribs.getNamedItem("remoteSchema");
if (node != null) {
remoteSchema = node.getNodeValue();
attribs.removeNamedItem("remoteSchema");
} else {
remoteSchema = null;
}

tableName = attribs.getNamedItem("table").getNodeValue();
columnName = attribs.getNamedItem("column").getNodeValue();
remoteSchema = attribs.getNamedItem("remoteSchema") == null ? null : attribs.getNamedItem("remoteSchema").getNodeValue();
for (int i = 0; i < attribs.getLength(); ++i) {
System.err.println("Unrecognized attribute '" + attribs.item(i).getNodeName() + "' in XML definition of foreignKey");
}
}

public String getTableName() {
Expand Down
22 changes: 20 additions & 2 deletions src/net/sourceforge/schemaspy/model/xml/TableColumnMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ public class TableColumnMeta {
String tmp;

name = attribs.getNamedItem("name").getNodeValue();
attribs.removeNamedItem("name");
Node node = attribs.getNamedItem("comments");
if (node != null) {
tmp = node.getNodeValue().trim();
comments = tmp.length() == 0 ? null : tmp;
attribs.removeNamedItem("comments");
} else {
comments = null;
}

node = attribs.getNamedItem("primaryKey");
isPrimary = node != null && evalBoolean(node.getNodeValue());
if (node != null) {
isPrimary = evalBoolean(node.getNodeValue());
attribs.removeNamedItem("primaryKey");
} else {
isPrimary = false;
}

node = attribs.getNamedItem("disableImpliedKeys");
if (node != null) {
Expand All @@ -51,19 +58,30 @@ public class TableColumnMeta {
System.err.println(" Valid values include 'to', 'from' and 'all'");
isImpliedChildrenDisabled = isImpliedParentsDisabled = false;
}

attribs.removeNamedItem("disableImpliedKeys");
} else {
isImpliedChildrenDisabled = isImpliedParentsDisabled = false;
}

node = attribs.getNamedItem("disableDiagramAssociations");
isExcluded = node != null && evalBoolean(node.getNodeValue());
if (node != null) {
isExcluded = evalBoolean(node.getNodeValue());
attribs.removeNamedItem("disableDiagramAssociations");
} else {
isExcluded = false;
}

NodeList fkNodes = ((Element)colNode.getChildNodes()).getElementsByTagName("foreignKey");

for (int i = 0; i < fkNodes.getLength(); ++i) {
Node fkNode = fkNodes.item(i);
foreignKeys.add(new ForeignKeyMeta(fkNode));
}

for (int i = 0; i < attribs.getLength(); ++i) {
System.err.println("Unrecognized attribute '" + attribs.item(i).getNodeName() + "' in XML definition of column '" + name + '\'');
}
}

private boolean evalBoolean(String exp) {
Expand Down
15 changes: 14 additions & 1 deletion src/net/sourceforge/schemaspy/model/xml/TableMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,35 @@ public class TableMeta {
NamedNodeMap attribs = tableNode.getAttributes();

name = attribs.getNamedItem("name").getNodeValue();
attribs.removeNamedItem("name");

Node commentNode = attribs.getNamedItem("comments");
if (commentNode != null) {
String tmp = commentNode.getNodeValue().trim();
comments = tmp.length() == 0 ? null : tmp;
attribs.removeNamedItem("comments");
} else {
comments = null;
}

Node remoteSchemaNode = attribs.getNamedItem("remoteSchema");
remoteSchema = remoteSchemaNode == null ? null : remoteSchemaNode.getNodeValue().trim();
if (remoteSchemaNode != null) {
attribs.removeNamedItem("remoteSchema");
remoteSchema = remoteSchemaNode.getNodeValue().trim();
} else {
remoteSchema = null;
}

NodeList columnNodes = ((Element)tableNode.getChildNodes()).getElementsByTagName("column");

for (int i = 0; i < columnNodes.getLength(); ++i) {
Node colNode = columnNodes.item(i);
columns.add(new TableColumnMeta(colNode));
}

for (int i = 0; i < attribs.getLength(); ++i) {
System.err.println("Unrecognized attribute '" + attribs.item(i).getNodeName() + "' in XML definition of table '" + name + '\'');
}
}

public String getName() {
Expand Down

0 comments on commit 167718f

Please sign in to comment.