Java 类org.apache.log4j.spi.OptionHandler 实例源码

项目:cacheonix-core    文件:SMTPAppender.java   
/**
   Activate the specified options, such as the smtp host, the
   recipient, from, etc. */
public
void activateOptions() {
  Session session = createSession();
  msg = new MimeMessage(session);

   try {
      addressMessage(msg);
      if(subject != null) {
      msg.setSubject(subject);
   }
   } catch(MessagingException e) {
     LogLog.error("Could not activate SMTPAppender options.", e );
   }

   if (evaluator instanceof OptionHandler) {
       ((OptionHandler) evaluator).activateOptions();
   }
}
项目:log4j-collector    文件:EmailAppender.java   
public
void activateOptions() {
    super.activateOptions();
    Session session = createSession();
    msg = new MimeMessage(session);
    try {
        addressMessage(msg);
        if(subject != null) {
            try {
                msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
            } catch(UnsupportedEncodingException ex) {
                LogLog.error("Unable to encode SMTP subject", ex);
            }
        }
    } catch(MessagingException e) {
        LogLog.error("Could not activate SMTPAppender options.", e );
    }

    if (evaluator!=null && evaluator instanceof OptionHandler) {
        ((OptionHandler) evaluator).activateOptions();
    }
}
项目:daq-eclipse    文件:RewriteAppender.java   
/**
 * {@inheritDoc}
 */
public boolean parseUnrecognizedElement(final Element element,
                                        final Properties props) throws Exception {
    final String nodeName = element.getNodeName();
    if ("rewritePolicy".equals(nodeName)) {
        Object rewritePolicy =
                org.apache.log4j.xml.DOMConfigurator.parseElement(
                        element, props, RewritePolicy.class);
        if (rewritePolicy != null) {
            if (rewritePolicy instanceof OptionHandler) {
                ((OptionHandler) rewritePolicy).activateOptions();
            }
            this.setRewritePolicy((RewritePolicy) rewritePolicy);
        }
        return true;
    }
    return false;
}
项目:daq-eclipse    文件:AppenderDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   appender instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) appender;
    oh.activateOptions();
    return "Options activated.";
  } else if (operationName.equals("setLayout")) {
    Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
                              params[0],
                              Layout.class,
                              null);
    appender.setLayout(layout);
    registerLayoutMBean(layout);
  }
  return null;
}
项目:daq-eclipse    文件:SMTPAppender.java   
/**
   Activate the specified options, such as the smtp host, the
   recipient, from, etc. */
public
void activateOptions() {
  Session session = createSession();
  msg = new MimeMessage(session);

   try {
      addressMessage(msg);
      if(subject != null) {
         try {
              msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
         } catch(UnsupportedEncodingException ex) {
              LogLog.error("Unable to encode SMTP subject", ex);
         }
      }
   } catch(MessagingException e) {
     LogLog.error("Could not activate SMTPAppender options.", e );
   }

   if (evaluator instanceof OptionHandler) {
       ((OptionHandler) evaluator).activateOptions();
   }
}
项目:nabs    文件:AppenderDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   appender instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) appender;
    oh.activateOptions();
    return "Options activated.";
  } else if (operationName.equals("setLayout")) {
    Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
                              params[0],
                              Layout.class,
                              null);
    appender.setLayout(layout);
    registerLayoutMBean(layout);
  }
  return null;
}
项目:cacheonix-core    文件:LayoutDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   layout instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) layout;
    oh.activateOptions();
    return "Options activated.";
  }
  return null;
}
项目:cacheonix-core    文件:AppenderDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   appender instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) appender;
    oh.activateOptions();
    return "Options activated.";
  } else if (operationName.equals("setLayout")) {
    Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
                              params[0],
                              Layout.class,
                              null);
    appender.setLayout(layout);
    registerLayoutMBean(layout);
  }
  return null;
}
项目:log4j-collector    文件:EmailDailyRollingFileAppender.java   
public
void activateOptions() {
    super.activateOptions();
    if(datePattern != null && fileName != null) {
        now.setTime(System.currentTimeMillis());
        sdf = new SimpleDateFormat(datePattern);
        int type = computeCheckPeriod();
        printPeriodicity(type);
        rc.setType(type);
        File file = new File(fileName);
        scheduledFilename = fileName+sdf.format(new Date(file.lastModified()));

    } else {
        LogLog.error("Either File or DatePattern options are not set for appender ["
                +name+"].");
    }

    Session session = createSession();
    msg = new MimeMessage(session);

    try {
        addressMessage(msg);
        if(subject != null) {
            try {
                msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", null));
            } catch(UnsupportedEncodingException ex) {
                LogLog.error("Unable to encode SMTP subject", ex);
            }
        }
    } catch(MessagingException e) {
        LogLog.error("Could not activate SMTPAppender options.", e );
    }

    if (evaluator!=null && evaluator instanceof OptionHandler) {
        ((OptionHandler) evaluator).activateOptions();
    }
}
项目:daq-eclipse    文件:LayoutDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   layout instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) layout;
    oh.activateOptions();
    return "Options activated.";
  }
  return null;
}
项目:nabs    文件:LayoutDynamicMBean.java   
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   layout instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) layout;
    oh.activateOptions();
    return "Options activated.";
  }
  return null;
}
项目:wildfly-core    文件:Log4jAppenderHandler.java   
/**
 * Activates the appender only if it's an {@link OptionHandler option handler}.
 */
