Wednesday, 4 November 2015

Spring intergration example

https://vrtoonjava.wordpress.com/2013/03/03/spring-integration-developing-application-from-the-scratch-part-1-2/
spring-integration-developing-application


Tuesday, 12 February 2013

when write a binding file ..how to refer it in code


<binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Java\JiBX-1.1.6a\docs\binding.xsd">
   <include path="layouts-binding.xml"/>
   <include path="dealing-rest-binding.xml" />
<mapping name="test"
class="uk.co.igindex.regression.service.testcase.model.TestCaseImpl">
<value name="name" field="name" style="attribute" />
<structure field="declare"
type="uk.co.igindex.regression.service.testcase.model.DeclareImpl" />
<collection field="actionList" type="java.util.ArrayList">
<structure
type="uk.co.igindex.regression.service.testcase.model.ActionImpl" />
</collection>
</mapping>

And the way to include it to be able to use the original file by application is:



<plugin>
<groupId>org.jibx</groupId>
<artifactId>maven-jibx-plugin</artifactId>
<version>1.1.6a</version>
<executions>
<execution>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
<configuration>
<directory>
src/main/resources/oxm-binding
</directory>
<includes>
<includes>regression-testcase-binding.xml</includes>
</includes>
<verbose>true</verbose>
</configuration>

Monday, 11 February 2013

Validation Code to validate a xml and make it parse


package uk.co.igindex.regression.service.util;

import java.io.StringReader;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;

/**
 *
 * @version 1.0
 * @author Jarvis Ragona
 */
public class SchemaValidatorImpl implements SchemaValidator {
private static final Logger LOG = Logger.getLogger(SchemaValidatorImpl.class);

/**
*
* @param document
* @return
*/
public void validateTestCaseDocument(Document document) throws SchemaValidationException {
try {
SchemaValidationErrorHandler errorHandler = getSchemaValidationErrorHandler();

SAXReader reader = new SAXReader();
reader.setValidation(true);
reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", getClass().getResourceAsStream("/schema/regression-test-case.xsd"));
reader.setErrorHandler(errorHandler);
reader.read(new StringReader(document.asXML()));

if(errorHandler.isValidationError()) {
String message = "XML Document has Error: " + errorHandler.isValidationError() + " " +errorHandler.getSaxParseException().getMessage();
LOG.error(message);
throw errorHandler.getSaxParseException();
}

LOG.debug("Test case XML document is valid");
} catch(Exception e) {
LOG.fatal(e.getMessage(), e);
throw new SchemaValidationException(e.getMessage(), e);
}
}

protected SchemaValidationErrorHandler getSchemaValidationErrorHandler() {
return (SchemaValidationErrorHandler)BeanFactory.getBean("schemaValidationErrorHandler");
}
}