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 @Override
48 public void add(final Marker marker) {
49 if (marker == null) {
50 throw new IllegalArgumentException();
51 }
52 final Marker m = factory.getMarker(marker.getName());
53 this.marker.addParents(((Log4jMarker)m).getLog4jMarker());
54 }
55
56 @Override
57 public boolean contains(final org.slf4j.Marker marker) {
58 if (marker == null) {
59 throw new IllegalArgumentException();
60 }
61 return this.marker.isInstanceOf(marker.getName());
62 }
63
64 @Override
65 public boolean contains(final String s) {
66 return s != null ? this.marker.isInstanceOf(s) : false;
67 }
68
69 @Override
70 public boolean equals(final Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj == null) {
75 return false;
76 }
77 if (!(obj instanceof Log4jMarker)) {
78 return false;
79 }
80 final Log4jMarker other = (Log4jMarker) obj;
81 if (marker == null) {
82 if (other.marker != null) {
83 return false;
84 }
85 } else if (!marker.equals(other.marker)) {
86 return false;
87 }
88 return true;
89 }
90
91 public org.apache.logging.log4j.Marker getLog4jMarker() {
92 return marker;
93 }
94
95 @Override
96 public String getName() {
97 return marker.getName();
98 }
99
100 @Override
101 public boolean hasChildren() {
102 return marker.hasParents();
103 }
104
105 @Override
106 public int hashCode() {
107 final int prime = 31;
108 int result = 1;
109 result = prime * result + ((marker == null) ? 0 : marker.hashCode());
110 return result;
111 }
112
113 @Override
114 public boolean hasReferences() {
115 return marker.hasParents();
116 }
117
118 @Override
119 public Iterator<Marker> iterator() {
120 final org.apache.logging.log4j.Marker[] log4jParents = this.marker.getParents();
121 final List<Marker> parents = new ArrayList<>(log4jParents.length);
122 for (final org.apache.logging.log4j.Marker m : log4jParents) {
123 parents.add(factory.getMarker(m.getName()));
124 }
125 return parents.iterator();
126 }
127
128 @Override
129 public boolean remove(final Marker marker) {
130 return marker != null ? this.marker.remove(MarkerManager.getMarker(marker.getName())) : false;
131 }
132 }