View Javadoc
1   /**
2    * Copyright (c) 2004-2011 QOS.ch
3    * All rights reserved.
4    *
5    * Permission is hereby granted, free  of charge, to any person obtaining
6    * a  copy  of this  software  and  associated  documentation files  (the
7    * "Software"), to  deal in  the Software without  restriction, including
8    * without limitation  the rights to  use, copy, modify,  merge, publish,
9    * distribute,  sublicense, and/or sell  copies of  the Software,  and to
10   * permit persons to whom the Software  is furnished to do so, subject to
11   * the following conditions:
12   *
13   * The  above  copyright  notice  and  this permission  notice  shall  be
14   * included in all copies or substantial portions of the Software.
15   *
16   * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
17   * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
18   * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
22   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23   *
24   */
25  package org.slf4j;
26  
27  import java.io.Serializable;
28  import java.util.Iterator;
29  
30  /**
31   * Markers are named objects used to enrich log statements. Conforming logging
32   * system Implementations of SLF4J determine how information conveyed by markers
33   * are used, if at all. In particular, many conforming logging systems ignore
34   * marker data.
35   * 
36   * <p>
37   * Markers can contain references to other markers, which in turn may contain 
38   * references of their own.
39   * 
40   * @author Ceki G&uuml;lc&uuml;
41   */
42  public interface Marker extends Serializable {
43  
44      /**
45       * This constant represents any marker, including a null marker.
46       */
47      public final String ANY_MARKER = "*";
48  
49      /**
50       * This constant represents any non-null marker.
51       */
52      public final String ANY_NON_NULL_MARKER = "+";
53  
54      /**
55       * Get the name of this Marker.
56       * 
57       * @return name of marker
58       */
59      public String getName();
60  
61      /**
62       * Add a reference to another Marker.
63       * 
64       * @param reference
65       *                a reference to another marker
66       * @throws IllegalArgumentException
67       *                 if 'reference' is null
68       */
69      public void add(Marker reference);
70  
71      /**
72       * Remove a marker reference.
73       * 
74       * @param reference
75       *                the marker reference to remove
76       * @return true if reference could be found and removed, false otherwise.
77       */
78      public boolean remove(Marker reference);
79  
80      /**
81       * @deprecated Replaced by {@link #hasReferences()}.
82       */
83      @Deprecated
84      public boolean hasChildren();
85  
86      /**
87       * Does this marker have any references?
88       * 
89       * @return true if this marker has one or more references, false otherwise.
90       */
91      public boolean hasReferences();
92  
93      /**
94       * Returns an Iterator which can be used to iterate over the references of this
95       * marker. An empty iterator is returned when this marker has no references.
96       * 
97       * @return Iterator over the references of this marker
98       */
99      public Iterator<Marker> iterator();
100 
101     /**
102      * Does this marker contain a reference to the 'other' marker? Marker A is defined 
103      * to contain marker B, if A == B or if B is referenced by A, or if B is referenced
104      * by any one of A's references (recursively).
105      * 
106      * @param other
107      *                The marker to test for inclusion.
108      * @throws IllegalArgumentException
109      *                 if 'other' is null
110      * @return Whether this marker contains the other marker.
111      */
112     public boolean contains(Marker other);
113 
114     /**
115      * Does this marker contain the marker named 'name'?
116      * 
117      * If 'name' is null the returned value is always false.
118      * 
119      * @param name The marker name to test for inclusion.
120      * @return Whether this marker contains the other marker.
121      */
122     public boolean contains(String name);
123 
124     /**
125      * Markers are considered equal if they have the same name.
126      *
127      * @param o
128      * @return true, if this.name equals o.name
129      *
130      * @since 1.5.1
131      */
132     public boolean equals(Object o);
133 
134     /**
135      * Compute the hash code based on the name of this marker.
136      * Note that markers are considered equal if they have the same name.
137      * 
138      * @return the computed hashCode
139      * @since 1.5.1
140      */
141     public int hashCode();
142 
143 }