📄 basetrackingobject.java
字号:
/*
* This is the base domain object class that stores common tracking
* attributes such as changedBy and changedOn and also provides the
* utlity method to convert an object to its xml representation.
*/
package svnexample;
import java.lang.reflect.Field;
import java.util.Date;
public abstract class BaseTrackingObject {
private String modifiedUser;
private Date modifiedDate;
private String modificationReason;
public BaseTrackingObject() {
//initialize the member attributes.
modifiedUser = "";
modificationReason = "";
}
/**
* @return The modification reason
*/
public String getModificationReason() {
return modificationReason;
}
/**
* @return
*/
public Date getModifiedDate() {
return modifiedDate;
}
/**
* @return
*/
public String getModifiedUser() {
return modifiedUser;
}
/**
* @param string - Sets the reason for the modification.
*/
public void setModificationReason(String string) {
modificationReason = string;
}
/**
* @param date - Sets date and time when the change was made.
*/
public void setModifiedDate(Date date) {
modifiedDate = date;
}
/**
* @param string - The user responsible for modifying the
* domain object.
*/
public void setModifiedUser(String string) {
modifiedUser = string;
}
public abstract Object getObjectId();
public abstract void setObjectId(Object pk);
/**
* @param string
*/
public String getXmlRepresentation() {
StringBuffer xmlRepresentation = new StringBuffer();
Class cls = getClass();
do {
java.lang.reflect.Field[] fields = cls.getDeclaredFields();
java.lang.reflect.AccessibleObject.setAccessible(fields, true);
for (int i = 0; i < fields.length; i++) {
try {
xmlRepresentation.append("<");
xmlRepresentation.append(fields[i].getName());
xmlRepresentation.append(">");
xmlRepresentation.append(fields[i].get(this));
xmlRepresentation.append("</");
xmlRepresentation.append(fields[i].getName());
xmlRepresentation.append(">");
xmlRepresentation.append(System.getProperty("line.separator"));
}
catch (IllegalAccessException e) {
e.printStackTrace(); //ignore the field..
}
}
cls = cls.getSuperclass();
}
while(cls != null && cls != Object.class);
return xmlRepresentation.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -