X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=srcjar_unused%2Forg%2Fapache%2Flog4j%2Fhelpers%2FAppenderAttachableImpl.java;fp=srcjar_unused%2Forg%2Fapache%2Flog4j%2Fhelpers%2FAppenderAttachableImpl.java;h=4aae5c1b0e888e432d9a0e6907a996b62c8fd695;hb=2639d90e2b52d49cf586c0b602bc606033c9b8ae;hp=0000000000000000000000000000000000000000;hpb=aaead18c6acb21da4d63f3ad9f454d9eb410152f;p=jalview.git diff --git a/srcjar_unused/org/apache/log4j/helpers/AppenderAttachableImpl.java b/srcjar_unused/org/apache/log4j/helpers/AppenderAttachableImpl.java new file mode 100644 index 0000000..4aae5c1 --- /dev/null +++ b/srcjar_unused/org/apache/log4j/helpers/AppenderAttachableImpl.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.log4j.helpers; + +import org.apache.log4j.spi.AppenderAttachable; +import org.apache.log4j.spi.LoggingEvent; + +import org.apache.log4j.Appender; +import java.util.Vector; +import java.util.Enumeration; + +/** + A straightforward implementation of the {@link AppenderAttachable} + interface. + + @author Ceki Gülcü + @since version 0.9.1 */ +public class AppenderAttachableImpl implements AppenderAttachable { + + /** Array of appenders. */ + protected Vector appenderList; + + /** + Attach an appender. If the appender is already in the list in + won't be added again. + */ + public + void addAppender(Appender newAppender) { + // Null values for newAppender parameter are strictly forbidden. + if(newAppender == null) { + return; + } + + if(appenderList == null) { + appenderList = new Vector(1); + } + if(!appenderList.contains(newAppender)) { + appenderList.addElement(newAppender); + } + } + + /** + Call the doAppend method on all attached appenders. */ + public + int appendLoopOnAppenders(LoggingEvent event) { + int size = 0; + Appender appender; + + if(appenderList != null) { + size = appenderList.size(); + for(int i = 0; i < size; i++) { + appender = (Appender) appenderList.elementAt(i); + appender.doAppend(event); + } + } + return size; + } + + + /** + Get all attached appenders as an Enumeration. If there are no + attached appenders null is returned. + + @return Enumeration An enumeration of attached appenders. + */ + public + Enumeration getAllAppenders() { + if(appenderList == null) { + return null; + } else { + return appenderList.elements(); + } + } + + /** + Look for an attached appender named as name. + +

Return the appender with that name if in the list. Return null + otherwise. + + */ + public + Appender getAppender(String name) { + if(appenderList == null || name == null) { + return null; + } + + int size = appenderList.size(); + Appender appender; + for(int i = 0; i < size; i++) { + appender = (Appender) appenderList.elementAt(i); + if(name.equals(appender.getName())) { + return appender; + } + } + return null; + } + + + /** + Returns true if the specified appender is in the + list of attached appenders, false otherwise. + + @since 1.2 */ + public + boolean isAttached(Appender appender) { + if(appenderList == null || appender == null) { + return false; + } + + int size = appenderList.size(); + Appender a; + for(int i = 0; i < size; i++) { + a = (Appender) appenderList.elementAt(i); + if(a == appender) { + return true; + } + } + return false; + } + + + + /** + * Remove and close all previously attached appenders. + * */ + public + void removeAllAppenders() { + if(appenderList != null) { + int len = appenderList.size(); + for(int i = 0; i < len; i++) { + Appender a = (Appender) appenderList.elementAt(i); + a.close(); + } + appenderList.removeAllElements(); + appenderList = null; + } + } + + + /** + Remove the appender passed as parameter form the list of attached + appenders. */ + public + void removeAppender(Appender appender) { + if(appender == null || appenderList == null) { + return; + } + appenderList.removeElement(appender); + } + + + /** + Remove the appender with the name passed as parameter form the + list of appenders. + */ + public + void removeAppender(String name) { + if(name == null || appenderList == null) { + return; + } + int size = appenderList.size(); + for(int i = 0; i < size; i++) { + if(name.equals(((Appender)appenderList.elementAt(i)).getName())) { + appenderList.removeElementAt(i); + break; + } + } + } + +}