Package org.jboss.xb.binding

Examples of org.jboss.xb.binding.AttributesImpl


               ContentHandler ch = ctx.getContentHandler();
               GenericElement ge = (GenericElement)o;

               try
               {
                  AttributesImpl attrs = null;
                  if(ge.getAttributesTotal() > 0)
                  {
                     attrs = new AttributesImpl(ge.getAttributesTotal() + 1);
                     Set attrNames = ge.getAttributeNames();
                     for(Iterator i = attrNames.iterator(); i.hasNext();)
                     {
                        String attrName = (String)i.next();
                        String attrValue = ge.getAttribute(attrName);
                        attrs.add(null, attrName, attrName, null, attrValue);
                     }
                  }
                  else
                  {
                     attrs = new AttributesImpl(1);
                  }

                  attrs.add(Constants.NS_XML_SCHEMA, "xmlns", "xmlns", null, ge.getNsUri());

                  ch.startElement(ge.getNsUri(), ge.getLocalName(), ge.getLocalName(), attrs);

                  String text = ge.getTextContent();
                  if(text != null && text.length() > 0)
View Full Code Here


         return count;
      }

      private AttributesImpl toSaxAttributes(XMLAttributes attributes)
      {
         AttributesImpl attrs = null;
         if(attributes != null)
         {
            attrs = new AttributesImpl(attributes.getLength());
            for(int i = 0; i < attributes.getLength(); ++i)
            {
               if(!"xmlns".equals(attributes.getPrefix(i)))
               {
                  attrs.add(attributes.getURI(i),
                     attributes.getLocalName(i),
                     attributes.getQName(i),
                     attributes.getType(i),
                     attributes.getValue(i)
                  );
View Full Code Here

               ContentHandler ch = ctx.getContentHandler();
               GenericElement ge = (GenericElement)o;

               try
               {
                  AttributesImpl attrs = null;
                  if(ge.getAttributesTotal() > 0)
                  {
                     attrs = new AttributesImpl(ge.getAttributesTotal() + 1);
                     Set attrNames = ge.getAttributeNames();
                     for(Iterator i = attrNames.iterator(); i.hasNext();)
                     {
                        String attrName = (String)i.next();
                        String attrValue = ge.getAttribute(attrName);
                        attrs.add(null, attrName, attrName, null, attrValue);
                     }
                  }
                  else
                  {
                     attrs = new AttributesImpl(1);
                  }

                  attrs.add(Constants.NS_XML_SCHEMA, "xmlns", "xmlns", null, ge.getNsUri());

                  ch.startElement(ge.getNsUri(), ge.getLocalName(), ge.getLocalName(), attrs);

                  String text = ge.getTextContent();
                  if(text != null && text.length() > 0)
View Full Code Here

            // XOPMarshaller callback will create the attachment part
            Object o = stack.peek();
            String cid = xopMarshaller.addMtomAttachment(new XOPObject(o), elementNs, elementLocal);

            // Create the xopInclude element from CID and exit
            AttributesImpl attrs = null;
            String prefix = getPrefix(elementNs);
            boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
            if(genPrefix)
            {
               prefix = "ns_" + elementLocal;
               attrs = new AttributesImpl(1);
               declareNs(attrs, prefix, elementNs);
            }

            String qName = prefixLocalName(prefix, elementLocal);
            content.startElement(elementNs, elementLocal, qName, attrs);

            AttributesImpl xopAttrs = new AttributesImpl(2);
            xopAttrs.add(Constants.NS_XML_SCHEMA, "xop", "xmlns:xop", "CDATA", Constants.NS_XOP_INCLUDE);
            xopAttrs.add(null, "href", "href", "CDATA", cid);

            content.startElement(Constants.NS_XOP_INCLUDE, "Include", "xop:Include", xopAttrs);
            content.endElement(Constants.NS_XOP_INCLUDE, "Include", "xop:Include");

            content.endElement(elementNs, elementLocal, qName);
View Full Code Here

      ctx.attrs = null;
      if((declareNs || declareXsiType) && nsRegistry.size() > 0)
      {
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(nsRegistry.size() + 1);
         }
         declareNs(ctx.attrs);
      }

      String elementNs = elementQName.getNamespaceURI();
      String elementLocal = elementQName.getLocalPart();

      String prefix = getPrefix(elementNs);
      boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
      if(genPrefix)
      {
         prefix = "ns_" + elementLocal;
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(1);
         }
         declareNs(ctx.attrs, prefix, elementNs);
      }

      if(declareXsiType)
      {
         declareXsiType(type.getQName(), ctx.attrs);
      }

      String typeName = type.getQName() == null ? null : type.getQName().getLocalPart();
      if(ctx.attrs == null && SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
          SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
          type.getItemType() != null &&
              (SimpleTypeBindings.XS_QNAME_NAME.equals(type.getItemType().getQName().getLocalPart()) ||
                  SimpleTypeBindings.XS_NOTATION_NAME.equals(type.getItemType().getQName().getLocalPart())
              )
          )
      {
         ctx.attrs = new AttributesImpl(5);
      }

      Object value = stack.peek();
      String marshalled = marshalCharacters(elementNs, prefix, type, value);
View Full Code Here

                                   boolean declareNs,
                                   boolean declareXsiType)
   {
      Collection attrBindings = type.getAttributes();
      int attrsTotal = declareNs || declareXsiType ? nsRegistry.size() + attrBindings.size() + 1: attrBindings.size();
      ctx.attrs = attrsTotal > 0 ? new AttributesImpl(attrsTotal) : null;

      if(declareNs && nsRegistry.size() > 0)
      {
         declareNs(ctx.attrs);
      }

      String generatedPrefix = null;
      if(declareXsiType)
      {
         generatedPrefix = declareXsiType(type.getQName(), ctx.attrs);
         if(generatedPrefix != null)
         {
            String typeNsWithGeneratedPrefix = type.getQName().getNamespaceURI();
            declareNs(ctx.attrs, generatedPrefix, typeNsWithGeneratedPrefix);
            declareNamespace(generatedPrefix, typeNsWithGeneratedPrefix);
         }
      }

      String elementNs = elementQName.getNamespaceURI();
      String elementLocal = elementQName.getLocalPart();

      String prefix = getPrefix(elementNs);
      boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
      if(genPrefix)
      {
         // todo: it's possible that the generated prefix already mapped. this should be fixed
         prefix = "ns_" + elementLocal;
         declareNamespace(prefix, elementNs);
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(1);
         }
         declareNs(ctx.attrs, prefix, elementNs);
      }

      if(!attrBindings.isEmpty())
      {
         for(Iterator i = attrBindings.iterator(); i.hasNext();)
         {
            AttributeBinding attrBinding = (AttributeBinding)i.next();
            QName attrQName = attrBinding.getQName();

            if(Constants.QNAME_XMIME_CONTENTTYPE.equals(attrQName))
            {
               continue;
            }

            ctx.attr = attrBinding;
            AttributeMarshaller marshaller = attrBinding.getMarshaller();
            String marshalledAttr = marshaller.marshal(ctx);

            if(marshalledAttr != null)
            {
               if(ctx.attrs == null)
               {
                  ctx.attrs = new AttributesImpl(5);
               }

               String attrNs = attrQName.getNamespaceURI();
               String attrLocal = attrQName.getLocalPart();
               String attrPrefix = null;
               if(attrNs != null)
               {
                  attrPrefix = getPrefix(attrNs);
                  if(attrPrefix == null && attrNs != null && attrNs.length() > 0)
                  {
                     attrPrefix = "ns_" + attrLocal;
                     declareNs(ctx.attrs, attrPrefix, attrNs);
                  }
               }

               String prefixedName = prefixLocalName(attrPrefix, attrLocal);
               ctx.attrs.add(attrNs, attrLocal, prefixedName, "CDATA", marshalledAttr);
            }
         }
         ctx.attr = null;
      }

      String characters = null;
      TypeBinding simpleType = type.getSimpleType();
      if(simpleType != null)
      {
         String fieldName = ctx.getSimpleContentProperty();
         CharactersMetaData charactersMetaData = type.getCharactersMetaData();
         PropertyMetaData propertyMetaData = charactersMetaData == null ? null : charactersMetaData.getProperty();
         if(propertyMetaData != null)
         {
            fieldName = propertyMetaData.getName();
         }

         if(fieldName != null)
         {
            boolean ignoreUnresolvedFieldOrClass = type.getSchemaBinding().isIgnoreUnresolvedFieldOrClass();
            Object o = stack.peek();
            Object value = getElementValue(o, fieldName, ignoreUnresolvedFieldOrClass);
            if(value != null)
            {
               String typeName = simpleType.getQName().getLocalPart();
               if(ctx.attrs == null && (SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
                   SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
                   simpleType.getItemType() != null &&
                       (SimpleTypeBindings.XS_QNAME_NAME.equals(simpleType.getItemType().getQName().getLocalPart()) ||
                           SimpleTypeBindings.XS_NOTATION_NAME.equals(simpleType.getItemType().getQName().getLocalPart())
                       )
               )
                   )
               {
                  ctx.attrs = new AttributesImpl(5);
               }

               characters = marshalCharacters(elementNs, prefix, simpleType, value);
            }
         }
View Full Code Here

      }

      String elementNs = elementQName.getNamespaceURI();
      String elementLocal = elementQName.getLocalPart();

      AttributesImpl attrs;
      String prefix = getPrefix(elementNs);
      if(prefix == null && elementNs != null && elementNs.length() > 0)
      {
         prefix = "ns_" + elementLocal;
         attrs = new AttributesImpl(2);
         declareNs(attrs, prefix, elementNs);
      }
      else
      {
         attrs = new AttributesImpl(1);
      }

      String xsiPrefix = getPrefix(Constants.NS_XML_SCHEMA_INSTANCE);
      if(xsiPrefix == null)
      {
         xsiPrefix = "xsi";
         declareNs(attrs, "xsi", Constants.NS_XML_SCHEMA_INSTANCE);
      }

      String nilQName = xsiPrefix + ":nil";
      attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "nil", nilQName, null, "1");

      String qName = prefixLocalName(prefix, elementLocal);
      content.startElement(elementNs, elementLocal, qName, attrs);
      content.endElement(elementNs, elementLocal, qName);
   }
