jtobject.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 2,226 行 · 第 1/5 页
JAVA
2,226 行
if (logStream == null) {
System.err.println (formatter.format(date) + ":" + msg);
return;
}
logStream.println (formatter.format(date) + ":" + msg);
logStream.flush ();
}
// handleError: handle error messages
/**
* Handles error messages. This method generates a JtException which
* is handled by the handleException method.
* This causes the error message and the stack trace to be sent to the screen or a log file.
* This method should be called each time an error is detected.
* Override this method if your application requires special error handling.
* @param msg error message
*/
public void handleError (String msg) {
try {
// generate a JtException
if (objErrors == null)
objErrors = new LinkedList ();
((LinkedList) objErrors).add(msg);
throw new JtException (msg);
} catch (JtException e) {
handleException (e);
}
}
// add: add an object to the Object table
private void add (Object id, Object obj) {
//private synchronized void add (String id, Object obj) {
if (id == null || obj == null)
return;
if (objTable == null)
objTable = new Hashtable ();
if (id instanceof String)
objTable.put (id, obj);
else
objTable.put(id.toString(), obj);
// handleTrace ("JtObject.add:" + id + ":" + obj);
return;
// }
}
// remove: remove an object from the object table
//private synchronized Object remove (String id) {
private Object remove (Object id) {
String objId;
//Hashtable ht;
if (id == null)
return (null);
if (id instanceof String)
objId = (String) id;
else
objId = id.toString();
if (objTable == null)
return (null);
if (objTable.get (objId) == null)
handleError ("JtObject.remove: unable to remove object (not found):" +
id);
return (objTable.remove (objId));
}
/**
* Gets the name of the file used for logging purposes (logFile).
*/
public String getLogFile() {
return logFile;
}
/**
* Specifies the file to be used for logging purposes (logFile).
* @param newLogFile name of the log file
*/
public void setLogFile(String newLogFile) {
if (newLogFile != null && logFile != null)
if (newLogFile.equals(logFile))
return;
logFile = newLogFile;
logging = true;
//this.setObjTrace (1);
if (logFile != null)
open_logfile ();
}
/**
* Returns the logging boolean.
*/
public boolean getLogging() {
return logging;
}
/**
* Specifies whether or not logging is enabled.
* @param logging
*/
public void setLogging(boolean logging) {
JtObject.logging = logging;
}
/**
* Returns the logging level.
*/
public int getLogLevel() {
return logLevel;
}
/**
* Specifies the logging level.
* @param logLevel
*/
public void setLogLevel(int logLevel) {
JtObject.logLevel = logLevel;
}
/**
* Gets the name of the Jt resource file. The default value for this attribute is Jt.properties.
* Attribute values are loaded from this resource file just after the object is created.
*/
public String getResourceFile() {
return resourceFile;
}
/**
* Specifies the file to be used as the Jt resource file. The default value for this attribute is Jt.properties.
* Attribute values are loaded from this resource file after the object is created.
* @param newResourceFile Jt resource file
*/
public void setResourceFile(String newResourceFile) {
resourceFile = newResourceFile;
if (resourceFile != null)
loadResourceFile (); // check
}
/**
* Gets the Resource table (internal framework method).
*/
public Hashtable getResTable() {
return resTable;
}
/**
* Specifies the Resource table (internal framework method).
*/
public void setResTable(Hashtable resTable) {
if (JtObject.resTable != null) {
handleTrace ("Jt Resources have been loaded already. ");
return;
}
JtObject.resTable = resTable;
}
/**
* Returns the resource input stream
*/
public InputStream getResourceStream() {
return resourceStream;
}
/**
* Specifies the resource input stream (internal use only)
*/
public void setResourceStream(InputStream resourceStream) {
JtObject.resourceStream = resourceStream;
//if (resTable != null) {
// handleTrace ("Jt Resources have been loaded already. ");
// return;
//}
loadResourcesFromStream (resourceStream);
}
/**
* Gets the Jt context.
*/
//public static JtContext getObjContext() {
// return objContext;
//}
/**
* Sets the Jt context.
*/
//public static void setObjContext(JtContext objContext) {
// JtObject.objContext = objContext;
//}
/**
* Gets the value of the object ID. This attribute contains the qualified name of the object.
*/
public String getObjName() {
return objName;
}
/**
* Sets the value of the object ID. This attribute contains the qualified name of the object.
*/
public void setObjName(String newObjName) {
objName = newObjName;
}
// Object Id (Being
public Object getObjErrors() {
return objErrors;
}
public void setObjErrors(Object objErrors) {
this.objErrors = objErrors;
}
/*
long getObjId() {
return objId;
}
void setObjId(long newObjId) {
objId = newObjId;
}
*/
/**
* Gets the value of objTrace. This attribute enables/disables the logging of trace messages.
*/
/*
public int getObjTrace() {
return objTrace;
}
*/
/**
* Gets the value of objTrace. This attribute enables/disables the logging of trace messages.
*/
/*
public void setObjTrace(int newObjTrace) {
objTrace = newObjTrace;
}
*/
// Object path
/*
public String getObjPath() {
return objPath;
}
public void setObjPath(String newObjPath) {
objPath = newObjPath;
}
*/
/**
* Gets the value of objException. This attribute is used to store exceptions detected
* while processing messages. The handleException method updates this attribute.
* Since handleError invokes handleException, it also updates this attribute.
*/
public Object getObjException() {
return objException;
}
/**
* Sets the value of objException. This attribute is used to store exceptions detected
* while processing messages. The handleException method updates this attribute.
* Since handleError invokes handleException, it also updates this attribute.
*/
public void setObjException(Object newObjException) {
objException = newObjException;
}
// Session
/*
public Object getObjSession() {
return objSession;
}
*/
/*
public void setObjSession(Object newObjSession) {
//handleTrace ("JtObject.setObjSession:" + newObjSession);
objSession = newObjSession;
}
*/
// create_dir: create the parent directory
/*
void create_dir (String name) {
File file;
String parentpath;
if (name == null)
return;
file = new File (name);
if (file == null) {
handleError ("JtFile: unable to create File object:" + name);
return;
}
parentpath = file.getParent ();
if (parentpath == null)
return;
//file = file.getParentFile ();
file = new File (parentpath);
if (file == null) {
handleError ("JtFile: unable to get parent File:" + name);
return;
}
if (!file.exists ())
if (!file.mkdirs ())
handleError ("JtFile: unable to create directories:" +
parentpath);
}
*/
JtResource parseResource (String line) {
//String resource_class
String tmp;
int index;
int length;
JtResource res;
if (line == null)
return (null);
length = line.length ();
if (length == 0)
return (null);
index = line.indexOf (":");
if (index < 0)
return (null);
if (index == length - 1)
return (null);
res = new JtResource ();
res.value = line.substring (index+1, length);
tmp = line.substring (0, index);
index = tmp.lastIndexOf (".");
if (index == -1)
return (null);
if (index == tmp.length () - 1)
return (null); // ends with a dot ?
res.rclass = tmp.substring (0, index);
res.name = tmp.substring (index + 1);
handleTrace ("Jt Resource: " + "(" +
res.rclass + "," + res.name + "," + res.value
+ ")");
return (res);
}
JtResource parseObjResource (String line) {
//String resource_class
String tmp;
int index;
int length;
JtResource res;
if (line == null)
return (null);
length = line.length ();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?