View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions Copyrighted [year] [name of copyright owner]".
13   *
14   *      Copyright 2014 ForgeRock AS
15   * Portions copyright 2023 Wren Security
16   */
17  package org.forgerock.i18n.slf4j;
18  
19  import java.util.Collections;
20  import java.util.Iterator;
21  
22  import org.forgerock.i18n.LocalizableMessage;
23  import org.slf4j.Marker;
24  
25  /**
26   * An implementation of SLF4J marker that contains a {@code LocalizableMessage}
27   * and does not allow to manage references to other markers.
28   */
29  public class LocalizedMarker implements Marker {
30  
31      private static final long serialVersionUID = 1L;
32  
33      private final LocalizableMessage message;
34  
35      /**
36       * Create a marker with provided localizable message.
37       * <p>
38       * Name of the marker is the resource name provided by the message.
39       *
40       * @param message
41       *            Message embedded into this marker.
42       */
43      public LocalizedMarker(LocalizableMessage message) {
44          this.message = message;
45      }
46  
47      /**
48       * Returns the message embedded into this marker.
49       *
50       * @return the localizable message.
51       */
52      public LocalizableMessage getMessage() {
53          return message;
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public String getName() {
59          return message.resourceName();
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public void add(Marker reference) {
65          // nothing to do
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public boolean remove(Marker reference) {
71          return false;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public boolean hasChildren() {
77          return false;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public boolean hasReferences() {
83          return false;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public Iterator<Marker> iterator() {
89          return Collections.<Marker>emptySet().iterator();
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public boolean contains(Marker other) {
95          return false;
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     public boolean contains(String name) {
101         return false;
102     }
103 
104 }