use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class InputXMLGenerationClient method getInputXMLString.
public static String getInputXMLString(String requestedOperationName, Map<String, Object> attributeMap, String xmlInputContextFile, String smooksConfigFile) {
String operationInputXMLString = null;
InputStream stream = null;
try {
List<Operation> availableOperations = new ArrayList<Operation>();
log.debug("XML Context File name to be loaded: {}", xmlInputContextFile);
stream = InputXMLGenerationClient.class.getClass().getResourceAsStream(xmlInputContextFile);
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(stream, smooksConfigFile);
@SuppressWarnings("unchecked") List<Operation> operationList = (List<Operation>) javaResult.getBean(XMLConstants.OPERATION_LIST_BEAN_NAME);
if (null != operationList && !operationList.isEmpty()) {
log.debug("{} operations found in configuration file", operationList.size());
for (Operation operation : operationList) {
if (operation.getName().equalsIgnoreCase(requestedOperationName)) {
log.debug("Found matching operation {}", operation.getName());
availableOperations.add(operation);
}
}
Operation operation = getModelSupportedOperation(attributeMap, availableOperations);
if (null != operation) {
operationInputXMLString = generateXMLString(operation, attributeMap);
} else {
log.error("No Operation found with the given model");
HDSException.exceptions.unableToGenerateInputXmlDueToUnSupportedModelFound();
}
} else {
log.error("No operation list found to generate input xml.");
HDSException.exceptions.unableToGenerateInputXmlDueToNoOperations();
}
} catch (Exception ex) {
HDSException.exceptions.unableToGenerateInputXmlForGivenRequest(ex.getLocalizedMessage());
}
return operationInputXMLString;
}
use of org.milyn.payload.JavaResult in project tutorials by eugenp.
the class OrderConverter method convertOrderXMLToOrderObject.
public Order convertOrderXMLToOrderObject(String path) throws IOException, SAXException {
Smooks smooks = new Smooks(OrderConverter.class.getResourceAsStream("/smooks/smooks-mapping.xml"));
try {
JavaResult javaResult = new JavaResult();
smooks.filterSource(new StreamSource(OrderConverter.class.getResourceAsStream(path)), javaResult);
return (Order) javaResult.getBean("order");
} finally {
smooks.close();
}
}
Aggregations