static {
   // Ugly hack. Here lies PropertyEditors.init(). Below code is progeny. It is required to
   // properly instantiate
   // ThreadPools. The threadpools dont do that for themselves. ThreadPools are in common-core.
   try {
     PropertyEditorFinder.getInstance().register(BlockingMode.class, BlockingModeEditor.class);
   } catch (Exception ignored) {
   }
 }
 @Before
 public void init() {
   // initialize locale, this is done for date editor, it wont pass test unless its run on EN
   // system :).
   Locale testLocale = Locale.US;
   Locale.setDefault(testLocale);
   // init editors
   finder = PropertyEditorFinder.getInstance();
 }
  private static Object newValue(final Class<?> type, final String value) {
    final PropertyEditor editor = PropertyEditorFinder.getInstance().find(type);
    if (editor == null) {
      SarLogger.ROOT_LOGGER.propertyNotFound(type);
      return null;
    }
    editor.setAsText(value);

    return editor.getValue();
  }
  public Element getElementServiceBindingValue(ServiceBinding binding, Element input) {
    if (input == null) throw new IllegalArgumentException("input cannot be null");

    PropertyEditor editor = PropertyEditorFinder.getInstance().find(Element.class);
    if (editor == null)
      throw new IllegalStateException("Cannot find PropertyEditor for type Element");

    editor.setValue(input);
    Reader reader = new StringReader(editor.getAsText());
    Writer writer = new StringWriter();

    doXslTransform(binding, getConfig(binding), reader, writer);

    editor.setAsText(writer.toString());
    return (Element) editor.getValue();
  }
  public Object getValue(ServiceValueContext valueContext) throws Exception {
    MBeanAttributeInfo attributeInfo = valueContext.getAttributeInfo();
    ClassLoader cl = valueContext.getClassloader();

    String typeName = attributeInfo.getType();
    if (typeName == null)
      throw new DeploymentException(
          "AttributeInfo for " + attributeInfo.getName() + " has no type");

    // see if it is a primitive type first
    Class typeClass = Classes.getPrimitiveTypeForName(typeName);
    if (typeClass == null) {
      // nope try look up
      try {
        typeClass = cl.loadClass(typeName);
      } catch (ClassNotFoundException e) {
        throw new DeploymentException(
            "Class not found for attribute: " + attributeInfo.getName(), e);
      }
    }

    PropertyEditor editor = PropertyEditorFinder.getInstance().find(typeClass);
    if (editor == null)
      throw new DeploymentException(
          "No property editor for attribute: "
              + attributeInfo.getName()
              + "; type="
              + typeClass.getName());

    // JBAS-1709, temporarily switch the TCL so that property
    // editors have access to the actual deployment ClassLoader.
    ClassLoader tcl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(cl);
    try {
      editor.setAsText(text);
      return editor.getValue();
    } finally {
      Thread.currentThread().setContextClassLoader(tcl);
    }
  }
  @Test
  public void testPropertyEditor() throws Exception {

    // test
    Class<T> type = getType();
    PropertyEditor editor = finder.find(type);

    String[] inputData = getInputData();
    Object[] expectedData = getOutputData();
    String[] expectedStringData = getConvertedToText();
    try {
      assertTrue("Did not find property editor for type: " + type, editor != null);
      assertEquals(
          "Editor has wrong package!",
          this.getClass().getPackage(),
          editor.getClass().getPackage());
      logger.finest(
          "Found property editor for: " + type + ", editor=" + editor.getClass().getName());
      assertEquals(editor + " input length", inputData.length, expectedData.length);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    for (int i = 0; i < inputData.length; i++) {
      String input = inputData[i];
      editor.setAsText(input);
      // TODO: check instance?
      T expected = (T) expectedData[i];
      T output = (T) editor.getValue();

      Comparator<T> c = getComparator();
      boolean equals = false;
      if (c == null) {
        equals = output != null ? output.equals(expected) : expected == null;
      } else {
        equals = c.compare(output, expected) == 0;
      }

      assertTrue(
          "Test at index '"
              + i
              + "'. Transform("
              + editor
              + ") of "
              + input
              + "\n does not equal! \nexpected = "
              + logT(expected)
              + "\noutput = "
              + logT(output),
          equals);

      String expectedStringOutput = expectedStringData[i];
      String stringOutput = editor.getAsText();
      logger.finest("setAsText '" + logString(input) + "'");
      logger.finest("getAsText '" + logString(stringOutput) + "'");
      if (type != Properties.class) {
        // We can't meaningfully compare the PropertiesEditor string output
        String msg =
            "Test at index '"
                + i
                + "'. PropertyEditor: "
                + editor.getClass().getName()
                + ", getAsText() == expectedStringOutput '";
        assertEquals(msg, expectedStringOutput, stringOutput);
      }
    }
  }