Example usage for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY

List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY.

Prototype

Class EMPTY_CLASS_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY.

Click Source Link

Document

An empty immutable Class array.

Usage

From source file:org.eclipse.wb.tests.designer.databinding.rcp.model.UiConfigurationTest.java

public void test_UpdateValueStrategy() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this,
            new String[] { "import org.eclipse.core.databinding.Binding;", "public class Test {",
                    "  protected Shell m_shell;", "  private DataBindingContext m_bindingContext;",
                    "  public static void main(String[] args) {", "    Test test = new Test();",
                    "    test.open();", "  }", "  public void open() {", "    Display display = new Display();",
                    "    createContents();", "    m_shell.open();", "    m_shell.layout();",
                    "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {",
                    "        display.sleep();", "      }", "    }", "  }",
                    "  protected void createContents() {", "    m_shell = new Shell();",
                    "    m_bindingContext = initDataBindings();", "  }",
                    "  private DataBindingContext initDataBindings() {",
                    "    IObservableValue observeValue = BeansObservables.observeValue(getClass(), \"name\");",
                    "    IObservableValue observeWidget = SWTObservables.observeText(m_shell);",
                    "    DataBindingContext bindingContext = new DataBindingContext();",
                    "    bindingContext.bindValue(observeWidget, observeValue, null, null);",
                    "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);// w  ww .j  av a2  s.  c  o m
    //
    DatabindingsProvider provider = getDatabindingsProvider();
    //
    assertEquals(1, provider.getBindings().size());
    assertInstanceOf(BindingInfo.class, provider.getBindings().get(0));
    BindingInfo binding = (BindingInfo) provider.getBindings().get(0);
    //
    assertNotNull(binding.getTargetStrategy());
    //
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingUiContentProviderContext context = new BindingUiContentProviderContext();
    context.setDirection("Target");
    //
    binding.getTargetStrategy().createContentProviders(providers, context);
    assertEquals(2, providers.size());
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(0));
    assertInstanceOf(ChooseClassConfiguration.class,
            ReflectionUtils.getFieldObject(providers.get(0), "m_configuration"));
    ChooseClassConfiguration actual = getConfiguration(providers.get(0));
    //
    ChooseClassConfiguration expected = new ChooseClassConfiguration();
    expected.setDialogFieldLabel("UpdateValueStrategy:");
    expected.setDefaultValues(
            new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expected.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expected.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy", "POLICY_UPDATE");
    expected.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expected.setEmptyClassErrorMessage("Target strategy class is empty.");
    expected.setErrorMessagePrefix("Target strategy");
    //
    assertEquals(expected, actual);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(1));
    //
    List<IUiContentProvider> subProviders = (List<IUiContentProvider>) ReflectionUtils
            .getFieldObject(providers.get(1), "m_providers");
    assertEquals(4, subProviders.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProviders.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActual = getConfiguration(subProviders.get(0));
    //
    ChooseClassConfiguration afterConvertValidatorExpected = new ChooseClassConfiguration();
    afterConvertValidatorExpected.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpected.setClearValue("N/S");
    afterConvertValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpected
            .setEmptyClassErrorMessage(context.getDirection() + " \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"AfterConvertValidator\"");
    //
    assertEquals(afterConvertValidatorExpected, afterConvertValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActual = getConfiguration(subProviders.get(1));
    //
    ChooseClassConfiguration afterGetValidatorExpected = new ChooseClassConfiguration();
    afterGetValidatorExpected.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpected.setClearValue("N/S");
    afterGetValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpected
            .setEmptyClassErrorMessage(context.getDirection() + " \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"AfterGetValidator\"");
    //
    assertEquals(afterGetValidatorExpected, afterGetValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActual = getConfiguration(subProviders.get(2));
    //
    ChooseClassConfiguration beforeSetValidatorExpected = new ChooseClassConfiguration();
    beforeSetValidatorExpected.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpected.setClearValue("N/S");
    beforeSetValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpected
            .setEmptyClassErrorMessage(context.getDirection() + " \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"BeforeSetValidator\"");
    //
    assertEquals(beforeSetValidatorExpected, beforeSetValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActual = getConfiguration(subProviders.get(3));
    //
    ChooseClassConfiguration converterExpected = new ChooseClassConfiguration();
    converterExpected.setDialogFieldLabel("Converter:");
    converterExpected.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setClearValue("N/S");
    converterExpected.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpected.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpected.setErrorMessagePrefix("Target converter");
    //
    assertEquals(converterExpected, converterActual);
}

From source file:org.eclipse.wb.tests.designer.databinding.rcp.model.UiConfigurationTest.java

public void test_BindingInfo() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this,
            new String[] { "import org.eclipse.core.databinding.Binding;", "public class Test {",
                    "  protected Shell m_shell;", "  private DataBindingContext m_bindingContext;",
                    "  public static void main(String[] args) {", "    Test test = new Test();",
                    "    test.open();", "  }", "  public void open() {", "    Display display = new Display();",
                    "    createContents();", "    m_shell.open();", "    m_shell.layout();",
                    "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {",
                    "        display.sleep();", "      }", "    }", "  }",
                    "  protected void createContents() {", "    m_shell = new Shell();",
                    "    m_bindingContext = initDataBindings();", "  }",
                    "  private DataBindingContext initDataBindings() {",
                    "    IObservableValue observeValue = BeansObservables.observeValue(getClass(), \"name\");",
                    "    IObservableValue observeWidget = SWTObservables.observeText(m_shell);",
                    "    DataBindingContext bindingContext = new DataBindingContext();",
                    "    bindingContext.bindValue(observeWidget, observeValue, null, null);",
                    "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);//  ww  w.  j  a  v  a2s.  c  o m
    //
    DatabindingsProvider provider = getDatabindingsProvider();
    //
    assertEquals(1, provider.getBindings().size());
    assertInstanceOf(BindingInfo.class, provider.getBindings().get(0));
    BindingInfo binding = (BindingInfo) provider.getBindings().get(0);
    //
    assertNotNull(binding.getTargetStrategy());
    //
    IPageListener listener = new IPageListener() {
        public void setTitleImage(Image image) {
        }

        public void setTitle(String title) {
        }

        public void setPageComplete(boolean complete) {
        }

        public void setMessage(String newMessage) {
        }

        public void setErrorMessage(String newMessage) {
        }
    };
    //
    List<IUiContentProvider> providers = provider.getContentProviders(binding, listener);
    //
    assertEquals(10, providers.size());
    // ---------------------------------------------------------------------------
    assertInstanceOf(LabelUiContentProvider.class, providers.get(0));
    assertEquals("Target:", ReflectionUtils.getFieldObject(providers.get(0), "m_title"));
    assertEquals("m_shell.text", ReflectionUtils.getFieldObject(providers.get(0), "m_value"));
    // ---------------------------------------------------------------------------
    assertInstanceOf(SwtDelayUiContentProvider.class, providers.get(1));
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(2));
    assertInstanceOf(ChooseClassConfiguration.class,
            ReflectionUtils.getFieldObject(providers.get(2), "m_configuration"));
    ChooseClassConfiguration actualTargetStrategy = getConfiguration(providers.get(2));
    //
    ChooseClassConfiguration expectedTargetStrategy = new ChooseClassConfiguration();
    expectedTargetStrategy.setDialogFieldLabel("UpdateValueStrategy:");
    expectedTargetStrategy.setDefaultValues(
            new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expectedTargetStrategy.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedTargetStrategy.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy",
            "POLICY_UPDATE");
    expectedTargetStrategy.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedTargetStrategy.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expectedTargetStrategy.setEmptyClassErrorMessage("Target strategy class is empty.");
    expectedTargetStrategy.setErrorMessagePrefix("Target strategy");
    //
    assertEquals(expectedTargetStrategy, actualTargetStrategy);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(3));
    //
    List<IUiContentProvider> subProvidersTargetStrategy = (List<IUiContentProvider>) ReflectionUtils
            .getFieldObject(providers.get(3), "m_providers");
    assertEquals(4, subProvidersTargetStrategy.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProvidersTargetStrategy.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActualTarget = getConfiguration(
            subProvidersTargetStrategy.get(0));
    //
    ChooseClassConfiguration afterConvertValidatorExpectedTarget = new ChooseClassConfiguration();
    afterConvertValidatorExpectedTarget.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedTarget.setClearValue("N/S");
    afterConvertValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpectedTarget
            .setEmptyClassErrorMessage("Target \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpectedTarget.setErrorMessagePrefix("Target \"AfterConvertValidator\"");
    //
    assertEquals(afterConvertValidatorExpectedTarget, afterConvertValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActualTarget = getConfiguration(
            subProvidersTargetStrategy.get(1));
    //
    ChooseClassConfiguration afterGetValidatorExpectedTarget = new ChooseClassConfiguration();
    afterGetValidatorExpectedTarget.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedTarget.setClearValue("N/S");
    afterGetValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpectedTarget.setEmptyClassErrorMessage("Target \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpectedTarget.setErrorMessagePrefix("Target \"AfterGetValidator\"");
    //
    assertEquals(afterGetValidatorExpectedTarget, afterGetValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActualTarget = getConfiguration(
            subProvidersTargetStrategy.get(2));
    //
    ChooseClassConfiguration beforeSetValidatorExpectedTarget = new ChooseClassConfiguration();
    beforeSetValidatorExpectedTarget.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedTarget.setClearValue("N/S");
    beforeSetValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpectedTarget.setEmptyClassErrorMessage("Target \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpectedTarget.setErrorMessagePrefix("Target \"BeforeSetValidator\"");
    //
    assertEquals(beforeSetValidatorExpectedTarget, beforeSetValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActualTarget = getConfiguration(subProvidersTargetStrategy.get(3));
    //
    ChooseClassConfiguration converterExpectedTarget = new ChooseClassConfiguration();
    converterExpectedTarget.setDialogFieldLabel("Converter:");
    converterExpectedTarget.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedTarget.setClearValue("N/S");
    converterExpectedTarget.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpectedTarget.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpectedTarget.setErrorMessagePrefix("Target converter");
    //
    assertEquals(converterExpectedTarget, converterActualTarget);
    // ---------------------------------------------------------------------------
    assertInstanceOf(SeparatorUiContentProvider.class, providers.get(4));
    // ---------------------------------------------------------------------------
    assertInstanceOf(LabelUiContentProvider.class, providers.get(5));
    assertEquals("Model:", ReflectionUtils.getFieldObject(providers.get(5), "m_title"));
    assertEquals("getClass().name", ReflectionUtils.getFieldObject(providers.get(5), "m_value"));
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(6));
    assertInstanceOf(ChooseClassConfiguration.class,
            ReflectionUtils.getFieldObject(providers.get(6), "m_configuration"));
    ChooseClassConfiguration actualModelStrategy = getConfiguration(providers.get(6));
    //
    ChooseClassConfiguration expectedModelStrategy = new ChooseClassConfiguration();
    expectedModelStrategy.setDialogFieldLabel("UpdateValueStrategy:");
    expectedModelStrategy.setDefaultValues(
            new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expectedModelStrategy.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedModelStrategy.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy",
            "POLICY_UPDATE");
    expectedModelStrategy.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedModelStrategy.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expectedModelStrategy.setEmptyClassErrorMessage("Model strategy class is empty.");
    expectedModelStrategy.setErrorMessagePrefix("Model strategy");
    //
    assertEquals(expectedModelStrategy, actualModelStrategy);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(7));
    //
    List<IUiContentProvider> subProvidersModelStrategy = (List<IUiContentProvider>) ReflectionUtils
            .getFieldObject(providers.get(7), "m_providers");
    assertEquals(4, subProvidersModelStrategy.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProvidersModelStrategy.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActualModel = getConfiguration(
            subProvidersModelStrategy.get(0));
    //
    ChooseClassConfiguration afterConvertValidatorExpectedModel = new ChooseClassConfiguration();
    afterConvertValidatorExpectedModel.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedModel.setClearValue("N/S");
    afterConvertValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpectedModel
            .setEmptyClassErrorMessage("Model \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpectedModel.setErrorMessagePrefix("Model \"AfterConvertValidator\"");
    //
    assertEquals(afterConvertValidatorExpectedModel, afterConvertValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActualModel = getConfiguration(subProvidersModelStrategy.get(1));
    //
    ChooseClassConfiguration afterGetValidatorExpectedModel = new ChooseClassConfiguration();
    afterGetValidatorExpectedModel.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedModel.setClearValue("N/S");
    afterGetValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpectedModel.setEmptyClassErrorMessage("Model \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpectedModel.setErrorMessagePrefix("Model \"AfterGetValidator\"");
    //
    assertEquals(afterGetValidatorExpectedModel, afterGetValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActualModel = getConfiguration(subProvidersModelStrategy.get(2));
    //
    ChooseClassConfiguration beforeSetValidatorExpectedModel = new ChooseClassConfiguration();
    beforeSetValidatorExpectedModel.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedModel.setClearValue("N/S");
    beforeSetValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpectedModel.setEmptyClassErrorMessage("Model \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpectedModel.setErrorMessagePrefix("Model \"BeforeSetValidator\"");
    //
    assertEquals(beforeSetValidatorExpectedModel, beforeSetValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActualModel = getConfiguration(subProvidersModelStrategy.get(3));
    //
    ChooseClassConfiguration converterExpectedModel = new ChooseClassConfiguration();
    converterExpectedModel.setDialogFieldLabel("Converter:");
    converterExpectedModel.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedModel.setClearValue("N/S");
    converterExpectedModel.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpectedModel.setEmptyClassErrorMessage("Model converter class is empty.");
    converterExpectedModel.setErrorMessagePrefix("Model converter");
    //
    assertEquals(converterExpectedModel, converterActualModel);
    // ---------------------------------------------------------------------------
    assertInstanceOf(SeparatorUiContentProvider.class, providers.get(8));
    // ---------------------------------------------------------------------------
    assertInstanceOf(BindingContentProvider.class, providers.get(9));
}

From source file:org.eclipse.wb.tests.designer.databinding.rcp.model.UiConfigurationTest.java

public void test_UpdateListStrategy() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] {
            "import org.eclipse.core.databinding.Binding;", "public class Test {", "  protected Shell m_shell;",
            "  private DataBindingContext m_bindingContext;", "  public static void main(String[] args) {",
            "    Test test = new Test();", "    test.open();", "  }", "  public void open() {",
            "    Display display = new Display();", "    createContents();", "    m_shell.open();",
            "    m_shell.layout();", "    while (!m_shell.isDisposed()) {",
            "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }",
            "  protected void createContents() {", "    m_shell = new Shell();",
            "    m_bindingContext = initDataBindings();", "  }",
            "  private DataBindingContext initDataBindings() {",
            "    IObservableList observeList1 = BeansObservables.observeList(getClass(), \"name\");",
            "    IObservableList observeList2 = BeansObservables.observeList(getClass(), \"modifiers\");",
            "    DataBindingContext bindingContext = new DataBindingContext();",
            "    bindingContext.bindList(observeList1, observeList2, null, null);",
            "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);//from w  w  w .  ja  v a2 s . co  m
    //
    DatabindingsProvider provider = getDatabindingsProvider();
    //
    assertEquals(1, provider.getBindings().size());
    assertInstanceOf(BindingInfo.class, provider.getBindings().get(0));
    BindingInfo binding = (BindingInfo) provider.getBindings().get(0);
    //
    assertNotNull(binding.getTargetStrategy());
    //
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingUiContentProviderContext context = new BindingUiContentProviderContext();
    context.setDirection("Target");
    binding.getTargetStrategy().createContentProviders(providers, context);
    assertEquals(2, providers.size());
    //
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(0));
    assertInstanceOf(ChooseClassConfiguration.class,
            ReflectionUtils.getFieldObject(providers.get(0), "m_configuration"));
    //
    ChooseClassConfiguration actual = getConfiguration(providers.get(0));
    //
    ChooseClassConfiguration expected = new ChooseClassConfiguration();
    expected.setDialogFieldLabel("UpdateListStrategy:");
    expected.setDefaultValues(new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST" });
    expected.setValueScope("org.eclipse.core.databinding.UpdateListStrategy");
    expected.setRetargetClassName("org.eclipse.core.databinding.UpdateListStrategy", "POLICY_UPDATE");
    expected.setBaseClassName("org.eclipse.core.databinding.UpdateListStrategy");
    expected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expected.setEmptyClassErrorMessage("Target strategy class is empty.");
    expected.setErrorMessagePrefix("Target strategy");
    //
    assertEquals(expected, actual);
    //
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(1));
    //
    List<IUiContentProvider> subProviders = (List<IUiContentProvider>) ReflectionUtils
            .getFieldObject(providers.get(1), "m_providers");
    assertEquals(1, subProviders.size());
    assertInstanceOf(ConverterUiContentProvider.class, subProviders.get(0));
    //
    ChooseClassConfiguration converterActual = getConfiguration(subProviders.get(0));
    //
    ChooseClassConfiguration converterExpected = new ChooseClassConfiguration();
    converterExpected.setDialogFieldLabel("Converter:");
    converterExpected.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setClearValue("N/S");
    converterExpected.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpected.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpected.setErrorMessagePrefix("Target converter");
    //
    assertEquals(converterExpected, converterActual);
}

From source file:org.eclipse.wb.tests.designer.databinding.rcp.model.UiConfigurationTest.java

public void test_UpdateSetStrategy() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this,
            new String[] { "import org.eclipse.core.databinding.Binding;", "public class Test {",
                    "  protected Shell m_shell;", "  private DataBindingContext m_bindingContext;",
                    "  public static void main(String[] args) {", "    Test test = new Test();",
                    "    test.open();", "  }", "  public void open() {", "    Display display = new Display();",
                    "    createContents();", "    m_shell.open();", "    m_shell.layout();",
                    "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {",
                    "        display.sleep();", "      }", "    }", "  }",
                    "  protected void createContents() {", "    m_shell = new Shell();",
                    "    m_bindingContext = initDataBindings();", "  }",
                    "  private DataBindingContext initDataBindings() {",
                    "    IObservableSet observeSet1 = BeansObservables.observeSet(getClass(), \"name\");",
                    "    IObservableSet observeSet2 = BeansObservables.observeSet(getClass(), \"modifiers\");",
                    "    DataBindingContext bindingContext = new DataBindingContext();",
                    "    bindingContext.bindSet(observeSet1, observeSet2, null, null);",
                    "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);//  www .j a  va 2  s  .c om
    //
    DatabindingsProvider provider = getDatabindingsProvider();
    //
    assertEquals(1, provider.getBindings().size());
    assertInstanceOf(BindingInfo.class, provider.getBindings().get(0));
    BindingInfo binding = (BindingInfo) provider.getBindings().get(0);
    //
    assertNotNull(binding.getTargetStrategy());
    //
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingUiContentProviderContext context = new BindingUiContentProviderContext();
    context.setDirection("Target");
    binding.getTargetStrategy().createContentProviders(providers, context);
    assertEquals(2, providers.size());
    //
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(0));
    assertInstanceOf(ChooseClassConfiguration.class,
            ReflectionUtils.getFieldObject(providers.get(0), "m_configuration"));
    //
    ChooseClassConfiguration actual = getConfiguration(providers.get(0));
    //
    ChooseClassConfiguration expected = new ChooseClassConfiguration();
    expected.setDialogFieldLabel("UpdateSetStrategy:");
    expected.setDefaultValues(new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST" });
    expected.setValueScope("org.eclipse.core.databinding.UpdateSetStrategy");
    expected.setRetargetClassName("org.eclipse.core.databinding.UpdateSetStrategy", "POLICY_UPDATE");
    expected.setBaseClassName("org.eclipse.core.databinding.UpdateSetStrategy");
    expected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expected.setEmptyClassErrorMessage("Target strategy class is empty.");
    expected.setErrorMessagePrefix("Target strategy");
    //
    assertEquals(expected, actual);
    //
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(1));
    //
    List<IUiContentProvider> subProviders = (List<IUiContentProvider>) ReflectionUtils
            .getFieldObject(providers.get(1), "m_providers");
    assertEquals(1, subProviders.size());
    assertInstanceOf(ConverterUiContentProvider.class, subProviders.get(0));
    //
    ChooseClassConfiguration converterActual = getConfiguration(subProviders.get(0));
    //
    ChooseClassConfiguration converterExpected = new ChooseClassConfiguration();
    converterExpected.setDialogFieldLabel("Converter:");
    converterExpected.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setClearValue("N/S");
    converterExpected.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpected.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpected.setErrorMessagePrefix("Target converter");
    //
    assertEquals(converterExpected, converterActual);
}

From source file:org.jdto.util.ClassUtils.java

/**
 * <p>Checks if an array of Classes can be assigned to another array of
 * Classes.</p>//from  w  w w. j a  v a  2s .  c o m
 *
 * <p>This method calls {@link #isAssignable(Class, Class) isAssignable} for
 * each Class pair in the input arrays. It can be used to check if a set of
 * arguments (the first parameter) are suitably compatible with a set of
 * method parameter types (the second parameter).</p>
 *
 * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method,
 * this method takes into account widenings of primitive classes and
 * <code>null</code>s.</p>
 *
 * <p>Primitive widenings allow an int to be assigned to a
 * <code>long</code>,
 * <code>float</code> or
 * <code>double</code>. This method returns the correct result for these
 * cases.</p>
 *
 * <p><code>Null</code> may be assigned to any reference type. This method
 * will return
 * <code>true</code> if
 * <code>null</code> is passed in and the toClass is non-primitive.</p>
 *
 * <p>Specifically, this method tests whether the type represented by the
 * specified
 * <code>Class</code> parameter can be converted to the type represented by
 * this
 * <code>Class</code> object via an identity conversion widening primitive
 * or widening reference conversion. See <em><a
 * href="http://java.sun.com/docs/books/jls/">The Java Language
 * Specification</a></em>, sections 5.1.1, 5.1.2 and 5.1.4 for details.</p>
 *
 * @param classArray the array of Classes to check, may be
 * <code>null</code>
 * @param toClassArray the array of Classes to try to assign into, may be
 * <code>null</code>
 * @param autoboxing whether to use implicit autoboxing/unboxing between
 * primitives and wrappers
 * @return
 * <code>true</code> if assignment possible
 * @since 2.5
 */
public static boolean isAssignable(Class[] classArray, Class[] toClassArray, boolean autoboxing) {
    if (ArrayUtils.isSameLength(classArray, toClassArray) == false) {
        return false;
    }
    if (classArray == null) {
        classArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (toClassArray == null) {
        toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    for (int i = 0; i < classArray.length; i++) {
        if (isAssignable(classArray[i], toClassArray[i], autoboxing) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.jdto.util.MethodUtils.java

/**
 * <p>Invoke a named method whose parameter type matches the object
 * type.</p>/*  w  w w  . j av  a 2  s.c  o  m*/
 *
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters via
 * passing in wrapping classes. So, for example, a
 * <code>Boolean</code> object would match a
 * <code>boolean</code> primitive.</p>
 *
 * @param object invoke method on this object
 * @param methodName get method with this name
 * @param args use these arguments - treat null as empty array
 * @param parameterTypes match these parameters - treat null as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the method
 * invoked
 * @throws IllegalAccessException if the requested method is not accessible
 * via reflection
 */
public static Object invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (parameterTypes == null) {
        parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (args == null) {
        args = ArrayUtils.EMPTY_OBJECT_ARRAY;
    }
    Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(
                "No such accessible method: " + methodName + "() on object: " + object.getClass().getName());
    }
    return method.invoke(object, args);
}

From source file:org.jdto.util.MethodUtils.java

/**
 * <p>Invoke a named static method whose parameter type matches the object
 * type.</p>/*from  w  w w. ja v  a 2  s .co  m*/
 *
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters via
 * passing in wrapping classes. So, for example, a
 * <code>Boolean</code> class would match a
 * <code>boolean</code> primitive.</p>
 *
 *
 * @param cls invoke static method on this class
 * @param methodName get method with this name
 * @param args use these arguments - treat null as empty array
 * @param parameterTypes match these parameters - treat null as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the method
 * invoked
 * @throws IllegalAccessException if the requested method is not accessible
 * via reflection
 */
public static Object invokeStaticMethod(Class cls, String methodName, Object[] args, Class[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (parameterTypes == null) {
        parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (args == null) {
        args = ArrayUtils.EMPTY_OBJECT_ARRAY;
    }
    Method method = getMatchingAccessibleMethod(cls, methodName, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(
                "No such accessible method: " + methodName + "() on class: " + cls.getName());
    }
    return method.invoke(null, args);
}

From source file:org.jnap.core.persistence.hibernate.PersistentEnumType.java

public void setParameterValues(Properties parameters) {
    String enumClassName = parameters.getProperty(ENUM_CLASS_PARAM);
    try {//from  ww w . java  2 s.  c  o  m
        enumClass = Class.forName(enumClassName).asSubclass(Enum.class);
    } catch (ClassNotFoundException cfne) {
        throw new HibernateException("Enum class not found", cfne);
    }

    String identifierMethodName = parameters.getProperty(IDENTIFIER_METHOD_PARAM,
            DEFAULT_IDENTIFIER_METHOD_NAME);

    try {
        identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]);
        identifierType = identifierMethod.getReturnType();
    } catch (Exception e) {
        throw new HibernateException("Failed to obtain identifier method", e);
    }

    type = (AbstractSingleColumnStandardBasicType) new TypeResolver().basic(identifierType.getName());

    if (type == null) {
        throw new HibernateException("Unsupported identifier type " + identifierType.getName());
    }

    sqlTypes = new int[] { type.getSqlTypeDescriptor().getSqlType() };

    try {
        valuesMethod = enumClass.getMethod("values", ArrayUtils.EMPTY_CLASS_ARRAY);
    } catch (Exception e) {
        throw new HibernateException("Failed to obtain values method", e);
    }
}

From source file:org.nebularis.defproxy.introspection.ReflectionUtils.java

/**
 * For each member of both class arrays, returns <code>true</code> if the
 * type from the first array is assignable from the type taken from the second array.
 * @param classArray//  w  ww. j a  v  a2  s. c o m
 * @param toClassArray
 * @return
 */
public static boolean isAssignable(Class[] classArray, Class[] toClassArray) {
    if (classArray == null) {
        classArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (toClassArray == null) {
        toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (ArrayUtils.isSameLength(classArray, toClassArray) == false) {
        return false;
    }
    for (int i = 0; i < classArray.length; i++) {
        if (isAssignable(classArray[i], toClassArray[i]) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.polymap.biotop.model.importer.AnnotatedCompositeImporter.java

public void fillEntity(Composite composite, Map<String, Object> row) {
    for (Map.Entry<String, Object> rowEntry : row.entrySet()) {
        String propName = nameMap.get(rowEntry.getKey());
        if (propName != null && rowEntry.getValue() != null) {
            try {
                Method m = type.getDeclaredMethod(propName, ArrayUtils.EMPTY_CLASS_ARRAY);
                Property p = (Property) m.invoke(composite, ArrayUtils.EMPTY_OBJECT_ARRAY);
                // String
                if (String.class.equals(p.type())) {
                    p.set(rowEntry.getValue().toString());
                }/*from  w  w w . ja  va 2s. com*/
                // Integer
                else if (Integer.class.equals(p.type())) {
                    p.set(((Number) rowEntry.getValue()).intValue());
                }
                // Long
                else if (Long.class.equals(p.type())) {
                    p.set(((Number) rowEntry.getValue()).longValue());
                }
                // Float
                else if (Float.class.equals(p.type())) {
                    p.set(((Number) rowEntry.getValue()).floatValue());
                }
                // Double
                else if (Double.class.equals(p.type())) {
                    p.set(((Number) rowEntry.getValue()).doubleValue());
                }
                // Boolean
                else if (Boolean.class.equals(p.type())) {
                    p.set(rowEntry.getValue());
                } else {
                    throw new RuntimeException("Unhandled property type: " + p.type());
                }
                //log.info( "    property: " + p.qualifiedName().name() + " = " + rowEntry.getValue() );
            } catch (Exception e) {
                throw new RuntimeException("Property: " + propName, e);
            }
        } else {
            //log.info( "    skipping column value: " + rowEntry.getKey() );
        }
    }
}