Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSAttributeDeclaration


   private void addAttributeMappings(XSObjectList attributes, JavaXmlTypeMapping jxtm)
   {
      for (int i = 0; i < attributes.getLength(); i++)
      {
         XSAttributeUse obj = (XSAttributeUse)attributes.item(i);
         XSAttributeDeclaration att = obj.getAttrDeclaration();
         XSSimpleTypeDefinition simple = att.getTypeDefinition();
         addJavaXMLTypeMap(simple, "none", "", "", jxtm.getJavaWsdlMapping(), true);
         VariableMapping vm = new VariableMapping(jxtm);
         String name = att.getName();
         vm.setXmlAttributeName(name);
         // JBWS-1170 Convert characters which are illegal in Java identifiers
         vm.setJavaVariableName(ToolsUtils.convertInvalidCharacters(Introspector.decapitalize(name)));
         jxtm.addVariableMapping(vm);
      }
View Full Code Here


      {
         int len = xsobjlist.getLength();
         for (int i = 0; i < len; i++)
         {
            XSAttributeUse obj = (XSAttributeUse)xsobjlist.item(i);
            XSAttributeDeclaration att = obj.getAttrDeclaration();
            XSSimpleTypeDefinition xstype = att.getTypeDefinition();
            QName qn = SchemaUtils.handleSimpleType(xstype);
            boolean primitive = obj.getRequired();
            VAR v = createVAR(qn, att.getName(), getPackageName(xstype.getNamespace()), primitive);
            if (vars == null)
               vars = new ArrayList();
            vars.add(v);
         }
      }
View Full Code Here

/*     */       }
/* 524 */       XSObjectList list = jxstype.getAttributeUses();
/* 525 */       for (int i = 0; i < list.getLength(); i++)
/*     */       {
/* 527 */         XSAttributeUse use = (XSAttributeUse)list.item(i);
/* 528 */         XSAttributeDeclaration decl = use.getAttrDeclaration();
/* 529 */         buf.append(write(decl));
/*     */       }
/*     */
/* 532 */       if (baseType != null)
/*     */       {
View Full Code Here

/*     */
/* 720 */     xsmp = xsmodel.getComponents(1);
/* 721 */     len = xsmp != null ? xsmp.getLength() : 0;
/* 722 */     for (int i = 0; i < len; i++)
/*     */     {
/* 724 */       XSAttributeDeclaration xsattr = (XSAttributeDeclaration)xsmp.item(i);
/* 725 */       jb.addXSAttributeDeclaration(xsattr);
/*     */     }
/*     */
/* 730 */     XSObjectList xo = xsmodel.getAnnotations();
/* 731 */     len = xo != null ? xo.getLength() : 0;
View Full Code Here

/*     */   {
/* 385 */     JBossXSNamedMap nmap = (JBossXSNamedMap)nsi.getComponents(1);
/* 386 */     int len = nmap.getLength();
/* 387 */     for (int i = 0; i < len; i++)
/*     */     {
/* 389 */       XSAttributeDeclaration xatt = (XSAttributeDeclaration)nmap.item(i);
/* 390 */       addXSAttributeDeclaration(xatt);
/*     */     }
/*     */
/* 394 */     nmap = (JBossXSNamedMap)nsi.getComponents(3);
/* 395 */     len = nmap.getLength();
View Full Code Here

/*  882 */     return binding;
/*      */   }
/*      */
/*      */   private AttributeBinding bindAttribute(XSAttributeUse attrUse)
/*      */   {
/*  887 */     XSAttributeDeclaration attr = attrUse.getAttrDeclaration();
/*  888 */     QName attrName = new QName(attr.getNamespace(), attr.getName());
/*      */
/*  890 */     XSSimpleTypeDefinition attrType = attr.getTypeDefinition();
/*  891 */     TypeBinding typeBinding = bindSimpleType(attrType);
/*      */
/*  893 */     if (this.trace)
/*      */     {
/*  895 */       log.trace("binding attribute " + attrName + ", required=" + attrUse.getRequired());
/*      */     }
/*      */
/*  898 */     AttributeBinding binding = new AttributeBinding(this.schema, attrName, typeBinding, DefaultHandlers.ATTRIBUTE_HANDLER);
/*  899 */     binding.setRequired(attrUse.getRequired());
/*  900 */     if (attrUse.getConstraintType() == 1)
/*      */     {
/*  903 */       binding.setDefaultConstraint(attrUse.getConstraintValue());
/*      */     }
/*      */
/*  906 */     if (this.processAnnotations)
/*      */     {
/*  908 */       XSAnnotation an = attr.getAnnotation();
/*  909 */       if (an != null)
/*      */       {
/*  911 */         if (this.trace)
/*      */         {
/*  913 */           log.trace(attrName + " attribute annotation");
View Full Code Here

/*      */     }
/*      */
/*  529 */     for (int i = 0; i < attributeUses.getLength(); i++)
/*      */     {
/*  531 */       this.currentAttribute = ((XSAttributeUse)attributeUses.item(i));
/*  532 */       XSAttributeDeclaration attrDec = this.currentAttribute.getAttrDeclaration();
/*  533 */       String attrNs = attrDec.getNamespace();
/*  534 */       String attrLocal = attrDec.getName();
/*  535 */       Object attrValue = this.provider.getAttributeValue(o, this.ctx, attrNs, attrLocal);
/*      */
/*  537 */       if (attrValue == null)
/*      */         continue;
/*  539 */       if (attrs == null)
/*      */       {
/*  541 */         attrs = new AttributesImpl(5);
/*      */       }
/*      */
/*  544 */       String attrPrefix = null;
/*  545 */       if (attrNs != null)
/*      */       {
/*  547 */         attrPrefix = getPrefix(attrNs);
/*  548 */         if ((attrPrefix == null) && (attrNs != null) && (attrNs.length() > 0))
/*      */         {
/*  550 */           attrPrefix = "ns_" + attrLocal;
/*  551 */           attrs.add(null, attrPrefix, "xmlns:" + attrPrefix, null, attrNs);
/*      */         }
/*      */       }
/*      */
/*  555 */       String qName = attrPrefix + ":" + attrLocal;
/*      */
/*  558 */       XSSimpleTypeDefinition attrType = attrDec.getTypeDefinition();
/*  559 */       if (attrType.getItemType() != null)
/*      */       {
/*  561 */         XSSimpleTypeDefinition itemType = attrType.getItemType();
/*  562 */         if ("http://www.w3.org/2001/XMLSchema".equals(itemType.getNamespace()))
/*      */         {
/*      */           List list;
/*  565 */           if ((attrValue instanceof List))
/*      */           {
/*  567 */             list = (List)attrValue;
/*      */           }
/*      */           else
/*      */           {
/*      */             List list;
/*  569 */             if (attrValue.getClass().isArray())
/*      */             {
/*  571 */               list = Arrays.asList((Object[])(Object[])attrValue);
/*      */             }
/*      */             else
/*      */             {
/*  575 */               throw new JBossXBRuntimeException("Expected value for list type is an array or " + List.class.getName() + " but got: " + attrValue);
/*      */             }
/*      */           }
/*      */           List list;
/*  582 */           if (Constants.QNAME_QNAME.getLocalPart().equals(itemType.getName()))
/*      */           {
/*  584 */             for (int listInd = 0; listInd < list.size(); listInd++)
/*      */             {
/*  586 */               QName item = (QName)list.get(listInd);
/*  587 */               String itemNs = item.getNamespaceURI();
/*  588 */               if ((itemNs == null) || (itemNs.length() <= 0))
/*      */                 continue;
/*      */               String itemPrefix;
/*      */               String itemPrefix;
/*  591 */               if (itemNs.equals(elementNsUri))
/*      */               {
/*  593 */                 itemPrefix = prefix;
/*      */               }
/*      */               else
/*      */               {
/*  597 */                 itemPrefix = getPrefix(itemNs);
/*  598 */                 if (itemPrefix == null)
/*      */                 {
/*  600 */                   itemPrefix = attrLocal + listInd;
/*  601 */                   declareNs(attrs, itemPrefix, itemNs);
/*      */                 }
/*      */               }
/*  604 */               item = new QName(item.getNamespaceURI(), item.getLocalPart(), itemPrefix);
/*  605 */               list.set(listInd, item);
/*      */             }
/*      */
/*      */           }
/*      */
/*  610 */           attrValue = SimpleTypeBindings.marshalList(itemType.getName(), list, null);
/*      */         }
/*      */         else
/*      */         {
/*  614 */           throw new JBossXBRuntimeException("Marshalling of list types with item types not from http://www.w3.org/2001/XMLSchema is not supported.");
/*      */         }
/*      */
/*      */       }
/*  619 */       else if ((attrType.getLexicalPattern().item(0) != null) && (attrType.derivedFrom("http://www.w3.org/2001/XMLSchema", Constants.QNAME_BOOLEAN.getLocalPart(), 2)))
/*      */       {
/*  626 */         String item = attrType.getLexicalPattern().item(0);
/*  627 */         if ((item.indexOf('0') != -1) && (item.indexOf('1') != -1))
/*      */         {
/*  629 */           attrValue = ((Boolean)attrValue).booleanValue() ? "1" : "0";
/*      */         }
/*      */         else
/*      */         {
/*  633 */           attrValue = ((Boolean)attrValue).booleanValue() ? "true" : "false";
/*      */         }
/*      */       }
/*  636 */       else if ((Constants.QNAME_QNAME.getNamespaceURI().equals(attrType.getNamespace())) && (Constants.QNAME_QNAME.getLocalPart().equals(attrType.getName())))
/*      */       {
/*  639 */         QName qNameValue = (QName)attrValue;
/*      */
/*  641 */         String qNamePrefix = null;
/*  642 */         boolean declarePrefix = false;
/*  643 */         String ns = qNameValue.getNamespaceURI();
/*  644 */         if ((ns != null) && (ns.length() > 0))
/*      */         {
/*  646 */           qNamePrefix = getPrefix(ns);
/*  647 */           if (qNamePrefix == null)
/*      */           {
/*  649 */             qNamePrefix = qNameValue.getPrefix();
/*  650 */             if ((qNamePrefix == null) || (qNamePrefix.length() == 0))
/*      */             {
/*  652 */               qNamePrefix = "ns_" + qNameValue.getLocalPart();
/*      */             }
/*  654 */             declareNs(attrs, qNamePrefix, ns);
/*  655 */             this.nsRegistry.addPrefixMapping(qNamePrefix, ns);
/*  656 */             declarePrefix = true;
/*      */           }
/*      */         }
/*      */
/*  660 */         attrValue = SimpleTypeBindings.marshalQName(qNameValue, this.nsRegistry);
/*      */
/*  662 */         if (declarePrefix)
/*      */         {
/*  664 */           this.nsRegistry.removePrefixMapping(qNamePrefix);
/*      */         }
/*      */       }
/*      */       else
/*      */       {
/*  669 */         attrValue = attrValue.toString();
/*      */       }
/*      */
/*  672 */       attrs.add(attrNs, attrLocal, qName, attrDec.getTypeDefinition().getName(), attrValue.toString());
/*      */     }
/*      */
/*  680 */     this.currentAttribute = null;
/*      */
/*  682 */     String characters = null;
View Full Code Here

/*     */   private void addAttributeMappings(XSObjectList attributes, JavaXmlTypeMapping jxtm)
/*     */   {
/* 796 */     for (int i = 0; i < attributes.getLength(); i++)
/*     */     {
/* 798 */       XSAttributeUse obj = (XSAttributeUse)attributes.item(i);
/* 799 */       XSAttributeDeclaration att = obj.getAttrDeclaration();
/* 800 */       XSSimpleTypeDefinition simple = att.getTypeDefinition();
/* 801 */       addJavaXMLTypeMap(simple, "none", "", "", jxtm.getJavaWsdlMapping(), true);
/* 802 */       VariableMapping vm = new VariableMapping(jxtm);
/* 803 */       String name = att.getName();
/* 804 */       vm.setXmlAttributeName(name);
/*     */
/* 806 */       vm.setJavaVariableName(ToolsUtils.convertInvalidCharacters(Introspector.decapitalize(name)));
/* 807 */       jxtm.addVariableMapping(vm);
/*     */     }
View Full Code Here

/*     */     {
/* 420 */       int len = xsobjlist.getLength();
/* 421 */       for (int i = 0; i < len; i++)
/*     */       {
/* 423 */         XSAttributeUse obj = (XSAttributeUse)xsobjlist.item(i);
/* 424 */         XSAttributeDeclaration att = obj.getAttrDeclaration();
/* 425 */         XSSimpleTypeDefinition xstype = att.getTypeDefinition();
/* 426 */         QName qn = SchemaUtils.handleSimpleType(xstype);
/* 427 */         boolean primitive = obj.getRequired();
/* 428 */         VAR v = createVAR(qn, att.getName(), this.pkgname, primitive);
/* 429 */         if (vars == null)
/* 430 */           vars = new ArrayList();
/* 431 */         vars.add(v);
/*     */       }
/*     */     }
View Full Code Here

      }

      for(int i = 0; i < attributeUses.getLength(); ++i)
      {
         currentAttribute = (XSAttributeUse)attributeUses.item(i);
         XSAttributeDeclaration attrDec = currentAttribute.getAttrDeclaration();
         String attrNs = attrDec.getNamespace();
         String attrLocal = attrDec.getName();
         Object attrValue = provider.getAttributeValue(o, ctx, attrNs, attrLocal);

         if(attrValue != null)
         {
            if(attrs == null)
            {
               attrs = new AttributesImpl(5);
            }

            String attrPrefix = null;
            if(attrNs != null)
            {
               attrPrefix = getPrefix(attrNs);
               if(attrPrefix == null && attrNs != null && attrNs.length() > 0)
               {
                  attrPrefix = "ns_" + attrLocal;
                  attrs.add(null, attrPrefix, "xmlns:" + attrPrefix, null, attrNs);
               }
            }

            String qName = attrPrefix == null || attrPrefix.length() == 0 ? attrLocal : attrPrefix + ":" + attrLocal;

            // todo: this is a quick fix for boolean pattern (0|1 or true|false) should be refactored
            XSSimpleTypeDefinition attrType = attrDec.getTypeDefinition();
            if(attrType.getItemType() != null)
            {
               XSSimpleTypeDefinition itemType = attrType.getItemType();
               if(Constants.NS_XML_SCHEMA.equals(itemType.getNamespace()))
               {
                  List<QName> list;
                  if(attrValue instanceof List)
                  {
                     list = (List<QName>)attrValue;
                  }
                  else if(attrValue.getClass().isArray())
                  {
                     list = Arrays.asList((QName[])attrValue);
                  }
                  else
                  {
                     throw new JBossXBRuntimeException("Expected value for list type is an array or " +
                        List.class.getName() +
                        " but got: " +
                        attrValue
                     );
                  }

                  if(Constants.QNAME_QNAME.getLocalPart().equals(itemType.getName()))
                  {
                     for(int listInd = 0; listInd < list.size(); ++listInd)
                     {
                        QName item = (QName)list.get(listInd);
                        String itemNs = item.getNamespaceURI();
                        if(itemNs != null && itemNs.length() > 0)
                        {
                           String itemPrefix;
                           if(itemNs.equals(elementNsUri))
                           {
                              itemPrefix = prefix;
                           }
                           else
                           {
                              itemPrefix = getPrefix(itemNs);
                              if(itemPrefix == null)
                              {
                                 itemPrefix = attrLocal + listInd;
                                 declareNs(attrs, itemPrefix, itemNs);
                              }
                           }
                           item = new QName(item.getNamespaceURI(), item.getLocalPart(), itemPrefix);
                           list.set(listInd, item);
                        }
                     }
                  }

                  attrValue = SimpleTypeBindings.marshalList(itemType.getName(), list, null);
               }
               else
               {
                  throw new JBossXBRuntimeException("Marshalling of list types with item types not from " +
                     Constants.NS_XML_SCHEMA + " is not supported."
                  );
               }
            }
            else if(attrType.getLexicalPattern().item(0) != null
               &&
               attrType.derivedFrom(Constants.NS_XML_SCHEMA,
                  Constants.QNAME_BOOLEAN.getLocalPart(),
                  XSConstants.DERIVATION_RESTRICTION
               ))
            {
               String item = attrType.getLexicalPattern().item(0);
               if(item.indexOf('0') != -1 && item.indexOf('1') != -1)
               {
                  attrValue = ((Boolean)attrValue).booleanValue() ? "1" : "0";
               }
               else
               {
                  attrValue = ((Boolean)attrValue).booleanValue() ? "true" : "false";
               }
            }
            else if(Constants.QNAME_QNAME.getNamespaceURI().equals(attrType.getNamespace()) &&
               Constants.QNAME_QNAME.getLocalPart().equals(attrType.getName()))
            {
               QName qNameValue = (QName)attrValue;

               String qNamePrefix = null;
               boolean declarePrefix = false;
               String ns = qNameValue.getNamespaceURI();
               if(ns != null && ns.length() > 0)
               {
                  qNamePrefix = getPrefix(ns);
                  if(qNamePrefix == null)
                  {
                     qNamePrefix = qNameValue.getPrefix();
                     if(qNamePrefix == null || qNamePrefix.length() == 0)
                     {
                        qNamePrefix = "ns_" + qNameValue.getLocalPart();
                     }
                     declareNs(attrs, qNamePrefix, ns);
                     nsRegistry.addPrefixMapping(qNamePrefix, ns);
                     declarePrefix = true;
                  }
               }

               attrValue = SimpleTypeBindings.marshalQName(qNameValue, nsRegistry);

               if(declarePrefix)
               {
                  nsRegistry.removePrefixMapping(qNamePrefix);
               }
            }
            else
            {
               attrValue = attrValue.toString();
            }

            attrs.add(attrNs,
               attrLocal,
               qName,
               attrDec.getTypeDefinition().getName(),
               attrValue.toString()
            );
         }
      }
      currentAttribute = null;
View Full Code Here

TOP

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

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.