Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) cedarsoft GmbH. Licensed under the GNU General Public License version 3 (the "License") with Classpath Exception; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.cedarsoft.org/gpl3ce (GPL 3 with Classpath Exception) This code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 only, as published by the Free Software Foundation. cedarsoft GmbH designates this particular file as subject to the "Classpath" exception as provided by cedarsoft GmbH in the LICENSE file that accompanied this code. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more details (a copy is included in the LICENSE file that accompanied this code). You should have received a copy of the GNU General Public License version 3 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. Please contact cedarsoft GmbH, 72810 Gomaringen, Germany, or visit www.cedarsoft.com if you need additional information or have any questions.
 
 
 package com.cedarsoft.serialization.stax.mate;
 
 
Abstract base class for stax mate based serializers

Parameters:
<T> the type
 
 public abstract class AbstractStaxMateSerializer<T> extends AbstractStaxBasedSerializer<T, SMOutputElement> {
   @Nonnull
   public static final String INDENT_STR = "\n                            ";
 
   protected AbstractStaxMateSerializer( @Nonnull String defaultElementName, @Nonnull String nameSpaceUriBase, @Nonnull VersionRange formatVersionRange ) {
     superdefaultElementNamenameSpaceUriBaseformatVersionRange );
   }
 
   @Override
   public void serialize( @Nonnull T object, @Nonnull OutputStream out ) throws IOException {
     try {
       SMOutputFactory factory = StaxMateSupport.getSmOutputFactory();
       SMOutputDocument doc = factory.createOutputDocumentout );
       if (! StaxMateSupport.isJsonEnabled() ) {
         doc.setIndentation, 1, 2 );
       }
 
       String nameSpaceUri = getNameSpace();
       SMNamespace nameSpace = doc.getNamespacenameSpaceUri );
 
       SMOutputElement root = doc.addElementnameSpacegetDefaultElementName() );
       serializerootobjectgetFormatVersion() );
       doc.closeRoot();
     } catch ( XMLStreamException e ) {
       throw new IOExceptione );
     }
   }

  
Serializes the given object into a sub element of serializeTo

Parameters:
object the object that is serialized
type the type
subElementName the name of the sub element
serializeTo the parent element
formatVersion the format version
<T> the type
Throws:
javax.xml.stream.XMLStreamException if there is an xml problem
java.io.IOException if there is an io problem
 
   public <T> void serialize( @Nonnull T object, @Nonnull Class<T> type, @Nonnull String subElementName, @Nonnull SMOutputElement serializeTo, @Nonnull Version formatVersion ) throws XMLStreamExceptionIOException {
     SMOutputElement element = serializeTo.addElementserializeTo.getNamespace(), subElementName );
     serializeobjecttypeelementformatVersion );
   }

  
Serializes the elements of a collection

Parameters:
objects the objects that are serialized
type the type
elementName the element name
serializeTo the object the elements are serialized to
formatVersion the format version
Throws:
javax.xml.stream.XMLStreamException if there is an xml problem
java.io.IOException if there is an io problem
  protected <T> void serializeCollection( @Nonnull Iterable<? extends T> objects, @Nonnull Class<T> type, @Nonnull String elementName, @Nonnull SMOutputElement serializeTo, @Nonnull Version formatVersion ) throws XMLStreamExceptionIOException {
    AbstractXmlSerializer<? super T, SMOutputElementXMLStreamReaderXMLStreamExceptionserializer = getSerializertype );
    Version resolvedVersion = getDelegatesMappings().resolveVersiontypeformatVersion );
    for ( T object : objects ) {
      SMOutputElement doorElement = serializeTo.addElementserializeTo.getNamespace(), elementName );
      serializer.serializedoorElementobjectresolvedVersion );
    }
  }
  protected <T> void serializeCollection( @Nonnull Iterable<? extends T> objects, @Nonnull Class<T> type, @Nonnull SMOutputElement serializeTo, @Nonnull Version formatVersion ) throws XMLStreamExceptionIOException {
    AbstractXmlSerializer<? super T, SMOutputElementXMLStreamReaderXMLStreamExceptionserializer = getSerializertype );
    Version resolvedVersion = getDelegatesMappings().resolveVersiontypeformatVersion );
    for ( T object : objects ) {
      SMOutputElement doorElement = serializeTo.addElementserializeTo.getNamespace(), serializer.getDefaultElementName() );
      serializer.serializedoorElementobjectresolvedVersion );
    }
  }

  
Serializes the elements of the collection to a own sub element

Parameters:
objects the objects that are serialized
type the type
collectionElementName the collection element name
elementName the element name
serializeTo the object the elements are serialized to
formatVersion the format version
Throws:
javax.xml.stream.XMLStreamException if there is an xml problem
java.io.IOException if there is an io problem
  protected <T> void serializeCollectionToElement( @Nonnull Iterable<? extends T> objects, @Nonnull Class<T> type, @Nonnull String collectionElementName, @Nonnull String elementName, @Nonnull SMOutputElement serializeToVersion formatVersion ) throws XMLStreamExceptionIOException {
    SMOutputElement collectionElement = serializeTo.addElementserializeTo.getNamespace(), collectionElementName );
    serializeCollectionobjectstypeelementNamecollectionElementformatVersion );
  }
  protected <T> void serializeCollectionToElement( @Nonnull Iterable<? extends T> objects, @Nonnull Class<T> type, @Nonnull String collectionElementName, @Nonnull SMOutputElement serializeToVersion formatVersion ) throws XMLStreamExceptionIOException {
    SMOutputElement collectionElement = serializeTo.addElementserializeTo.getNamespace(), collectionElementName );
    serializeCollectionobjectstypecollectionElementformatVersion );
  }
  protected void serializeToElementWithCharacters( @Nonnull String elementName, @Nonnull String characters, @Nonnull SMOutputElement serializeTo ) throws XMLStreamException {
    serializeTo.addElementWithCharactersserializeTo.getNamespace(), elementNamecharacters );
  }

  
Serializes an enum (as attribute)

Parameters:
enumValue the num value
propertyName the property name
serializeTo the object to serialize to
Throws:
javax.xml.stream.XMLStreamException
  public void serializeEnum( @Nonnull Enum<?> enumValue, @Nonnull String propertyName, @Nonnull SMOutputElement serializeTo ) throws XMLStreamException {
    serializeTo.addAttributepropertyNameenumValue.name() );
  }
New to GrepCode? Check out our FAQ X