Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.logging.metadata;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
import org.jboss.logmanager.Logger;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.jboss.logmanager.filters.AllFilter;
import org.jboss.logmanager.filters.AnyFilter;
import org.jboss.logmanager.filters.AcceptAllFilter;
import org.jboss.logmanager.filters.DenyAllFilter;
import org.jboss.logmanager.filters.InvertFilter;
import org.jboss.logmanager.filters.RegexFilter;
import org.jboss.logmanager.filters.SubstituteFilter;
import org.jboss.logmanager.filters.LevelFilter;
import org.jboss.logmanager.filters.LevelRangeFilter;
import org.jboss.logmanager.filters.LevelChangingFilter;
import org.jboss.logmanager.errormanager.OnlyOnceErrorManager;
import org.jboss.logmanager.log4j.handlers.Log4jAppenderHandler;
import org.jboss.logmanager.handlers.AsyncHandler;
import org.jboss.logmanager.handlers.ConsoleHandler;
import org.jboss.logmanager.handlers.FileHandler;
import org.jboss.logmanager.handlers.NullHandler;
import org.jboss.logmanager.handlers.PeriodicRotatingFileHandler;
import org.jboss.logmanager.handlers.SizeRotatingFileHandler;
import org.jboss.dependency.spi.ControllerMode;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.EnumMap;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Handler;
import java.util.logging.Filter;
import java.util.logging.Level;
public final class LoggingMetaDataHelper {
private LoggingMetaDataHelper() {
}
private static final AtomicInteger sequence = new AtomicInteger();
public static void createBeanMetaData(final List beanMetaDataList, final LoggingMetaData loggingMetaData) {
final String context = loggingMetaData.getContext();
if (context == null) {
// context should be "system" by default
throw new NullPointerException("context is null");
}
final List abstractLoggerMetaDataList = loggingMetaData.getLoggerMetaDataList();
if (abstractLoggerMetaDataList != null) for (AbstractLoggerMetaData abstractLoggerMetaData : abstractLoggerMetaDataList) {
createLoggerBeanMetaData(beanMetaDataList, abstractLoggerMetaData, context);
}
final List handlerMetaDataList = loggingMetaData.getHandlerMetaDataList();
if (handlerMetaDataList != null) for (AbstractHandlerMetaData abstractHandlerMetaData : handlerMetaDataList) {
getValue(beanMetaDataList, abstractHandlerMetaData, context);
}
final List installHandlerMetaDataList = loggingMetaData.getInstallHandlerMetaDataList();
if (installHandlerMetaDataList != null) for (InstallHandlerMetaData installMetaData : installHandlerMetaDataList) {
final String installerName = getInstallerName(context, "*");
final RefMetaData handlerRef = installMetaData.getHandlerRef();
final List loggerRefs = installMetaData.getLoggerRefList();
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(installerName, HandlerInstallerHelper.class.getName());
final List handlerList = builder.createList();
final List targetList = builder.createList();
handlerList.add(builder.createInject(getName(context, Kind.HANDLER, handlerRef.getName())));
for (AbstractLoggerRefMetaData loggerRef : loggerRefs) {
final String refContext = loggerRef.getContext();
final String refName;
if (loggerRef instanceof LoggerRefMetaData) {
refName = ((LoggerRefMetaData)loggerRef).getCategory();
} else {
refName = "";
}
targetList.add(getLoggerInjectValue(refContext == null ? context : refContext, refName));
}
builder.addPropertyMetaData("handlerList", (ValueMetaData) handlerList);
builder.addPropertyMetaData("targetList", (ValueMetaData) targetList);
beanMetaDataList.add(builder.getBeanMetaData());
}
}
private static void createLoggerBeanMetaData(final List beanMetaDataList, final AbstractLoggerMetaData abstractLoggerMetaData, final String context) {
final String name;
final String humanName;
if (abstractLoggerMetaData instanceof LoggerMetaData) {
name = humanName = ((LoggerMetaData) abstractLoggerMetaData).getCategory();
} else {
name = "";
humanName = "";
}
final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(getName(context, Kind.LOGGER, humanName), Logger.class.getName());
builder.setFactory(builder.createInject(getContextName(context)));
builder.setFactoryMethod("getLogger");
builder.addConstructorParameter(String.class.getName(), name);
if (abstractLoggerMetaData instanceof LoggerMetaData) {
builder.addPropertyMetaData("useParentHandlers", Boolean.valueOf(((LoggerMetaData) abstractLoggerMetaData).isUseParentHandlers()));
}
final RefMetaData levelRef = abstractLoggerMetaData.getLevelMetaData();
if (levelRef != null) {
builder.addPropertyMetaData("level", getLevelInjectValue(context, levelRef.getName()));
}
final FilterMetaData filterMetaData = abstractLoggerMetaData.getFilterMetaData();
if (filterMetaData != null) {
builder.addPropertyMetaData("filter", getValue(beanMetaDataList, context, filterMetaData));
}
final BeanMetaData loggerBeanMetaData = builder.getBeanMetaData();
// now install handlers
final List