JAVA : Collections

java.util.Collections

List Interface

A List cares about the index. All three List implementations are
ordered by index position – a position that you determine either by
setting an object at a specific index or by adding it without
specifying position, in which case the object is added to the end.

ArrayList

  • Ordered, by index
  • Unsorted
  • Fast iteration, but not fast insertion and deletion
  • Implements RandomAccess marker interface – supports
    fast (generally constant time) random access

Vector

  • Ordered, by index
  • Unsorted
  • Methods are synchronized
  • Implements RandomAccess marker interface – supports
    fast (generally constant time) random access
  • One of the the Original collections

LinkedList

  • Ordered, by index
  • Unsorted
  • Elements are doubly-linked
  • Fast insertion and deletion, not fast iteration
  • Good for implementing stacks and queues, supports adding or
    removing from beginning or end



Set Interface

A Set does not allow duplicates, it uses equals() to determine
the uniqueness

HashSet

  • Unordered
  • Unsorted
  • Uses hashCode() of the object being inserted, why?

LinkedHashSet

  • Ordered, by insertion order
  • Elements are doubly-linked
  • Use it when you care about the insertion order

TreeSet

  • Sorted, by natural order or custom implementation
  • Implements NavigableSet



Map Interface

It is about key/value pairs, keys should be unique. Relies on equals() to determine the keys’ uniqueness

HashMap

  • Unordered
  • Unsorted
  • Allows one null key and multiple null values in a collection
  • Uses hashCode(), why?
  • Faster insertion and deletion, not fast iteration

Hashtable

  • Unordered
  • Unsorted
  • Methods are synchronized
  • Does not allow null

LinkedHashMap

  • Ordered, by insertion order
  • Unsorted
  • Faster insertion, not fast insertion and deletion
  • Doubly-linked?

TreeMap

  • Sorted, by natural order or custom implementation



