Package org.jboss.beans.metadata.plugins

Examples of org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData


    * @param annotation the annotation
    * @return value factory meta data
    */
   static ValueMetaData createValueMetaData(ValueFactory annotation)
   {
      AbstractValueFactoryMetaData factory = new AbstractValueFactoryMetaData(annotation.bean(), annotation.method());
      if (isAttributePresent(annotation.defaultValue()))
         factory.setDefaultValue(annotation.defaultValue());
      List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>();
      if (isAttributePresent(annotation.parameter()))
         parameters.add(new AbstractParameterMetaData(String.class.getName(), annotation.parameter()));
      if (annotation.parameters().length > 0)
      {
         if (parameters.size() > 0)
            throw new IllegalArgumentException("Cannot set both parameter and parameters!");
         for(Parameter parameter : annotation.parameters())
         {
            AbstractParameterMetaData apmd = new AbstractParameterMetaData(createValueMetaData(parameter));
            if (isAttributePresent(parameter.type()))
               apmd.setType(parameter.type().getName());
            parameters.add(apmd);
         }
      }
      factory.setParameters(parameters);
      factory.setDependentState(new ControllerState(annotation.dependantState()));
      factory.setWhenRequiredState(new ControllerState(annotation.whenRequiredState()));
      return factory;
   }
View Full Code Here


      // Bean2TypeFactory
      GenericBeanFactoryMetaData Bean2TypeFactory = new GenericBeanFactoryMetaData("Bean2TypeFactory",
      "org.jboss.test.kernel.deployment.support.container.Bean2Type");
      Set<PropertyMetaData> Bean2TypeFactory_propertys = new HashSet<PropertyMetaData>();
      AbstractValueFactoryMetaData bean1CreateMethod = new AbstractValueFactoryMetaData("Bean1TypePool", "createBean");
      Bean2TypeFactory_propertys.add(new AbstractPropertyMetaData("bean1", bean1CreateMethod));
      Bean2TypeFactory.setProperties(Bean2TypeFactory_propertys);
      beanFactories.add(Bean2TypeFactory);
      // Bean2TypePool
      AbstractBeanMetaData Bean2TypePool = new AbstractBeanMetaData("Bean2TypePool",
View Full Code Here

      ldap.addConstructorParameter(Map.class.getName(), map);
      LDAPFactory lf = (LDAPFactory)instantiate(controller, ldap.getBeanMetaData());
      assertNotNull(lf);

      // simple one
      AbstractValueFactoryMetaData vfmd1 = new AbstractValueFactoryMetaData("ldap", "getValue");
      List<ParameterMetaData> parameters1 = new ArrayList<ParameterMetaData>();
      vfmd1.setParameters(parameters1);
      parameters1.add(new AbstractParameterMetaData(String.class.getName(), "foo.bar.key"));

      BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder("PropHolder", PropHolder.class.getName());
      builder.addConstructorParameter(String.class.getName(), vfmd1);
      builder.addPropertyMetaData("value", vfmd1);
     
      AbstractListMetaData listMD = new AbstractListMetaData();
      listMD.add(vfmd1);
      // default from 2nd param
      AbstractValueFactoryMetaData vfmd2 = new AbstractValueFactoryMetaData("ldap", "getValue");
      List<ParameterMetaData> parameters2 = new ArrayList<ParameterMetaData>();
      vfmd2.setParameters(parameters2);
      parameters2.add(new AbstractParameterMetaData(String.class.getName(), "foo.bar.key"));
      parameters2.add(new AbstractParameterMetaData(String.class.getName(), "qaz"));
      listMD.add(vfmd2);
      // with transformer
      AbstractValueFactoryMetaData vfmd3 = new AbstractValueFactoryMetaData("ldap", "getValue");
      List<ParameterMetaData> parameters3 = new ArrayList<ParameterMetaData>();
      vfmd3.setParameters(parameters3);
      parameters3.add(new AbstractParameterMetaData(String.class.getName(), "xyz.key"));
      parameters3.add(new AbstractParameterMetaData(String.class.getName(), "xyz"));
      // instantiate transformer
      BeanMetaDataBuilder tranformer = BeanMetaDataBuilderFactory.createBuilder("t", TrimTransformer.class.getName());
      assertNotNull(instantiate(controller, tranformer.getBeanMetaData()));
      parameters3.add(new AbstractParameterMetaData(Transformer.class.getName(), tranformer.getBeanMetaData()));
      listMD.add(vfmd3);
      // null, use default
      AbstractValueFactoryMetaData vfmd4 = new AbstractValueFactoryMetaData("ldap", "getValue", "QWERT");
      List<ParameterMetaData> parameters4 = new ArrayList<ParameterMetaData>();
      vfmd4.setParameters(parameters4);
      parameters4.add(new AbstractParameterMetaData(String.class.getName(), "no.such.key"));
      listMD.add(vfmd4);
      builder.addPropertyMetaData("list", listMD);
      return (PropHolder)instantiate(controller, builder.getBeanMetaData());
   }
