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

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


        return schema;
    }

    protected void initComponent(SchemaBinding schema)
    {
        TypeBinding componentType = schema.getType(componentTypeQName);
        // handler
        componentType.setHandler(ComponentHandler.HANDLER);
        // bean has a classloader
        componentType.pushInterceptor(BeanSchemaBinding20.classloaderQName, BeanClassLoaderInterceptor.INTERCEPTOR);
        // bean has a constructor
        componentType.pushInterceptor(BeanSchemaBinding20.constructorQName, BeanConstructorInterceptor.INTERCEPTOR);
        // bean has properties
        componentType.pushInterceptor(BeanSchemaBinding20.propertyQName, BeanPropertyInterceptor.INTERCEPTOR);
        // bean has a create
        componentType.pushInterceptor(BeanSchemaBinding20.createQName, BeanCreateInterceptor.INTERCEPTOR);
        // bean has a start
        componentType.pushInterceptor(BeanSchemaBinding20.startQName, BeanStartInterceptor.INTERCEPTOR);
        // bean has a stop
        componentType.pushInterceptor(BeanSchemaBinding20.stopQName, BeanStopInterceptor.INTERCEPTOR);
        // bean has a destroy
        componentType.pushInterceptor(BeanSchemaBinding20.destroyQName, BeanDestroyInterceptor.INTERCEPTOR);
        // bean has annotations
        componentType.pushInterceptor(BeanSchemaBinding20.annotationQName, BeanAnnotationInterceptor.INTERCEPTOR);
        // bean has installs
        componentType.pushInterceptor(BeanSchemaBinding20.installQName, BeanInstallInterceptor.INTERCEPTOR);
        // bean has uninstalls
        componentType.pushInterceptor(BeanSchemaBinding20.uninstallQName, BeanUninstallInterceptor.INTERCEPTOR);
        // bean has depends
        componentType.pushInterceptor(BeanSchemaBinding20.dependsQName, BeanDependsInterceptor.INTERCEPTOR);
        // bean has demands
        componentType.pushInterceptor(BeanSchemaBinding20.demandQName, BeanDemandsInterceptor.INTERCEPTOR);
        // bean has supplies
        componentType.pushInterceptor(BeanSchemaBinding20.supplyQName, BeanSuppliesInterceptor.INTERCEPTOR);
    }
View Full Code Here


        componentType.pushInterceptor(BeanSchemaBinding20.supplyQName, BeanSuppliesInterceptor.INTERCEPTOR);
    }

    protected void initLookup(SchemaBinding schema)
    {
        TypeBinding lookuptype = schema.getType(lookupTypeQName);
        // handler
        lookuptype.setHandler(LookupHandler.HANDLER);
    }
