当前位置: 首页>>代码示例>>Java>>正文


Java OptionConverter.toLevel方法代码示例

本文整理汇总了Java中org.apache.log4j.helpers.OptionConverter.toLevel方法的典型用法代码示例。如果您正苦于以下问题:Java OptionConverter.toLevel方法的具体用法?Java OptionConverter.toLevel怎么用?Java OptionConverter.toLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.helpers.OptionConverter的用法示例。


在下文中一共展示了OptionConverter.toLevel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertArg

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
/**
   Convert <code>val</code> a String parameter to an object of a
   given type.
*/
protected
Object convertArg(String val, Class type) {
  if(val == null)
    return null;

  String v = val.trim();
  if (String.class.isAssignableFrom(type)) {
    return val;
  } else if (Integer.TYPE.isAssignableFrom(type)) {
    return new Integer(v);
  } else if (Long.TYPE.isAssignableFrom(type)) {
    return new Long(v);
  } else if (Boolean.TYPE.isAssignableFrom(type)) {
    if ("true".equalsIgnoreCase(v)) {
      return Boolean.TRUE;
    } else if ("false".equalsIgnoreCase(v)) {
      return Boolean.FALSE;
    }
  } else if (Priority.class.isAssignableFrom(type)) {
    return OptionConverter.toLevel(v, (Level) Level.DEBUG);
  }
  return null;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:28,代码来源:PropertySetter.java

示例2: setAttribute

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setAttribute(Attribute attribute) throws AttributeNotFoundException,
                                              InvalidAttributeValueException,
                                              MBeanException,
                                              ReflectionException {

  // Check attribute is not null to avoid NullPointerException later on
  if (attribute == null) {
    throw new RuntimeOperationsException(
                new IllegalArgumentException("Attribute cannot be null"),
 "Cannot invoke a setter of "+dClassName+" with null attribute");
  }
  String name = attribute.getName();
  Object value = attribute.getValue();

  if (name == null) {
    throw new RuntimeOperationsException(
             new IllegalArgumentException("Attribute name cannot be null"),
      "Cannot invoke the setter of "+dClassName+
      " with null attribute name");
  }

  if(name.equals(THRESHOLD)) {
    Level l = OptionConverter.toLevel((String) value,
			   hierarchy.getThreshold());
    hierarchy.setThreshold(l);
  }


}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:31,代码来源:HierarchyDynamicMBean.java

示例3: convertArg

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
/**
   Convert <code>val</code> a String parameter to an object of a
   given type.
*/
protected
Object convertArg(String val, Class type) {
  if(val == null)
    return null;

  String v = val.trim();
  if (String.class.isAssignableFrom(type)) {
    return val;
  } else if (Integer.TYPE.isAssignableFrom(type)) {
    return new Integer(v);
  } else if (Long.TYPE.isAssignableFrom(type)) {
    return new Long(v);
  } else if (Boolean.TYPE.isAssignableFrom(type)) {
    if ("true".equalsIgnoreCase(v)) {
      return Boolean.TRUE;
    } else if ("false".equalsIgnoreCase(v)) {
      return Boolean.FALSE;
    }
  } else if (Priority.class.isAssignableFrom(type)) {
    return OptionConverter.toLevel(v, (Level) Level.DEBUG);
  } else if (ErrorHandler.class.isAssignableFrom(type)) {
    return OptionConverter.instantiateByClassName(v, 
 ErrorHandler.class, null);
  }
  return null;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:31,代码来源:PropertySetter.java

示例4: setLevelToMatch

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void setLevelToMatch(String level) {
  levelToMatch = OptionConverter.toLevel(level, null);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:5,代码来源:LevelMatchFilter.java

示例5: setAttribute

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
 void setAttribute(Attribute attribute) throws AttributeNotFoundException,
                                               InvalidAttributeValueException,
                                               MBeanException,
                                               ReflectionException {

   // Check attribute is not null to avoid NullPointerException later on
   if (attribute == null) {
     throw new RuntimeOperationsException(
                 new IllegalArgumentException("Attribute cannot be null"),
	  "Cannot invoke a setter of " + dClassName +
	  " with null attribute");
   }
   String name = attribute.getName();
   Object value = attribute.getValue();

   if (name == null) {
     throw new RuntimeOperationsException(
                   new IllegalArgumentException("Attribute name cannot be null"),
	    "Cannot invoke the setter of "+dClassName+
	    " with null attribute name");
   }



   MethodUnion mu = (MethodUnion) dynamicProps.get(name);

   if(mu != null && mu.writeMethod != null) {
     Object[] o = new Object[1];

     Class[] params = mu.writeMethod.getParameterTypes();
     if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
				(Level) getAttribute(name));
     }
     o[0] = value;

     try {
mu.writeMethod.invoke(layout,  o);

     } catch(Exception e) {
cat.error("FIXME", e);
     }
   } else {
     throw(new AttributeNotFoundException("Attribute " + name +
				   " not found in " +
				   this.getClass().getName()));
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:50,代码来源:LayoutDynamicMBean.java

示例6: setAttribute

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
 void setAttribute(Attribute attribute) throws AttributeNotFoundException,
                                               InvalidAttributeValueException,
                                               MBeanException,
                                               ReflectionException {

   // Check attribute is not null to avoid NullPointerException later on
   if (attribute == null) {
     throw new RuntimeOperationsException(
                 new IllegalArgumentException("Attribute cannot be null"),
	  "Cannot invoke a setter of " + dClassName +
	  " with null attribute");
   }
   String name = attribute.getName();
   Object value = attribute.getValue();

   if (name == null) {
     throw new RuntimeOperationsException(
                   new IllegalArgumentException("Attribute name cannot be null"),
	    "Cannot invoke the setter of "+dClassName+
	    " with null attribute name");
   }


   if(name.equals("priority")) {
     if (value instanceof String) {
String s = (String) value;
Level p = logger.getLevel();
if(s.equalsIgnoreCase("NULL")) {
  p = null;
} else {
  p = OptionConverter.toLevel(s, p);
}
logger.setLevel(p);
     }
   } else {
     throw(new AttributeNotFoundException("Attribute " + name +
				   " not found in " +
				   this.getClass().getName()));
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:42,代码来源:LoggerDynamicMBean.java

示例7: setAttribute

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
 void setAttribute(Attribute attribute) throws AttributeNotFoundException,
                                               InvalidAttributeValueException,
                                               MBeanException,
                                               ReflectionException {

   // Check attribute is not null to avoid NullPointerException later on
   if (attribute == null) {
     throw new RuntimeOperationsException(
                 new IllegalArgumentException("Attribute cannot be null"),
	  "Cannot invoke a setter of " + dClassName +
	  " with null attribute");
   }
   String name = attribute.getName();
   Object value = attribute.getValue();

   if (name == null) {
     throw new RuntimeOperationsException(
                   new IllegalArgumentException("Attribute name cannot be null"),
	    "Cannot invoke the setter of "+dClassName+
	    " with null attribute name");
   }



   MethodUnion mu = (MethodUnion) dynamicProps.get(name);

   if(mu != null && mu.writeMethod != null) {
     Object[] o = new Object[1];

     Class[] params = mu.writeMethod.getParameterTypes();
     if(params[0] == org.apache.log4j.Priority.class) {
value = OptionConverter.toLevel((String) value,
				(Level) getAttribute(name));
     }
     o[0] = value;

     try {
mu.writeMethod.invoke(appender,  o);

     } catch(Exception e) {
cat.error("FIXME", e);
     }
   } else if(name.endsWith(".layout")) {

   } else {
     throw(new AttributeNotFoundException("Attribute " + name +
				   " not found in " +
				   this.getClass().getName()));
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:52,代码来源:AppenderDynamicMBean.java

示例8: toLevelTest1

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest1() {
  String val = "INFO";
  Level p = OptionConverter.toLevel(val, null);
  assertEquals(p, Level.INFO);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:OptionConverterTestCase.java

示例9: toLevelTest2

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest2() {
  String val = "INFO#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);
  assertEquals(p, Level.INFO);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:OptionConverterTestCase.java

示例10: toLevelTest3

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest3() {
  String val = "TRACE#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, XLevel.TRACE);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:OptionConverterTestCase.java

示例11: toLevelTest4

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest4() {
  String val = "TR#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, null);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:OptionConverterTestCase.java

示例12: toLevelTest5

import org.apache.log4j.helpers.OptionConverter; //导入方法依赖的package包/类
public
void toLevelTest5() {
  String val = "INFO#org.apache.log4j.xml.TOTO";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, null);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:OptionConverterTestCase.java


注:本文中的org.apache.log4j.helpers.OptionConverter.toLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。