Package org.jboss.test.xml.pojoserver.metadata

Examples of org.jboss.test.xml.pojoserver.metadata.AbstractPropertyMetaData


            {
               String localName = attrs.getLocalName(i);
               if ("name".equals(localName))
                  bean.setName(attrs.getValue(i));
               else if ("class".equals(localName))
                  properties.add(new AbstractPropertyMetaData("bean", attrs.getValue(i)));
            }
         }
      });

      // bean has a constructor
      beanType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
            bean.setConstructor(constructor);
         }
      });

      // beanfactory has a constructor
      beanFactoryType.pushInterceptor(constructorQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) child;
            Set properties = bean.getProperties();
            properties.add(new AbstractPropertyMetaData("constructor", new AbstractValueMetaData(constructor)));
         }
      });

      // constructor binding
      TypeBinding constructorType = schemaBinding.getType(constructorTypeQName);
      constructorType.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new AbstractConstructorMetaData();
         }

         public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
         {
            AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) o;
            for (int i = 0; i < attrs.getLength(); ++i)
            {
               String localName = attrs.getLocalName(i);
               if ("factoryClass".equals(localName))
                  constructor.setFactoryClass(attrs.getValue(i));
               else if ("factoryMethod".equals(localName))
                  constructor.setFactoryMethod(attrs.getValue(i));
            }
         }
      });

      // constructor has a factory
      constructorType.pushInterceptor(factoryQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
            AbstractDependencyValueMetaData factory = (AbstractDependencyValueMetaData) child;
            constructor.setFactory(factory);
         }
      });

      // constructor has a list parameters
      constructorType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) parent;
            AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
            List parameters = constructor.getParameters();
            if (parameters == null)
            {
               parameters = new ArrayList();
               constructor.setParameters(parameters);
            }
            parameters.add(parameter);
         }
      });
     
      // parameter binding
      TypeBinding parameterType = schemaBinding.getType(parameterTypeQName);
      configureValueBindings(parameterType);
      parameterType.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new AbstractParameterMetaData();
         }

         public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
         {
            AbstractParameterMetaData parameter = (AbstractParameterMetaData) o;
            for (int i = 0; i < attrs.getLength(); ++i)
            {
               String localName = attrs.getLocalName(i);
               if ("class".equals(localName))
                  parameter.setType(attrs.getValue(i));
            }
         }
      });
     
      // parameter can take a value
      parameterType.setSimpleType(new CharactersHandler()
      {
         public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
         {
            return new StringValueMetaData(value);
         }

         public void setValue(QName qName, ElementBinding element, Object owner, Object value)
         {
            AbstractParameterMetaData parameter = (AbstractParameterMetaData) owner;
            parameter.setValue((StringValueMetaData) value);
         }
      });

      // bean has a create
      beanType.pushInterceptor(createQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
            bean.setCreate(lifecycle);
         }
      });

      // bean has a start
      beanType.pushInterceptor(startQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
            bean.setStart(lifecycle);
         }
      });

      // bean has a stop
      beanType.pushInterceptor(stopQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
            bean.setStop(lifecycle);
         }
      });

      // bean has a destroy
      beanType.pushInterceptor(destroyQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) child;
            bean.setDestroy(lifecycle);
         }
      });

      // lifecycle binding
      TypeBinding lifecycleType = schemaBinding.getType(lifecycleTypeQName);
      lifecycleType.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new AbstractLifecycleMetaData();
         }

         public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
         {
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) o;
            for (int i = 0; i < attrs.getLength(); ++i)
            {
               String localName = attrs.getLocalName(i);
               if ("method".equals(localName))
                  lifecycle.setMethodName(attrs.getValue(i));
            }
         }
      });

      // lifecycle has a list parameters
      lifecycleType.pushInterceptor(parameterQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractLifecycleMetaData lifecycle = (AbstractLifecycleMetaData) parent;
            AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
            List parameters = lifecycle.getParameters();
            if (parameters == null)
            {
               parameters = new ArrayList();
               lifecycle.setParameters(parameters);
            }
            parameters.add(parameter);
         }
      });

      // bean has a set of properties
      beanType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
            Set properties = bean.getProperties();
            if (properties == null)
            {
               properties = new HashSet();
               bean.setProperties(properties);
            }
            properties.add(property);
         }
      });

      // beanfactory has a set of properties
      beanFactoryType.pushInterceptor(propertyQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            Set properties = bean.getProperties();
            AbstractPropertyMetaData props = null;
            for (Iterator i = properties.iterator(); i.hasNext();)
            {
               AbstractPropertyMetaData prop = (AbstractPropertyMetaData) i.next();
               if ("properties".equals(prop.getName()))
               {
                  props = prop;
                  break;
               }
            }
            AbstractMapMetaData map = null;
            if (props == null)
            {
               map = new AbstractMapMetaData();
               props = new AbstractPropertyMetaData("properties", map);
               properties.add(props);
            }
            else
            {
               map = (AbstractMapMetaData) props.getValue();
            }

            AbstractPropertyMetaData property = (AbstractPropertyMetaData) child;
            ValueMetaData valueMetaData = property.getValue();
            valueMetaData = new AbstractValueMetaData(valueMetaData);
            map.put(new AbstractValueMetaData(property.getName()), valueMetaData);
         }
      });

      // bean has a set of depends
      beanType.pushInterceptor(dependsQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractDependencyMetaData dependency = (AbstractDependencyMetaData) child;
            Set demands = bean.getDemands();
            if (demands == null)
            {
               demands = new HashSet();
               bean.setDemands(demands);
            }
            demands.add(dependency);
         }
      });

      // bean has a set of demands
      beanType.pushInterceptor(demandQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractDemandMetaData demand = (AbstractDemandMetaData) child;
            Set demands = bean.getDemands();
            if (demands == null)
            {
               demands = new HashSet();
               bean.setDemands(demands);
            }
            demands.add(demand);
         }
      });

      // bean has a set of supplies
      beanType.pushInterceptor(supplyQName, new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            AbstractBeanMetaData bean = (AbstractBeanMetaData) parent;
            AbstractSupplyMetaData supply = (AbstractSupplyMetaData) child;
            Set supplies = bean.getSupplies();
            if (supplies == null)
            {
               supplies = new HashSet();
               bean.setSupplies(supplies);
            }
            supplies.add(supply);
         }
      });

      // property binding
      TypeBinding propertyType = schemaBinding.getType(propertyTypeQName);
      configureValueBindings(propertyType);
      propertyType.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new AbstractPropertyMetaData();
         }

         public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
         {
            AbstractPropertyMetaData property = (AbstractPropertyMetaData) o;
            for (int i = 0; i < attrs.getLength(); ++i)
            {
               String localName = attrs.getLocalName(i);
               if ("name".equals(localName))
                  property.setName(attrs.getValue(i));
               else if ("class".equals(localName))
               {
                  StringValueMetaData svmd = new StringValueMetaData();
                  svmd.setType(attrs.getValue(i));
                  property.setValue(svmd);
               }
            }
         }
        
         public Object endElement(Object o, QName qName, ElementBinding element)
         {
            AbstractPropertyMetaData x = (AbstractPropertyMetaData) o;
            String name = x.getName();
            if (name == null || name.trim().length() == 0)
               throw new IllegalArgumentException("Null or empty property name.");
            return o;
         }
      });

      // property can take a value
      propertyType.setSimpleType(new CharactersHandler()
      {
         public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, org.jboss.xb.binding.metadata.ValueMetaData valueMetaData, String value)
         {
            return new StringValueMetaData(value);
         }

         public void setValue(QName qName, ElementBinding element, Object owner, Object value)
         {
            AbstractPropertyMetaData property = (AbstractPropertyMetaData) owner;
            StringValueMetaData svmd = (StringValueMetaData) value;
            ValueMetaData vmd = property.getValue();
            if (vmd != null && vmd instanceof StringValueMetaData)
            {
               StringValueMetaData previous = (StringValueMetaData) vmd;
               String type = previous.getType();
               if (type != null)
                  svmd.setType(type);
            }
            property.setValue(svmd);
         }
      });

      // dependency binding
      TypeBinding dependsType = schemaBinding.getType(dependsTypeQName);