View Full Code Here

            // XOPMarshaller callback will create the attachment part
            Object o = stack.peek();
            String cid = xopMarshaller.addMtomAttachment(new XOPObject(o), elementNs, elementLocal);

            // Create the xopInclude element from CID and exit
            AttributesImpl attrs = null;
            String prefix = getPrefix(elementNs);
            boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
            if(genPrefix)
            {
               prefix = "ns_" + elementLocal;
               attrs = new AttributesImpl(1);
               declareNs(attrs, prefix, elementNs);
            }

            String qName = prefixLocalName(prefix, elementLocal);
            content.startElement(elementNs, elementLocal, qName, attrs);

            AttributesImpl xopAttrs = new AttributesImpl(2);
            xopAttrs.add(Constants.NS_XML_SCHEMA, "xop", "xmlns:xop", "CDATA", Constants.NS_XOP_INCLUDE);
            xopAttrs.add(null, "href", "href", "CDATA", cid);

            content.startElement(Constants.NS_XOP_INCLUDE, "Include", "xop:Include", xopAttrs);
            content.endElement(Constants.NS_XOP_INCLUDE, "Include", "xop:Include");

            content.endElement(elementNs, elementLocal, qName);
View Full Code Here

      ctx.attrs = null;
      if((declareNs || declareXsiType) && nsRegistry.size() > 0)
      {
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(nsRegistry.size() + 1);
         }
         declareNs(ctx.attrs);
      }

      String elementNs = elementQName.getNamespaceURI();
      String elementLocal = elementQName.getLocalPart();

      String prefix = getPrefix(elementNs);
      boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
      if(genPrefix)
      {
         prefix = "ns_" + elementLocal;
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(1);
         }
         declareNs(ctx.attrs, prefix, elementNs);
      }

      if(declareXsiType)
      {
         declareXsiType(type.getQName(), ctx.attrs);
      }

      String typeName = type.getQName() == null ? null : type.getQName().getLocalPart();
      if(ctx.attrs == null && SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
          SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
          type.getItemType() != null &&
              (SimpleTypeBindings.XS_QNAME_NAME.equals(type.getItemType().getQName().getLocalPart()) ||
                  SimpleTypeBindings.XS_NOTATION_NAME.equals(type.getItemType().getQName().getLocalPart())
              )
          )
      {
         ctx.attrs = new AttributesImpl(5);
      }

      Object value = stack.peek();
      String marshalled = marshalCharacters(elementNs, prefix, type, value);
