001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyrighted [year] [name of copyright owner]".
013 *
014 *      Copyright 2014 ForgeRock AS
015 */
016package org.forgerock.i18n.slf4j;
017
018import java.util.Collections;
019import java.util.Iterator;
020
021import org.forgerock.i18n.LocalizableMessage;
022import org.slf4j.Marker;
023
024/**
025 * An implementation of SLF4J marker that contains a {@code LocalizableMessage}
026 * and does not allow to manage references to other markers.
027 */
028public class LocalizedMarker implements Marker {
029
030    private static final long serialVersionUID = 1L;
031
032    private final LocalizableMessage message;
033
034    /**
035     * Create a marker with provided localizable message.
036     * <p>
037     * Name of the marker is the resource name provided by the message.
038     *
039     * @param message
040     *            Message embedded into this marker.
041     */
042    public LocalizedMarker(LocalizableMessage message) {
043        this.message = message;
044    }
045
046    /**
047     * Returns the message embedded into this marker.
048     *
049     * @return the localizable message.
050     */
051    public LocalizableMessage getMessage() {
052        return message;
053    }
054
055    /** {@inheritDoc} */
056    @Override
057    public String getName() {
058        return message.resourceName();
059    }
060
061    /** {@inheritDoc} */
062    @Override
063    public void add(Marker reference) {
064        // nothing to do
065    }
066
067    /** {@inheritDoc} */
068    @Override
069    public boolean remove(Marker reference) {
070        return false;
071    }
072
073    /** {@inheritDoc} */
074    @Override
075    public boolean hasChildren() {
076        return false;
077    }
078
079    /** {@inheritDoc} */
080    @Override
081    public boolean hasReferences() {
082        return false;
083    }
084
085    /** {@inheritDoc} */
086    @Override
087    public Iterator<?> iterator() {
088        return Collections.emptySet().iterator();
089    }
090
091    /** {@inheritDoc} */
092    @Override
093    public boolean contains(Marker other) {
094        return false;
095    }
096
097    /** {@inheritDoc} */
098    @Override
099    public boolean contains(String name) {
100        return false;
101    }
102
103}