Generating Java Classes from IFC4 XSD Schema

To generate Java classes representing IFC Objects using IFC4 schema, I tried many ways and I got through this by using XJC XML Binding. But since JAXB is getting confused compiling the complex schema we have to specify confusing bindings in a separate file and provide it as a supporting file to solve the confusions.

if you run the following command it will get confused about the Path property.
(The -d is where the generated classes should be placed and -p is the package name of the classes being generated.)

$ xjc -d src/ -p com.test ifcXML4.xsd
parsing a schema…
[ERROR] Property “Path” is already defined. Use to resolve this conflict.
line 8381 of file:/media/isuru/Projects/stuff/ifcXML4.xsd
[ERROR] The following location is relevant to the above error
line 12910 of file:/media/isuru/Projects/stuff/ifcXML4.xsd
Failed to parse a schema.

To solve this add the following bindings.xjb file to the same folder where the schema is. Continue reading

Strategy Pattern

The definition of the strategy pattern is:

The Strategy Pattern defines a family of algorithms, 
encapsulates each one, and makes them interchangeable. 
Strategy lets the algorithm vary independently from clients that use it.

What are algorithms here?

"Identify the aspects of the application 
that vary and separate them from what stays the same."

Those aspects are the algorithms which can be encapsulated and make interchangeable, and it lets those varying aspects to vary independently from the client which uses those.

Continue reading

Design Principles

1. Identify the aspects of your application that vary and separate them from what stays the same.

Take what varies and encapsulate it so it won’t affect the rest of your code

The result is : Fewer unintended consequences from code changes and more flexibility in your systmes

2. Program to an interface (super type), not an implementation.


3. Favor composition over inheritance.

‘Has a’ can be better than ‘Is a’


4. Strive for loosely coupled designs between objects that interact.

Loosely coupled designs allow us to build flexible OO systems that can handle change because they minimize the inter-dependency between objects.


5. Classes should be open for extension, but closed for modification.


6. Depend upon abstractions. Do not depend upon concrete classes.

This is the Dependency Inversion Principle. High level components should not depend on low level components, instead they should both depend on abstractions. * Factory Method adheres to the dependency inversion principle.

Why it is called Dependency Inversion?
Normally higher level components depends on lower level components. After adhering to this principle, lower level components depends on higher level abstraction. So the top to bottom dependency chart has inverted itself and both higher level and lower level components start depending on abstraction.

Usage of Fault mediator in WSO2 ESB

This post explains, an usage of Fault mediator in wso2 ESB.

The sample scenario, refuses and sends an exception back to the client based on the Content-Type header property.

This example is tested in ESB 4.7.0

First validate the content-type - using filter mediator

If true, send back an exception to the client - using fault mediator

If false, continue the flow

Here is the sample proxy,

Continue reading

How to send an Email using WSO2 ESB

This post explains how to send an email in WSO2 ESB using Payload Factory mediator . You can find plenty of examples which do the same by using Script mediator.

This example is tested in WSO2 ESB 4.8

1.Uncomment and configure the SMTP server information ESB_HOME/repository/conf/axis/axis2.xml file as below

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
   <parameter name=""></parameter>
   <parameter name="mail.smtp.port">587</parameter>
   <parameter name="mail.smtp.starttls.enable">true</parameter>
   <parameter name="mail.smtp.auth">true</parameter>
   <parameter name="mail.smtp.user">esbadmin</parameter>
   <parameter name="mail.smtp.password">*****</parameter>
   <parameter name="mail.smtp.from"></parameter>

Continue reading

WSO2 DSS Scheduled Task Example

This post explains how the scheduled task works in WSO2 DSS

This example is tested in WSO2 DSS 3.0.1

1. Write the following class which extends the org.wso2.carbon.dataservices.task.DataTask interface.

package com.example.DssSchedlueTask;

import java.util.HashMap;
import java.util.Map;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.engine.ParamValue;
import org.wso2.carbon.dataservices.task.DataTask;
import org.wso2.carbon.dataservices.task.DataTaskContext;

public class ScheduledDataTask_abcCompany implements DataTask {

	public void execute(DataTaskContext ctx) {
		System.out.println("Data Task executing...");
		String soldItems = getSoldItems();
		Map<String, ParamValue> params = new HashMap<String, ParamValue>();
		params.put("soldItems", new ParamValue(soldItems));
		params.put("productCode", new ParamValue("0001a3"));
		try {
			ctx.invokeOperation("abcCompany", "UpdateSales", params);
			System.out.println("Successfully updated the database. \tSoldItems = "+soldItems);
		} catch (DataServiceFault e) {

	private String getSoldItems(){
		int soldItems = (int )(Math.random() * 10000 + 1);
		return Integer.toString(soldItems);

Assume that you are getting sold items from another service, here you will get a random number for the sold items, and you are going to update your system with that value.

2.Then create the jar of the above class and copy it to the DSS_HOME/repository/components/lib folder and start the WSO2 DSS server.

3. Create a Keyspace name ‘abcCompany’ in cassandra db.  Then create a columnfamily name ‘salesDetails’ in abcCompany keyspace.

cqlsh:abccompany> CREATE COLUMNFAMILY salesDetails ( productCode varchar PRIMARY KEY , productName varchar , soldItems int, instock int) ;

4. Insert following dummy values to the above created column family.

cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0001a3', 'phone a3', 9999, 10000);
cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0001b2', 'phone b2', 99, 100);
cqlsh:abccompany> INSERT INTO abcCompany.salesDetails (productCode, productName, soldItems, instock) VALUES ( '0002x5', 'phone x5', 9, 10);

Continue reading

WSO2 ESB Rule Mediator Example

This post is to demonstrate how to write Rule mediator in WSO2 ESB.
This example is tested in WSO2 ESB 4.7.0
The example, get the list of students with marks for their subjects and, inside the proxy it check whether the each student has passed the each subject and print the result. To define type of the input data POJO adapters are used in this example.

1.Write the following POJO classes.

Student class

package com.example.rulemediator;

public class Student {

	private String indexNumber;
	private String name;
	private Subject[] subjects;

	public String getIndexNumber() {
		return indexNumber;
	public void setIndexNumber(String indexNumber) {
		this.indexNumber = indexNumber;
	public String getName() {
		return name;
	public void setName(String name) { = name;
	public Subject[] getSubjects() {
		return subjects;
	public void setSubjects(Subject[] subjects) {
		this.subjects = subjects;

Subject class

package com.example.rulemediator;

public class Subject {

	private String subjectCode;
	private String subjectName;
	private int score;

	public String getSubjectCode() {
		return subjectCode;
	public void setSubjectCode(String subjectCode) {
		this.subjectCode = subjectCode;
	public String getSubjectName() {
		return subjectName;
	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	public int getScore() {
		return score;
	public void setScore(int score) {
		this.score = score;

2. Then create a Jar file containing above classes and copy it to ESB_HOME/repository/components/lib folder and start the ESB.

Continue reading