public void load(URI location)
throws IOException,XMLException
{
DocumentLoader loader = new SAXDocumentLoader();
Document doc = loader.load(location);
Element top = doc.getDocumentElement();
if (!top.getName().equals(AdminXML.NM_SERVER)) {
throw new XMLException("Expecting "+AdminXML.NM_SERVER+" but found "+top.getName());
}
String value = top.getAttributeValue("autoconf-check");
if (value!=null) {
autoconfCheck = Long.parseLong(value)*1000;
}
storageClassName = top.getAttributeValue("storage-class");
value = top.getAttributeValue("logs");
if (location.getScheme().equals("file")) {
File locFile = new File(location.getSchemeSpecificPart());
File test = new File(locFile,value==null ? "logs" : value);
if (test.exists()) {
logDir = test;
} else {
logDir = new File(value==null ? "logs" : value);
}
}
value = top.getAttributeValue("temp.dir");
if (location.getScheme().equals("file")) {
File locFile = new File(location.getSchemeSpecificPart());
tmpDir = value==null ? locFile.getParentFile() : new File(locFile,value);
} else {
tmpDir = new File(".");
}
Iterator<Element> autoconfElements = top.getElementsByName(AdminXML.NM_AUTOCONF);
while (autoconfElements.hasNext()) {
Element autoconfE = autoconfElements.next();
String href = autoconfE.getAttributeValue("href");
if (href!=null) {
Link l = new Link("autoconf",MediaType.APPLICATION_ATOM_XML,autoconfE.getBaseURI().resolve(href));
l.setIdentity(autoconfE.getAttributeValue("username"),autoconfE.getAttributeValue("password"));
autoconfs.add(l);
}
}
Iterator<Element> interfaceElements = top.getElementsByName(AdminXML.NM_INTERFACE);
while (interfaceElements.hasNext()) {
Element interfaceE = interfaceElements.next();
String addr = interfaceE.getAttributeValue("address");
String portS = interfaceE.getAttributeValue("port");
boolean secure = interfaceE.getAttributeValue("secure")==null || "true".equals(interfaceE.getAttributeValue("secure"));
int port = portS==null ? (secure ? 443 : 80) : Integer.parseInt(portS);
interfaces.add(new Interface(addr,port,secure));
}
Iterator<Element> hostElements = top.getElementsByName(AdminXML.NM_HOST);
while (hostElements.hasNext()) {
Host host = createHost(hostElements.next());
String key = host.getName();
if (host.getPort()<0) {
key = key+":*";
} else {
key = key+":"+host.getPort();
}
hosts.put(key,host);
}
Iterator<Element> adminElements = top.getElementsByName(AdminXML.NM_ADMIN);
while (adminElements.hasNext()) {
AdminHost host = createAdminHost(adminElements.next());
admins.put(host.getName(),host);
}
Iterator<Element> resourceElements = top.getElementsByName(AdminXML.NM_RESOURCE);
while (resourceElements.hasNext()) {
Element spec = resourceElements.next();
String type = spec.getAttributeValue("type");
if (type==null || type.equals("database")) {
ResourceHost host = createResourceHost(spec);
resources.put(host.getName(),host);
} else {
throw new XMLException("Unrecognized resource host type "+type);
}
}
Iterator<Element> databaseElements = top.getElementsByName(AdminXML.NM_DATABASE);
while (databaseElements.hasNext()) {
Element databaseE = databaseElements.next();
String dbName = databaseE.getAttributeValue("name");
String auth = databaseE.getAttributeValue("auth");
String group = databaseE.getAttributeValue("group");
String alias = databaseE.getAttributeValue("alias");
Database database = new Database(dbName,auth,group,alias);
databases.put(dbName,database);
}
Iterator<Element> authElements = top.getElementsByName(AdminXML.NM_AUTH);
while (authElements.hasNext()) {
Element authE = authElements.next();
try {
Auth auth = createAuth(authE);
authServices.put(auth.getName(),auth);
} catch (ClassNotFoundException ex) {
throw new XMLException("Cannot load class "+authE.getAttributeValue("class")+" for auth service "+authE.getAttributeValue("name"),ex);
}
}
Element keystoreE = top.getFirstElementNamed(AdminXML.NM_KEYSTORE);
String href = keystoreE.getAttributeValue("href");
URI keystoreRef = keystoreE.getBaseURI().resolve(href);
keystoreFile = new File(keystoreRef.getSchemeSpecificPart());
keystorePassword = keystoreE.getAttributeValue("password");
keyPassword = keystorePassword;
String altPassword = keystoreE.getAttributeValue("key-password");
if (altPassword!=null) {
keyPassword = altPassword;
}
}