Package org.jboss.xb.binding.sunday.unmarshalling

Examples of org.jboss.xb.binding.sunday.unmarshalling.ElementBinding


   {
      SchemaBinding schemaBinding = JBossXBBuilder.build(root);
      assertNotNull(schemaBinding);
     
      QName elementName = new QName(XMLConstants.NULL_NS_URI, JBossXBBuilder.generateXMLNameFromJavaName(root.getSimpleName(), true, true));
      ElementBinding elementBinding = schemaBinding.getElement(elementName);
      assertNotNull(elementBinding);
     
      ModelGroupBinding group = (ModelGroupBinding) elementBinding.getType().getParticle().getTerm();
      assertRepeatableElementBinding(group);
   }
View Full Code Here


      QName qName = SimpleTypeBindings.typeQName(expected.getClass());
      assertNotNull(qName);
      TypeBinding expectedTypeBinding = schemaBinding.getType(qName);
     
      QName elementName = new QName(XMLConstants.NULL_NS_URI, JBossXBBuilder.generateXMLNameFromJavaName(root.getSimpleName(), true, true));
      ElementBinding elementBinding = schemaBinding.getElement(elementName);
      assertNotNull(elementBinding);
      TypeBinding typeBinding = elementBinding.getType();
      assertNotNull(typeBinding);
      QName attributeName = new QName(XMLConstants.NULL_NS_URI, "attribute");
      AttributeBinding attribute = typeBinding.getAttribute(attributeName);
      assertNotNull(attribute);
      TypeBinding attributeType = attribute.getType();
View Full Code Here

      QName qName = new QName("testNamespace", "nondefaults");
      TypeBinding type = schemaBinding.getType(qName);
      assertNull(type);
     
      QName elementName = new QName(XMLConstants.NULL_NS_URI, "root");
      ElementBinding elementBinding = schemaBinding.getElement(elementName);
      assertNotNull(elementBinding);
      TypeBinding typeBinding = elementBinding.getType();
     
      ValueAdapter valueAdapter = typeBinding.getValueAdapter();
      assertNotNull(valueAdapter);
      assertTrue(valueAdapter instanceof EnumValueAdapter);
      EnumValueAdapter enumValueAdapter = (EnumValueAdapter) valueAdapter;
