}
}
public ObjectNode retrieveObject(Connection connection, Uri uri)
throws ServiceAccessException, ObjectNotFoundException {
ObjectNode result = null;
try {
PreparedStatement statement = null;
ResultSet res = null;
String className;
Vector children = new Vector();
Vector parents = new Vector();
Vector links = new Vector();
try {
statement =
connection.prepareStatement(
"select o.CLASS_NAME from OBJECT o, URI u where o.URI_ID = u.URI_ID and u.URI_STRING = ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
if (res.next()) {
className = res.getString(1);
} else {
throw new ObjectNotFoundException(uri);
}
} finally {
close(statement, res);
}
try {
statement =
connection.prepareStatement(
"SELECT c.NAME, cu.URI_STRING FROM URI u, URI cu, BINDING c WHERE cu.URI_ID = c.CHILD_UURI_ID AND c.URI_ID = u.URI_ID and u.URI_STRING = ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
children.addElement(new ObjectNode.Binding(res.getString(1), res.getString(2)));
}
} finally {
close(statement, res);
}
try {
statement =
connection.prepareStatement(
"SELECT c.NAME, cu.URI_STRING FROM URI u, URI cu, PARENT_BINDING c WHERE cu.URI_ID = c.PARENT_UURI_ID AND c.URI_ID = u.URI_ID and u.URI_STRING = ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
parents.addElement(new ObjectNode.ParentBinding(res.getString(1), res.getString(2)));
}
} finally {
close(statement, res);
}
try {
statement =
connection.prepareStatement(
"SELECT lu.URI_STRING FROM URI u, URI lu, LINKS l WHERE lu.URI_ID = l.URI_ID AND l.LINK_TO_ID = u.URI_ID and u.URI_STRING = ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
links.addElement(res.getString(1));
}
} finally {
close(statement, res);
}
if (className.equals(LinkNode.class.getName())) {
try {
statement =
connection.prepareStatement(
"SELECT lu.URI_STRING FROM URI u, URI lu, LINKS l WHERE lu.URI_ID = l.LINK_TO_ID AND l.URI_ID = u.URI_ID and u.URI_STRING = ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
if (res.next()) {
String linkTarget = res.getString(1);
result = new LinkNode(uri.toString(), children, links, linkTarget);
} else {
result = new LinkNode(uri.toString(), children, links);
}
} finally {
close(statement, res);
}
} else {
try {
Class objclass = Class.forName(className);
Class argClasses[] = { String.class, Vector.class, Vector.class, Vector.class };
Object arguments[] = { uri.toString(), children, parents, links };
Constructor constructor = objclass.getConstructor(argClasses);
result = (ObjectNode) constructor.newInstance(arguments);
result.setUri(result.getUuri());
} catch (Exception e) {
throw new ServiceAccessException(service, e);
}
}
} catch (SQLException e) {