1 package com.protomatter.syslog.xml; 2 3 52 53 import java.io.*; 54 import java.net.*; 55 import java.util.*; 56 import java.text.*; 57 58 import com.protomatter.xml.*; 59 import com.protomatter.syslog.*; 60 import org.jdom.*; 61 62 65 public class PrintWriterLog_Helper 66 extends BasicLogger_Helper 67 { 68 109 public void configure(Object o, Element e) 110 throws SyslogInitException 111 { 112 super.configure(o, e); 113 114 PrintWriterLog log = (PrintWriterLog)o; 115 116 boolean setStream = false; 117 118 String value = e.getChildTextTrim("stream", e.getNamespace()); 119 if (value != null) 120 { 121 if (value.equals("System.out")) 122 { 123 log.setWriter(new PrintWriter(System.out)); 124 log.setStreamName(value); 125 } 126 else if (value.equals("System.err")) 127 { 128 log.setWriter(new PrintWriter(System.err)); 129 log.setStreamName(value); 130 } 131 else 132 throw new IllegalArgumentException (MessageFormat.format( 133 Syslog.getResourceString(MessageConstants.PARAM_MUST_BE_A_OR_B_MESSAGE), 134 new Object [] { "stream", "System.out", "System.err" } )); 135 } 136 else 137 { 138 throw new IllegalArgumentException (MessageFormat.format( 139 Syslog.getResourceString(MessageConstants.XML_MUST_SPECIFY_PARAM_MESSAGE), 140 new Object [] { "stream" } )); 141 } 142 } 143 144 public Element getConfiguration(Object o, Element element) 145 { 146 Element e = super.getConfiguration(o, element); 147 148 PrintWriterLog log = (PrintWriterLog)o; 149 String streamName = log.getStreamName(); 150 if ("System.out".equals(streamName) || "System.err".equals(streamName)) 151 { 152 e.getChildren().add((new Element("stream")).setText(streamName)); 153 } 154 else 155 { 156 e.getChildren().clear(); 157 Comment comment = new Comment( 158 "This PrintWriterLog instance was attached to a PrintWriter\n" + 159 "other than System.out or System.err, and so the configuration\n" + 160 "cannot be stored in an XML representation. Sorry."); 161 e.getChildren().add(comment); 162 } 163 164 return e; 165 } 166 } 167 | Popular Tags |