Examples of XMLBinding

More advanced bindings can also be created through sub-classing.[code] // XML binding using reflection. public ReflectionBinding extends XMLBinding { protected XMLFormat getFormat(Class forClass) { Field[] fields = forClass.getDeclaredFields(); return new XMLReflectionFormat(fields); } } // XML binding read from DTD input source. public DTDBinding extends XMLBinding { public DTDBinding(InputStream dtd) { ... } } // XML binding overriding default formats. public MyBinding extends XMLBinding { // Non-static formats use unmapped XMLFormat instances. XMLFormat myStringFormat = new XMLFormat(null) {...} XMLFormat myCollectionFormat = new XMLFormat(null) {...} protected XMLFormat getFormat(Class forClass) throws XMLStreamException { if (String.class.equals(forClass)) return myStringFormat; if (Collection.class.isAssignableFrom(forClass)) return myCollectionFormat; return super.getFormat(cls); } } [/code]

The default XML binding implementation supports all static XML formats (static members of the classes being mapped) as well as the following types:

@author Jean-Marie Dautelle @version 5.4, December 1, 2009
  • org.apache.cxf.binding.xml.XMLBinding
  • org.eclipse.sapphire.modeling.xml.annotations.XmlBinding
  • org.milyn.javabean.binding.xml.XMLBinding
    XML Binding class.

    This class is designed specifically for reading and writing XML data (does not work for other data formats) to and from Java Object models using nothing more than standard <jb:bean> configurations i.e. no need to write a template for serializing the Java Objects to an output character based format, as with Smooks v1.4 and before. @author tom.fennelly@gmail.com @since 1.5


  • Examples of org.apache.cxf.binding.xml.XMLBinding

                }
            }
        }

        public Binding createBinding(BindingInfo bi) {
            XMLBinding binding = new XMLBinding();
           
            binding.getInInterceptors().add(new DispatchInterceptor());
            binding.getInInterceptors().add(new URIParameterInterceptor());

            binding.getOutInterceptors().add(new StaxOutInterceptor());
            binding.getOutInterceptors().add(new ContentTypeOutInterceptor());
            binding.getOutInterceptors().add(new WrappedOutInterceptor());
            binding.getOutInterceptors().add(new XMLMessageOutInterceptor());
           

            binding.getInFaultInterceptors().add(new XMLFaultInInterceptor());
           
            binding.getOutFaultInterceptors().add(new StaxOutInterceptor());
            binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
           
            return binding;
        }
    View Full Code Here

    Examples of org.apache.cxf.binding.xml.XMLBinding

        public JAXRSBindingFactory() {
        }

        public Binding createBinding(BindingInfo bi) {
            XMLBinding binding = new XMLBinding(bi);

            binding.getInInterceptors().add(new JAXRSInInterceptor());
           
            binding.getOutInterceptors().add(new JAXRSOutInterceptor());
           
            binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
            binding.getOutFaultInterceptors().add(new StaxOutInterceptor());

            return binding;
        }
    View Full Code Here

    Examples of org.apache.cxf.binding.xml.XMLBinding

            strategies.add(new JRAStrategy());
            strategies.add(new ConventionStrategy());
        }

        public Binding createBinding(BindingInfo bi) {
            XMLBinding binding = new XMLBinding(bi);
           
            binding.getInInterceptors().add(new AttachmentInInterceptor());
            binding.getInInterceptors().add(new DatabindingInSetupInterceptor());

            binding.getOutInterceptors().add(new AttachmentOutInterceptor());
            binding.getOutInterceptors().add(new ContentTypeOutInterceptor());

            binding.getOutInterceptors().add(new DatabindingOutSetupInterceptor());
           
            binding.getInFaultInterceptors().add(new XMLFaultInInterceptor());
           
            binding.getOutFaultInterceptors().add(new ContentTypeOutInterceptor());
            binding.getOutFaultInterceptors().add(new StaxOutInterceptor());
            binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
           
            return binding;
        }
    View Full Code Here

    Examples of org.apache.cxf.binding.xml.XMLBinding

        public JAXRSBindingFactory(Bus b) {
            super(b);
        }

        public Binding createBinding(BindingInfo bi) {
            XMLBinding binding = new XMLBinding(bi);

            binding.getInInterceptors().add(new JAXRSInInterceptor());
           
            binding.getOutInterceptors().add(new JAXRSOutInterceptor());
           
            binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
            binding.getOutFaultInterceptors().add(new StaxOutInterceptor());

            return binding;
        }
    View Full Code Here

    Examples of org.apache.cxf.binding.xml.XMLBinding

            strategies.add(new JRAStrategy());
            strategies.add(new ConventionStrategy());
        }

        public Binding createBinding(BindingInfo bi) {
            XMLBinding binding = new XMLBinding(bi);
           
            binding.getInInterceptors().add(new AttachmentInInterceptor());
            binding.getInInterceptors().add(new DatabindingInSetupInterceptor());

            binding.getOutInterceptors().add(new AttachmentOutInterceptor());
            binding.getOutInterceptors().add(new ContentTypeOutInterceptor());

            binding.getOutInterceptors().add(new DatabindingOutSetupInterceptor());
           
            binding.getInFaultInterceptors().add(new XMLFaultInInterceptor());
           
            binding.getOutFaultInterceptors().add(new ContentTypeOutInterceptor());
            binding.getOutFaultInterceptors().add(new StaxOutInterceptor());
            binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
           
            return binding;
        }
    View Full Code Here

    Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

                final SortedSet<ElementType> possible = this.possibleTypesService.types();
                this.modelElementTypes = possible.toArray( new ElementType[ possible.size() ] );

                if( xmlElementBindingAnnotation == null )
                {
                    final XmlBinding xmlBindingAnnotation = property.getAnnotation( XmlBinding.class );
                   
                    if( xmlBindingAnnotation != null && possible.size() == 1 )
                    {
                        final String path = xmlBindingAnnotation.path();
                        final int slashIndex = path.lastIndexOf( '/' );
                       
                        if( slashIndex == -1 )
                        {
                            this.xmlElementNames = new QName[] { createQualifiedName( path, xmlNamespaceResolver ) };
    View Full Code Here

    Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

               
                pathString = xmlElementBindingAnnotation.path();
            }
            else
            {
                final XmlBinding xmlBindingAnnotation = property.definition().getAnnotation( XmlBinding.class );
               
                if( xmlBindingAnnotation != null )
                {
                    pathString = xmlBindingAnnotation.path();
                }
                else
                {
                    pathString = property.name();
                }
    View Full Code Here

    Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

                }
            }
           
            if( this.rootElementController == null )
            {
                final XmlBinding xmlBindingAnnotation = modelElementType.getAnnotation( XmlBinding.class );
       
                if( xmlBindingAnnotation != null && xmlBindingAnnotation.path().length() != 0 )
                {
                    final XmlPath path = new XmlPath( xmlBindingAnnotation.path(), getXmlNamespaceResolver() );
                    final QName qualifiedName = path.getSegment( 0 ).getQualifiedName();
                    final String localName = qualifiedName.getLocalPart();
                    final String prefix = qualifiedName.getPrefix();
                    final String namespace = qualifiedName.getNamespaceURI();
                   
    View Full Code Here

    Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

       
        public static QName createDefaultElementName( final ElementType type )
        {
            QName name = null;
           
            final XmlBinding xmlBindingAnnotation = type.getAnnotation( XmlBinding.class );
            final XmlNamespaceResolver xmlNamespaceResolver = new StandardXmlNamespaceResolver( type );
           
            if( xmlBindingAnnotation != null )
            {
                final XmlPath path = new XmlPath( xmlBindingAnnotation.path(), xmlNamespaceResolver );
               
                if( path.getSegmentCount() == 1 )
                {
                    final XmlPath.Segment firstSegment = path.getSegment( 0 );
                   
    View Full Code Here

    Examples of org.eclipse.sapphire.modeling.xml.annotations.XmlBinding

           
            for( PropertyDef property : type.properties() )
            {
                String xmlPath = null;
               
                final XmlBinding xmlBindingAnnotation = property.getAnnotation( XmlBinding.class );
               
                if( xmlBindingAnnotation != null )
                {
                    xmlPath = xmlBindingAnnotation.path();
                }

                if( xmlPath == null )
                {
                    final XmlValueBinding xmlValueBindingAnnotation = property.getAnnotation( XmlValueBinding.class );
                   
                    if( xmlValueBindingAnnotation != null )
                    {
                        xmlPath = xmlValueBindingAnnotation.path();
                    }
                }
               
                if( xmlPath == null )
                {
                    final XmlElementBinding xmlElementBindingAnnotation = property.getAnnotation( XmlElementBinding.class );
                   
                    if( xmlElementBindingAnnotation != null )
                    {
                        final int mappingsCount = xmlElementBindingAnnotation.mappings().length;
                       
                        if( mappingsCount == 0 )
                        {
                            xmlPath = xmlElementBindingAnnotation.path();
                        }
                        else if( mappingsCount == 1 )
                        {
                            xmlPath = xmlElementBindingAnnotation.mappings()[ 0 ].element();
                           
                            if( xmlElementBindingAnnotation.path().length() > 0 )
                            {
                                xmlPath = xmlElementBindingAnnotation.path() + "/" + xmlPath;
                            }
                        }
                        else
                        {
                            continue; // todo: report unsupported
                        }
                    }
                }
               
                if( xmlPath == null )
                {
                    final XmlListBinding xmlListBindingAnnotation = property.getAnnotation( XmlListBinding.class );
                   
                    if( xmlListBindingAnnotation != null )
                    {
                        if( xmlListBindingAnnotation.mappings().length == 1 )
                        {
                            xmlPath = xmlListBindingAnnotation.mappings()[ 0 ].element();
                           
                            if( xmlListBindingAnnotation.path().length() > 0 )
                            {
                                xmlPath = xmlListBindingAnnotation.path() + "/" + xmlPath;
                            }
                        }
                        else
                        {
                            continue; // todo: report unsupported
                        }
                    }
                }
               
                if( xmlPath != null )
                {
                    properties.put( xmlPath, property );
                }
            }
           
            // Write the summary document fragment
           
            out.println( "<table>" );
            out.println( "  <tr>" );
            out.println( "    <th>Element</th>" );
            out.println( "    <th>Cardinality</th>" );
            out.println( "    <th>Description</th>" );
            out.println( "  </tr>" );
           
            for( Map.Entry<String,PropertyDef> entry : properties.entrySet() )
            {
                final String xmlPath = entry.getKey();
                final PropertyDef property = entry.getValue();
               
                final String cardinality;
               
                if( property instanceof ValueProperty )
                {
                    if( property.hasAnnotation( Required.class ) )
                    {
                        cardinality = "1";
                    }
                    else
                    {
                        cardinality = "0 or 1";
                    }
                }
                else if( property instanceof ElementProperty )
                {
                    cardinality = "0 or 1";
                }
                else if( property instanceof ListProperty )
                {
                    cardinality = "0 or more";
                }
                else
                {
                    throw new IllegalStateException();
                }
               
                out.println( "  <tr>" );

                out.println( td( xmlPath ) );
                out.println( td( cardinality ) );
               
                out.println( "    <td>" );
               
                if( property.hasAnnotation( Documentation.class ) )
                {
                    documentation( out, property.getAnnotation( Documentation.class ) );
                }
                else
                {
                    out.println( "&nbsp;" );
                }
               
                if( property instanceof ElementProperty || property instanceof ListProperty )
                {
                    boolean skip = false;
                   
                    final ElementType childType = property.service( PossibleTypesService.class ).types().first();
                    final SortedSet<PropertyDef> childTypeProperties = childType.properties();
                   
                    if( childTypeProperties.size() == 1 )
                    {
                        final PropertyDef childTypeProperty = childTypeProperties.first();
                       
                        if( childTypeProperty instanceof ValueProperty )
                        {
                            if( childTypeProperty.hasAnnotation( XmlBinding.class ) )
                            {
                                final XmlBinding b = childTypeProperty.getAnnotation( XmlBinding.class );
                               
                                if( b != null && b.path().length() == 0 )
                                {
                                    skip = true;
                                }
                            }
                            else if( childTypeProperty.hasAnnotation( XmlValueBinding.class ) )
                            {
                                final XmlValueBinding b = childTypeProperty.getAnnotation( XmlValueBinding.class );
                               
                                if( b != null && b.path().length() == 0 )
                                {
                                    skip = true;
                                }
                            }
                        }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. 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.