View Full Code Here


            ValueMetaData value = (ValueMetaData) child;
            valueMetaData.setValue(value);
         }
         else if (parent instanceof AbstractPropertyMetaData)
         {
            AbstractPropertyMetaData valueMetaData = (AbstractPropertyMetaData) parent;
            ValueMetaData value = (ValueMetaData) child;
            valueMetaData.setValue(value);
         }
         else
         {
            AbstractValueMetaData valueMetaData = (AbstractValueMetaData) parent;
            ValueMetaData value = (ValueMetaData) child;
            valueMetaData.setValue(value);
         }
      }
View Full Code Here

      assertEquals("GenericBeanFactory", genericBeanFactory.getName());
      assertEquals(GenericBeanFactory.class.getName(), genericBeanFactory.getBean());
      assertNotNull(genericBeanFactory.getProperties());
      assertEquals(3, genericBeanFactory.getProperties().size());

      AbstractPropertyMetaData beanProp = null;
      AbstractPropertyMetaData ctorProp = null;
      AbstractPropertyMetaData propsProp = null;

      for(Iterator i = genericBeanFactory.getProperties().iterator(); i.hasNext();)
      {
         AbstractPropertyMetaData prop = (AbstractPropertyMetaData)i.next();
         if("bean".equals(prop.getName()))
         {
            beanProp = prop;
         }
         else if("constructor".equals(prop.getName()))
         {
            ctorProp = prop;
         }
         else if("properties".equals(prop.getName()))
         {
            propsProp = prop;
         }
         else
         {
            fail("Unexpected property: " + prop.getName());
         }
      }

      assertEquals("bean", beanProp.getName());
      assertEquals("org.jboss.test.xml.pojoserver.SimpleBeanImpl", beanProp.getValue().getUnderlyingValue());