View Full Code Here

   {
      SchemaBinding schemaBinding = JBossXBBuilder.build(ListObjectWildcard.class);
      assertNotNull(schemaBinding);
     
      QName qName = new QName(XMLConstants.NULL_NS_URI, "list-object-wildcard");
      ElementBinding element = schemaBinding.getElement(qName);
      assertNotNull(element);
      TypeBinding type = element.getType();
      assertNotNull(type);
      ParticleBinding particle = type.getParticle();
      assertNotNull(particle);
      TermBinding term = particle.getTerm();
      assertNotNull(term);
View Full Code Here

   {
      SchemaBinding schemaBinding = JBossXBBuilder.build(ElementPropertiesAndWildcard.class);
      assertNotNull(schemaBinding);
     
      QName qName = new QName(XMLConstants.NULL_NS_URI, "element-properties-and-wildcard");
      ElementBinding element = schemaBinding.getElement(qName);
      assertNotNull(element);
      TypeBinding type = element.getType();
      assertNotNull(type);
      ParticleBinding particle = type.getParticle();
      assertNotNull(particle);
      TermBinding term = particle.getTerm();
      assertNotNull(term);
      assertTrue(term instanceof SequenceBinding || term instanceof UnorderedSequenceBinding);
     
     
      Collection<ParticleBinding> particles = ((ModelGroupBinding)term).getParticles();
      assertEquals(3, particles.size());
     
      Iterator<ParticleBinding> i = particles.iterator();
     
      ParticleBinding e1p = null;
      ParticleBinding e2p = null;
      ParticleBinding wp = null;
      if(term instanceof SequenceBinding)
      {
         e1p = i.next();
         e2p = i.next();
         wp = i.next();
      }
      else
      {
         while(i.hasNext())
         {
            particle = i.next();
            term = particle.getTerm();
            if(term.isElement())
            {
               if("e1".equals(((ElementBinding)term).getQName().getLocalPart()))
                  e1p = particle;
               else
                  e2p = particle;
            }
            else
               wp = particle;
         }
      }
     
      assertTrue(e1p.getTerm().isElement());
      assertEquals(0, e1p.getMinOccurs());
      assertEquals(1, e1p.getMaxOccurs());
      assertFalse(e1p.getMaxOccursUnbounded());
      element = (ElementBinding) e1p.getTerm();
      assertEquals(new QName("e1"), element.getQName());
      particles = ((ModelGroupBinding)element.getType().getParticle().getTerm()).getParticles();
      assertEquals(1, particles.size());
      particle = particles.iterator().next();
      assertWildcardTerm(element.getType(), particle, (short) 2);

      assertTrue(e2p.getTerm().isElement());
      assertEquals(0, e2p.getMinOccurs());
      assertEquals(1, e2p.getMaxOccurs());
      assertFalse(e2p.getMaxOccursUnbounded());
      element = (ElementBinding) e2p.getTerm();
      assertEquals(new QName("e2"), element.getQName());
      particles = ((ModelGroupBinding)element.getType().getParticle().getTerm()).getParticles();
      assertEquals(1, particles.size());
      particle = particles.iterator().next();
      assertWildcardTerm(element.getType(), particle, (short) 2);

      assertWildcardTerm(type, wp, (short) 3);
      WildcardBinding wildcardBinding = type.getWildcard();
      ParticleHandler particleHandler = wildcardBinding.getWildcardHandler();
      assertNotNull(particleHandler);
View Full Code Here

   }

   public void testBinding() throws Exception
   {
      SchemaBinding schema = JBossXBBuilder.build(RootWithChoiceCollectionXmlType.class);
      ElementBinding e = schema.getElement(new QName("root"));
      assertNotNull(e);
      TypeBinding type = e.getType();
      TermBinding t = type.getParticle().getTerm();
      assertNull(type.getSimpleType());
      assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
      ModelGroupBinding s = (ModelGroupBinding) t;
      Collection<ParticleBinding> particles = s.getParticles();
      assertEquals(1, particles.size());
      ParticleBinding p = particles.iterator().next();
      t = p.getTerm();
      assertTrue(t.isElement());
      assertEquals(0, p.getMinOccurs());
      assertEquals(1, p.getMaxOccurs());
      assertFalse(p.getMaxOccursUnbounded());
      e = (ElementBinding)t;
      assertEquals(new QName("choices"), e.getQName());
      type = e.getType();
      assertEquals(1, type.getAttributes().size());
      assertNotNull(type.getAttribute(new QName("a")));
      assertNotNull(type.getSimpleType());
     
      t = type.getParticle().getTerm();
View Full Code Here

   }

   public void testBinding() throws Exception
   {
      SchemaBinding schema = JBossXBBuilder.build(RootWithParticlesChoice.class);
      ElementBinding e = schema.getElement(new QName("root"));
      assertNotNull(e);
      TermBinding t = e.getType().getParticle().getTerm();
      assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
      ModelGroupBinding s = (ModelGroupBinding) t;
      assertParticleChoiceBinding(s);
   }
View Full Code Here

   }

   public void testBinding() throws Exception
   {
      SchemaBinding schema = JBossXBBuilder.build(RootWithTwoParticleGroups.class);
      ElementBinding e = schema.getElement(new QName("main-root"));
      assertNotNull(e);
      TermBinding t = e.getType().getParticle().getTerm();

      assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
      Collection<ParticleBinding> particles = ((ModelGroupBinding)t).getParticles();
      assertEquals(2, particles.size());
      Iterator<ParticleBinding> i = particles.iterator();
     
      ParticleBinding group1Particle;
      ParticleBinding group2Particle;
      if(t instanceof SequenceBinding)
      {
         group1Particle = i.next();
         group2Particle = i.next();
      }
      else
      {
         ParticleBinding p = i.next();
         if(((ElementBinding)p.getTerm()).getQName().equals(new QName("group1")))
         {
            group1Particle = p;
            group2Particle = i.next();
         }
         else
         {
            group2Particle = p;
            group1Particle = i.next();
         }
      }
     
      t = group1Particle.getTerm();
      assertTrue(t.isElement());
      assertEquals(0, group1Particle.getMinOccurs());
      assertEquals(1, group1Particle.getMaxOccurs());
      assertFalse(group1Particle.getMaxOccursUnbounded());
      e = (ElementBinding) t;
      assertEquals(new QName("group1"), e.getQName());
      assertParticleChoiceBinding((ModelGroupBinding) e.getType().getParticle().getTerm());
     
      t = group2Particle.getTerm();
      assertTrue(t.isElement());
      assertEquals(0, group2Particle.getMinOccurs());
      assertEquals(1, group2Particle.getMaxOccurs());
      assertFalse(group2Particle.getMaxOccursUnbounded());
      e = (ElementBinding) t;
      assertEquals(new QName("group2"), e.getQName());
      assertParticleChoiceBinding((ModelGroupBinding) e.getType().getParticle().getTerm());
   }
