1   /* 
2    * Copyright (c) 2004-2008 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 child markers, which in turn can contain children of
38   * 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 child Marker to this Marker.
63     * 
64     * @param child
65     *                a child marker
66     */
67    public void add(Marker child);
68  
69    /**
70     * Remove a child Marker.
71     * 
72     * @param child
73     *                the child Marker to remove
74     * @return true if child could be found and removed, false otherwise.
75     */
76    public boolean remove(Marker child);
77  
78    /**
79     * Does this marker have children?
80     * 
81     * @return true if this marker has children, false otherwise.
82     */
83    public boolean hasChildren();
84  
85    /**
86     * Returns an Iterator which can be used to iterate over the children of this
87     * marker. An empty iterator is returned when this marker has no children.
88     * 
89     * @return Iterator over the children of this marker
90     */
91    public Iterator iterator();
92  
93    /**
94     * Does this marker contain the 'other' marker? Marker A is defined to contain
95     * marker B, if A == B or if B is a child of A.
96     * 
97     * @param other
98     *                The marker to test for inclusion.
99     * @throws IllegalArgumentException
100    *                 if 'other' is null
101    * @return Whether this marker contains the other marker.
102    */
103   public boolean contains(Marker other);
104 
105   /**
106    * Does this marker contain the marker named 'name'?
107    * 
108    * If 'name' is null the returned value is always false.
109    * 
110    * @param other
111    *                The marker to test for inclusion.
112    * @return Whether this marker contains the other marker.
113    */
114   public boolean contains(String name);
115 
116   /**
117    * Markers are considered equal if they have the same name.
118    *
119    * @param o
120    * @return true, if this.name equals o.name
121    *
122    * @since 1.5.1
123    */
124   public boolean equals(Object o);
125 
126   /**
127    * Compute the hash code based on the name of this marker.
128    * Note that markers are considered equal if they have the same name.
129    * 
130    * @return the computed hashCode
131    * @since 1.5.1
132    */
133   public int hashCode();
134 
135 }