View Full Code Here

      AbstractBeanMetaData bean = (AbstractBeanMetaData)deployment.getBeans().get(0);
      assertEquals("SimpleBean1", bean.getName());
      assertEquals("org.jboss.test.kernel.xml.support.SimpleBeanImpl", bean.getBean());
      assertNotNull(bean.getProperties());
      assertEquals(1, bean.getProperties().size());
      AbstractPropertyMetaData prop = (AbstractPropertyMetaData)bean.getProperties().iterator().next();
      assertNotNull(prop);
      assertEquals("other", prop.getName());
      assertTrue(prop.getValue() instanceof AbstractDependencyValueMetaData);
      AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData)prop.getValue();
      assertEquals("SimpleBean2", dependency.getValue());

      bean = (AbstractBeanMetaData)deployment.getBeans().get(1);
      assertEquals("SimpleBean2", bean.getName());
      assertEquals("org.jboss.test.kernel.xml.support.SimpleBeanImpl", bean.getBean());
View Full Code Here

      AbstractBeanMetaData bean = (AbstractBeanMetaData)deployment.getBeans().get(0);
      assertEquals("SimpleBean1", bean.getName());
      assertEquals("org.jboss.test.xml.pojoserver.SimpleBeanImpl", bean.getBean());
      assertNotNull(bean.getProperties());
      assertEquals(1, bean.getProperties().size());
      AbstractPropertyMetaData prop = (AbstractPropertyMetaData)bean.getProperties().iterator().next();
      assertNotNull(prop);
      assertEquals("other", prop.getName());
      assertTrue(prop.getValue() instanceof AbstractDependencyValueMetaData);
      AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData)prop.getValue();
      assertEquals("SimpleBean2", dependency.getValue());

      bean = (AbstractBeanMetaData)deployment.getBeans().get(1);
      assertEquals("SimpleBean2", bean.getName());
      assertEquals("org.jboss.test.kernel.xml.support.SimpleBeanImpl", bean.getBean());
View Full Code Here

      assertNotNull(bean.getProperties());
      assertEquals(18, bean.getProperties().size());

      for(Iterator i = bean.getProperties().iterator(); i.hasNext();)
      {
         AbstractPropertyMetaData prop = (AbstractPropertyMetaData)i.next();
         String name = prop.getName();
         Object value = prop.getValue().getUnderlyingValue();
         assertConfigureProperty(name, value);
      }
   }
View Full Code Here

      assertNotNull(bean.getProperties());
      assertEquals(19, bean.getProperties().size());

      for(Iterator i = bean.getProperties().iterator(); i.hasNext();)
      {
         AbstractPropertyMetaData prop = (AbstractPropertyMetaData)i.next();
         String name = prop.getName();
         if("other".equals(name))
         {
            /** TODO AbstractBeanMetaData nested = (AbstractBeanMetaData)prop.getValue("NestedSimpleBean1");
            assertEquals("org.jboss.test.xml.pojoserver.SimpleBeanImpl", bean.getBean());
            assertNotNull(nested);
            assertNotNull(bean.getProperties());
            assertEquals(19, bean.getProperties().size());
            for(Iterator j = nested.getProperties().iterator(); j.hasNext();)
            {
               AbstractPropertyMetaData nestedProp = (AbstractPropertyMetaData)j.next();
               String nestedName = nestedProp.getName();
               if("other".equals(nestedName))
               {
                  assertNull(nestedProp.getValue());
               }
               else
               {
                  Object value = nestedProp.getValue().getUnderlyingValue();
                  assertConfigureProperty(nestedName, value);
               }
            } */
         }
         else
         {
            Object value = prop.getValue().getUnderlyingValue();
            assertConfigureProperty(name, value);
         }
      }
   }