Queue Interface

  • Typically FIFO, but other orders are possible.
  • Priority

    • Sorted, by to-do order
    • priority-in, priority-out
    Advertisements

    Hibernate : Mapping object associations

    Suppose there are two persistent classes called A and B. The relationship of A and
    B is called one-to-one if any instance of A is associated with only a single instance
    of B, and no more. A one-to-one association is always presented as an instance of B
    defined as a property of A, or vice versa.

    The association is called one-to-many from A to B if any instance of A can be
    associated with more than one instance of B. This relationship is established by a
    property of a collection type of B instances in class A. The one-to-many relationship
    from A to B is called many-to-one when going from B to A. In other words, when
    more than one instance of B can be associated with one instance of A.

    The final type of relationship, which is rare, is many-to-many: more than one
    instance of A can be associated with more than one instance of B. In this
    relationship, each instance of A holds a collection of B instances, and vice versa.

    one-to-one

    Two persistent classes may be associated with each other in a one-to-one
    relationship. A relationship is called one-to-one when each instance of a class
    is associated with a single instance of another class, and vice versa. If, when you
    have an instance of one class, and the other instance can be reached, then the
    one-to-one relationship is called bidirectional. On the other hand, if the objects
    cannot be reached from both sides, the relationship is unidirectional.

    • Using identical primary keys
    • 	// unidirectional
      	@Entity
      	public class Student {
      	@Id
      	private int id;
      	@OneToOne
      	@PrimaryKeyJoinColumn
      	private Phone phone;
      	//other fields and getter/setter methods
      	}
      	
      // bidirectional public class Phone { @OneToOne(mappedBy="student") // mappedBy=<propert name> private Student student; }
    • Foreign key one-to-one
    • 	public class Student {
      	@OneToOne
      	@JoinColumn(name="PHONE_ID")
      	private Phone phone;
      	}
      	

    many-to-one

    public class Student {
    	@ManyToOne
    	@JoinColumn(name="ADDRESS_ID")
    	private Address address;
    }
    

    one-to-many

    
    public class School {
    	@OneToMany(mappedBy = "school")
    	private List students = new ArrayList();
    }
    
    // ManyToOne annotation is used to map the reverse side of the one-to-many relationship public class Student { @ManyToOne @JoinColumn(name = "SCHOOL_ID") private School school; }

    many-to-many

    
    	@ManyToMany(cascade = CascadeType.ALL)
    	@JoinTable(name = "STUDENT_COURSE", joinColumns = { @JoinColumn(name = "STUDENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "COURSE_ID") })
    	public Set getCourses() { // or List
    		return courses;
    	}
    
    @Entity @Table(name = "COURSE") public class Course { @Id @GeneratedValue @Column(name = "ID") public int getId() { return id; } }

    Hibernate : Mapping inheritance hierarchy

    Hibernate has three distinct ways to map an inheritance
    relationship

    • Use one table for each concrete (nonabstract) class
    • Use one table for each class hierarchy
    • Use one table for each subclass, including interfaces and
      abstract classes

    Use one table for each concrete (nonabstract) class

    		@Entity
    		@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
    		public class Student implements Serializable {
    			...
    		}
    	


    Use one table for each class hierarchy

    		@Entity
    		@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    		@DiscriminatorColumn(
    		name="PERSON_TYPE",
    		discriminatorType=STRING
    		)
    		@DiscriminatorValue("PE")
    		public class Person implements Serializable {
    		...
    		}
    		
    @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorValue("ST") public class Student extends Person{ ... }

    One table per subclass

    		@Entity
    		@Inheritance(strategy=InheritanceType.JOINED)
    		public class Person implements Serializable {
    		...
    		}
    		@Entity
    		public class Student extends Person{
    		...
    		}	
    		
    // If tables are joined by columns with different names @Entity @PrimaryKeyJoinColumn(name="STUDENT_ID") public class Student extends Person{ ... }

    JAVA: Registration Form With Spring and Hibernate

    Not working 😀

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    	<display-name>StudentReg</display-name>
    	<welcome-file-list>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
      
    	<servlet>
    		<servlet-name>dispatcher</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/config/spring-config.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>dispatcher</servlet-name>
    		<url-pattern>/</url-pattern>
    	</servlet-mapping>
      
    </web-app>
    

    spring-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    	http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    	<context:component-scan base-package="sam.reg" />
    	
    	<mvc:annotation-driven />
    
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="order" value="1"/>
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix">
    			<value>/WEB-INF/pages/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    	
    	<import resource="db-config.xml" />
    	      
    </beans>
    

    db-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName">
    			<value>com.mysql.jdbc.Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:mysql://localhost/reg</value>
    		</property>
    		<property name="username">
    			<value>root</value>
    		</property>
    		<property name="password">
    			<value></value>
    		</property>
    	</bean>
        
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource"/>
    		</property>
    		<property name="packagesToScan" value="sam.reg.model" />
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				<prop key="hibernate.show_sql">false</prop>
    				<prop key="hibernate.hbm2ddl.auto">update</prop>
    			</props>
    		</property>
    	</bean>
        
    	<tx:annotation-driven/>
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory"/>
    		</property>
    	</bean>   
    
    </beans>
    

    Course.java

    package sam.reg.model;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.Version;
    
    @Entity
    @Table(name = "COURSE")
    public class Course {
    
    	private int id;
    	private int version;
    	private String name;
    	private String code;
    
    	@Id
    	@GeneratedValue
    	@Column(name = "ID")
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	@Column(name = "NAME", nullable = false)
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	@Column(name = "CODE", nullable = false)
    	public String getCode() {
    		return code;
    	}
    
    	public void setCode(String code) {
    		this.code = code;
    	}
    
    	@Version
    	@Column(name = "VERSION", nullable = false)
    	public int getVersion() {
    		return version;
    	}
    
    	public void setVersion(int version) {
    		this.version = version;
    	}
    
    	@Override
    	public String toString() {
    		return this.name;
    	}	
    	
    }
    

    Student.java

    package sam.reg.model;
    
    import java.util.Set;
    
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Inheritance;
    import javax.persistence.InheritanceType;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
    import javax.persistence.Table;
    import javax.persistence.Version;
    
    @Entity
    @Table(name = "STUDENT")
    @Inheritance(strategy = InheritanceType.JOINED)
    public class Student {
    
    	private int id;
    	private int version;
    	private String firstName;
    	private String lastName;
    	private String gender;
    	private String email;
    	private String password;
    	private Set<Course> courses;
    
    	@Id
    	@GeneratedValue
    	@Column(name = "ID")
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	@ManyToMany(cascade = CascadeType.ALL)
    	@JoinTable(name = "STUDENT_COURSE", joinColumns = { @JoinColumn(name = "STUDENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "COURSE_ID") })
    	public Set<Course> getCourses() {
    		return courses;
    	}
    
    	public void setCourses(Set<Course> courses) {
    		this.courses = courses;
    	}
    
    	@Column(name = "FIRST_NAME", nullable = false)
    	public String getFirstName() {
    		return firstName;
    	}
    
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    
    	@Column(name = "LAST_NAME", nullable = false)
    	public String getLastName() {
    		return lastName;
    	}
    
    	public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    
    	@Column(name = "GENDER", nullable = false)
    	public String getGender() {
    		return gender;
    	}
    
    	public void setGender(String gender) {
    		this.gender = gender;
    	}
    
    	@Column(name = "EMAIL", nullable = false)
    	public String getEmail() {
    		return email;
    	}
    
    	public void setEmail(String email) {
    		this.email = email;
    	}
    
    	@Column(name = "PASSWORD", nullable = false)
    	public String getPassword() {
    		return password;
    	}
    
    	public void setPassword(String password) {
    		this.password = password;
    	}
    
    	@Version
    	@Column(name = "VERSION", nullable = false)
    	public int getVersion() {
    		return version;
    	}
    
    	public void setVersion(int version) {
    		this.version = version;
    	}
    
    }
    

    Undergraduate.java

    package sam.reg.model;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.PrimaryKeyJoinColumn;
    
    @Entity
    @PrimaryKeyJoinColumn(name="ID")
    public class Undergraduate extends Student {
    
    	private int id;
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    }
    

    PostGraduate.java

    package sam.reg.model;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.JoinColumn;
    import javax.persistence.PrimaryKeyJoinColumn;
    
    @Entity
    @PrimaryKeyJoinColumn(name = "ID")
    public class PostGraduate extends Student {
    
    	private int id;
    	private String field;
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	@Column(name = "FIELD")
    	public String getField() {
    		return field;
    	}
    
    	public void setField(String field) {
    		this.field = field;
    	}
    }
    

    CourseDao.java

    package sam.reg.dao.hibernate;
    
    import java.util.List;
    
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import org.springframework.stereotype.Repository;
    
    import sam.reg.model.Course;
    
    @Repository
    public class CourseDao implements sam.reg.dao.CourseDao {
    
    	private HibernateTemplate template;
    
    	@Autowired
    	public void setTemplate(SessionFactory factory) {
    		this.template = new HibernateTemplate(factory);
    	}
    
    	@Override
    	public Course save(Course course) {
    		template.saveOrUpdate(course);
    		return course;
    	}
    
    	@SuppressWarnings("unchecked")
    	@Override
    	public List<Course> retrieveAll() {
    		return template.find("from Course");
    	}
    }
    

    UndergraduateDao.java

    package sam.reg.dao.hibernate;
    
    import java.util.List;
    
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import org.springframework.stereotype.Repository;
    
    import sam.reg.model.Course;
    
    @Repository
    public class CourseDao implements sam.reg.dao.CourseDao {
    
    	private HibernateTemplate template;
    
    	@Autowired
    	public void setTemplate(SessionFactory factory) {
    		this.template = new HibernateTemplate(factory);
    	}
    
    	@Override
    	public Course save(Course course) {
    		template.saveOrUpdate(course);
    		return course;
    	}
    
    	@SuppressWarnings("unchecked")
    	@Override
    	public List<Course> retrieveAll() {
    		return template.find("from Course");
    	}
    }
    

    CourseService.java

    package sam.reg.service;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import sam.reg.dao.hibernate.CourseDao;
    import sam.reg.model.Course;
    
    @Service
    public class CourseService {
    
    	private CourseDao dao;
    
    	@Autowired
    	public void setDao(CourseDao dao) {
    		this.dao = dao;
    	}
    	
    	@Transactional
    	public Course create(Course course) {
    		return dao.save(course);
    	}
    
    	@Transactional(readOnly = true)
    	public List<Course> readAll() {
    		return dao.retrieveAll();
    	}
    }
    

    UndergraduateService.java

    package sam.reg.service;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import sam.reg.dao.hibernate.UndergraduateDao;
    import sam.reg.model.Undergraduate;
    
    @Service
    public class UndergraduateService {
    
    	private UndergraduateDao dao;
    
    	@Autowired
    	public void setDao(UndergraduateDao undergraduateDao) {
    		this.dao = undergraduateDao;
    	}
    
    	@Transactional
    	public Undergraduate create(Undergraduate undergraduate) {
    		return dao.save(undergraduate);
    	}
    
    	@Transactional(readOnly = true)
    	public Undergraduate read(int id) {
    		return dao.retrieve(id);
    	}
    
    	@Transactional(readOnly = true)
    	public List<Undergraduate> readAll(int id) {
    		return dao.retrieveAll();
    	}
    
    	@Transactional
    	public Undergraduate update(Undergraduate undergraduate) {
    		return dao.save(undergraduate);
    	}
    
    	@Transactional
    	public void delete(Undergraduate undergraduate) {
    		dao.delete(undergraduate);
    	}
    }
    

    CourseController.java

    package sam.reg.web;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import sam.reg.model.Course;
    import sam.reg.service.CourseService;
    
    @Controller
    @RequestMapping(value = "/course")
    public class CourseController {
    
    	private CourseService courseService;
    
    	@Autowired
    	public void setCourseService(CourseService courseService) {
    		this.courseService = courseService;
    	}
    
    	@RequestMapping(value = "/add", method = RequestMethod.GET)
    	public @ResponseBody String add() {
    		Course course = new Course();
    		course.setName("test");
    		course.setCode("455");
    		courseService.create(course);
    		return "successfuly added";
    	}
    	
    	@RequestMapping(value = "/count", method = RequestMethod.GET)
    	public @ResponseBody String readCount() {		
    		return "" + courseService.readAll().size();
    	}
    }
    

    StudentController.java

    package sam.reg.web;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.support.SessionStatus;
    
    import sam.reg.model.Course;
    import sam.reg.model.Student;
    import sam.reg.model.Undergraduate;
    import sam.reg.service.CourseService;
    import sam.reg.service.UndergraduateService;
    
    @Controller
    @RequestMapping(value = "/student")
    public class StudentController {
    
    	private CourseService courseService;
    	private UndergraduateService undergraduateService;	
    	
    	@Autowired
    	public void setUndergraduateService(UndergraduateService undergraduateService) {
    		this.undergraduateService = undergraduateService;
    	}
    
    	@Autowired
    	public void setCourseService(CourseService courseService) {
    		this.courseService = courseService;
    	}
    
    	// initialize form
    	@RequestMapping(value = "", method = RequestMethod.GET)
    	public String initForm(ModelMap model) {
    		Student student = new Undergraduate();
    		model.addAttribute("student", student);
    		return "reg-form";
    	}
    
    	// process form
    	@RequestMapping(value = "", method = RequestMethod.POST)
    	public @ResponseBody String processForm(ModelMap model,
    			@ModelAttribute("student") Undergraduate student, BindingResult result,
    			SessionStatus status) {
    		undergraduateService.create(student);
    		return student.toString();
    	}
    
    	// gender
    	@ModelAttribute("genderList")
    	public List<String> populateGenderList() {
    		List<String> list = new ArrayList<String>();
    		list.add("Male");
    		list.add("Female");
    		return list;
    	}
    
    	// degree type
    	@ModelAttribute("degreeList")
    	public List<String> populateDegreeList() {
    		List<String> list = new ArrayList<String>();
    		list.add("B.Sc.");
    		list.add("M.Sc.");
    		return list;
    	}
    
    	// courses
    	@ModelAttribute("courseList")
    	public List<Course> populateCourseList() {
    		return courseService.readAll();
    	}
    	
    	// test
    	
    	@RequestMapping(value = "/test", method = RequestMethod.GET)
    	public String test(ModelMap model) {
    		Undergraduate student = new Undergraduate();
    		student.setFirstName("fiestName");
    		student.setLastName("lastName");
    		student.setGender("gender");
    		student.setEmail("email");
    		student.setPassword("password");
    		undergraduateService.create(student);
    		return "reg-form";
    	}
    }
    

    reg-form.jsp

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <html>
    <head>
    <title>Registration</title>
    </head>
    <body>
    	<h3>Registration Form</h3>
    
    	<form:form commandName="student" name="reg-form" method="POST">
    
    		<table>
    			<tr>
    				<td></td>
    				<td></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>First Name</td>
    				<td><form:input path="firstName" /></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>Last Name</td>
    				<td><form:input path="lastName" /></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>Gender</td>
    				<td><form:select path="gender">
    						<form:options items="${genderList}" />
    					</form:select></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>Email</td>
    				<td><form:input path="email" /></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>Password</td>
    				<td><form:input path="password" /></td>
    				<td></td>
    			</tr>
    			<tr>
    				<td>Degree type</td>
    				<td><select name="degreeType">
    						<c:forEach var="dType" items="${degreeList}">
    							<option value="${dType}">${dType}</option>
    						</c:forEach>
    				</select></td>
    				<td></td>
    			</tr>
    			<!--<tr>
    				<td>Courses</td>
    				<td><select name="crs">
    						<c:forEach var="course" items="${courseList}">
    							<option value="${course.name}">${course.name}</option>
    						</c:forEach>
    				</select></td>
    				<td></td>
    			</tr>
    			 -->
    			<tr>
    				<td>Courses</td>
    				<td><form:checkboxes items="${courseList}" path="courses" /> </td>
    				<td></td>
    			</tr>
    			<tr>
    				<td></td>
    				<td><input type="submit" value="Submit" /><input type="button"
    					value="Clear" /></td>
    				<td></td>
    			</tr>
    		</table>
    
    	</form:form>
    
    
    </body>
    </html>
    
    
    		

    Eclipse : Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

    If you get this even if you have added requred jars,

    Right click on the project and click on Add Spring Nature to this project (If you have installed Spring tools)

    Hibernate : Exception java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass cannot be cast to org.hibernate.mapping.RootClass

    you can’t have @Id in both super class and Subclass

    Solution

    Remove @Id from Subclass

    ————————–

    If tables are joined by different names use @PrimaryKeyJoinColumn(name = “IDColumn”)

    ————————–

    @Entity
    @Table(name = "STUDENT")
    @Inheritance(strategy = InheritanceType.JOINED)
    public class Student {
    ...
    }
    
    @Entity
    @PrimaryKeyJoinColumn(name="ID")
    public class Undergraduate extends Student {
    	private int id;
    ...
    }
    

    JAVA: Registration form with Spring

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    	<display-name>Registration Form</display-name>
    	<welcome-file-list>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
      
    	<servlet>
    		<servlet-name>mvc-dispatcher</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/config/spring-config.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
      
    	<servlet-mapping>
    		<servlet-name>mvc-dispatcher</servlet-name>
    		<url-pattern>/</url-pattern>
    	</servlet-mapping>
      
    </web-app>
    

    spring.config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    	http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    	
    	<context:component-scan base-package="sam.reg" />
    	
    	<mvc:annotation-driven />
    	
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="order" value="1"/>
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix">
    			<value>/WEB-INF/pages/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    	
    	<!-- <bean class="sam.reg.util.StudentValidator" /> -->
    	
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename" value="resources/Student" />
    	</bean>
    	
    </beans>
    

    Student.properties WEB-INF/classes/resources/Student.properties

    required.name.student.name=Student name required
    

    Student.java

    package sam.reg.domain;
    
    public class Student {
    
    	private String name;
    	private short age;
    	private byte gender;
    	private String phone;
    	private String email;
    	private String password;
    	private String degree;
    	private String department;
    
    	// getters and setters ....
    }
    

    StudentController.java

    package sam.reg.web;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.support.SessionStatus;
    
    import sam.reg.domain.Student;
    import sam.reg.util.StudentValidator;
    
    @Controller
    @RequestMapping(value = "/student")
    public class StudentController {
    
    	private StudentValidator validator;
    
    	@Autowired
    	public void setValidator(StudentValidator validator) {
    		this.validator = validator;
    	}
    
    	// initForm
    	@RequestMapping(value = "", method = RequestMethod.GET)
    	public String initForm(ModelMap model) {
    		Student student = new Student();
    		model.addAttribute("student", student);
    		return "reg-form";
    	}
    
    	// processForm
    	@RequestMapping(value = "", method = RequestMethod.POST)
    	public String processForm(ModelMap model,
    			@ModelAttribute("student") Student student, BindingResult result,
    			SessionStatus status) {
    		validator.validate(student, result);
    		if (result.hasErrors()) {
    			return "reg-form";
    		} else {
    			status.setComplete();
    			return "successful";
    		}
    	}
    
    	// degree List
    	@ModelAttribute("degreeList")
    	public List<String> populateDegreeList() {
    		List<String> list = new ArrayList<String>();
    		list.add("B.Sc.");
    		list.add("M.Sc.");
    		return list;
    	}
    
    	// department list
    	@ModelAttribute("departmentList")
    	public List<String> populateDepartmentList() {
    		List<String> list = new ArrayList<String>();
    		list.add("IT");
    		list.add("Management");
    		return list;
    	}
    
    }
    

    StudentValidator.java

    package sam.reg.util;
    
    import org.springframework.stereotype.Component;
    import org.springframework.validation.Errors;
    import org.springframework.validation.ValidationUtils;
    import org.springframework.validation.Validator;
    
    import sam.reg.domain.Student;
    
    @Component
    public class StudentValidator implements Validator {
    
    	@Override
    	public boolean supports(Class<?> arg0) {
    		return Student.class.isAssignableFrom(arg0);
    	}
    
    	@Override
    	public void validate(Object arg0, Errors arg1) {
    		Student student = (Student) arg0;
    		ValidationUtils.rejectIfEmptyOrWhitespace(arg1, "name", "required.name");
    	}
    
    }
    

    reg-form.jsp

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <html>
    <head>
    <title>Student Registration Form</title>
    
    <style type="text/css">
    .error {
    	color: red;
    }
    </style>
    
    <script type="text/javascript">
    	function clearFields() {
    		document.forms["reg-form"]["name"].value = "";
    		document.forms["reg-form"]["age"].value = "";
    		//document.forms["reg-form"]["gender"].checked = false;
    		document.forms["reg-form"]["phone"].value = "";
    		document.forms["reg-form"]["email"].value = "";
    		document.forms["reg-form"]["password"].value = "";
    		document.forms["reg-form"]["degree"].selectedIndex = 0;
    		document.forms["reg-form"]["department"].selectedIndex = 0;
    	}
    
    	function validateFields() {
    		return true;
    	}
    </script>
    
    </head>
    <body>
    	<form:form method="POST" commandName="student" name="reg-form"
    		onsubmit="return validateFields()">
    		<table>
    			<tr>
    				<td colspan="3"><form:errors path="*" cssClass="error" /></td>
    			<tr>
    				<!-- NAME -->
    			<tr>
    				<td></td>
    				<td><form:input path="name" /></td>
    				<td><form:errors path="name" cssClass="error" /></td>
    			<tr>
    				<!-- AGE -->
    			<tr>
    				<td></td>
    				<td><form:input path="age" /></td>
    				<td><form:errors path="age" cssClass="error" /></td>
    			<tr>
    				<!-- GENDER -->
    			<tr>
    				<td></td>
    				<td>
    				<form:radiobutton path="gender" value="0" label="Female" />
    				<form:radiobutton path="gender" value="1" label="Male" />				
    				</td>
    				<td></td>
    			<tr>
    				<!-- PHONE -->
    			<tr>
    				<td></td>
    				<td><form:input path="phone" /></td>
    				<td><form:errors path="phone" cssClass="error" /></td>
    			<tr>
    				<!-- EMAIL -->
    			<tr>
    				<td></td>
    				<td><form:input path="email" /></td>
    				<td><form:errors path="email" cssClass="error" /></td>
    			<tr>
    				<!-- PASSWORD -->
    			<tr>
    				<td></td>
    				<td><form:input path="password" /></td>
    				<td><form:errors path="password" cssClass="error" /></td>
    			<tr>
    				<!-- DEGREE -->
    			<tr>
    				<td></td>
    				<td><form:select path="degree">
    						<form:options items="${degreeList}" />
    					</form:select></td>
    				<td></td>
    			<tr>
    				<!-- DEPARTMENT -->
    			<tr>
    				<td></td>
    				<td><form:select path="department">
    						<form:options items="${departmentList}" />
    					</form:select></td>
    				<td></td>
    			<tr>
    			<tr>
    				<td></td>
    				<td><input type="submit" value="Submit" /> <input
    					type="button" value="Clear" onclick="clearFields()" /></td>
    				<td></td>
    			<tr>
    		</table>
    	</form:form>
    </body>
    </html>
    

    References
    Mkyong

    Eclipse: JS validation bug – Cannot return from outside a function or method

    <form:form method="POST" commandName="student" name="reg-form" onsubmit="return validateFields()">
    </form:form>
    

    Issue
    Cannot return from outside a function or method.

    Solution
    We can just ignore it

    Reference
    StackOverflow

    Form : Basic

    student-registration.jsp

    
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
    	<jsp:directive.page language="java"
    		contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
    	<jsp:text>
    		<![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
    	</jsp:text>
    	<jsp:text>
    		<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
    	</jsp:text>
    	<html xmlns="http://www.w3.org/1999/xhtml">
    <SCRIPT type="text/javascript">
    	function clearFields() {
    		document.forms["reg-form"]["name"].value = "";
    		document.forms["reg-form"]["age"].value = "";
    		document.forms["reg-form"]["gender"].value = "";
    		document.forms["reg-form"]["email"].value = "";
    	}
    
    	function validateForm() {
    		var name = document.forms["reg-form"]["name"].value;
    		if (name == null || name == "") {
    			alert("Name must be filled out");
    			return false;
    		}
    		return false;
    	}
    </SCRIPT>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Student Registration Form</title>
    </head>
    <body>
    	<FORM action="student-register.do" method="post" name="reg-form"
    		onsubmit="return validateForm()">
    		<TABLE border="1" align="center">
    			<TR>
    				<TD></TD>
    				<TD>${message}</TD>
    			</TR>
    			<TR>
    				<TD>Name</TD>
    				<TD><INPUT type="text" name="name" /></TD>
    			</TR>
    			<TR>
    				<TD>Age</TD>
    				<TD><INPUT type="text" name="age" /></TD>
    			</TR>
    			<TR>
    				<TD>Gender</TD>
    				<TD><INPUT type="text" name="gender" /></TD>
    			</TR>
    			<TR>
    				<TD>Email</TD>
    				<TD><INPUT type="text" name="email" /></TD>
    			</TR>
    			<TR>
    				<TD></TD>
    				<TD><INPUT type="submit" value="Submit" /> <INPUT
    					type="button" value="Clear" onclick="clearFields();" /></TD>
    			</TR>
    		</TABLE>
    	</FORM>
    </body>
    	</html>
    </jsp:root>
    
    

    StudentRegistrationController.java

    
    package jkcs.basic;
    
    import java.io.IOException;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.xml.ws.Response;
    
    import org.apache.catalina.connector.Request;
    
    /**
     * Servlet implementation class StudentRegistrationController
     */
    public class StudentRegistrationController extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
    	/**
    	 * @see HttpServlet#HttpServlet()
    	 */
    	public StudentRegistrationController() {
    		super();
    		// TODO Auto-generated constructor stub
    	}
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
    	 *      response)
    	 */
    	protected void doGet(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    		response.getWriter().write("S T U D E N T");
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
    	 *      response)
    	 */
    	protected void doPost(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    		String name = request.getParameter("name");
    		String age = request.getParameter("age");
    		String gender = request.getParameter("gender");
    		String email = request.getParameter("email");
    
    		// validation
    		boolean validForm = false;
    		// name
    		if (checkEmpty(name) && checkEmpty(age) && checkEmpty(gender)
    				&& checkEmpty(email)) {
    			// further validation
    			validForm = true;
    		} else {
    			response.getWriter().write("errors");
    			validForm = false;
    		}
    
    		RequestDispatcher view = request
    				.getRequestDispatcher("student-registration.jsp");
    		if (validForm) {
    			request.setAttribute("message", "Thank you!");
    		} else {
    			request.setAttribute("message",
    					"Please recheck and submit");
    		}
    
    		view.forward(request, response);
    
    	}
    
    	public boolean checkEmpty(String data) {
    		if (data.equals("") || data == null) {
    			return false;
    		}
    		// more validation
    		return true;
    	}
    
    }
    
    

    Reference

    XSLT: Academic search example

    Research-Publications-Schema.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
    
    	<xsd:element name="publications">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="publication" type="publication-type"
    					minOccurs="1" maxOccurs="unbounded" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    
    	<xsd:complexType name="publication-type">
    		<xsd:sequence>
    			<xsd:element name="title" type="xsd:string" />
    			<xsd:element name="author" type="author-type" minOccurs="1"
    				maxOccurs="unbounded" />
    			<xsd:element name="abstract" type="xsd:string" />
    			<xsd:element name="citation" type="citation-type"
    				minOccurs="0" maxOccurs="unbounded" />
    			<xsd:element name="conference" type="conference-type"
    				minOccurs="0" maxOccurs="1" />
    			<xsd:element name="doi" type="doi-type" minOccurs="0"
    				maxOccurs="1" />
    			<xsd:element name="download-link" type="xsd:string"
    				minOccurs="0" maxOccurs="1" />
    			<xsd:element name="links" type="link-type" minOccurs="0" />
    			<xsd:element name="references" type="citation-type"
    				minOccurs="0" maxOccurs="unbounded" />
    		</xsd:sequence>
    		<xsd:attribute name="id" type="xsd:string" />
    		<xsd:attribute name="type">
    			<xsd:simpleType>
    				<xsd:restriction base="xsd:string">
    					<xsd:pattern value="(paper|book)"></xsd:pattern>
    				</xsd:restriction>
    			</xsd:simpleType>
    		</xsd:attribute>
    	</xsd:complexType>
    
    	<xsd:complexType name="citation-type">
    		<xsd:sequence>
    			<xsd:element name="publication-id" type="xsd:integer" />
    			<xsd:element name="year" type="xsd:integer" minOccurs="0"
    				maxOccurs="1" />
    		</xsd:sequence>
    	</xsd:complexType>
    
    	<xsd:complexType name="author-type">
    		<xsd:sequence>
    			<xsd:element name="name" type="xsd:string" />
    		</xsd:sequence>
    		<xsd:attribute name="id" type="xsd:integer" />
    	</xsd:complexType>
    
    	<xsd:complexType name="conference-type">
    		<xsd:sequence>
    			<xsd:element name="type">
    				<xsd:simpleType>
    					<xsd:restriction base="xsd:string">
    						<xsd:pattern value="(conference|journal)">
    						</xsd:pattern>
    					</xsd:restriction>
    				</xsd:simpleType>
    			</xsd:element>
    			<xsd:element name="title" type="xsd:string" />
    			<xsd:element name="year" type="xsd:string" />
    		</xsd:sequence>
    		<xsd:attribute name="id" type="xsd:integer" />
    	</xsd:complexType>
    
    	<xsd:complexType name="doi-type">
    		<xsd:sequence>
    			<xsd:element name="link" type="xsd:string" />
    		</xsd:sequence>
    	</xsd:complexType>
    
    	<xsd:complexType name="link-type">
    		<xsd:sequence>
    			<xsd:element name="link" type="xsd:string" minOccurs="0"
    				maxOccurs="unbounded" />
    		</xsd:sequence>
    	</xsd:complexType>
    
    </xsd:schema>
    

    Research-Publications.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="convert-publication.xsl"?>
    <publications xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:noNamespaceSchemaLocation="Research-Publications-Schema.xsd">
    	<!-- PUBLICATION 01 -->
    	<publication id="27617837" type="paper">
    		<title>
    			The Streaming Complexity of Validating XML Documents
    		</title>
    		<author id="17903870">
    			<name>Christopher Konrad</name>
    		</author>
    		<abstract>
    			We study the complexity of validating XML documents against
    			any given DTD in the context of streaming algorithms with
    			external memory. We design a deterministic algorithm that
    			solves this problem with memory space $O(\log^2 N)$, a
    			constant number of auxiliary read/write streams, and $O(\log
    			N)$ total number of passes on the XML document of size $N$
    			and auxiliary streams. An important intermediate step is the
    			memory-efficient computation of the FCNS encoding of the
    			initial XML document. Then, validity can already be decided
    			in one-pass with memory space $O(\sqrt{N\log N})$, and no
    			auxiliary streams. A second but reverse pass makes the
    			memory space collapse to $O(\log^2 N)$. This suggests a
    			systematic use of the FCNS encoding for large XML documents,
    			since, without this encoding, there are DTDs against which
    			validating XML documents requires memory space $\Omega(N/p)$
    			for any $p$-pass streaming algorithm without auxiliary
    			streams, even if randomization is allowed. Last, for the
    			special case of validating XML documents encoding binary
    			trees, we give a deterministic one-pass algorithm with
    			memory space $O(\sqrt{N})$, and prove its optimality, up to
    			a multiplicative constant, even if randomization is allowed.
    		</abstract>
    		<conference id="299">
    			<type>journal</type>
    			<title>Computing Research Repository - CORR</title>
    			<year>, vol. abs/1012.3, 2010</year>
    		</conference>
    		<links>
    			<link>http://arxiv.org/abs/1012.3311</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/journals/corr/corr1012.html#abs-1012-3311
    			</link>
    		</links>
    	</publication>
    	<!-- PUBLICATION 02 -->
    	<publication id="12981188" type="paper">
    		<title>WSMX A Semantic Service-OrientedArchitecture</title>
    		<author id="54923108">
    			<name>Cimpian Adrian</name>
    		</author>
    		<author id="52495940">
    			<name>Mocan Eyal</name>
    		</author>
    		<author id="39187">
    			<name>Christoph Bussler</name>
    		</author>
    		<abstract>
    			Web Services offer an interoperability model thut from the
    			idiosyncrasies of implementations; they were introduced to
    			address the need for seamless interoperability between in
    			the Business- to-Business domain. We analyse the
    			requirements this domain and show that to fully address
    			interoperability de- mands we need to make use of
    			descriptions of Web Services. We therefore introduce the Web
    			Service Execution Envi- ronment (WSMX), a software system
    			that enables the cre- ation and execution of Semantic
    			WebServices based on the Web Service Modelling Ontology.
    			Providers can use it to register and their services and
    			requesters can use it to dynamically discover und invoke
    			relevant services. WSMX allows a requesterto mediate and
    			invoke WebSer-vices in order to curry out its tasks, based
    			on services avail- able on the Internet.
    		</abstract>
    		<links>
    			<link>
    				http://cs.gmu.edu/~jpsousa/classes/443/materials/semanticWebServices.pdf
    			</link>
    		</links>
    		<references>
    			<publication-id>1241161</publication-id>
    			<year>2004</year>
    		</references>
    		<references>
    			<publication-id>1992594</publication-id>
    			<year>1994</year>
    		</references>
    		<references>
    			<publication-id>2583643</publication-id>
    			<year>2004</year>
    		</references>
    		<references>
    			<publication-id>2583643</publication-id>
    			<year>2004</year>
    		</references>
    		<references>
    			<publication-id>11008919</publication-id>
    		</references>
    		<references>
    			<publication-id>4595079</publication-id>
    		</references>
    	</publication>
    	<!-- PUBLICATION 03 -->
    	<publication id="48171933" type="book">
    		<title>
    			Design of Domain Specific Language for Web Services QoS
    			Constraints Definition
    		</title>
    		<author id="47451926">
    			<name>Monika Sikri</name>
    		</author>
    		<abstract>
    			Semantic Webservices (SWS) has raised interest in mechanisms
    			for Ontological representation of Web Services. A number of
    			mechanisms most notably WSMO and OWL-S are being developed
    			to represent the same. An important area in description of
    			Web Services is the QoS characterization and discovery which
    			is the focus of research for this paper. A Domain Specific
    			language is being proposed for definition of observable QoS
    			characteristics and conditions. The syntax of this proposed
    			language is being kept closer to WSML considering it the
    			standard modeling language.
    		</abstract>
    		<doi>
    			<link>
    				http://dx.doi.org/10.1007%2f978-3-642-20573-6_73
    			</link>
    		</doi>
    		<links>
    			<link>
    				http://www.springerlink.com/content/lg7741866m7436h0
    			</link>
    			<link>
    				http://www.springerlink.com/index/lg7741866m7436h0.pdf
    			</link>
    		</links>
    		<references>
    			<publication-id>6013167</publication-id>
    			<year>2009</year>
    		</references>
    		<references>
    			<publication-id>4245151</publication-id>
    			<year>2007</year>
    		</references>
    		<references>
    			<publication-id>4720243</publication-id>
    			<year>2008</year>
    		</references>
    		<references>
    			<publication-id>4084599</publication-id>
    			<year>2005</year>
    		</references>
    		<references>
    			<publication-id>4301331</publication-id>
    			<year>2006</year>
    		</references>
    	</publication>
    	<!-- PUBLICATION 04 -->
    	<publication id="6031124" type="paper">
    		<title>
    			Semantic Web Enabled Composition of Semantic Web Services
    		</title>
    		<author id="3615116">
    			<name>Duygu Celik</name>
    		</author>
    		<author id="3508963">
    			<name>Atilla Elci</name>
    		</author>
    		<abstract>
    			This article presents semantic-based composition of
    			processes of Semantic Web Services using predetermined
    			semantic descriptions of the services. Currently most
    			proposed techniques are syntactically, rather than
    			semantically, oriented. Our proposed method involves a
    			semantic-based composition agent which is called Semantic
    			Composition Agent (SCA). The novel design of SCA applies two
    			different well-known approaches, namely process algebra and
    			Armstrong axioms, in its two major components (planner and
    			inference engine respectively) of the process composition
    			framework. In order to demonstrate its applicability, a
    			prototype of SCA was implemented and tested against a number
    			of Web services composition cases.
    		</abstract>
    		<conference id="592">
    			<type>conference</type>
    			<title>
    				COMPSAC - International Computer Software and
    				Applications Conference
    			</title>
    			<year>, vol. 2, pp. 46-51, 2009</year>
    		</conference>
    		<doi>
    			<link>http://dx.doi.org/10.1109%2fCOMPSAC.2009.113</link>
    		</doi>
    		<download-link>
    			http://academic.research.microsoft.com/Publication/2298586/semantic-web-enabled-composition-of-web-services
    		</download-link>
    		<links>
    			<link>http://dx.doi.org/10.1109/COMPSAC.2009.113</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/conf/compsac/compsac2009-2.html#CelikE09
    			</link>
    			<link>
    				http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=5254152
    			</link>
    		</links>
    	</publication>
    	<!-- PUBLICATION 05 -->
    	<publication id="1890852" type="book">
    		<title>
    			The Design of Webservices Framework Support Ontology Based
    			Dynamic Service Composition
    		</title>
    		<author id="56692">
    			<name>Seungkeun Lee</name>
    		</author>
    		<author id="21901014">
    			<name>Sehoon Lee</name>
    		</author>
    		<author id="3531565">
    			<name>Kiwook Lim</name>
    		</author>
    		<author id="1051645">
    			<name>Junghyun Lee</name>
    		</author>
    		<abstract>
    			The coupling of webservices and semantic web technology
    			provides the ability to automatically discover, compose and
    			execute webservices. Most importantly, automatic composition
    			can provide access methods for all activities on the WWW. As
    			a result of this popularity, a number of people are
    			researching this area. However, the composition of
    			webservices is generally static because these webservices
    			are usually described using BPEL4WS or WSFL, restricting
    			dynamic operation because the composite service only has a
    			sequence execution plan. This dynamic composition cannot
    			generate a parallel execution plan for many Internet
    			business applications. In this paper, we design an ontology
    			based framework for dynamic webservice composition. Also, we
    			present a semantic webservice framework using dynamic
    			composition model. This dynamic composition model can
    			generate a parallel execution plan. These plans are
    			calculated using QoS model, hence the best execution plan is
    			selected.
    		</abstract>
    		<citation>
    			<publication-id>50890876</publication-id>
    			<year>2010</year>
    		</citation>
    		<citation>
    			<publication-id>4315712</publication-id>
    			<year>2007</year>
    		</citation>
    		<citation>
    			<publication-id>2468630</publication-id>
    			<year>2006</year>
    		</citation>
    		<citation>
    			<publication-id>48685574</publication-id>
    		</citation>
    		<conference id="1773">
    			<type>conference</type>
    			<title>Asia Information Retrieval Symposium - AIRS</title>
    			<year>, pp. 721-726, 2005</year>
    		</conference>
    		<doi>
    			<link>http://dx.doi.org/10.1007%2f11562382_74</link>
    		</doi>
    		<links>
    			<link>
    				http://www.springerlink.com/content/p8m6505887023439
    			</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/conf/airs/airs2005.html#LeeLLL05
    			</link>
    			<link>http://dx.doi.org/10.1007/11562382_74</link>
    		</links>
    	</publication>
    	<!-- PUBLICATION 06 -->
    	<publication id="11568610" type="paper">
    		<title>
    			Implementation of Rich Metadata Formats and Semantic Tools
    			using DSpace
    		</title>
    		<author id="8226770">
    			<name>Imma Subirats</name>
    		</author>
    		<author id="50436554">
    			<name>Areti Ramachandra Durga Prasad</name>
    		</author>
    		<author id="7983442">
    			<name>Johannes Keizer</name>
    		</author>
    		<author id="50757849">
    			<name>Andrew Bagdanov</name>
    		</author>
    		<abstract>
    			This poster explores the customization of DSpace to allow
    			the use of the AGRIS Application Profile metadata standard
    			and the AGROVOC thesaurus. The objective is the adaptation
    			of DSpace, through the least invasive code changes either in
    			the form of plug-ins or add-ons, to the specific needs of
    			the Agricultural Sciences and Technology community. Metadata
    			standards such as AGRIS AP, and Knowledge Organization
    			Systems such as the AGROVOC thesaurus, provide mechanisms
    			for sharing information in a standardized manner by
    			recommending the use of common semantics and interoperable
    			syntax (Subirats et al., 2007). AGRIS AP was created to
    			enhance the description, exchange and subsequent retrieval
    			of agricultural Document-like Information Objects (DLIOs).
    			It is a metadata schema which draws from Metadata standards
    			such as Dublin Core (DC), the Australian Government Locator
    			Service Metadata (AGLS) and the Agricultural Metadata
    			Element Set (AgMES) namespaces. It allows sharing of
    			information across dispersed bibliographic systems (FAO,
    			2005). AGROVOC68 is a multilingual structured thesaurus
    			covering agricultural and related domains. Its main role is
    			to standardize the indexing process in order to make
    			searching simpler and more efficient. AGROVOC is developed
    			by FAO (Lauser et al., 2006). The customization of the
    			DSpace is taking place in several phases. First, the AGRIS
    			AP metadata schema was mapped onto the metadata DSpace
    			model, with several enhancements implemented to support
    			AGRIS AP elements. Next, AGROVOC will be integrated as a
    			controlled vocabulary accessed through a local SKOS or OWL
    			file. Eventually the system will be configurable to access
    			AGROVOC through local files or remotely via webservices.
    			Finally, spell checking and tooltips will be incorporated in
    			the user interface to support metadata editing. Adapting
    			DSpace to support AGRIS AP and annotation using the
    			semantically-rich AGROVOC thesaurus transform DSpace into a
    			powerful, domain-specific system for annotation and exchange
    			of bibliographic metadata in the agricultural domain.
    		</abstract>
    		<download-link>
    			http://academic.research.microsoft.com/Publication/11568610/implementation-of-rich-metadata-formats-and-semantic-tools-using-dspace
    		</download-link>
    		<references>
    			<publication-id>6098466</publication-id>
    			<year>2008</year>
    		</references>
    	</publication>
    	<!-- PUBLICATION 07 -->
    	<publication id="487004" type="book">
    		<title>
    			Ten-Step Survival Guide for the Emerging Business Web
    		</title>
    		<author id="204553">
    			<name>Aad P. A. Van Moorsel</name>
    		</author>
    		<abstract>
    			Webservices technology is converging, and today we are at
    			least able to define what we mean if we use the term
    			webservice (SOAP, XML, WSDL). Given the matur- ing
    			technology, it is opportune to get concrete about the future
    			of webservices-based technologies. An area that
    			traditionally has been assumed to become a major benefici-
    			ary of webservices technology is that of
    			business-to-business interactions. In this pa- per we try to
    			get to the core issues we face in creating this emerging
    			'business web,' these dynamic, digital business ecosystems.
    			For the reader's entertainment, we do this in the form of a
    			10-step survival guide, each step being a technology
    			'invariant,' that is, a statement about the future business
    			web that we expect to remain true for considerable time to
    			come. Our hope is that this will provide you with enough
    			insides to find your way among all the hype in the emerging
    			business web, or at least allow you to survive a variety of
    			water cooler con- versations in the years to come. In
    			addition, while going through the 10 steps we un- cover the
    			principles of the architecture that will support the future
    			business web.2
    		</abstract>
    		<citation>
    			<publication-id>50486609</publication-id>
    			<year>2006</year>
    		</citation>
    		<citation>
    			<publication-id>1869524</publication-id>
    			<year>2005</year>
    		</citation>
    		<citation>
    			<publication-id>1689519</publication-id>
    			<year>2005</year>
    		</citation>
    		<citation>
    			<publication-id>436147</publication-id>
    			<year>2003</year>
    		</citation>
    		<citation>
    			<publication-id>4604815</publication-id>
    		</citation>
    		<conference id="487">
    			<type>conference</type>
    			<title>
    				Web Services, E-Business, and the Semantic Web - WES
    			</title>
    			<year>, pp. 1-11, 2002</year>
    		</conference>
    		<doi>
    			<link>http://dx.doi.org/10.1007%2f3-540-36189-8_1</link>
    		</doi>
    		<download-link>
    			http://www.cs.newcastle.ac.uk/publications/books/papers/247.pdf
    		</download-link>
    		<links>
    			<link>
    				http://www.springerlink.com/content/nmd1gr21yhjw6l94
    			</link>
    			<link>
    				http://www.springerlink.com/index/nmd1gr21yhjw6l94.pdf
    			</link>
    			<link>
    				http://dirc.org.uk/research/pubs/books/papers/247.pdf
    			</link>
    			<link>
    				http://link.springer.de/link/service/series/0558/bibs/2512/25120001.htm
    			</link>
    			<link>
    				http://www.hpl.hp.com/techreports/2002/HPL-2002-203.pdf
    			</link>
    			<link>
    				http://www.cs.newcastle.ac.uk/publications/books/papers/247.pdf
    			</link>
    			<link>
    				http://www.cs.ncl.ac.uk/publications/books/papers/247.pdf
    			</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/conf/wes/wes2002.html#Moorsel02
    			</link>
    		</links>
    		<references>
    			<publication-id>1296364</publication-id>
    			<year>1999</year>
    		</references>
    		<references>
    			<publication-id>2125960</publication-id>
    			<year>2002</year>
    		</references>
    		<references>
    			<publication-id>2142809</publication-id>
    			<year>2002</year>
    		</references>
    		<references>
    			<publication-id>776924</publication-id>
    			<year>2002</year>
    		</references>
    		<references>
    			<publication-id>88364</publication-id>
    			<year>2001</year>
    		</references>
    	</publication>
    	<!-- PUBLICATION 08 -->
    	<publication id="2191450" type="book">
    		<title>
    			Dynamic Service Composition Model for Ubiquitous Service
    			Environments
    		</title>
    		<author id="56692">
    			<name>Seungkeun Lee</name>
    		</author>
    		<author id="1051645">
    			<name>Junghyun Lee</name>
    		</author>
    		<abstract>
    			There are a lot of services in ubiquitous computing
    			environments. So, ubiquitous service need a service
    			matchmaker which presents more easily and with accuracy. The
    			coupling of webservices and semantic web technology provides
    			the ability to automatically discover, compose and execute
    			webservices. However, the composition of services is
    			generally static because these services are usually
    			described using BPEL4WS or WSFL, restricting dynamic
    			operation because the composite service only has a sequence
    			execution plan. This dynamic composition cannot generate a
    			parallel execution plan for many Internet business
    			applications. In this paper, we design an ontology based
    			framework for dynamic webservice composition. Also, we
    			present a semantic webservice framework using dynamic
    			composition model. This dynamic composition model can
    			generate a parallel execution plan. These plans are
    			calculated using QoS model, hence the best execution plan is
    			selected.
    		</abstract>
    		<conference id="1493">
    			<type>conference</type>
    			<title>
    				Pacific Rim International Workshop on Multi-Agents -
    				PRIMA
    			</title>
    			<year>, pp. 742-747, 2006</year>
    		</conference>
    		<doi>
    			<link>http://dx.doi.org/10.1007%2f11802372_88</link>
    		</doi>
    		<links>
    			<link>
    				http://www.springerlink.com/index/8420821716601nt6.pdf
    			</link>
    			<link>
    				http://www.springerlink.com/content/8420821716601nt6
    			</link>
    			<link>http://dx.doi.org/10.1007/11802372_88</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/conf/prima/prima2006.html#LeeL06a
    			</link>
    		</links>
    		<references>
    			<publication-id>2197037</publication-id>
    			<year>2006</year>
    		</references>
    		<references>
    			<publication-id>4442286</publication-id>
    			<year>2008</year>
    		</references>
    		<references>
    			<publication-id>862991</publication-id>
    			<year>2002</year>
    		</references>
    		<references>
    			<publication-id>588895</publication-id>
    			<year>2003</year>
    		</references>
    		<references>
    			<publication-id>27806920</publication-id>
    			<year>2001</year>
    		</references>
    	</publication>
    	<!-- PUBLICATION 09 -->
    	<publication id="4302112" type="paper">
    		<title>Smartweb: multimodal web services on the road</title>
    		<author id="1070219">
    			<name>Wolfgang Wahlster</name>
    		</author>
    		<abstract>
    			SmartWeb provides a context-aware user interface to
    			webservices, so that it can support the mobile user in
    			differentroles, e.g. as a car driver, a motorbiker, or a
    			pedestrian. Itprovides a symmetric multimodal dialogue
    			system [2] combiningspeech, gesture, haptic and video input
    			with speech, haptic, videoand acoustic output. It goes
    			beyond traditional keyword searchengines like Google by
    			delivering higher quality results that areadapted to the
    			mobile user's current task and situation. In
    			mobilesituations, users don't want to deal with hypertext
    			lists ofretrieved webpages, but simply want an answer to
    			their query. If adesperate driver with a crying and acutely
    			ill child on thebackseat asks SmartWeb "Who is the closest
    			paediatrician?" he needsjust the name and address of the
    			doctor. Based on SmartWeb'sability to combine various web
    			services, the driver can then askSmartWeb a follow-up
    			question about route guidance to the doctor'spractice. One
    			of the innovative features of SmartWeb is that theuser can
    			specify whether he wants a textual or pictorial answer,
    			avideo clip or a sound file as a query result.SmartWeb [1]
    			provides not only an open-domain question answeringmachine
    			but a multimodal web service interface for coherentdialogue,
    			where questions and commands are interpreted according tothe
    			context of the previous conversation. For example, if
    			thedriver of our Mercedes-Benz R-Class test car asks
    			SmartWeb "Whereis the closest Italian restaurant", it will
    			access a web service tofind an appropriate restaurant and
    			show its location on a digitalmap presented on the large
    			dashboard display. The user may continuehis dialog with a
    			command like "Please guide me there with arefuelling stop at
    			the lowest price gas station". In this case,SmartWeb
    			combines a navigation service with a special web servicethat
    			finds low gas prices. SmartWeb includes plan-based
    			compositionmethods for semantic web services, so that
    			complex tasks can becarried out for the mobile user.One
    			version of SmartWeb has been deployed on a BMW
    			motorbikeR1200RT, using a swivel with force feedback
    			integrated in thehandle bar. Similar to the control knob
    			known from the iDriveinterface of BMW automobiles, the biker
    			can rotate the swivel orpush it right or left in order to
    			browse through menus or selectitems displayed by SmartWeb on
    			the large high-resolution screen inthe middle of the
    			cockpit. In combination with these pointingactions, the
    			biker can use speech input over the microphoneintegrated in
    			a Bluetooth helmet to interact with SmartWeb. Themultimodal
    			dialogue system combines visual displays with speech
    			andearcons over the speakers integrated in the helmet and
    			haptic forcefeedback for output generation. For example, the
    			biker can ask forweather forecasts along his planned route.
    			SmartWeb accesseslocation-based web services via the bike's
    			3G wireless connectionto retrieve the relevant weather
    			forecasts. In addition, SmartWebexploits ad-hoc Wifi
    			connections for vehicle-to-vehiclecommunication based on a
    			local danger warning ontology so that themotorbike driver
    			can be informed of a danger ahead by a car infront of him.
    			For example, a car detecting a large wedge of waterunder its
    			wheels will pass the information wirelessly to the
    			bikefollowing it and SmartWeb will generate the warning
    			"Attention!Risk of aquaplaning 100 meters ahead" using the
    			GPS coordinates ofboth vehicles to compute the distance to
    			the upcoming dangerousarea. Another distinguishing feature
    			of SmartWeb is the generationof adaptive multimodal
    			presentations taking into account thepredicted cognitive
    			load of the biker depending on the drivingspeed and other
    			factors.This keynote presents the anatomy of SmartWeb,
    			itsontology-based information extraction and web service
    			compositiontechnology and explains the distinguishing
    			features of itsmultimodal dialogue and answer engine.
    		</abstract>
    		<citation>
    			<publication-id>39234751</publication-id>
    			<year>2011</year>
    		</citation>
    		<citation>
    			<publication-id>39246971</publication-id>
    			<year>2010</year>
    		</citation>
    		<citation>
    			<publication-id>6056832</publication-id>
    			<year>2009</year>
    		</citation>
    		<citation>
    			<publication-id>6043248</publication-id>
    			<year>2009</year>
    		</citation>
    		<citation>
    			<publication-id>50737258</publication-id>
    			<year>2008</year>
    		</citation>
    		<conference id="167">
    			<type>conference</type>
    			<title>ACM Multimedia Conference - MM</title>
    			<year>, pp. 16-16, 2007</year>
    		</conference>
    		<doi>
    			<link>http://dx.doi.org/10.1145%2f1291233.1291243</link>
    		</doi>
    		<download-link>
    			http://academic.research.microsoft.com/Publication/4302112/smartweb-multimodal-web-services-on-the-road
    		</download-link>
    		<links>
    			<link>http://portal.acm.org/citation.cfm?id=1291243</link>
    			<link>http://doi.acm.org/10.1145/1291233.1291243</link>
    			<link>
    				http://www.informatik.uni-trier.de/~ley/db/conf/mm/mm2007.html#Wahlster07
    			</link>
    		</links>
    		<references>
    			<publication-id>2488610</publication-id>
    			<year>2007</year>
    		</references>
    	</publication>
    	<!-- PUBLICATION 10 -->
    	<publication id="5008727" type="paper">
    		<title>
    			Assessment of modifying versus non-modifying protein
    			interactions
    		</title>
    		<author id="2208470">
    			<name>Dietrich Rebholz-Schuhmann</name>
    		</author>
    		<author id="23522795">
    			<name>Antonio Jimeno</name>
    		</author>
    		<author id="3514572">
    			<name>Miguel Arregui</name>
    		</author>
    		<author id="248379">
    			<name>Harald Kirsch</name>
    		</author>
    		<abstract>
    			Motivation: The identification of events such as
    			protein-protein interactions (PPIs) from the scientific
    			literature is a complex task. One of the reasons is that
    			there is no formal definition for the syntactical-semantic
    			repre- sentation of the relations with which authors of
    			manuscripts have to comply. In this study, we assess the
    			distribution of verbs de- noting binary relations between
    			proteins us- ing different corpora (AIMed, BioInfer,
    			BioCreAtIve II) for protein-protein interac- tions and
    			measure their performance for the identification of PPI
    			events (in the BioCreA- tIve II corpus) based on syntactical
    			patterns. We distinguish modifying interactions (MIs) such
    			as post-translational modifications (PTMs) from
    			non-modifying interactions. We found that MIs are less
    			frequent in the corpus but can be extracted at the same pre-
    			cision levels as PPIs. Programmatic access to the text
    			processing modules is available online ( www.ebi.ac.uk/
    			webservices/whatizit/info.jsf ,
    			http://www.ebi.ac.uk/Rebholz-srv/pcorral/).
    		</abstract>
    		<download-link>
    			http://www.bootstrep.org/pub/Extern/PublicationPage/EBI_2008_RebholzSchuhmann_SMBM.pdf
    		</download-link>
    		<links>
    			<link>
    				http://mars.cs.utu.fi/smbm2008/files/smbm2008proceedings/smbmpaper_30.pdf
    			</link>
    			<link>
    				http://www.bootstrep.eu/pub/Extern/PublicationPage/EBI_2008_RebholzSchuhmann_SMBM.pdf
    			</link>
    			<link>
    				http://www.bootstrep.org/pub/Extern/PublicationPage/EBI_2008_RebholzSchuhmann_SMBM.pdf
    			</link>
    		</links>
    		<references>
    			<publication-id>1729464</publication-id>
    			<year>2005</year>
    		</references>
    		<references>
    			<publication-id>552316</publication-id>
    			<year>2001</year>
    		</references>
    		<references>
    			<publication-id>2180973</publication-id>
    			<year>2005</year>
    		</references>
    		<references>
    			<publication-id>2148340</publication-id>
    			<year>2005</year>
    		</references>
    		<references>
    			<publication-id>3540421</publication-id>
    			<year>2005</year>
    		</references>
    	</publication>
    </publications>
    

    Convert-Publications.xsl

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:template match="/">
    		<html>
    			<body>
    				<table border="0" align="center" cellpadding="2">
    					<caption>
    						<b>Publications Search Result</b>
    					</caption>
    					<tr>
    						<td>
    							<font size="5" color="orange">
    								Publications</font>
    							<font size="5" color="orange">
    								(
    								<xsl:value-of select="count(publications/publication)" />
    								)
    							</font>
    
    						</td>
    					</tr>
    					<xsl:for-each select="publications/publication">
    						<!-- Title -->
    						<tr>
    							<td>
    								<link>
    									<xsl:attribute name="href">
    										http://academic.research.microsoft.com/Publication/<xsl:value-of
    										select="@id" />/<xsl:value-of select="title" />	
    									</xsl:attribute>
    									<font size="4" color="blue">
    										<xsl:value-of select="title" />
    									</font>
    									<!-- Citations -->
    									<xsl:if test="count(citation) != 0">
    										<font size="2">
    											(Citations: <xsl:value-of select="count(citation)" />)
    										</font>
    									</xsl:if>
    									<!-- Link -->
    									<xsl:if test="download-link != ''">
    										<link>
    											<xsl:attribute name="href">
    										 		<xsl:value-of select="download-link" />
    										 	</xsl:attribute>
    											<xsl:choose>
    												<xsl:when test="contains(download-link, '.pdf')">
    													<img><xsl:attribute name="src">images/pdf.png</xsl:attribute></img>
    												</xsl:when>
    												<xsl:otherwise>
    													<img><xsl:attribute name="src">images/view.png</xsl:attribute></img>
    												</xsl:otherwise>
    											</xsl:choose>
    										</link>
    									</xsl:if>
    								</link>
    							</td>
    						</tr>
    						<!-- Authors -->
    						<tr>
    							<td>
    								<font size="3">
    									<xsl:for-each select="author">
    										<link>
    											<xsl:attribute name="href">
    										http://academic.research.microsoft.com/Author/<xsl:value-of
    												select="@id" />/<xsl:value-of select="name" />	
    										</xsl:attribute>
    											<xsl:value-of select="name" />
    										</link>
    										<xsl:if test="position() != last()">
    											,
    										</xsl:if>
    									</xsl:for-each>
    								</font>
    							</td>
    						</tr>
    						<!-- Abstract -->
    						<tr>
    							<td>
    								<xsl:value-of select="abstract" />
    							</td>
    						</tr>
    						<!-- Conference -->
    						<tr>
    							<td>
    								<xsl:if test="conference/type = 'conference'">
    									Conference:
    									<link>
    										<xsl:attribute name="href">
    										http://academic.research.microsoft.com/Conference/<xsl:value-of
    											select="@id" />/<xsl:value-of select="conference/title" />	
    										</xsl:attribute>
    										<xsl:value-of select="conference/title" />
    									</link>
    									<xsl:value-of select="conference/year" />
    								</xsl:if>
    								<xsl:if test="conference/type = 'journal'">
    									Journal:
    									<link>
    										<xsl:attribute name="href">
    										http://academic.research.microsoft.com/Conference/<xsl:value-of
    											select="@id" />/<xsl:value-of select="conference/title" />	
    										</xsl:attribute>
    										<xsl:value-of select="conference/title" />
    									</link>
    									<xsl:value-of select="conference/year" />
    								</xsl:if>
    							</td>
    						</tr>
    						<br />
    					</xsl:for-each>
    				</table>
    			</body>
    		</html>
    	</xsl:template>
    </xsl:stylesheet>
    

    To convert this with SAXON

    >java -cp saxon8.jar net.sf.saxon.Transform -o test-result.html Research-Publications.xml Convert-Publications.xsl