public void activate() {
    if (appender instanceof OptionHandler) {
        ((OptionHandler) appender).activateOptions();
        if (LoggingLogger.ROOT_LOGGER.isDebugEnabled()) {
            LoggingLogger.ROOT_LOGGER.debugf("Invoking OptionHandler.activateOptions() on appender %s (%s)", appender.getName(), appender.getClass().getCanonicalName());
        }
    }
}
项目:au-log4j    文件:SMTPAppender.java   
/**
 * Activate the specified options, such as the smtp host, the recipient,
 * from, etc.
 */
public void activateOptions()
{
    super.activateOptions();
    final Session session = createSession();
    msg = new MimeMessage(session);

    if (evaluator instanceof OptionHandler)
    {
        ((OptionHandler) evaluator).activateOptions();
    }
}
项目:cacheonix-core    文件:PropertyConfigurator.java   
Appender parseAppender(Properties props, String appenderName) {
   Appender appender = registryGet(appenderName);
   if((appender != null)) {
     LogLog.debug("Appender \"" + appenderName + "\" was already parsed.");
     return appender;
   }
   // Appender was not previously initialized.
   String prefix = APPENDER_PREFIX + appenderName;
   String layoutPrefix = prefix + ".layout";

   appender = (Appender) OptionConverter.instantiateByKey(props, prefix,
                      org.apache.log4j.Appender.class,
                      null);
   if(appender == null) {
     LogLog.error(
             "Could not instantiate appender named \"" + appenderName+"\".");
     return null;
   }
   appender.setName(appenderName);

   if(appender instanceof OptionHandler) {
     if(appender.requiresLayout()) {
Layout layout = (Layout) OptionConverter.instantiateByKey(props,
                              layoutPrefix,
                              Layout.class,
                              null);
if(layout != null) {
  appender.setLayout(layout);
  LogLog.debug("Parsing layout options for \"" + appenderName +"\".");
  //configureOptionHandler(layout, layoutPrefix + ".", props);
         PropertySetter.setProperties(layout, props, layoutPrefix + ".");
  LogLog.debug("End of parsing for \"" + appenderName +"\".");
}
     }
     //configureOptionHandler((OptionHandler) appender, prefix + ".", props);
     PropertySetter.setProperties(appender, props, prefix + ".");
     LogLog.debug("Parsed \"" + appenderName +"\" options.");
   }
   registryPut(appender);
   return appender;
 }