View Full Code Here

      assertNotNull(bean.getProperties());
      assertEquals(4, bean.getProperties().size());

      for(Iterator i = bean.getProperties().iterator(); i.hasNext();)
      {
         AbstractPropertyMetaData prop = (AbstractPropertyMetaData)i.next();
         String name = prop.getName();
         if("aList".equals(name))
         {
            AbstractListMetaData list = (AbstractListMetaData) prop.getValue();
            assertNotNull(list);
            assertEquals(2, list.size());
            assertEquals("value0", ((StringValueMetaData) list.get(0)).getValue());
            assertEquals("value1", ((StringValueMetaData) list.get(1)).getValue());
         }
         else if("aSet".equals(name))
         {
            AbstractSetMetaData set = (AbstractSetMetaData) prop.getValue();
            assertNotNull(set);
            assertEquals(2, set.size());
            boolean found0 = false;
            boolean found1 = false;
            for (Iterator j = set.iterator(); j.hasNext();)
            {
               StringValueMetaData value = (StringValueMetaData) j.next();
               assertNull(value.getType());
               String stringValue = (String) value.getValue();
               if ("value0".equals(stringValue))
                  found0 = true;
               else if ("value1".equals(stringValue))
                  found1 = true;
               else
                  fail("Unexpected value " + stringValue);
            }
            assertTrue(found0);
            assertTrue(found1);
         }
         else if("aMap".equals(name))
         {
            AbstractMapMetaData map = (AbstractMapMetaData) prop.getValue();
            assertNotNull(map);
            assertEquals("testMapClass", map.getType());
            assertEquals("testKeyClass", map.getKeyType());
            assertEquals("testValueClass", map.getValueType());
            assertEquals(2, map.size());
            for (Iterator j = map.entrySet().iterator(); j.hasNext();)
            {
               Map.Entry entry = (Map.Entry) j.next();
               Object key = entry.getKey();
               assertTrue(key.getClass().getName(), key instanceof StringValueMetaData);
               StringValueMetaData keyValue = (StringValueMetaData) key;
               assertNull(keyValue.getType());
               String realKey = (String) keyValue.getValue();
               if ("nullKey".equals(realKey))
               {
                  Object value = entry.getValue();
                  assertTrue(value instanceof AbstractValueMetaData);
                  AbstractValueMetaData valueValue = (AbstractValueMetaData) value;
                  assertNull(valueValue.getValue());
               }
               else if ("other".equals(realKey))
               {
                  Object value = entry.getValue();
                  assertTrue(value instanceof AbstractDependencyValueMetaData);
                  AbstractDependencyValueMetaData valueValue = (AbstractDependencyValueMetaData) value;
                  assertEquals("SimpleBean2", valueValue.getValue());
                  assertEquals(ControllerState.INSTALLED, valueValue.getDependentState());
               }
               else
                  fail("Unexpected key " + realKey);
            }
         }
         else if("props".equals(name))
         {
            AbstractMapMetaData map = (AbstractMapMetaData) prop.getValue();
            assertNotNull(map);
            assertEquals("java.util.Properties", map.getType());
            assertEquals("java.lang.String", map.getKeyType());
            assertEquals("java.lang.String", map.getValueType());
            assertEquals(2, map.size());
View Full Code Here

            AbstractParameterMetaData valueMetaData = (AbstractParameterMetaData) parent;
            valueMetaData.setValue(new AbstractValueMetaData());
         }
         else if (parent instanceof AbstractPropertyMetaData)
         {
            AbstractPropertyMetaData valueMetaData = (AbstractPropertyMetaData) parent;
            valueMetaData.setValue(new AbstractValueMetaData());
         }
         else
         {
            AbstractValueMetaData valueMetaData = (AbstractValueMetaData) parent;
            valueMetaData.setValue(new AbstractValueMetaData());
         }
      }
View Full Code Here

      AbstractBeanMetaData bean = deployment.getBeans().get(0);
      assertEquals("SimpleBean1", bean.getName());
      assertEquals("org.jboss.test.kernel.xml.support.SimpleBeanImpl", bean.getBean());
      assertNotNull(bean.getProperties());
      assertEquals(1, bean.getProperties().size());
      AbstractPropertyMetaData prop = bean.getProperties().iterator().next();
      assertNotNull(prop);
      assertEquals("other", prop.getName());
      assertTrue(prop.getValue() instanceof AbstractDependencyValueMetaData);
      AbstractDependencyValueMetaData dependency = (AbstractDependencyValueMetaData)prop.getValue();
      assertEquals("SimpleBean2", dependency.getValue());

      bean = deployment.getBeans().get(1);
      assertEquals("SimpleBean2", bean.getName());
      assertEquals("org.jboss.test.kernel.xml.support.SimpleBeanImpl", bean.getBean());
View Full Code Here

TOP

Related Classes of org.jboss.test.xml.pojoserver.metadata.AbstractPropertyMetaData

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.