}
public void load(URI location)
throws IOException,XMLException
{
Document doc = docLoader.load(location);
Element top = doc.getDocumentElement();
if (!top.getName().equals(COMPONENT)) {
throw new XMLException("Expecting "+COMPONENT+" but found "+top.getName());
}
String value = top.getAttributeValue("autoconf-check");
if (value!=null) {
autoconfCheck = Long.parseLong(value) * 1000;
}
Element keyStoreE = top.getFirstElementNamed(KEYSTORE);
if (keyStoreE!=null) {
URI fileRef = keyStoreE.getBaseURI().resolve(keyStoreE.getAttributeValue("file"));
this.keyStorePath = new File(fileRef.getSchemeSpecificPart());
this.keyStorePassword = keyStoreE.getAttributeValue("password");
}
Iterator<Element> appdefElements = top.getElementsByName(DEFINE);
while (appdefElements.hasNext()) {
Element appdefE = appdefElements.next();
String name = appdefE.getAttributeValue("name");
String className = appdefE.getAttributeValue("class");
String ref = appdefE.getAttributeValue("ref");
if (ref!=null) {
ClassLoader theLoader = loaders.get(ref.trim());
if (theLoader==null) {
throw new XMLException("Cannot find definition: "+ref);
}
if (className==null || name==null) {
continue;
}
try {
Class cdef = theLoader.loadClass(className);
definitions.put(name,cdef);
} catch (ClassNotFoundException ex) {
throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
}
continue;
}
if (name!=null) {
List<URL> libraries = new ArrayList<URL>();
Iterator<Element> libraryElements = appdefE.getElementsByName(LIBRARY);
while (libraryElements.hasNext()) {
Element libE = libraryElements.next();
String href = libE.getAttributeValue("href");
if (href!=null) {
URI u = libE.getBaseURI().resolve(href);
libraries.add(u.toURL());
}
}
ClassLoader theLoader = this.getClass().getClassLoader();
if (libraries.size()!=0) {
URL [] list = new URL[libraries.size()];
list = libraries.toArray(list);
theLoader = new URLClassLoader(list,this.getClass().getClassLoader());
LOG.fine("ClassLoader: "+name+" -> "+theLoader);
LOG.fine(" Libraries: "+libraries);
loaders.put(name, theLoader);
}
if (className!=null) {
try {
Class cdef = theLoader.loadClass(className);
definitions.put(name,cdef);
} catch (ClassNotFoundException ex) {
throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
}
}
} else if (name!=null) {
LOG.warning("The 'class' attribute is missing on the definition of '"+name+"'");
}
}
Iterator<Element> clientElements = top.getElementsByName(CLIENT);
while (clientElements.hasNext()) {
Element clientDef = clientElements.next();
String protocol = clientDef.getAttributeValue("protocol");
if (protocol!=null) {
Protocol p = Protocol.valueOf(protocol.trim());
clients.add(p);
}
}
Iterator<Element> interfaceElements = top.getElementsByName(SERVER);
while (interfaceElements.hasNext()) {
Element serverE = interfaceElements.next();
String addr = serverE.getAttributeValue("address");
String portS = serverE.getAttributeValue("port");
String protocol = serverE.getAttributeValue("protocol");
Protocol p = Protocol.HTTP;
if (protocol!=null) {
p = Protocol.valueOf(protocol.trim());
}
int port = portS==null ? p.getDefaultPort() : Integer.parseInt(portS);
Server server = new Server(addr,port,p);
servers.add(server);
Iterator<Element> links = serverE.getElementsByName(LINK);
while (links.hasNext()) {
Element linkE = links.next();
String href = linkE.getAttributeValue("href");
if (href!=null) {
URI tlocation = linkE.getBaseURI().resolve(href);
String mtype = linkE.getAttributeValue("type");
Link l = new Link(linkE.getAttributeValue("rel"),mtype==null ? null : MediaType.valueOf(mtype),tlocation);
l.setIdentity(linkE.getAttributeValue("username"),linkE.getAttributeValue("password"));
if (l.getRelation()!=null) {
server.getLinks().put(l.getRelation(),l);
}
}
}
Iterator<Element> hostElements = serverE.getElementsByName(HOST);
while (hostElements.hasNext()) {
Element hostE = hostElements.next();
Host host = createHost(hostE);
server.getHosts().put(host.getName(),host);
}
}