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
018 package org.apache.geronimo.system.logging.log4j;
019
020 import org.apache.log4j.spi.Filter;
021 import org.apache.log4j.spi.LoggingEvent;
022
023 /**
024 *
025 *
026 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
027 */
028 public class NamedNDCFilter extends Filter {
029 private NamedNDC namedNDC;
030 private String name;
031 private String value;
032 private boolean acceptOnMatch = true;
033
034 public String getName() {
035 return name;
036 }
037
038 public void setName(final String name) {
039 this.name = name;
040 namedNDC = NamedNDC.getNamedNDC(name);
041 }
042
043 public String getValue() {
044 return value;
045 }
046
047 public void setValue(final String value) {
048 this.value = value;
049 }
050
051 public boolean getAcceptOnMatch() {
052 return acceptOnMatch;
053 }
054
055 public void setAcceptOnMatch(final boolean acceptOnMatch) {
056 this.acceptOnMatch = acceptOnMatch;
057 }
058
059 public int decide(LoggingEvent event) {
060 if (value == null) {
061 return Filter.NEUTRAL;
062 }
063
064 Object ndcValue = namedNDC.get();
065 if (ndcValue == null) {
066 return Filter.NEUTRAL;
067 }
068
069 if (value.equals(ndcValue.toString())) {
070 if (acceptOnMatch) {
071 return Filter.ACCEPT;
072 } else {
073 return Filter.DENY;
074 }
075 }
076 return Filter.NEUTRAL;
077 }
078 }