public void prepare() throws IOException {
if (log.isDebugEnabled())
log.debug("Checking parameters");
XMLElement element = new XMLElement();
try {
element.parseFromReader(new InputStreamReader(
new ByteArrayInputStream(processParameters(
session,
descriptor
.createProcessedDescriptorElement(session),
descriptor, shortcut).getBytes())));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (log.isDebugEnabled())
log.debug("Received a response from server");
if (!element.getName().equals("application")
&& !element.getName().equals("error")
&& !element.getName().equals("extension")) {
throw new IOException(
"URL does not point to an application descriptor");
} else if (element.getName().equals("error")) {
throw new IOException(element.getContent());
}
name = (String) element.getAttribute("extension");
if (name == null) {
name = (String) element.getAttribute("application");
}
typeName = (String) element.getAttribute("type");
try {
type = (ApplicationServerType) Class
.forName(
"com.adito.applications.types."
+ (String.valueOf(typeName.charAt(0))
.toUpperCase() + typeName
.substring(1)) + "Type")
.newInstance();
} catch (Throwable t) {
throw new IOException(
"Failed to load the application description extension for application type of "
+ typeName + ".");
}
if (log.isDebugEnabled())
log.debug("Application name is " + name);
if (log.isDebugEnabled())
log.debug("Creating install folder");
installDir = File.createTempFile("server", "tmp");
installDir.delete();
installDir = new File(installDir.getParent(), installDir.getName()
+ "dir");
installDir.mkdirs();
if (log.isDebugEnabled())
log.debug("Installing to " + installDir.getAbsolutePath());
Enumeration e = element.enumerateChildren();
while (e.hasMoreElements()) {
XMLElement el = (XMLElement) e.nextElement();
if (el.getName().equalsIgnoreCase("files")) {
processFiles(el);
} else if (el.getName().equalsIgnoreCase("parameter")) {
addParameter(el);
} else if (el.getName().equalsIgnoreCase("messages")) {
// Ignore as its a server side element
} else if (el.getName().equalsIgnoreCase("description")) {
// Simply ignore.. should we throw an exception if an element is
// not known?
} else if (el.getName().equalsIgnoreCase("replacements")) {
FileReplacement replacement = new FileReplacement(installDir);
replacement.processReplacementXML(el, this);
replacements.put(replacement.getId(), replacement);
} else if (processLauncherElement(el)) {
// This allows us to override more element types in extended
// application launchers (i.e. registry parameters)
continue;
} else if (el.getName().equalsIgnoreCase("transform")) {
ParameterTransformation trans = new ParameterTransformation(el,
this);
transformations.addElement(trans);
} else {
type.prepare(this, null, el);