View Full Code Here

      if(SCHEMA == null)
      {
         SCHEMA = XsdBinder.bind(new StringReader(XSD), null);
         SCHEMA.setIgnoreUnresolvedFieldOrClass(false);
        
         TypeBinding stringType = SCHEMA.getType(Constants.QNAME_STRING);

         // stringType
         stringType.setBeforeMarshallingCallback(new TermBeforeMarshallingCallback()
         {
            public Object beforeMarshalling(Object o, MarshallingContext ctx)
            {
               if(o != null)
               {
                  ParticleBinding particle = ctx.getParticleBinding();
                  assertNotNull(particle);
                  TermBinding term = particle.getTerm();
                  assertTrue(term.isElement());
                  ElementBinding element = (ElementBinding) term;
                  String localPart = element.getQName().getLocalPart();
                  assertTrue("stringType".endsWith(localPart) || "item".equals(localPart));
                  TypeBinding type = element.getType();
                  assertEquals(Constants.QNAME_STRING, type.getQName());
                 
                  o = ((GlobalElement.StringType)o).data;
               }
               return o;
            }
         });        
         stringType.setBeforeSetParentCallback(new TermBeforeSetParentCallback()
         {
            public Object beforeSetParent(Object o, UnmarshallingContext ctx)
            {
               ParticleBinding particle = ctx.getParticle();
               assertNotNull(particle);
               assertTrue(particle.getTerm().isElement());
               ElementBinding element = (ElementBinding) particle.getTerm();
              
               String eName = element.getQName().getLocalPart();
               if(eName.equals("stringType"))
               {
                  assertTrue(ctx.getParentValue() instanceof GlobalElement);
                  TermBinding parentTerm = ctx.getParentParticle().getTerm();
                  assertTrue(parentTerm.isElement());
                  assertEquals("global", ((ElementBinding)parentTerm).getQName().getLocalPart());

                  assertEquals("stringType", ctx.resolvePropertyName());
                  assertEquals(StringType.class, ctx.resolvePropertyType());
               }
               else if(eName.equals("item"))
               {
                  assertTrue(ctx.getParentValue() instanceof GlobalElement.Sequence);
                  TermBinding parentTerm = ctx.getParentParticle().getTerm();
                  assertTrue(parentTerm instanceof SequenceBinding);
                 
                  assertEquals("item", ctx.resolvePropertyName());
                  assertEquals(StringType.class, ctx.resolvePropertyType());
               }
               else
               {
                  fail("Expected stringType or item but got " + eName);
               }
               return o == null ? null : new GlobalElement.StringType((String)o);
            }
         });
        
         // have to override string type's handlers
         ElementBinding global = SCHEMA.getElement(new QName("http://jboss.org/ns/test", "global"));
         SequenceBinding sequence = (SequenceBinding) global.getType().getParticle().getTerm();
         Iterator iter = sequence.getParticles().iterator();
         iter.next(); // stringType element
         ElementBinding stringElement = (ElementBinding) ((ParticleBinding)iter.next()).getTerm();
         stringElement.setBeforeMarshallingCallback(new TermBeforeMarshallingCallback()
         {
            public Object beforeMarshalling(Object o, MarshallingContext ctx)
            {
               ParticleBinding particle = ctx.getParticleBinding();
               assertNotNull(particle);
               assertTrue(particle.getTerm().isElement());
               ElementBinding element = (ElementBinding) particle.getTerm();
               assertEquals(new QName("http://jboss.org/ns/test", "stringElement"), element.getQName());
              
               TypeBinding type = element.getType();
               assertEquals(Constants.QNAME_STRING, type.getQName());
              
               return o == null ? null : (String)o;
            }
         });        
         stringElement.setBeforeSetParentCallback(new TermBeforeSetParentCallback()
View Full Code Here

   public void testManual() throws Exception
   {
      SchemaBinding schema = new SchemaBinding();

      // Type declarations
      TypeBinding mapType = new TypeBinding();
      // default model group is all, we want sequence
      mapType.setParticle(new ParticleBinding(new SequenceBinding(schema)));

      TypeBinding entry1Type = new TypeBinding();
      TypeBinding entry2Type = new TypeBinding();
      TypeBinding entry3Type = new TypeBinding();
      TypeBinding entry4Type = new TypeBinding();

      // Schema assembling
      mapType.addElement(QNAME_ENTRY1, entry1Type, 0, true);
      mapType.addElement(QNAME_ENTRY2, entry2Type, 0, true);
      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 map = (Map)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;
View Full Code Here

      String javaType = exceptionMapping.getExceptionType();
      log.trace("processExceptionMapping: [xmlType=" + xmlType + ",javaType=" + javaType + "]");
     
      if (schemaBinding.getType(xmlType) == null)
      {
         TypeBinding typeBinding = new TypeBinding(xmlType);
         ClassMetaData cmd = new ClassMetaData();
         cmd.setUseNoArgCtor(Boolean.FALSE);
         cmd.setImpl(javaType);
         typeBinding.setClassMetaData(cmd);
         typeBinding.setSimple(false);
         schemaBinding.addType(typeBinding);
      }
   }
View Full Code Here

   {
      QName xmlType = getXmlType(typeMapping);
      String javaType = typeMapping.getJavaType();
      log.trace("processNonArrayType: [xmlType=" + xmlType + ",javaType=" + javaType + "]");

      TypeBinding typeBinding = getTypeBinding(schemaBinding, typeMapping);
      if (typeBinding != null)
      {
         // Set the java type, but skip SimpleTypes
         boolean isSimpleTypeBinding = (typeBinding instanceof SimpleTypeBinding);
         if(isSimpleTypeBinding == false)
         {
         ClassMetaData classMetaData = typeBinding.getClassMetaData();
         if (classMetaData == null)
         {
            classMetaData = new ClassMetaData();
            typeBinding.setClassMetaData(classMetaData);
         }
         classMetaData.setImpl(javaType);

         // exception mapping drives whether we should use the noarg ctor
         JavaWsdlMapping wsdlMapping = typeMapping.getJavaWsdlMapping();
         for (ExceptionMapping aux : wsdlMapping.getExceptionMappings())
         {
            if (javaType.equals(aux.getExceptionType()))
            {
               classMetaData.setUseNoArgCtor(false);
               break;
            }
         }

         if (log.isTraceEnabled())
         {
            QName typeQName = typeBinding.getQName();
            log.trace("Bound: [xmlType=" + typeQName + ",javaType=" + javaType + "]");
            }
         }

         VariableMapping[] variableMappings = typeMapping.getVariableMappings();
View Full Code Here

         return getAnonymousTypeBinding(schemaBinding, anonymousTypeQName);
      }

      QName xmlType = typeMapping.getRootTypeQName();

      TypeBinding typeBinding = null;
      if ("complexType".equals(qnameScope) || "simpleType".equals(qnameScope))
      {
         typeBinding = schemaBinding.getType(xmlType);
         if (typeBinding == null)
         {
View Full Code Here

      return element.getType();
   }

   public void bindParameterToElement(SchemaBinding schemaBinding, QName xmlName, QName xmlType)
   {
      TypeBinding typeBinding;
      boolean isAnonymousType = xmlType.getLocalPart().startsWith(">");
      if (isAnonymousType)
      {
         typeBinding = getAnonymousTypeBinding(schemaBinding, xmlType);
      }
View Full Code Here

   private ElementBinding findLocalPathElementInTypes(Iterator types, String[] path)
   {
      while (types.hasNext())
      {
         TypeBinding type = (TypeBinding)types.next();
         if (type.getQName().getLocalPart().equals(path[0]))
         {
            ParticleBinding particle = type.getParticle();
            if (particle == null)
               continue;

            TermBinding term = particle.getTerm();
            if (!term.isModelGroup())
View Full Code Here

   public static void register(SchemaBinding schemaBinding)
   {
      JBossXBContentAdapter contentAdapter = new JBossXBContentAdapter();

      // base64 simple types
      TypeBinding base64Type = schemaBinding.getType(org.jboss.xb.binding.Constants.QNAME_BASE64BINARY);
      base64Type.setBeforeMarshallingCallback( contentAdapter );
      base64Type.setBeforeSetParentCallback( contentAdapter );

      // xmime complex types
      TypeBinding xmimeBase64Type = schemaBinding.getType(XMIME_BASE_64);
      if(xmimeBase64Type!=null)
      {
         xmimeBase64Type.setBeforeMarshallingCallback( contentAdapter );
         xmimeBase64Type.setBeforeSetParentCallback( contentAdapter );

         // xop:Include
         /*ModelGroupBinding modelGroup = (ModelGroupBinding)xmimeBase64Type.getParticle().getTerm();
         ParticleBinding particle = (ParticleBinding)modelGroup.getParticles().iterator().next();
         ElementBinding xopInclude = (ElementBinding)particle.getTerm();
View Full Code Here

TOP

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

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.