Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSAttributeDeclaration


                        Boolean.TRUE);

        XSModel model = fSchemaLoader
                .loadURI(getResourceURL("XSAttributeAnnotationsTest03.xsd"));

        XSAttributeDeclaration attr = model.getAttributeDeclaration("attr",
                "XSAttributeAnnotationsTest");
        XSObjectList annotations = attr.getAnnotations();

        assertEquals("Synthetic Annotation Empty", 1, annotations.getLength());
    }
View Full Code Here


                        Boolean.FALSE);

        XSModel model = fSchemaLoader
                .loadURI(getResourceURL("XSAttributeAnnotationsTest03.xsd"));

        XSAttributeDeclaration attr = model.getAttributeDeclaration("attr",
                "XSAttributeAnnotationsTest");
        XSAnnotation annotation = attr.getAnnotation();

        assertNull("Synthetic Annotation Not Null", annotation);
    }
View Full Code Here

                        Boolean.TRUE);

        XSModel model = fSchemaLoader
                .loadURI(getResourceURL("XSAttributeAnnotationsTest03.xsd"));

        XSAttributeDeclaration attr = model.getAttributeDeclaration("attr1",
                "XSAttributeAnnotationsTest");
        XSObjectList annotations = attr.getAnnotations();

        assertEquals("Synthetic Annotation Empty", 0, annotations.getLength());
    }
View Full Code Here

      if(xobj1.getLength() != xobj2.getLength())
         return false;
      int len = xobj1.getLength();
      for(int i=0; i<len ; i++)
      {
         XSAttributeDeclaration xat1 = (XSAttributeDeclaration)xobj1.item(i);
         XSAttributeDeclaration xat2 = (XSAttributeDeclaration)xobj1.item(i);
         bool =  checkXSAttributesEquality(xat1,xat2);
      }

      //Validate the particles
      XSParticle xspart1 = xc1.getParticle();
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 list;
                  if(attrValue instanceof List)
                  {
                     list = (List)attrValue;
                  }
                  else if(attrValue.getClass().isArray())
                  {
                     list = Arrays.asList((Object[])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

   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

      return binding;
   }

   private static AttributeBinding bindAttributes(Context ctx, TypeBinding type, XSAttributeUse attrUse)
   {
      XSAttributeDeclaration attr = attrUse.getAttrDeclaration();
      QName attrName = new QName(attr.getNamespace(), attr.getName());

      if (ctx.trace)
      {
         log.trace("binding attribute " + attrName + " for " + type.getQName() + ", required=" + attrUse.getRequired());
      }

      XSSimpleTypeDefinition attrType = attr.getTypeDefinition();
      TypeBinding typeBinding = bindSimpleType(ctx, attrType);
      AttributeBinding binding = type.addAttribute(attrName, typeBinding, DefaultHandlers.ATTRIBUTE_HANDLER);
      binding.setRequired(attrUse.getRequired());
      if(attrUse.getConstraintType() == XSConstants.VC_DEFAULT)
      {
         // Associate the default value with the binding
         binding.setDefaultConstraint(attrUse.getConstraintValue());
      }

      if (ctx.processAnnotations)
      {
         XSAnnotation an = attr.getAnnotation();
         if(an != null)
         {
            if (ctx.trace)
            {
               log.trace(attrName + " attribute annotation");
View Full Code Here

      return binding;
   }

   private AttributeBinding bindAttribute(XSAttributeUse attrUse)
   {
      XSAttributeDeclaration attr = attrUse.getAttrDeclaration();
      QName attrName = new QName(attr.getNamespace(), attr.getName());

      XSSimpleTypeDefinition attrType = attr.getTypeDefinition();
      TypeBinding typeBinding = bindSimpleType(attrType);

      if (trace)
      {
         log.trace("binding attribute " + attrName + ", required=" + attrUse.getRequired());
      }

      AttributeBinding binding = new AttributeBinding(schema, attrName, typeBinding, DefaultHandlers.ATTRIBUTE_HANDLER);
      binding.setRequired(attrUse.getRequired());
      if(attrUse.getConstraintType() == XSConstants.VC_DEFAULT)
      {
         // Associate the default value with the binding
         binding.setDefaultConstraint(attrUse.getConstraintValue());
      }

      if (processAnnotations)
      {
         XSAnnotation an = attr.getAnnotation();
         if(an != null)
         {
            if (trace)
            {
               log.trace(attrName + " attribute annotation");
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 list;
                  if(attrValue instanceof List)
                  {
                     list = (List)attrValue;
                  }
                  else if(attrValue.getClass().isArray())
                  {
                     list = Arrays.asList((Object[])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.