KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > feedback > EmitConfigurationType


1 /**
2  * $Id: EmitConfigurationType.java 186 2007-03-16 13:42:35Z ssmc $
3  * Copyright 2002-2003 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.feedback;
30
31 import java.text.DateFormat JavaDoc;
32 import java.text.FieldPosition JavaDoc;
33 import java.text.SimpleDateFormat JavaDoc;
34 import java.util.Date JavaDoc;
35
36 import org.apache.tools.ant.BuildException;
37 import org.apache.tools.ant.Project;
38 import org.apache.tools.ant.types.Reference;
39
40 import com.idaremedia.apis.DiagnosticsEmitter;
41 import com.idaremedia.apis.DiagnosticsEmitterFactory;
42
43 import com.idaremedia.antx.AntX;
44 import com.idaremedia.antx.AssertableDataType;
45 import com.idaremedia.antx.FixtureComponent;
46 import com.idaremedia.antx.NoiseLevel;
47 import com.idaremedia.antx.helpers.DateTimeFormat;
48 import com.idaremedia.antx.helpers.Setting;
49 import com.idaremedia.antx.helpers.Strings;
50 import com.idaremedia.antx.helpers.Tk;
51
52 /**
53  * Holder of a fixed set of EmitConfiguration bits; usually defined &lt;emitconfiguration&gt;.
54  * This type allows users to create shareable configuration for various emit-aware tasks.
55  * Any attributes not defined or defined as "inherited" return the values returned by the
56  * configuration's default configuration (which is either the build-iteration fixture's
57  * default configuration or the configuration referred-to by the <i>defaults</i> parameter).
58  * The build-iteration default configuration is often the fixed {@linkplain
59  * DefaultEmitConfiguration log4j configuration}.
60  * <p>
61  * Because configurations are referred-to by multiple executing tasks, a configuration "own"
62  * APIs return only the explicit values assigned to their instance. These methods will
63  * not look at the build-iteration context. However, the public {@linkplain EmitConfiguration}
64  * APIs might read the build-iteration's context if told too (by using the "enclosing" value
65  * for the <i>wrt</i> parameter). Users should be careful when setting a configuration to look
66  * at the enclosing context because that context in turn cannot be setup to reference
67  * that same configuration (an infinite loop will occur).
68  * <p>
69  * <b>Examples:</b><pre>
70  * &lt;<b>emitconfiguration</b> id="emit.defaults"
71  * from="AntX"
72  * wrt="longdate"
73  * noiselevel="info"
74  * echo="yes"
75  * /&gt;
76  * &lt;<b>emitconfiguration</b> id="emit.checkpoint"
77  * wrt="enclosing"
78  * echo="no"
79  * timestampFormat="short"
80  * /&gt;
81  * &lt;<b>emitconfiguration</b> id="goal.documents"
82  * wrt="enclosing"
83  * from="Documentation"
84  * timestamp="no"
85  * echo="no"
86  * /&gt;
87  * &lt;<b>emitconfiguration</b> id="emit.defaults.jdk14log"
88  * from="AntX/builds/nightly"
89  * noiselevel="info"
90  * emitterfactory="mycompany.antx.Jdk14Emitter"
91  * groupingseparator="/"
92  * /&gt;
93  * </pre>
94  *
95  * @since JWare/AntX 0.1
96  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
97  * @version 0.5
98  * @.safety guarded (once fully configured)
99  * @.group api,helper
100  * @see EmitConfigureTask
101  **/