View Full Code Here

                                   boolean declareNs,
                                   boolean declareXsiType)
   {
      Collection attrBindings = type.getAttributes();
      int attrsTotal = declareNs || declareXsiType ? nsRegistry.size() + attrBindings.size() + 1: attrBindings.size();
      ctx.attrs = attrsTotal > 0 ? new AttributesImpl(attrsTotal) : null;

      if(declareNs && nsRegistry.size() > 0)
      {
         declareNs(ctx.attrs);
      }

      String generatedPrefix = null;
      if(declareXsiType)
      {
         generatedPrefix = declareXsiType(type.getQName(), ctx.attrs);
         if(generatedPrefix != null)
         {
            String typeNsWithGeneratedPrefix = type.getQName().getNamespaceURI();
            declareNs(ctx.attrs, generatedPrefix, typeNsWithGeneratedPrefix);
            declareNamespace(generatedPrefix, typeNsWithGeneratedPrefix);
         }
      }

      String elementNs = elementQName.getNamespaceURI();
      String elementLocal = elementQName.getLocalPart();

      String prefix = getPrefix(elementNs);
      boolean genPrefix = prefix == null && elementNs != null && elementNs.length() > 0;
      if(genPrefix)
      {
         // todo: it's possible that the generated prefix already mapped. this should be fixed
         prefix = "ns_" + elementLocal;
         declareNamespace(prefix, elementNs);
         if(ctx.attrs == null)
         {
            ctx.attrs = new AttributesImpl(1);
         }
         declareNs(ctx.attrs, prefix, elementNs);
      }

      if(!attrBindings.isEmpty())
      {
         for(Iterator i = attrBindings.iterator(); i.hasNext();)
         {
            AttributeBinding attrBinding = (AttributeBinding)i.next();
            QName attrQName = attrBinding.getQName();

            if(Constants.QNAME_XMIME_CONTENTTYPE.equals(attrQName))
            {
               continue;
            }

            ctx.attr = attrBinding;
            AttributeMarshaller marshaller = attrBinding.getMarshaller();
            String marshalledAttr = marshaller.marshal(ctx);

            if(marshalledAttr != null)
            {
               if(ctx.attrs == null)
               {
                  ctx.attrs = new AttributesImpl(5);
               }

               String attrNs = attrQName.getNamespaceURI();
               String attrLocal = attrQName.getLocalPart();
               String attrPrefix = null;
               if(attrNs != null)
               {
                  attrPrefix = getPrefix(attrNs);
                  if(attrPrefix == null && attrNs != null && attrNs.length() > 0)
                  {
                     attrPrefix = "ns_" + attrLocal;
                     declareNs(ctx.attrs, attrPrefix, attrNs);
                  }
               }

               String prefixedName = prefixLocalName(attrPrefix, attrLocal);
               ctx.attrs.add(attrNs, attrLocal, prefixedName, "CDATA", marshalledAttr);
            }
         }
         ctx.attr = null;
      }

      String characters = null;
      TypeBinding simpleType = type.getSimpleType();
      if(simpleType != null && !Constants.QNAME_ANYTYPE.equals(type.getQName()))
      {
         String fieldName = ctx.getSimpleContentProperty();
         CharactersMetaData charactersMetaData = type.getCharactersMetaData();
         PropertyMetaData propertyMetaData = charactersMetaData == null ? null : charactersMetaData.getProperty();
         if(propertyMetaData != null)
         {
            fieldName = propertyMetaData.getName();
         }

         if(fieldName != null)
         {
            boolean ignoreUnresolvedFieldOrClass = type.getSchemaBinding().isIgnoreUnresolvedFieldOrClass();
            Object o = stack.peek();
            Object value = getElementValue(o, fieldName, ignoreUnresolvedFieldOrClass);
            if(value != null)
            {
               String typeName = simpleType.getQName().getLocalPart();
               if(ctx.attrs == null && (SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
                   SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName) ||
                   simpleType.getItemType() != null &&
                       (SimpleTypeBindings.XS_QNAME_NAME.equals(simpleType.getItemType().getQName().getLocalPart()) ||
                           SimpleTypeBindings.XS_NOTATION_NAME.equals(simpleType.getItemType().getQName().getLocalPart())
                       )
               )
                   )
               {
                  ctx.attrs = new AttributesImpl(5);
               }

               characters = marshalCharacters(elementNs, prefix, simpleType, value);
            }
         }
View Full Code Here

TOP

Related Classes of org.jboss.xb.binding.AttributesImpl

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.