jtdaostrategy.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 140 行
JAVA
140 行
package Jt.DAO;
import Jt.JtFactory;
import Jt.JtMessage;
import Jt.JtObject;
import Jt.JtStrategy;
/**
* DAO Strategy. This class is based on the Strategy design pattern.
* Several DAO strategies are available: a) a native DAO implementation
* based on the JDBC adapter. b) a Hibernate strategy.
* Additional DAO strategies can be used in conjuntion with this class.
*
*/
public class JtDAOStrategy extends JtStrategy {
public static final String JtCLASS_NAME = JtDAOStrategy.class.getName();
private static final long serialVersionUID = 1L;
private String concreteStrategyClassName = JtDAOAdapter.JtCLASS_NAME;
private boolean initted = false;
private JtFactory factory = new JtFactory ();
public JtDAOStrategy () {
}
public String getConcreteStrategyClassName() {
return concreteStrategyClassName;
}
public void setConcreteStrategyClassName(String concreteStrategyClassName) {
this.concreteStrategyClassName = concreteStrategyClassName;
}
// Propagate Exceptions
private Exception propagateException (Object obj)
{
Exception ex;
if (obj == null)
return null;
ex = (Exception) factory.getValue(obj, "objException");
if (ex != null)
//setValue (this, "objException", ex);
this.setObjException(ex);
return (ex);
}
private void initialize () {
JtFactory factory = new JtFactory ();
if (concreteStrategy == null) {
// handleError ("processMessage: concreteStrategy attribute must be set");
// return (null);
if (concreteStrategyClassName == null) {
handleError ("processMessage: concreteStrategyClassName attribute must be set");
return;
}
concreteStrategy = factory.createObject(concreteStrategyClassName);
}
}
/**
* Process object messages.
* <ul>
* </ul>
*/
public Object processMessage (Object message) {
String msgid = null;
JtMessage e = (JtMessage) message;
JtFactory factory = new JtFactory ();
Object reply;
if (e == null)
return null;
msgid = (String) e.getMsgId ();
if (msgid == null)
return null;
//content = e.getMsgContent();
//data = e.getMsgData ();
if (!initted) {
initialize ();
initted = true;
}
if (msgid.equals (JtObject.JtINITIALIZE)) {
if (!initted) {
initialize ();
initted = true;
}
return null;
}
if (msgid.equals (JtDAOAdapter.JtREAD_MAPPING_STREAM)) {
// Ignore JtDAOAdapter.JtREAD_MAPPING_STREAM unless the concrete
// strategy is the default strategy (JtDAOAdapter)
if (!JtDAOAdapter.JtCLASS_NAME.equals(concreteStrategyClassName))
return (null);
}
// Let the concrete strategy process the message
reply = super.processMessage (message);
if (concreteStrategy != null) {
propagateException (concreteStrategy);
}
return (reply);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?