项目:cacheonix-core    文件:PropertySetter.java   
public
void activate() {
  if (obj instanceof OptionHandler) {
    ((OptionHandler) obj).activateOptions();
  }
}
项目:daq-eclipse    文件:PropertyConfigurator.java   
Appender parseAppender(Properties props, String appenderName) {
   Appender appender = registryGet(appenderName);
   if((appender != null)) {
     LogLog.debug("Appender \"" + appenderName + "\" was already parsed.");
     return appender;
   }
   // Appender was not previously initialized.
   String prefix = APPENDER_PREFIX + appenderName;
   String layoutPrefix = prefix + ".layout";

   appender = (Appender) OptionConverter.instantiateByKey(props, prefix,
                      org.apache.log4j.Appender.class,
                      null);
   if(appender == null) {
     LogLog.error(
             "Could not instantiate appender named \"" + appenderName+"\".");
     return null;
   }
   appender.setName(appenderName);

   if(appender instanceof OptionHandler) {
     if(appender.requiresLayout()) {
Layout layout = (Layout) OptionConverter.instantiateByKey(props,
                              layoutPrefix,
                              Layout.class,
                              null);
if(layout != null) {
  appender.setLayout(layout);
  LogLog.debug("Parsing layout options for \"" + appenderName +"\".");
  //configureOptionHandler(layout, layoutPrefix + ".", props);
         PropertySetter.setProperties(layout, props, layoutPrefix + ".");
  LogLog.debug("End of parsing for \"" + appenderName +"\".");
}
     }
     final String errorHandlerPrefix = prefix + ".errorhandler";
     String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
     if (errorHandlerClass != null) {
        ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByKey(props,
                  errorHandlerPrefix,
                  ErrorHandler.class,
                  null);
        if (eh != null) {
              appender.setErrorHandler(eh);
              LogLog.debug("Parsing errorhandler options for \"" + appenderName +"\".");
              parseErrorHandler(eh, errorHandlerPrefix, props, repository);
              final Properties edited = new Properties();
              final String[] keys = new String[] { 
                      errorHandlerPrefix + "." + ROOT_REF,
                      errorHandlerPrefix + "." + LOGGER_REF,
                      errorHandlerPrefix + "." + APPENDER_REF_TAG
              };
              for(Iterator iter = props.entrySet().iterator();iter.hasNext();) {
                  Map.Entry entry = (Map.Entry) iter.next();
                  int i = 0;
                  for(; i < keys.length; i++) {
                      if(keys[i].equals(entry.getKey())) break;
                  }
                  if (i == keys.length) {
                      edited.put(entry.getKey(), entry.getValue());
                  }
              }
              PropertySetter.setProperties(eh, edited, errorHandlerPrefix + ".");
              LogLog.debug("End of errorhandler parsing for \"" + appenderName +"\".");
        }

     }
     //configureOptionHandler((OptionHandler) appender, prefix + ".", props);
     PropertySetter.setProperties(appender, props, prefix + ".");
     LogLog.debug("Parsed \"" + appenderName +"\" options.");
   }
   parseAppenderFilters(props, appenderName, appender);
   registryPut(appender);
   return appender;
 }
项目:daq-eclipse    文件:PropertySetter.java   
public
void activate() {
  if (obj instanceof OptionHandler) {
    ((OptionHandler) obj).activateOptions();
  }
}
项目:nabs    文件:PropertyConfigurator.java   
Appender parseAppender(Properties props, String appenderName) {
   Appender appender = registryGet(appenderName);
   if((appender != null)) {
     LogLog.debug("Appender \"" + appenderName + "\" was already parsed.");
     return appender;
   }
   // Appender was not previously initialized.
   String prefix = APPENDER_PREFIX + appenderName;
   String layoutPrefix = prefix + ".layout";

   appender = (Appender) OptionConverter.instantiateByKey(props, prefix,
                      org.apache.log4j.Appender.class,
                      null);
   if(appender == null) {
     LogLog.error(
             "Could not instantiate appender named \"" + appenderName+"\".");
     return null;
   }
   appender.setName(appenderName);

   if(appender instanceof OptionHandler) {
     if(appender.requiresLayout()) {
Layout layout = (Layout) OptionConverter.instantiateByKey(props,
                              layoutPrefix,
                              Layout.class,
                              null);
if(layout != null) {
  appender.setLayout(layout);
  LogLog.debug("Parsing layout options for \"" + appenderName +"\".");
  //configureOptionHandler(layout, layoutPrefix + ".", props);
         PropertySetter.setProperties(layout, props, layoutPrefix + ".");
  LogLog.debug("End of parsing for \"" + appenderName +"\".");
}
     }
     //configureOptionHandler((OptionHandler) appender, prefix + ".", props);
     PropertySetter.setProperties(appender, props, prefix + ".");
     LogLog.debug("Parsed \"" + appenderName +"\" options.");
   }
   registryPut(appender);
   return appender;
 }
项目:nabs    文件:PropertySetter.java   
public
void activate() {
  if (obj instanceof OptionHandler) {
    ((OptionHandler) obj).activateOptions();
  }
}