001/**
002 * Copyright (c) 2004-2011 QOS.ch
003 * All rights reserved.
004 *
005 * Permission is hereby granted, free  of charge, to any person obtaining
006 * a  copy  of this  software  and  associated  documentation files  (the
007 * "Software"), to  deal in  the Software without  restriction, including
008 * without limitation  the rights to  use, copy, modify,  merge, publish,
009 * distribute,  sublicense, and/or sell  copies of  the Software,  and to
010 * permit persons to whom the Software  is furnished to do so, subject to
011 * the following conditions:
012 *
013 * The  above  copyright  notice  and  this permission  notice  shall  be
014 * included in all copies or substantial portions of the Software.
015 *
016 * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
017 * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
018 * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
021 * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023 *
024 */
025package org.slf4j;
026
027import java.io.Serializable;
028import java.util.Iterator;
029
030/**
031 * Markers are named objects used to enrich log statements. Conforming logging
032 * system implementations of SLF4J should determine how information conveyed by
033 * any markers are used, if at all. Many conforming logging systems ignore marker
034 * data entirely.
035 *
036 * <p>Markers can contain references to nested markers, which in turn may
037 * contain references of their own. Note that the fluent API (new in 2.0) allows adding
038 * multiple markers to a logging statement. It is often preferable to use
039 * multiple markers instead of nested markers.
040 * </p>
041 *
042 * @author Ceki G&uuml;lc&uuml;
043 */
044public interface Marker extends Serializable {
045
046    /**
047     * This constant represents any marker, including a null marker.
048     */
049    public final String ANY_MARKER = "*";
050
051    /**
052     * This constant represents any non-null marker.
053     */
054    public final String ANY_NON_NULL_MARKER = "+";
055
056    /**
057     * Get the name of this Marker.
058     * 
059     * @return name of marker
060     */
061    public String getName();
062
063    /**
064     * Add a reference to another Marker.
065     *
066     * <p>Note that the fluent API allows adding multiple markers to a logging statement.
067     * It is often preferable to use multiple markers instead of nested markers.
068     * </p>
069     *
070     * @param reference
071     *                a reference to another marker
072     * @throws IllegalArgumentException
073     *                 if 'reference' is null
074     */
075    public void add(Marker reference);
076
077    /**
078     * Remove a marker reference.
079     * 
080     * @param reference
081     *                the marker reference to remove
082     * @return true if reference could be found and removed, false otherwise.
083     */
084    public boolean remove(Marker reference);
085
086    /**
087     * @deprecated Replaced by {@link #hasReferences()}.
088     */
089    @Deprecated
090    public boolean hasChildren();
091
092    /**
093     * Does this marker have any references?
094     * 
095     * @return true if this marker has one or more references, false otherwise.
096     */
097    public boolean hasReferences();
098
099    /**
100     * Returns an Iterator which can be used to iterate over the references of this
101     * marker. An empty iterator is returned when this marker has no references.
102     * 
103     * @return Iterator over the references of this marker
104     */
105    public Iterator<Marker> iterator();
106
107    /**
108     * Does this marker contain a reference to the 'other' marker? Marker A is defined 
109     * to contain marker B, if A == B or if B is referenced by A, or if B is referenced
110     * by any one of A's references (recursively).
111     * 
112     * @param other
113     *                The marker to test for inclusion.
114     * @throws IllegalArgumentException
115     *                 if 'other' is null
116     * @return Whether this marker contains the other marker.
117     */
118    public boolean contains(Marker other);
119
120    /**
121     * Does this marker contain the marker named 'name'?
122     * 
123     * If 'name' is null the returned value is always false.
124     * 
125     * @param name The marker name to test for inclusion.
126     * @return Whether this marker contains the other marker.
127     */
128    public boolean contains(String name);
129
130    /**
131     * Markers are considered equal if they have the same name.
132     *
133     * @param o
134     * @return true, if this.name equals o.name
135     *
136     * @since 1.5.1
137     */
138    public boolean equals(Object o);
139
140    /**
141     * Compute the hash code based on the name of this marker.
142     * Note that markers are considered equal if they have the same name.
143     * 
144     * @return the computed hashCode
145     * @since 1.5.1
146     */
147    public int hashCode();
148
149}