LiteralDecoder.java

  1. package de.turnertech.ows.filter;

  2. import javax.xml.stream.XMLStreamException;
  3. import javax.xml.stream.XMLStreamReader;

  4. import de.turnertech.ows.common.OwsContext;

  5. /**
  6.  * Leaf Decoder
  7.  *
  8.  * Note, must consume the input to its return element
  9.  */
  10. class LiteralDecoder {
  11.    
  12.     private LiteralDecoder() {

  13.     }

  14.     public static Literal decode(final XMLStreamReader in, final OwsContext owsContext) throws XMLStreamException {
  15.        
  16.         System.out.println(">" + "Literal");

  17.         // This consumes the element and content, moving us to the element
  18.         final String elementText = in.getElementText();
  19.         Object typedObject = null;

  20.         try {
  21.             typedObject = Long.valueOf(elementText);
  22.         } catch (Exception e) {
  23.             // Do Nothing
  24.         }

  25.         if(typedObject == null) {
  26.             try {
  27.                 typedObject = Double.valueOf(elementText);
  28.             } catch (Exception e) {
  29.                 // Do Nothing
  30.             }

  31.             if(typedObject == null) {
  32.                 typedObject = elementText;
  33.             }
  34.         }

  35.         final Literal returnLiteral = new Literal(typedObject);

  36.         return returnLiteral;
  37.     }

  38. }