1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.slf4j;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.apache.logging.log4j.MarkerManager;
24 import org.slf4j.IMarkerFactory;
25 import org.slf4j.Marker;
26 import org.slf4j.impl.StaticMarkerBinder;
27
28
29
30
31 public class Log4jMarker implements Marker {
32
33 public static final long serialVersionUID = 1590472L;
34
35 private final IMarkerFactory factory = StaticMarkerBinder.SINGLETON.getMarkerFactory();
36
37 private final org.apache.logging.log4j.Marker marker;
38
39
40
41
42
43 public Log4jMarker(final org.apache.logging.log4j.Marker marker) {
44 this.marker = marker;
45 }
46
47 public org.apache.logging.log4j.Marker getLog4jMarker() {
48 return marker;
49 }
50
51 @Override
52 public void add(final Marker marker) {
53 final Marker m = factory.getMarker(marker.getName());
54 this.marker.addParents(((Log4jMarker)m).getLog4jMarker());
55 }
56
57 @Override
58 public boolean remove(final Marker marker) {
59 return this.marker.remove(MarkerManager.getMarker(marker.getName()));
60 }
61
62 @Override
63 public String getName() {
64 return marker.getName();
65 }
66
67 @Override
68 public boolean hasReferences() {
69 return marker.hasParents();
70 }
71
72 @Override
73 public boolean hasChildren() {
74 return marker.hasParents();
75 }
76
77 @Override
78 @SuppressWarnings("rawtypes")
79 public Iterator iterator() {
80 final List<Marker> parents = new ArrayList<Marker>();
81 for (final org.apache.logging.log4j.Marker m : this.marker.getParents()) {
82 parents.add(factory.getMarker(m.getName()));
83 }
84 return parents.iterator();
85 }
86
87 @Override
88 public boolean contains(final org.slf4j.Marker marker) {
89 return this.marker.isInstanceOf(marker.getName());
90 }
91
92 @Override
93 public boolean contains(final String s) {
94 return this.marker.isInstanceOf(s);
95 }
96 }