Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSWildcard


      particleBinding.setMaxOccurs(particle.getMaxOccurs());
      particleBinding.setMaxOccursUnbounded(particle.getMaxOccursUnbounded());
      particleBinding.setMinOccurs(particle.getMinOccurs());
      group.addParticle(particleBinding);

      XSWildcard wildcard = (XSWildcard)particle.getTerm();
      if(wildcard.getName() != null)
      {
         binding.setQName(new QName(wildcard.getNamespace(), wildcard.getName()));
      }

      binding.setProcessContents(wildcard.getProcessContents());

      if (processAnnotations)
      {
         XSAnnotation annotation = wildcard.getAnnotation();
         if(annotation != null)
         {
            customizeTerm(annotation, binding, trace);
         }
      }
View Full Code Here


      return marshalled;
   }

   private boolean marshalWildcard(XSParticle particle, boolean declareNs)
   {
      XSWildcard wildcard = (XSWildcard)particle.getTerm();
      Object o = stack.peek();
      ClassMapping mapping = getClassMapping(o.getClass());
      if(mapping == null)
      {
         // todo: YAH (yet another hack)
         QName autoType = SimpleTypeBindings.typeQName(o.getClass());
         if(autoType != null)
         {
            String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o, null);
            content.characters(marshalled.toCharArray(), 0, marshalled.length());
            return true;
         }
         else
         {
            if(ignoreUnresolvedWildcard)
            {
               log.warn("Failed to marshal wildcard. Class mapping not found for " +
                  o.getClass() +
                  "@" +
                  o.hashCode() +
                  ": " + o
               );
               return true;
            }
            else
            {
               throw new IllegalStateException("Failed to marshal wildcard. Class mapping not found for " +
                  o.getClass() +
                  "@" +
                  o.hashCode() +
                  ": " + o
               );
            }
         }
      }

      GenericObjectModelProvider parentProvider = this.provider;
      Object parentRoot = this.root;
      Stack parentStack = this.stack;
      XSModel parentModel = this.model;

      this.root = o;
      this.stack = new StackImpl();
      this.model = mapping.schemaUrl == null ? this.model : Util.loadSchema(mapping.schemaUrl, schemaResolver);
      if(mapping.provider != null)
      {
         this.provider = mapping.provider;
      }

      boolean marshalled;
      if(mapping.elementName != null)
      {
         XSElementDeclaration elDec = model.getElementDeclaration(mapping.elementName.getLocalPart(),
            mapping.elementName.getNamespaceURI()
         );

         if(elDec == null)
         {
            throw new JBossXBRuntimeException("Element " + mapping.elementName + " is not declared in the schema.");
         }

         Object elementValue = provider.getRoot(root, null, elDec.getNamespace(), elDec.getName());
         marshalled = marshalElementOccurence(elDec.getNamespace(),
            elDec.getName(),
            elDec.getTypeDefinition(),
            elementValue,
            elDec.getNillable(),
            particle.getMinOccurs() == 0,
            declareNs
         );
      }
      else if(mapping.typeName != null)
      {
         XSTypeDefinition typeDef = model.getTypeDefinition(mapping.typeName.getLocalPart(),
            mapping.typeName.getNamespaceURI()
         );

         if(typeDef == null)
         {
            List typeNames = new ArrayList();
            XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
            for(int i = 0; i < types.getLength(); ++i)
            {
               XSObject type = types.item(i);
               if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
               {
                  typeNames.add(new QName(type.getNamespace(), type.getName()));
               }
            }
            throw new JBossXBRuntimeException("Type " +
               mapping.typeName +
               " is not defined in the schema." +
               " Defined types are: " + typeNames
            );
         }

         Object elementValue = provider.getRoot(root, null, wildcard.getNamespace(), wildcard.getName());
         marshalled =
            marshalElementOccurence(wildcard.getNamespace(),
               wildcard.getName(),
               typeDef,
               elementValue,
               true,
               particle.getMinOccurs() == 0,
               declareNs
View Full Code Here

/* 1077 */     particleBinding.setMaxOccurs(particle.getMaxOccurs());
/* 1078 */     particleBinding.setMaxOccursUnbounded(particle.getMaxOccursUnbounded());
/* 1079 */     particleBinding.setMinOccurs(particle.getMinOccurs());
/* 1080 */     group.addParticle(particleBinding);
/*      */
/* 1082 */     XSWildcard wildcard = (XSWildcard)particle.getTerm();
/* 1083 */     if (wildcard.getName() != null)
/*      */     {
/* 1085 */       binding.setQName(new QName(wildcard.getNamespace(), wildcard.getName()));
/*      */     }
/*      */
/* 1088 */     binding.setProcessContents(wildcard.getProcessContents());
/*      */
/* 1090 */     if (this.processAnnotations)
/*      */     {
/* 1092 */       XSAnnotation annotation = wildcard.getAnnotation();
/* 1093 */       if (annotation != null)
/*      */       {
/* 1095 */         customizeTerm(annotation, binding, this.trace);
/*      */       }
/*      */     }
View Full Code Here

/*  910 */     return marshalled;
/*      */   }
/*      */
/*      */   private boolean marshalWildcard(XSParticle particle, boolean declareNs)
/*      */   {
/*  915 */     XSWildcard wildcard = (XSWildcard)particle.getTerm();
/*  916 */     Object o = this.stack.peek();
/*  917 */     AbstractMarshaller.ClassMapping mapping = getClassMapping(o.getClass());
/*  918 */     if (mapping == null)
/*      */     {
/*  921 */       QName autoType = SimpleTypeBindings.typeQName(o.getClass());
/*  922 */       if (autoType != null)
/*      */       {
/*  924 */         String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o, null);
/*  925 */         this.content.characters(marshalled.toCharArray(), 0, marshalled.length());
/*  926 */         return true;
/*      */       }
/*      */
/*  930 */       if (this.ignoreUnresolvedWildcard)
/*      */       {
/*  932 */         this.log.warn("Failed to marshal wildcard. Class mapping not found for " + o.getClass() + "@" + o.hashCode() + ": " + o);
/*      */
/*  938 */         return true;
/*      */       }
/*      */
/*  942 */       throw new IllegalStateException("Failed to marshal wildcard. Class mapping not found for " + o.getClass() + "@" + o.hashCode() + ": " + o);
/*      */     }
/*      */
/*  952 */     GenericObjectModelProvider parentProvider = this.provider;
/*  953 */     Object parentRoot = this.root;
/*  954 */     AbstractMarshaller.Stack parentStack = this.stack;
/*  955 */     XSModel parentModel = this.model;
/*      */
/*  957 */     this.root = o;
/*  958 */     this.stack = new AbstractMarshaller.StackImpl();
/*  959 */     this.model = (mapping.schemaUrl == null ? this.model : Util.loadSchema(mapping.schemaUrl, this.schemaResolver));
/*  960 */     if (mapping.provider != null)
/*      */     {
/*  962 */       this.provider = mapping.provider;
/*      */     }
/*      */     boolean marshalled;
/*  966 */     if (mapping.elementName != null)
/*      */     {
/*  968 */       XSElementDeclaration elDec = this.model.getElementDeclaration(mapping.elementName.getLocalPart(), mapping.elementName.getNamespaceURI());
/*      */
/*  972 */       if (elDec == null)
/*      */       {
/*  974 */         throw new JBossXBRuntimeException("Element " + mapping.elementName + " is not declared in the schema.");
/*      */       }
/*      */
/*  977 */       Object elementValue = this.provider.getRoot(this.root, null, elDec.getNamespace(), elDec.getName());
/*  978 */       marshalled = marshalElementOccurence(elDec.getNamespace(), elDec.getName(), elDec.getTypeDefinition(), elementValue, elDec.getNillable(), particle.getMinOccurs() == 0, declareNs);
/*      */     }
/*      */     else
/*      */     {
/*      */       boolean marshalled;
/*  987 */       if (mapping.typeName != null)
/*      */       {
/*  989 */         XSTypeDefinition typeDef = this.model.getTypeDefinition(mapping.typeName.getLocalPart(), mapping.typeName.getNamespaceURI());
/*      */
/*  993 */         if (typeDef == null)
/*      */         {
/*  995 */           List typeNames = new ArrayList();
/*  996 */           XSNamedMap types = this.model.getComponents(3);
/*  997 */           for (int i = 0; i < types.getLength(); i++)
/*      */           {
/*  999 */             XSObject type = types.item(i);
/* 1000 */             if ("http://www.w3.org/2001/XMLSchema".equals(type.getNamespace()))
/*      */               continue;
/* 1002 */             typeNames.add(new QName(type.getNamespace(), type.getName()));
/*      */           }
/*      */
/* 1005 */           throw new JBossXBRuntimeException("Type " + mapping.typeName + " is not defined in the schema." + " Defined types are: " + typeNames);
/*      */         }
/*      */
/* 1012 */         Object elementValue = this.provider.getRoot(this.root, null, wildcard.getNamespace(), wildcard.getName());
/* 1013 */         marshalled = marshalElementOccurence(wildcard.getNamespace(), wildcard.getName(), typeDef, elementValue, true, particle.getMinOccurs() == 0, declareNs);
/*      */       }
/*      */       else
/*      */       {
/* 1025 */         throw new JBossXBRuntimeException("Class mapping for " + mapping.cls + " is associated with neither global element name nor global type name.");
/*      */       }
View Full Code Here

      return marshalled;
   }

   private boolean marshalWildcard(XSParticle particle, boolean declareNs)
   {
      XSWildcard wildcard = (XSWildcard)particle.getTerm();
      Object o = stack.peek();
      ClassMapping mapping = getClassMapping(o.getClass());
      if(mapping == null)
      {
         // todo: YAH (yet another hack)
         QName autoType = SimpleTypeBindings.typeQName(o.getClass());
         if(autoType != null)
         {
            String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o, null);
            content.characters(marshalled.toCharArray(), 0, marshalled.length());
            return true;
         }
         else
         {
            if(ignoreUnresolvedWildcard)
            {
               log.warn("Failed to marshal wildcard. Class mapping not found for " +
                  o.getClass() +
                  "@" +
                  o.hashCode() +
                  ": " + o
               );
               return true;
            }
            else
            {
               throw new IllegalStateException("Failed to marshal wildcard. Class mapping not found for " +
                  o.getClass() +
                  "@" +
                  o.hashCode() +
                  ": " + o
               );
            }
         }
      }

      GenericObjectModelProvider parentProvider = this.provider;
      Object parentRoot = this.root;
      Stack parentStack = this.stack;
      XSModel parentModel = this.model;

      this.root = o;
      this.stack = new StackImpl();
      this.model = mapping.schemaUrl == null ? this.model : Util.loadSchema(mapping.schemaUrl, schemaResolver);
      if(mapping.provider != null)
      {
         this.provider = mapping.provider;
      }

      boolean marshalled;
      if(mapping.elementName != null)
      {
         XSElementDeclaration elDec = model.getElementDeclaration(mapping.elementName.getLocalPart(),
            mapping.elementName.getNamespaceURI()
         );

         if(elDec == null)
         {
            throw new JBossXBRuntimeException("Element " + mapping.elementName + " is not declared in the schema.");
         }

         Object elementValue = provider.getRoot(root, null, elDec.getNamespace(), elDec.getName());
         marshalled = marshalElementOccurence(elDec.getNamespace(),
            elDec.getName(),
            elDec.getTypeDefinition(),
            elementValue,
            elDec.getNillable(),
            particle.getMinOccurs() == 0,
            declareNs
         );
      }
      else if(mapping.typeName != null)
      {
         XSTypeDefinition typeDef = model.getTypeDefinition(mapping.typeName.getLocalPart(),
            mapping.typeName.getNamespaceURI()
         );

         if(typeDef == null)
         {
            List<QName> typeNames = new ArrayList<QName>();
            XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
            for(int i = 0; i < types.getLength(); ++i)
            {
               XSObject type = types.item(i);
               if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
               {
                  typeNames.add(new QName(type.getNamespace(), type.getName()));
               }
            }
            throw new JBossXBRuntimeException("Type " +
               mapping.typeName +
               " is not defined in the schema." +
               " Defined types are: " + typeNames
            );
         }

         Object elementValue = provider.getRoot(root, null, wildcard.getNamespace(), wildcard.getName());
         marshalled =
            marshalElementOccurence(wildcard.getNamespace(),
               wildcard.getName(),
               typeDef,
               elementValue,
               true,
               particle.getMinOccurs() == 0,
               declareNs
View Full Code Here

      {
         log.trace("added wildcard to " + group);
         log.trace("added wildcard to type " + type.getQName());
      }

      XSWildcard wildcard = (XSWildcard)particle.getTerm();
      if(wildcard.getName() != null)
      {
         binding.setQName(new QName(wildcard.getNamespace(), wildcard.getName()));
      }

      binding.setProcessContents(wildcard.getProcessContents());

      if (ctx.processAnnotations)
      {
         XSAnnotation annotation = wildcard.getAnnotation();
         if(annotation != null)
         {
            customizeTerm(annotation, binding, ctx.trace);
         }
      }
View Full Code Here

TOP

Related Classes of org.apache.xerces.xs.XSWildcard

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.