package org.apache.struts2.showcase.model;
import java.io.Serializable;
IdEntity. Interface.
public interface IdEntity extends Serializable {
Serializable getId ();
void setId ( Serializable id );
}
public class Employee implements IdEntity {
private static final long serialVersionUID = -6226845151026823748L;
private Long empId; //textfield w/ conversion
public Employee() {
}
public Employee(Long empId) {
this.empId = empId;
}
public Long getEmpId() {
return empId;
}
public void setEmpId(Long empId) {
this.empId = empId;
}
public Serializable getId() {
return getEmpId();
}
public void setId(Serializable id) {
setEmpId((Long) id);
}
}
package org.apache.struts2.showcase.dao;
import java.io.Serializable;
import java.util.Collection;
import org.apache.struts2.showcase.exception.CreateException;
import org.apache.struts2.showcase.exception.StorageException;
import org.apache.struts2.showcase.exception.UpdateException;
import org.apache.struts2.showcase.model.IdEntity;
/**
* Dao. Interface.
*
*/
public interface Dao {
Class getFeaturedClass();
----->public Class getFeaturedClass() {
return Employee.class;
}
IdEntity get(Serializable id);
Serializable create(IdEntity object) throws CreateException;
IdEntity update(IdEntity object) throws UpdateException;
Serializable merge(IdEntity object) throws StorageException;
int delete(Serializable id) throws CreateException;
int delete(IdEntity object) throws CreateException;
Collection findAll();
}
package org.apache.struts2.showcase.filedownload;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
/**
* Demonstrates file resource download.
* Set filePath to the local file resource to download,
* relative to the application root ("/images/struts.gif").
*
*/
public class FileDownloadAction implements Action {
private String inputPath;
public void setInputPath(String value) {
inputPath = value;
}
public InputStream getInputStream() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}
public String execute() throws Exception {
return SUCCESS;
}
}