Package org.codehaus.jettison.badgerfish

Examples of org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader


import org.codehaus.jettison.json.JSONObject;

public class BadgerFishXMLStreamReaderTest extends TestCase {
    public void testRootWithText() throws Exception {
        JSONObject obj = new JSONObject("{ \"alice\": { \"$\" : \"bob\" } }");
        AbstractXMLStreamReader reader = new BadgerFishXMLStreamReader(obj);
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
       
        assertEquals(-1, reader.getLocation().getLineNumber());
       
        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
        assertEquals("bob", reader.getText());
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
        assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
    }
View Full Code Here


  
    public void testTwoChildren() throws Exception {
        JSONObject obj = new JSONObject(
                        "{ \"alice\": { \"bob\" : { \"$\": \"charlie\" }," +
                        " \"david\": { \"$\": \"edgar\"} } }");
        AbstractXMLStreamReader reader = new BadgerFishXMLStreamReader(obj);
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
        assertEquals("charlie", reader.getText());
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("david", reader.getName().getLocalPart());
        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
        assertEquals("edgar", reader.getText());
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("david", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
    }
View Full Code Here

    }
   
    public void testTwoChildrenWithSameName() throws Exception {
        JSONObject obj = new JSONObject(
        "{ \"alice\": { \"bob\" : [ {\"$\": \"charlie\" }, {\"$\": \"david\" } ] } }");
        AbstractXMLStreamReader reader = new BadgerFishXMLStreamReader(obj);
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
        assertEquals("charlie", reader.getText());
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
        assertEquals("david", reader.getText());
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("bob", reader.getName().getLocalPart());
       
        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
        assertEquals("alice", reader.getName().getLocalPart());
    }
View Full Code Here

   }

   public Object unmarshal(Reader reader)
           throws JAXBException
   {
      BadgerFishXMLStreamReader badger = null;
      badger = getBadgerFishReader(reader);
      return unmarshaller.unmarshal(badger);
   }
View Full Code Here

   }

   protected BadgerFishXMLStreamReader getBadgerFishReader(Reader reader)
           throws JAXBException
   {
      BadgerFishXMLStreamReader badger;
      char[] buffer = new char[100];
      StringBuffer buf = new StringBuffer();
      BufferedReader bufferedReader = new BufferedReader(reader);

      try
      {
         int wasRead = 0;
         do
         {
            wasRead = bufferedReader.read(buffer, 0, 100);
            if (wasRead > 0) buf.append(buffer, 0, wasRead);
         } while (wasRead > -1);
         badger = new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(buf.toString())));

      }
      catch (Exception e)
      {
         throw new JAXBException(e);
View Full Code Here

                } catch (Exception ex) {
                    throw new XMLStreamException(ex);
                }
            case BADGERFISH:
                try {
                    return new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(ReaderWriter.readFromAsString
                            (nonEmptyReader))));
                } catch (Exception ex) {
                    throw new XMLStreamException(ex);
                }
        }
View Full Code Here

    }

    public XMLStreamReader transform(Object source, TransformationContext context) {
        try {
            JSONObject json = JSONHelper.toJettison(source);
            return new BadgerFishXMLStreamReader(json);
        } catch (Exception e) {
            throw new TransformationException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader

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.