org.apache.log4j.helpers.OptionConverter#toLevel ( )源码实例Demo

下面列出了org.apache.log4j.helpers.OptionConverter#toLevel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cacheonix-core   文件: PropertySetter.java
/**
   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;
}
 
源代码2 项目: cacheonix-core   文件: HierarchyDynamicMBean.java
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);
  }


}
 
源代码3 项目: cacheonix-core   文件: LevelMatchFilter.java
public
void setLevelToMatch(String level) {
  levelToMatch = OptionConverter.toLevel(level, null);
}
 
源代码4 项目: cacheonix-core   文件: LayoutDynamicMBean.java
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()));
   }
 }
 
源代码5 项目: cacheonix-core   文件: LoggerDynamicMBean.java
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()));
   }
 }
 
源代码6 项目: cacheonix-core   文件: AppenderDynamicMBean.java
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()));
   }
 }
 
源代码7 项目: cacheonix-core   文件: OptionConverterTestCase.java
public
void toLevelTest1() {
  String val = "INFO";
  Level p = OptionConverter.toLevel(val, null);
  assertEquals(p, Level.INFO);
}
 
源代码8 项目: cacheonix-core   文件: OptionConverterTestCase.java
public
void toLevelTest2() {
  String val = "INFO#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);
  assertEquals(p, Level.INFO);
}
 
源代码9 项目: cacheonix-core   文件: OptionConverterTestCase.java
public
void toLevelTest3() {
  String val = "TRACE#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, XLevel.TRACE);
}
 
源代码10 项目: cacheonix-core   文件: OptionConverterTestCase.java
public
void toLevelTest4() {
  String val = "TR#org.apache.log4j.xml.XLevel";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, null);
}
 
源代码11 项目: cacheonix-core   文件: OptionConverterTestCase.java
public
void toLevelTest5() {
  String val = "INFO#org.apache.log4j.xml.TOTO";
  Level p = OptionConverter.toLevel(val, null);    
  assertEquals(p, null);
}