001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.slf4j;
018    
019    import java.util.ArrayList;
020    import java.util.Iterator;
021    import java.util.List;
022    
023    import org.apache.logging.log4j.MarkerManager;
024    import org.slf4j.IMarkerFactory;
025    import org.slf4j.Marker;
026    import org.slf4j.impl.StaticMarkerBinder;
027    
028    /**
029     *
030     */
031    public class Log4jMarker implements Marker {
032    
033        public static final long serialVersionUID = 1590472L;
034    
035        private final IMarkerFactory factory = StaticMarkerBinder.SINGLETON.getMarkerFactory();
036    
037        private final org.apache.logging.log4j.Marker marker;
038    
039        public Log4jMarker(final org.apache.logging.log4j.Marker marker) {
040            this.marker = marker;
041        }
042    
043        public org.apache.logging.log4j.Marker getLog4jMarker() {
044            return marker;
045        }
046    
047        @Override
048        public void add(final Marker marker) {
049            final Marker m = factory.getMarker(marker.getName());
050            this.marker.addParents(((Log4jMarker)m).getLog4jMarker());
051        }
052    
053        @Override
054        public boolean remove(final Marker marker) {
055            return this.marker.remove(MarkerManager.getMarker(marker.getName()));
056        }
057    
058        @Override
059        public String getName() {
060            return marker.getName();
061        }
062    
063        @Override
064        public boolean hasReferences() {
065            return marker.hasParents();
066        }
067    
068        @Override
069        public boolean hasChildren() {
070            return marker.hasParents();
071        }
072    
073        @Override
074        @SuppressWarnings("rawtypes")
075        public Iterator iterator() {
076            final List<Marker> parents = new ArrayList<Marker>();
077            for (final org.apache.logging.log4j.Marker m : this.marker.getParents()) {
078                parents.add(factory.getMarker(m.getName()));
079            }
080            return parents.iterator();
081        }
082    
083        @Override
084        public boolean contains(final org.slf4j.Marker marker) {
085            return this.marker.isInstanceOf(marker.getName());
086        }
087    
088        @Override
089        public boolean contains(final String s) {
090            return this.marker.isInstanceOf(s);
091        }
092    }