View Full Code Here

      mapType.addElement(QNAME_ENTRY3, entry3Type, 0, true);
      mapType.addElement(QNAME_ENTRY4, entry4Type, 0, true);

      // sequence as entry
      SequenceBinding entrySeq = new SequenceBinding(schema);
      ElementBinding keyElement = new ElementBinding(schema, new QName(NS, "key"), new TypeBinding());
      entrySeq.addParticle(new ParticleBinding(keyElement));
      ElementBinding valueElement = new ElementBinding(schema, new QName(NS, "value"), new TypeBinding());
      entrySeq.addParticle(new ParticleBinding(valueElement));

      ParticleBinding entryParticle = new ParticleBinding(entrySeq);
      entryParticle.setMinOccurs(0);
      entryParticle.setMaxOccursUnbounded(true);
      mapType.addParticle(entryParticle);

      mapType.addElement(QNAME_SUBMAP, mapType, 0, true);
      schema.addElement(QNAME_MAP, mapType);

      // Handler implementations
      mapType.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new HashMap();
         }
      }
      );

      ElementInterceptor addMapEntryInterceptor = new DefaultElementInterceptor()
      {
         public void add(Object parent, Object child, QName name)
         {
            Map<Object, Object> map = (Map<Object, Object>)parent;
            Object[] arr = (Object[])child;
            map.put(arr[0], arr[1]);
         }
      };
      mapType.pushInterceptor(QNAME_ENTRY1, addMapEntryInterceptor);
      mapType.pushInterceptor(QNAME_ENTRY2, addMapEntryInterceptor);
      mapType.pushInterceptor(QNAME_ENTRY3, addMapEntryInterceptor);
      mapType.pushInterceptor(QNAME_ENTRY4, addMapEntryInterceptor);
      mapType.pushInterceptor(QNAME_SUBMAP, addMapEntryInterceptor);

      entry1Type.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new Object[2];
         }
      }
      );
      entry1Type.pushInterceptor(QNAME_KEY1, new DefaultElementInterceptor()
      {
         public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
         {
            Object[] arr = (Object[])o;
            arr[0] = text;
         }
      }
      );
      entry1Type.pushInterceptor(QNAME_VALUE1, new DefaultElementInterceptor()
      {
         public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
         {
            Object[] arr = (Object[])o;
            arr[1] = text;
         }
      }
      );

      entry2Type.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new Object[2];
         }

         public void attributes(Object o,
                                QName elementName,
                                ElementBinding element,
                                Attributes attrs,
                                NamespaceContext nsCtx)
         {
            Object[] arr = (Object[])o;
            for(int i = 0; i < attrs.getLength(); ++i)
            {
               String lName = attrs.getLocalName(i);
               if("key2".equals(lName))
               {
                  arr[0] = attrs.getValue(i);
               }
            }
         }
      }
      );
      entry2Type.pushInterceptor(QNAME_VALUE2, new DefaultElementInterceptor()
      {
         public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
         {
            Object[] arr = (Object[])o;
            arr[1] = text;
         }
      }
      );

      entry3Type.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new Object[2];
         }

         public void attributes(Object o,
                                QName elementName,
                                ElementBinding element,
                                Attributes attrs,
                                NamespaceContext nsCtx)
         {
            Object[] arr = (Object[])o;
            for(int i = 0; i < attrs.getLength(); ++i)
            {
               String lName = attrs.getLocalName(i);
               if("key3".equals(lName))
               {
                  arr[0] = attrs.getValue(i);
               }
               else if("value3".equals(lName))
               {
                  arr[1] = attrs.getValue(i);
               }
            }
         }
      }
      );

      entry4Type.setHandler(new DefaultElementHandler()
      {
         public Object startElement(Object parent, QName name, ElementBinding element)
         {
            return new Object[2];
         }

         public void attributes(Object o,
                                QName elementName,
                                ElementBinding element,
                                Attributes attrs,
                                NamespaceContext nsCtx)
         {
            Object[] arr = (Object[])o;
            for(int i = 0; i < attrs.getLength(); ++i)
            {
               String lName = attrs.getLocalName(i);
               if("key4".equals(lName))
               {
                  arr[0] = attrs.getValue(i);
               }
            }
         }

      }
      );
      entry4Type.setSimpleType(new CharactersHandler()
      {
         public void setValue(QName qName, ElementBinding element, Object owner, Object value)
         {
            Object[] arr = (Object[])owner;
            arr[1] = value;
         }
      }
      );

      mapType.pushInterceptor(QNAME_SUBMAP, new DefaultElementInterceptor()
      {
         public Object startElement(Object parent, QName name, TypeBinding type)
         {
            return new Object[2];
         }

         public void attributes(Object o,
                                QName elementName,
                                TypeBinding type,
                                Attributes attrs,
                                NamespaceContext nsCtx)
         {
            Object[] arr = (Object[])o;
            for(int i = 0; i < attrs.getLength(); ++i)
            {
               String lName = attrs.getLocalName(i);
               if("key".equals(lName))
               {
                  arr[0] = attrs.getValue(i);
               }
            }
         }

         public void add(Object parent, Object child, QName qName)
         {
            Object[] arr = (Object[])parent;
            Map<?, ?> submap = (Map<?, ?>)child;
            arr[1] = submap;
         }
      }
      );

      // sequence entry
      entrySeq.setHandler(new ParticleHandler()
      {
         public Object startParticle(Object parent,
                                     QName elementName,
                                     ParticleBinding particle,
                                     Attributes attrs,
                                     NamespaceContext nsCtx)
         {
            return new Object[2];
         }

         public Object endParticle(Object o, QName elementName, ParticleBinding particle)
         {
            return o;
         }

         public void setParent(Object parent,
                               Object o,
                               QName elementName,
                               ParticleBinding particle,
                               ParticleBinding parentParticle)
         {
            Map<Object, Object> map = (Map<Object, Object>)parent;
            Object[] arr = (Object[])o;
            map.put(arr[0], arr[1]);
         }
      }
      );

      keyElement.pushInterceptor(new DefaultElementInterceptor()
      {
         public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
         {
            Object[] arr = (Object[])o;
            arr[0] = text;
         }
      });

      valueElement.pushInterceptor(new DefaultElementInterceptor()
      {
         public void characters(Object o, QName name, TypeBinding type, NamespaceContext nsCtx, String text)
         {
            Object[] arr = (Object[])o;
            arr[1] = text;
View Full Code Here

   }

   public void testSharedElementForwardsAndBackwards() throws Exception
   {
      SchemaBinding schema = bind("SharedElement.xsd");
      ElementBinding element1 = schema.getElement(new QName(NS, "element1"));
      assertNotNull(element1);
      ElementBinding element2 = schema.getElement(new QName(NS, "element2"));
      assertNotNull(element2);
      ElementBinding element3 = schema.getElement(new QName(NS, "element3"));
      assertNotNull(element3);
     
      TypeBinding type = element2.getType();
      assertNotNull(type);
      ParticleBinding particle = type.getParticle();
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.sunday.unmarshalling.ElementBinding

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.