Object object = cx.getThreadLocal(MashupConstants.AXIS2_SERVICE);
AxisService axisService;
if (object instanceof AxisService) {
axisService = (AxisService) object;
} else {
throw new CarbonException("Error obtaining the AxisService.");
}
Object resourceFileObject = axisService
.getParameterValue(MashupConstants.RESOURCES_FOLDER);
File resourceFolder;
if (resourceFileObject != null && resourceFileObject instanceof File) {
resourceFolder = (File) resourceFileObject;
} else {
throw new CarbonException("Resources folder not found.");
}
if (args.length == 1 & !(args[0] == Context.getUndefinedValue())) {
if (args[0] instanceof String) {
String filePath = FilenameUtils.normalizeNoEndSeparator((String) args[0]);
if (filePath == null) {
throw new CarbonException(
"FileHostObject : Illegal file path, Cannot navigate away from resources directory");
}
result.file = new File(resourceFolder, filePath);
if (result.file.isDirectory()) {
throw new CarbonException(
"Given path is not a File. This object does not support directories.");
}
} else if (args[0] instanceof XML) {
//TODO: Initial code bits to handle MTOM using the file object. Yet to be completed.
XML xml = (XML) args[0];
OMNode node = xml.getAxiomFromXML();
if (node instanceof OMText) {
OMText textNode = (OMText) node;
if (textNode.isBinary()) {
result.dataHandler = (DataHandler) textNode.getDataHandler();
} else {
// TODO support directly writing XML to the file
throw new CarbonException(
"XML content given for the File does not contain base64Binary.");
}
} else {
// TODO support directly writing XML to the file
throw new CarbonException(
"XML content given for the File does not contain base64Binary.");
}
} else {
throw new CarbonException("Invalid parameters.");
}
}
return result;
}