View Full Code Here

      return (AbstractValueFactoryMetaData) value;
   }

   public void testValueFactoryWithBean() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithBean.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      assertNull(dependency.getDependentState());
   }
View Full Code Here

      assertNull(dependency.getDependentState());
   }

   public void testValueFactoryWithParameter() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithParameter.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      List<ParameterMetaData> parameters = dependency.getParameters();
      assertNotNull(parameters);
      assertFalse(parameters.isEmpty());
      assertTrue(parameters.size() == 1);
      ParameterMetaData pmd = parameters.get(0);
      assertNotNull(pmd);
      ValueMetaData value = pmd.getValue();
      assertNotNull(value);
      assertEquals("foo.bar.key", value.getUnderlyingValue());
      assertNull(dependency.getDependentState());
   }
View Full Code Here

      assertNull(dependency.getDependentState());
   }

   public void testValueFactoryWithParameters() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithParameters.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      List<ParameterMetaData> parameters = dependency.getParameters();
      assertNotNull(parameters);
      assertFalse(parameters.isEmpty());
      assertTrue(parameters.size() == 2);
      ParameterMetaData pmd1 = parameters.get(0);
      assertNotNull(pmd1);
      ValueMetaData value1 = pmd1.getValue();
      assertNotNull(value1);
      assertEquals("foo.bar.key", value1.getUnderlyingValue());
      ParameterMetaData pmd2 = parameters.get(1);
      assertNotNull(pmd2);
      ValueMetaData value2 = pmd2.getValue();
      assertNotNull(value2);
      assertEquals("mydefault", value2.getUnderlyingValue());
      assertNull(dependency.getDependentState());
   }
View Full Code Here

      assertNull(dependency.getDependentState());
   }

   public void testValueFactoryWithDefault() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithDefault.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      assertEquals("mydefault", dependency.getDefaultValue());
      assertNull(dependency.getDependentState());
   }
View Full Code Here

      assertNull(dependency.getDependentState());
   }

   public void testValueFactoryWithState() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithState.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      assertEquals(ControllerState.CONFIGURED, dependency.getDependentState());
   }
View Full Code Here

      assertEquals(ControllerState.CONFIGURED, dependency.getDependentState());
   }

   public void testValueFactoryWithWhenRequired() throws Exception
   {
      AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithWhenRequired.xml");
      assertEquals("Dummy", dependency.getValue());
      assertEquals("getValue", dependency.getMethod());
      assertEquals(ControllerState.CREATE, dependency.getWhenRequiredState());
   }
View Full Code Here

   public void testValueFactoryBadNoBean() throws Exception
   {
      try
      {
         AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryBadNoBean.xml");
         assertNull(dependency.getValue());
      }
      catch (Exception expected)
      {
         checkJBossXBException(IllegalArgumentException.class, expected);
      }
View Full Code Here

TOP

Related Classes of org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.