001: /*
002: * Created on Jan 8, 2004
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl;
008:
009: import java.util.HashMap;
010:
011: import java.io.IOException;
012: import java.io.ObjectOutput;
013:
014: import org.apache.log4j.*;
015:
016: import org.xdev.base.core.BASE;
017:
018: /**
019: * @author AYegorov
020: *
021: * To change the template for this generated type comment go to
022: * Window>Preferences>Java>Code Generation>Code and Comments
023: */
024:
025: public class XLogger extends XSSLObject implements ObjectOutput {
026: public static final String LEVEL = "level";
027: public static final String LOGGER_ID = "logger";
028: public static final String RETURN_OBJECT = "return";
029: public static final String MESSAGE = "message";
030:
031: /**
032: * @param id
033: */
034: public XLogger(String id) {
035: super (id);
036: // XXX Auto-generated constructor stub
037: }
038:
039: /**
040: * @param id
041: * @param properties
042: */
043: public XLogger(String id, HashMap properties) {
044: super (id, properties);
045: // XXX Auto-generated constructor stub
046: }
047:
048: /* (non-Javadoc)
049: * @see org.xdev.base.xssl.XSSLObject#processObject(java.lang.Object)
050: */
051: protected Object processObject(Object obj) throws Exception {
052: if (obj == null && this .getCount() > 0) {
053: XSSLReturn r = (XSSLReturn) this .getElement(0);
054:
055: if (r.execute()) {
056: obj = r.getObjectValue();
057: }
058:
059: this .logDebug("Logger has received value: " + obj);
060:
061: r = null;
062: }
063:
064: obj = (obj == null ? "" : obj);
065:
066: String loggerId = this .getProperty(XLogger.LOGGER_ID);
067: Object value = this .getProperty(XLogger.MESSAGE) + " "
068: + BASE.getValueFromObject(obj);
069: Level level = (Level) this .getPropertyAsObject(XLogger.LEVEL);
070:
071: level = level == null ? XLogger.DEBUG : level;
072:
073: if ("".equals(loggerId)) {
074: this .logCustom(value, level);
075: } else {
076: this .logCustom(loggerId, value, level);
077: }
078:
079: this .logDebug("Logger has logged message: [ " + value + " ]");
080:
081: return this .getBooleanProperty(XLogger.RETURN_OBJECT) ? obj
082: : "";
083: }
084:
085: /* (non-Javadoc)
086: * @see java.io.ObjectOutput#flush()
087: */
088: public void flush() throws IOException {
089: }
090:
091: /* (non-Javadoc)
092: * @see java.io.ObjectOutput#write(int)
093: */
094: public void write(int b) throws IOException {
095: this .writeObject(new Byte((byte) b));
096: }
097:
098: /* (non-Javadoc)
099: * @see java.io.ObjectOutput#write(byte[])
100: */
101: public void write(byte[] b) throws IOException {
102: this .writeObject(b);
103: }
104:
105: /* (non-Javadoc)
106: * @see java.io.ObjectOutput#write(byte[], int, int)
107: */
108: public void write(byte[] b, int off, int len) throws IOException {
109: for (int i = off; i < len; i++) {
110: this .write(b[i]);
111: }
112: }
113:
114: /* (non-Javadoc)
115: * @see java.io.ObjectOutput#writeObject(java.lang.Object)
116: */
117: public void writeObject(Object obj) throws IOException {
118:
119: try {
120:
121: this .processObject(obj);
122: } catch (Exception ex) {
123: throw new IOException(BASE.getValueFromObject(ex));
124: }
125: }
126:
127: /* (non-Javadoc)
128: * @see java.io.DataOutput#writeDouble(double)
129: */
130: public void writeDouble(double v) throws IOException {
131: this .writeObject(new Double(v));
132: }
133:
134: /* (non-Javadoc)
135: * @see java.io.DataOutput#writeFloat(float)
136: */
137: public void writeFloat(float v) throws IOException {
138: this .writeObject(new Float(v));
139: }
140:
141: /* (non-Javadoc)
142: * @see java.io.DataOutput#writeByte(int)
143: */
144: public void writeByte(int v) throws IOException {
145: this .write(v);
146: }
147:
148: /* (non-Javadoc)
149: * @see java.io.DataOutput#writeChar(int)
150: */
151: public void writeChar(int v) throws IOException {
152: this .writeObject(String.valueOf(v));
153: }
154:
155: /* (non-Javadoc)
156: * @see java.io.DataOutput#writeInt(int)
157: */
158: public void writeInt(int v) throws IOException {
159: this .writeObject(new Integer(v));
160: }
161:
162: /* (non-Javadoc)
163: * @see java.io.DataOutput#writeShort(int)
164: */
165: public void writeShort(int v) throws IOException {
166: this .writeObject(new Short((short) v));
167: }
168:
169: /* (non-Javadoc)
170: * @see java.io.DataOutput#writeLong(long)
171: */
172: public void writeLong(long v) throws IOException {
173: this .writeObject(new Long(v));
174: }
175:
176: /* (non-Javadoc)
177: * @see java.io.DataOutput#writeBoolean(boolean)
178: */
179: public void writeBoolean(boolean v) throws IOException {
180: this .writeObject(new Boolean(v));
181: }
182:
183: /* (non-Javadoc)
184: * @see java.io.DataOutput#writeBytes(java.lang.String)
185: */
186: public void writeBytes(String s) throws IOException {
187: this .writeObject(s);
188: }
189:
190: /* (non-Javadoc)
191: * @see java.io.DataOutput#writeChars(java.lang.String)
192: */
193: public void writeChars(String s) throws IOException {
194: this .writeBytes(s);
195: }
196:
197: /* (non-Javadoc)
198: * @see java.io.DataOutput#writeUTF(java.lang.String)
199: */
200: public void writeUTF(String str) throws IOException {
201: this .writeBytes(str);
202: }
203:
204: public void close() throws IOException {
205:
206: try {
207:
208: super .close();
209: } catch (Exception ex) {
210: throw new IOException(BASE.getValueFromObject(ex));
211: }
212: }
213: }
|