102
103 public class EmitConfigurationType extends AssertableDataType
104     implements EmitConfiguration, FixtureComponent, Cloneable JavaDoc
105 {
106     /**
107      * Initializes a new EmitConfigurationType instance.
108      **/

109     public EmitConfigurationType()
110     {
111         super(AntX.feedback+"configure");
112     }
113
114
115     /**
116      * Initializes a new CV-labeled EmitConfigurationType instance.
117      * @param iam CV-label (non-null)
118      **/

119     public EmitConfigurationType(String JavaDoc iam)
120     {
121         super(iam);
122     }
123
124
125     /**
126      * Marks this type instance as acting on behalf of another
127      * object (usually a task).
128      * @param controller this type's controlling object (non-null)
129      * @since JWare/AntX 0.4
130      **/

131     public final void setController(Object JavaDoc controller)
132     {
133         m_controller = controller;
134     }
135
136
137     /**
138      * Returns the emit configuration referenced by this instance.
139      * Only call if actually is a reference.
140      * @throws BuildException if this object is not a reference
141      **/

142     protected final EmitConfigurationType getOtherEC()
143     {
144         return (EmitConfigurationType)getCheckedRef
145             (EmitConfigurationType.class, "emitconfiguration");
146     }
147
148
149     /**
150      * Returns a clone of this configuration. Supports copying
151      * of configurations between parent and forked child projects.
152      * @since JWare/AntX 0.3
153      **/

154     public synchronized Object JavaDoc clone()
155     {
156         if (isReference()) {
157             return getOtherEC().clone();
158         }
159         try {
160             EmitConfigurationType cloned = (EmitConfigurationType)super.clone();
161             if (getOwnEmitterFactory()!=null) {
162                 cloned.m_emitterFactory = null;
163                 cloned.setEmitterFactory(getOwnEmitterFactory().getClass());
164             }
165             if (getOwnTimestampFormat()!=null) {
166                 if (m_df instanceof SimpleDateFormat JavaDoc) {
167                     cloned.m_df = (DateFormat JavaDoc)((SimpleDateFormat JavaDoc)m_df).clone();
168                 } else {
169                     cloned.m_timestampFormat = null;
170                     cloned.setTimestampFormat(getOwnTimestampFormat());
171                 }
172             }
173             cloned.m_defaultsEC= null;//NB:force into own space
174
return cloned;
175
176         } catch(CloneNotSupportedException JavaDoc clnx) {
177             throw new Error JavaDoc(uistrs().get(AntX.CLONE_BROKEN_MSGID));
178         }
179     }
180
181
182     /**
183      * Capture our identifier for feedback since types don't always
184      * get correct location information.
185      **/

186     public void setId(String JavaDoc id)
187     {
188         m_Id= id;
189     }
190
191
192     /**
193      * Returns a unique identifier for this configuration. Either
194      * returns a script-defined {@linkplain #setId id} or a
195      * combination of this instance's system identity and its class
196      * name. Never returns <i>null</i>.
197      **/

198     public final String JavaDoc getId()
199     {
200         if (m_Id!=null) {
201             return m_Id;
202         }
203         if (isReference()) {
204             return getOtherEC().getId();
205         }
206         return super.getId();
207     }
208
209
210 // ---------------------------------------------------------------------------------------
211
// Inheritance/Defaults Behavior:
212
// ---------------------------------------------------------------------------------------
213

214     /**
215      * Sets this configuration to refer to a another configuration
216      * as its defaults. The referred-to object must exist and implement
217      * the EmitConfiguration interface.
218      * @since JWare/AntX 0.3
219      **/

220     public void setDefaults(Reference r)
221     {
222         require_(r!=null,"setDflt- nonzro ref");
223         if (isReference()) {
224             throw tooManyAttributes();
225         }
226         m_defaultsRef = r;
227         edited();
228     }
229
230
231     /**
232      * Returns this configuration's user-defined defaults. Will return
233      * <i>null</i> if never set (meaning the fixture's default configuration
234      * will be used).
235      * @since JWare/AntX 0.3
236      **/

237     public final Reference getOwnDefaults()
238     {
239         if (isReference()) {
240             return getOtherEC().getOwnDefaults();
241         }
242         return m_defaultsRef;
243     }
244
245
246     /**
247      * Sets this configuration's defaults directly. Useful when a configuration
248      * is being delegated to by another configuration-type implementation.
249      * @.safety guarded
250      * @param defaults new defaults instance (use <i>null</i> to reset)
251      **/

252     public synchronized void setDefaultConfiguration(EmitConfiguration defaults)
253     {
254         m_defaultsEC = defaults;
255     }
256
257
258     /**
259      * Returns the effective default configuration used by this type.
260      * Usually returns either the fixture's defaults or the nearest
261      * installed emit configuration taskset.
262      * @since JWare/AntX 0.3
263      **/

264     protected synchronized EmitConfiguration getDefaults()
265     {
266         if (m_defaultsEC!=null) {
267             return m_defaultsEC;
268         }
269         if (m_defaultsRef!=null) {
270             EmitConfiguration ec = (EmitConfiguration)getReferencedObject
271                 (getProject(),m_defaultsRef.getRefId(),EmitConfiguration.class);
272             verifyNotCircular(ec);
273             m_defaultsEC = ec;
274             return m_defaultsEC;
275         }
276         return EmitContext.getDefaultConfiguration();
277     }
278
279
280 // ---------------------------------------------------------------------------------------
281
// Emitter Grouping Path:
282
// ---------------------------------------------------------------------------------------
283

284     /**
285      * Sets the default grouping or log4j category of messages emitted
286      * using this configuration.
287      * @param grpId this configuration's new default category
288      * @see #getOwnFrom
289      **/

290     public void setFrom(String JavaDoc grpId)
291     {
292         require_(grpId!=null,"setFrom- nonzro grpId");
293         if (isReference()) {
294             throw tooManyAttributes();
295         }
296         m_grpId = grpId;
297         edited();
298     }
299
300
301     /**
302      * Returns this configuration's direct grouping or log4j category.
303      * The returned value (which can be <i>null</i>) is <em>not</em>
304      * necessarily the grouping used to determine this configuration's
305      * default grouping. That setting is a combination of the result
306      * of this method and the {@linkplain #getOwnWrt wrt} setting.
307      * @since JWare/AntX 0.3
308      **/

309     public final String JavaDoc getOwnFrom()
310     {
311         if (isReference()) {
312             return getOtherEC().getOwnFrom();
313         }
314         return m_grpId;
315     }
316
317
318     /**
319      * Returns the default grouping or log4j category of messages
320      * emitted using this configuration. The returned path includes
321      * the effect an this configuration's '{@linkplain #setWrt wrt}'
322      * option. Can return <i>null</i> if never set and no 'wrt'
323      * option is specified.
324      * @.safety guarded
325      * @.impl Do not cache calculated paths (can be context-specific)
326      * @.impl Uses defaults
327      * @throws BuildException if detect circular reference to self
328      **/

329     public String JavaDoc getFrom()
330     {
331         if (isReference()) {
332             return getOtherEC().getFrom();
333         }
334
335         String JavaDoc from = getOwnFrom();
336         String JavaDoc base = null;
337         String JavaDoc ISEP = getGroupingPathSeparator();
338
339         if (getOwnWrt()!=null) {
340             if (m_wrtImpl!=null) {
341                 base = m_wrtImpl;
342             } else {
343                 String JavaDoc wrt = Tk.lowercaseFrom(getOwnWrt());
344                 if (Strings.DEFAULT.equals(wrt)) {
345                     EmitConfiguration ec = getDefaults();
346                     base = ec.getFrom();
347                     ISEP = ec.getGroupingPathSeparator();
348                 }
349                 else if (wrt.length()==0 || "root".equals(wrt)) {
350                     base = "";
351                 }
352                 else if (Strings.ENCLOSING.equals(wrt)) {
353                     EmitConfiguration ec = EmitContext.getConfigurationNoNull();//danger!
354
verifyNotCircular(ec);
355                     base = ec.getFrom();
356                     ISEP = ec.getGroupingPathSeparator();
357                 }
358                 else {
359                     boolean isIt=false;
360                     if (getProject().getReference(wrt)!=null) {
361                         Object JavaDoc o = getProject().getReference(wrt);
362                         if (o instanceof EmitConfiguration) {
363                             EmitConfiguration ec = (EmitConfiguration)o;
364                             verifyNotCircular(ec);
365                             base = ec.getFrom();
366                             ISEP = ec.getGroupingPathSeparator();
367                             isIt = true;
368                         }
369                     }
370                     if (base==null && !isIt) {
371                         String JavaDoc warning = uistrs().get("emit.invalid.wrt",getId(),wrt);
372                         log(warning,Project.MSG_WARN);
373                     }
374                 }//as-refid
375
}
376         }
377         if (base!=null) {
378             if (from==null || from.length()==0) {
379                 from = base;
380             }
381             else if (base.length()>0) {
382                 from = base + ISEP + from;
383             }
384         }
385         return from;
386     }
387
388
389     /**
390      * Defines this configuration's grouping as relative to
391      * something else. If either of the symbolic date groupings are
392      * specified, this type takes a date snapshot <em>now</em> and uses
393      * that as the grouping until reset or cleared.
394      * @param wrt the something else (use <i>null</i> to clear)
395      * @since JWare/AntX 0.3
396      **/

397     public void setWrt(String JavaDoc wrt)
398     {
399         if (isReference()) {
400             throw tooManyAttributes();
401         }
402         m_wrt = wrt;
403         m_wrtImpl = null;
404         if (wrt!=null) {
405             wrt = Tk.lowercaseFrom(wrt);
406             if ("longdate".equals(wrt)) {
407                 synchronized(DateTimeFormat.STANDARD_DATE) {
408                     m_wrtImpl = DateTimeFormat.STANDARD_DATE.format(new Date JavaDoc());
409                 }
410             } else if ("shortdate".equals(wrt)) {
411                 synchronized(DateTimeFormat.ABBREV_DATE) {
412                     m_wrtImpl = DateTimeFormat.ABBREV_DATE.format(new Date JavaDoc());
413                 }
414             }
415         }
416         edited();
417     }
418
419
420     /**
421      * Returns what this configuration's grouping is relative to.
422      * Returns the value as given to {@linkplain #setWrt setWrt}-- does not
423      * returned the process values. Returns <i>null</i> if never set or
424      * been reset.
425      * @since JWare/AntX 0.3
426      **/

427     public String JavaDoc getOwnWrt()
428     {
429         if (isReference()) {
430             return getOtherEC().getOwnWrt();
431         }
432         return m_wrt;
433     }
434
435
436     /**
437      * Sets a custom emitter factory's grouping path separator.
438      * Only useful if the emitter factory is also customized.
439      * @since JWare/AntX 0.3
440      **/

441     public void setGroupingSeparator(String JavaDoc separator)
442     {
443         require_(separator!=null,"setGrpSep- nonzro sep");
444         if (isReference()) {
445             throw tooManyAttributes();
446         }
447         m_emitterSeparator = separator;
448         edited();
449     }
450
451
452
453     /**
454      * Returns the default grouping category separator for this
455      * configuration. If not defined, returns whatever this type's
456      * default configuration's separator is.
457      * @since JWare/AntX 0.3
458      * @.impl Uses defaults
459      **/

460     public String JavaDoc getGroupingPathSeparator()
461     {
462         if (isReference()) {
463             return getOtherEC().getGroupingPathSeparator();
464         }
465         return m_emitterSeparator!=null ? m_emitterSeparator
466             : getDefaults().getGroupingPathSeparator();
467     }
468
469
470 // ---------------------------------------------------------------------------------------
471
// Automatically Included Properties (Environment Snapshot):
472
// ---------------------------------------------------------------------------------------
473

474     /**
475      * Sets the list of property names to be automatically attached
476      * to any emitted messages.
477      * @param nameList comma-delimited list of property names
478      **/

479     public void setProperties(String JavaDoc nameList)
480     {
481         require_(nameList!=null,"setProps- nonzro names");
482         if (isReference()) {
483             throw tooManyAttributes();
484         }
485         m_propertyNames= nameList;
486         edited();
487     }
488
489
490     /**
491      * Returns name list of properties to be automatically included
492      * in any emitted messages. Returns <i>null</i> (for none)
493      * if never set.
494      **/

495     public final String JavaDoc getOwnProperties()
496     {
497         if (isReference()) {
498             return getOtherEC().getOwnProperties();
499         }
500         return m_propertyNames;
501     }
502
503
504     /**
505      * Adds any custom property names to given list. Does nothing
506      * and returns <i>false</i> if additional properties never
507      * defined.
508      * @param list names buffer to update
509      * @return <i>true</i> if list buffer modified
510      * @see #setProperties
511      * @.impl Uses defaults
512      **/

513     public boolean getPropertiesNameList(StringBuffer JavaDoc list)
514     {
515         require_(list!=null,"getNams- nonzro listbuf");
516         if (isReference()) {
517             return getOtherEC().getPropertiesNameList(list);
518         }
519         boolean dflts = getDefaults().getPropertiesNameList(list);
520
521         String JavaDoc myList = getOwnProperties();
522         if (myList!=null) {
523             if (list.length()>0) {
524                 list.append(",");
525             }
526             list.append(myList);
527         }
528         return dflts || myList!=null;
529     }
530
531
532 // ---------------------------------------------------------------------------------------
533
// Noise Making:
534
// ---------------------------------------------------------------------------------------
535

536     /**
537      * Sets the default priority level for emitted messages.
538      * @param nl default message noise level
539      **/

540     public void setNoiseLevel(NoiseLevel nl)
541     {
542         require_(nl!=null,"setNoiz- nonzro lvl");
543         if (isReference()) {
544             throw tooManyAttributes();
545         }
546         m_noiseLevel = nl;
547         edited();
548     }
549
550
551     /**
552      * Returns this type's noise level setting. Will return
553      * <i>null</i> if never set.
554      **/

555     public NoiseLevel getOwnNoiseLevel()
556     {
557         if (isReference()) {
558             return getOtherEC().getOwnNoiseLevel();
559         }
560         return m_noiseLevel;
561     }
562
563
564     /**
565      * Returns this configuration's default message priority level.
566      * Will return this type's default noise level if never set.
567      * @.impl Uses defaults
568      **/

569     public NoiseLevel getNoiseLevel()
570     {
571         if (isReference()) {
572             return getOtherEC().getNoiseLevel();
573         }
574         return m_noiseLevel!=null ? m_noiseLevel : getDefaults().getNoiseLevel();
575     }
576
577
578     /**
579      * Sets whether emissions should also be echo to the standard
580      * Ant logging system.
581      * @param wantIt preference setting (yes,no,inherit)
582      **/

583     public void setEcho(String JavaDoc wantIt)
584     {
585         require_(wantIt!=null,"setEcho- nonzro setin");
586         if (isReference()) {
587             throw tooManyAttributes();
588         }
589         m_echoPref= Setting.from(wantIt, Setting.INHERITED);
590         edited();
591     }
592
593
594     /**
595      * Returns the echo-to-Ant-log preference for this configuration.
596      * Will return <i>Setting.INHERITED</i> if never set.
597      **/

598     public final Setting getOwnEcho()
599     {
600         if (isReference()) {
601             return getOtherEC().getOwnEcho();
602         }
603         return m_echoPref;
604     }
605
606
607     /**
608      * Returns <i>true</i> if emitted messages should also echo to
609      * the standard Ant logging system.
610      * @.impl Uses defaults
611      **/

612     public boolean shouldEcho()
613     {
614         if (isReference()) {
615             return getOtherEC().shouldEcho();
616         }
617         switch (getOwnEcho().getIndex()) {
618             case Setting.ON_INDEX: {
619                 return true;
620             }
621             case Setting.OFF_INDEX:{
622                 return false;
623             }
624         }
625         return getDefaults().shouldEcho();
626     }
627
628 // ---------------------------------------------------------------------------------------
629
// Timestamping (Checkpoints):
630
// ---------------------------------------------------------------------------------------
631

632     /**
633      * Sets the preferred format of generated timestamps. Useful for
634      * checkpoints where the only message can be a timestamp. The
635      * incoming format can be one of three special format identifiers:
636      * "short", "long", or "GMT". These identifiers select predefined
637      * formats; otherwise the format string is considered the datetime
638      * formatting specifier.
639      * @param format new timestamp format (non-null)
640      **/

641     public void setTimestampFormat(String JavaDoc format)
642     {
643         require_(format!=null,"setDtTmFmt- nonzro fmt");
644         if (isReference()) {
645             throw tooManyAttributes();
646         }
647         String JavaDoc normal= Tk.lowercaseFrom(format);
648         if ("short".equals(normal)) {
649             m_df = DateTimeFormat.ABBREV;
650         } else if ("long".equals(normal)) {
651             m_df = DateTimeFormat.STANDARD;
652         } else if ("gmt".equals(normal)) {
653             m_df = DateTimeFormat.GMT;
654         }
655         m_timestampFormat = format;
656         edited();
657     }
658
659
660     /**
661      * Returns this configuration's preferred timestamp format.
662      * Will return <i>null</i> if never set.
663      **/

664     public final String JavaDoc getOwnTimestampFormat()
665     {
666         if (isReference()) {
667             return getOtherEC().getOwnTimestampFormat();
668         }
669         return m_timestampFormat;
670     }
671
672
673     /**
674      * Returns this configuration's custom timestamp formatter. Returns
675      * <i>null</i> if this configuration has no custom timestamp formatter.
676      * @see #setTimestampFormat
677      * @.safety guarded
678      **/

679     protected final synchronized DateFormat JavaDoc getDateTimeFormatter()
680     {
681         if (m_df!=null) {
682             return m_df;
683         }
684         String JavaDoc fmt = getOwnTimestampFormat();
685         if (!Tk.isWhitespace(fmt)) {
686             m_df = new SimpleDateFormat JavaDoc(fmt);
687             return m_df;
688         }
689         return null;
690     }
691
692
693     /**
694      * Creates readable date-time string of given timestamp (milliseconds).
695      * If this configuration's timestamp format has been set, the formatted
696      * string will be in this format; otherwise, an AntX ABBREVIATED
697      * date/time formatted string is returned.
698      * @.safety guarded
699      * @.impl Uses defaults
700      **/

701     public String JavaDoc stampify(long ms)
702     {
703         if (isReference()) {
704             return getOtherEC().stampify(ms);
705         }
706         DateFormat JavaDoc df= getDateTimeFormatter();
707         if (df!=null) {
708             synchronized(df) {
709                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc(40);
710                 df.format(new Date JavaDoc(ms),sb,new FieldPosition JavaDoc(0));
711                 return sb.substring(0);
712             }
713         }
714         return getDefaults().stampify(ms);
715     }
716
717
718     /**
719      * Sets the include-timestamp preference for this configuration.
720      * @param wantIt preference setting (yes,no,inherit)
721      **/

722     public void setTimestamp(String JavaDoc wantIt)
723     {
724         require_(wantIt!=null,"setTimstmp- nonzro setin");
725         if (isReference()) {
726             throw tooManyAttributes();
727         }
728         m_timestampPref= Setting.from(wantIt, Setting.INHERITED);
729         edited();
730     }
731
732
733     /**
734      * Returns the include-timestamp preference for this configuration.
735      * Returns <i>Setting.INHERITED</i> if never set.
736      **/

737     public final Setting getOwnTimestamp()
738     {
739         if (isReference()) {
740             return getOtherEC().getOwnTimestamp();
741         }
742         return m_timestampPref;
743     }
744
745
746     /**
747      * Returns <i>true</i> if timestamp information should be included
748      * in any emitted messages.
749      * @.impl Uses defaults
750      **/

751     public boolean wantTimestamp()
752     {
753         if (isReference()) {
754             return getOtherEC().wantTimestamp();
755         }
756         switch (getOwnTimestamp().getIndex()) {
757             case Setting.ON_INDEX: {
758                 return true;
759             }
760             case Setting.OFF_INDEX:{
761                 return false;
762             }
763         }
764         return getDefaults().wantTimestamp();
765     }
766
767 // ---------------------------------------------------------------------------------------
768
// Diagnostics Emitters:
769
// ---------------------------------------------------------------------------------------
770

771     /**
772      * Returns this configuration's default emitter. Never returns
773      * <i>null</i>.
774      * @see #setFrom
775      * @.impl Do not cache calculated emiters (can be context-specific)
776      * @.impl Uses defaults
777      * @.safety guarded
778      **/

779     public DiagnosticsEmitter getEmitter()
780     {
781         if (isReference()) {
782             return getOtherEC().getEmitter();
783         }
784         String JavaDoc from = getFrom();
785         boolean root = Tk.isWhitespace(from);
786
787         if (getOwnEmitterFactory()!=null) {
788             if (root) {
789                 return getOwnEmitterFactory().newEmitter();
790             }
791             return getOwnEmitterFactory().newEmitter(from);
792         } else if (root) {
793             return getDefaults().getEmitter();
794         } else {
795             return getDefaults().getCustomEmitter(from);
796         }
797     }
798
799
800     /**
801      * Returns a custom diagnostics emitter for specified grouping. If
802      * this configuration has a custom emitter factory it is used to produce
803      * the new emitter; otherwise, the default configuration's factory
804      * is used.
805      * @param grpId category's name (non-null)
806      * @.impl Uses defaults
807      **/

808     public DiagnosticsEmitter getCustomEmitter(String JavaDoc grpId)
809     {
810         if (isReference()) {
811             return getOtherEC().getCustomEmitter(grpId);
812         }
813         if (getOwnEmitterFactory()!=null) {
814             return getOwnEmitterFactory().newEmitter(grpId);
815         }
816         return getDefaults().getCustomEmitter(grpId);
817     }
818
819
820     /**
821      * Sets the custom emitter factory used by this configuration.
822      * @param emitterFactoryClass custom emitter factory implementation (non-null)
823      * @throws BuildException if unable to create a DiagnosticsEmitterFactory
824      * instance from given class instance
825      **/

826     public void setEmitterFactory(Class JavaDoc emitterFactoryClass)
827     {
828         require_(emitterFactoryClass!=null,"setEmitFctry- nonzro clas");
829         if (isReference()) {
830             throw tooManyAttributes();
831         }
832         try {
833             m_emitterFactory = (DiagnosticsEmitterFactory)
834                 emitterFactoryClass.newInstance();
835         } catch (Exception JavaDoc anyX) {
836             log(AntX.uistrs().get("emit.invalid.factory",
837                                   emitterFactoryClass.getName()),
838                 Project.MSG_ERR);
839             throw new BuildException(anyX);
840         }
841         edited();
842     }
843
844
845     /**
846      * Returns this configuration's custom emitter factory. Will return
847      * <i>null</i> if a custom emitter factory has not be defined.
848      * @see LJDiagnosticsEmitter#FACTORY
849      **/

850     public final DiagnosticsEmitterFactory getOwnEmitterFactory()
851     {
852         if (isReference()) {
853             return getOtherEC().getOwnEmitterFactory();
854         }
855         return m_emitterFactory;
856     }
857
858
859
860     private void verifyNotCircular(EmitConfiguration ec)
861     {
862         //UNIMPL: needs to do real circular check (ssmc)
863
if (ec==this || ec==m_controller) {
864             String JavaDoc ermsg = uistrs().get("emit.circular.defaults");
865             log(ermsg, Project.MSG_ERR);
866             throw new BuildException(ermsg);
867         }
868     }
869
870
871 // ---------------------------------------------------------------------------------------
872

873     private String JavaDoc m_Id;
874     private Reference m_defaultsRef;
875     private EmitConfiguration m_defaultsEC;//=> cached-1st-use
876

877     private NoiseLevel m_noiseLevel;//NB:=> AntX|Project default-level (INFO)
878
private String JavaDoc m_propertyNames;//NB:=>none
879
private Setting m_echoPref = Setting.INHERITED;//NB:=> yes
880
private Setting m_timestampPref=Setting.INHERITED;//NB:=> no
881
private String JavaDoc m_timestampFormat;//NB:=>none
882
private DateFormat JavaDoc m_df;//NB:=>none
883

884     private String JavaDoc m_grpId;//NB:=>inherited default from
885
private String JavaDoc m_wrt="", m_wrtImpl;//NB:=>inherited default
886
private DiagnosticsEmitterFactory m_emitterFactory;//NB:inherited=>log4j
887
private String JavaDoc m_emitterSeparator;//NB:=>inherited default
888
private Object JavaDoc m_controller;//NB:=> acting on this thing's behalf
889
}
890
891 /* end-of-EmitConfigurationType.java */
892
Popular Tags