示例#1
1
  /**
   * Generate the xml top level element and start streaming the components.
   *
   * @param components
   * @param contentHandler
   * @throws SAXException
   */
  protected static void generateXML(
      Components components, ContentHandler contentHandler, boolean isScrPrivateFile)
      throws SAXException {
    // detect namespace to use
    final String namespace;
    if (components.getSpecVersion() == Constants.VERSION_1_0) {
      namespace = NAMESPACE_URI_1_0;
    } else if (components.getSpecVersion() == Constants.VERSION_1_1) {
      namespace = NAMESPACE_URI_1_1;
    } else {
      namespace = NAMESPACE_URI_1_1_FELIX;
    }
    contentHandler.startDocument();
    contentHandler.startPrefixMapping(PREFIX, namespace);

    // wrapper element to generate well formed xml
    contentHandler.startElement(
        "",
        ComponentDescriptorIO.COMPONENTS,
        ComponentDescriptorIO.COMPONENTS,
        new AttributesImpl());
    IOUtils.newline(contentHandler);

    for (final Component component : components.getComponents()) {
      if (component.isDs()) {
        generateXML(namespace, component, contentHandler, isScrPrivateFile);
      }
    }
    // end wrapper element
    contentHandler.endElement(
        "", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS);
    IOUtils.newline(contentHandler);
    contentHandler.endPrefixMapping(PREFIX);
    contentHandler.endDocument();
  }
示例#2
0
 @Override
 public void parse(final String id) throws SAXException {
   try {
     contentHandler.startDocument();
     serialize(item);
     contentHandler.endDocument();
   } catch (final Exception ex) {
     throw new SAXException(ex);
   }
 }
示例#3
0
  public String parseGetContent(File file, String id) {

    ContentHandler handler = new ContentHandler(id);
    try {

      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();
      saxParser.parse(file, handler);

    } catch (Exception e) {
    }
    return handler.getResult();
  }
  public void outputDelimiter(ContentHandler contentHandler, String classes, String id)
      throws SAXException {

    reusableAttributes.clear();
    if (id != null) reusableAttributes.addAttribute("", "id", "id", ContentHandlerHelper.CDATA, id);

    if (classes != null)
      reusableAttributes.addAttribute("", "class", "class", ContentHandlerHelper.CDATA, classes);

    final String delimiterQName = XMLUtils.buildQName(delimiterPrefix, delimiterLocalName);
    contentHandler.startElement(
        delimiterNamespaceURI, delimiterLocalName, delimiterQName, reusableAttributes);
    contentHandler.endElement(delimiterNamespaceURI, delimiterLocalName, delimiterQName);
  }
示例#5
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
示例#6
0
 /**
  * This will invoke the <code>endPrefixMapping</code> callback in the <code>ContentHandler</code>
  * when a namespace is goes out of scope in the <code>Document</code>.
  *
  * @param namespace Namespace leaving scope.
  */
 private void endPrefixMapping(Namespace namespace) throws JDOMException {
   try {
     contentHandler.endPrefixMapping(namespace.getPrefix());
   } catch (SAXException se) {
     throw new JDOMException("Exception in endPrefixMapping", se);
   }
 }
示例#7
0
 /**
  * Write the xml for a {@link Interface}.
  *
  * @param interf
  * @param contentHandler
  * @throws SAXException
  */
 protected static void generateXML(Interface interf, ContentHandler contentHandler)
     throws SAXException {
   final AttributesImpl ai = new AttributesImpl();
   IOUtils.addAttribute(ai, "interface", interf.getInterfacename());
   IOUtils.indent(contentHandler, 3);
   contentHandler.startElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.INTERFACE,
       ComponentDescriptorIO.INTERFACE_QNAME,
       ai);
   contentHandler.endElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.INTERFACE,
       ComponentDescriptorIO.INTERFACE_QNAME);
   IOUtils.newline(contentHandler);
 }
示例#8
0
 /**
  * Write the xml for a {@link Implementation}.
  *
  * @param implementation
  * @param contentHandler
  * @throws SAXException
  */
 protected static void generateXML(Implementation implementation, ContentHandler contentHandler)
     throws SAXException {
   final AttributesImpl ai = new AttributesImpl();
   IOUtils.addAttribute(ai, "class", implementation.getClassame());
   IOUtils.indent(contentHandler, 2);
   contentHandler.startElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.IMPLEMENTATION,
       ComponentDescriptorIO.IMPLEMENTATION_QNAME,
       ai);
   contentHandler.endElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.IMPLEMENTATION,
       ComponentDescriptorIO.IMPLEMENTATION_QNAME);
   IOUtils.newline(contentHandler);
 }
示例#9
0
 /**
  * This method is always the second method of all callbacks in all handlers to be invoked
  * (setDocumentLocator is always first).
  */
 private void startDocument() throws JDOMException {
   try {
     contentHandler.startDocument();
   } catch (SAXException se) {
     throw new JDOMException("Exception in startDocument", se);
   }
 }
示例#10
0
 /**
  * This will be called for each chunk of character data encountered.
  *
  * @param elementText all text in an element, including whitespace.
  */
 private void characters(String elementText) throws JDOMException {
   char[] c = elementText.toCharArray();
   try {
     contentHandler.characters(c, 0, c.length);
   } catch (SAXException se) {
     throw new JDOMException("Exception in characters", se);
   }
 }
示例#11
0
 @Override
 protected void pi(final byte[] name, final byte[] value) throws IOException {
   try {
     contentHandler.processingInstruction(string(name), string(value));
   } catch (final SAXException ex) {
     throw new IOException(ex);
   }
 }
示例#12
0
 /** Convert an Object to a String and generate SAX characters events. */
 public static void objectToCharacters(Object o, ContentHandler contentHandler) {
   try {
     char[] charValue = (o == null) ? null : o.toString().toCharArray();
     if (charValue != null) contentHandler.characters(charValue, 0, charValue.length);
   } catch (Exception e) {
     throw new OXFException(e);
   }
 }
示例#13
0
  public void parse(File file, ContentHandler handler) throws IOException {

    BufferedReader readerWithBuffer = null;
    String line;

    try {
      readerWithBuffer = new BufferedReader(new FileReader(file));
    } catch (FileNotFoundException exc) {
      System.out.println("Error opening file ...");
    }

    while ((line = readerWithBuffer.readLine()) != null) {
      if (line.startsWith("#")) handler.commentLine(line);
      else handler.defaultLine(line);
    }

    readerWithBuffer.close();
  }
示例#14
0
  /** Always the last method of all callbacks in all handlers to be invoked. */
  private void endDocument() throws JDOMException {
    try {
      contentHandler.endDocument();

      // reset locator
      locator = null;
    } catch (SAXException se) {
      throw new JDOMException("Exception in endDocument", se);
    }
  }
示例#15
0
 @Override
 protected void text(final byte[] value, final FTPos ftp) throws IOException {
   try {
     final String s = string(value);
     final char[] c = s.toCharArray();
     contentHandler.characters(c, 0, c.length);
   } catch (final SAXException ex) {
     throw new IOException(ex);
   }
 }
示例#16
0
  /**
   * Write the xml for a {@link Component}.
   *
   * @param component
   * @param contentHandler
   * @throws SAXException
   */
  protected static void generateXML(
      final String namespace,
      final Component component,
      final ContentHandler contentHandler,
      final boolean isScrPrivateFile)
      throws SAXException {
    final AttributesImpl ai = new AttributesImpl();
    IOUtils.addAttribute(ai, COMPONENT_ATTR_ENABLED, component.isEnabled());
    IOUtils.addAttribute(ai, COMPONENT_ATTR_IMMEDIATE, component.isImmediate());
    IOUtils.addAttribute(ai, COMPONENT_ATTR_NAME, component.getName());
    IOUtils.addAttribute(ai, COMPONENT_ATTR_FACTORY, component.getFactory());

    // attributes new in 1.1
    if (NAMESPACE_URI_1_1.equals(namespace) || NAMESPACE_URI_1_1_FELIX.equals(namespace)) {
      IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy());
      IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate());
      IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate());
      IOUtils.addAttribute(ai, COMPONENT_ATTR_MODIFIED, component.getModified());
    }

    IOUtils.indent(contentHandler, 1);
    contentHandler.startElement(
        namespace, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME, ai);
    IOUtils.newline(contentHandler);
    generateXML(component.getImplementation(), contentHandler);
    if (component.getService() != null) {
      generateXML(component.getService(), contentHandler);
    }
    if (component.getProperties() != null) {
      for (final Property property : component.getProperties()) {
        generateXML(property, contentHandler, isScrPrivateFile);
      }
    }
    if (component.getReferences() != null) {
      for (final Reference reference : component.getReferences()) {
        generateXML(namespace, reference, contentHandler, isScrPrivateFile);
      }
    }
    IOUtils.indent(contentHandler, 1);
    contentHandler.endElement(
        namespace, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME);
    IOUtils.newline(contentHandler);
  }
示例#17
0
  /**
   * This will invoke the <code>endElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   */
  private void endElement(Element element) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    try {
      contentHandler.endElement(namespaceURI, localName, rawName);
    } catch (SAXException se) {
      throw new JDOMException("Exception in endElement", se);
    }
  }
示例#18
0
 /**
  * This will invoke the <code>ContentHandler.skippedEntity</code> callback when an entity
  * reference is encountered.
  *
  * @param entity <code>EntityRef</code>.
  */
 private void entityRef(EntityRef entity) throws JDOMException {
   if (entity != null) {
     try {
       // No need to worry about appending a '%' character as
       // we do not support parameter entities
       contentHandler.skippedEntity(entity.getName());
     } catch (SAXException se) {
       throw new JDOMException("Exception in entityRef", se);
     }
   }
 }
示例#19
0
 /**
  * This will invoke the <code>ContentHandler.processingInstruction</code> callback when a
  * processing instruction is encountered.
  *
  * @param pi <code>ProcessingInstruction</code> containing target and data.
  */
 private void processingInstruction(ProcessingInstruction pi) throws JDOMException {
   if (pi != null) {
     String target = pi.getTarget();
     String data = pi.getData();
     try {
       contentHandler.processingInstruction(target, data);
     } catch (SAXException se) {
       throw new JDOMException("Exception in processingInstruction", se);
     }
   }
 }
示例#20
0
 /**
  * This will invoke the <code>endPrefixMapping</code> callback in the <code>ContentHandler</code>
  * when a namespace is goes out of scope in the <code>Document</code>.
  *
  * @param namespaces <code>List</code> stack of Namespaces in scope.
  * @param previouslyDeclaredNamespaces number of previously declared namespaces
  */
 private void endPrefixMapping(NamespaceStack namespaces, int previouslyDeclaredNamespaces)
     throws JDOMException {
   while (namespaces.size() > previouslyDeclaredNamespaces) {
     String prefix = namespaces.pop();
     try {
       contentHandler.endPrefixMapping(prefix);
     } catch (SAXException se) {
       throw new JDOMException("Exception in endPrefixMapping", se);
     }
   }
 }
示例#21
0
 /**
  * Write the xml for a {@link Service}.
  *
  * @param service
  * @param contentHandler
  * @throws SAXException
  */
 protected static void generateXML(Service service, ContentHandler contentHandler)
     throws SAXException {
   final AttributesImpl ai = new AttributesImpl();
   IOUtils.addAttribute(ai, "servicefactory", String.valueOf(service.isServicefactory()));
   IOUtils.indent(contentHandler, 2);
   contentHandler.startElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.SERVICE,
       ComponentDescriptorIO.SERVICE_QNAME,
       ai);
   if (service.getInterfaces() != null && service.getInterfaces().size() > 0) {
     IOUtils.newline(contentHandler);
     for (final Interface interf : service.getInterfaces()) {
       generateXML(interf, contentHandler);
     }
     IOUtils.indent(contentHandler, 2);
   }
   contentHandler.endElement(
       INNER_NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME);
   IOUtils.newline(contentHandler);
 }
示例#22
0
 /**
  * Read characters from a Reader and generate SAX characters events.
  *
  * <p>The caller has to close the Reader if needed.
  */
 public static void readerToCharacters(Reader reader, ContentHandler contentHandler) {
   try {
     // Work with buffered Reader
     reader = new BufferedReader(reader);
     // Read and write in chunks
     char[] buf = new char[1024];
     int count;
     while ((count = reader.read(buf)) != -1) contentHandler.characters(buf, 0, count);
   } catch (Exception e) {
     throw new OXFException(e);
   }
 }
示例#23
0
 @Override
 protected void finishClose() throws IOException {
   try {
     final String uri = string(namespaces.get(elem.prefix()));
     final String lname = string(elem.local());
     final String rname = string(elem.string());
     contentHandler.endElement(uri, lname, rname);
     namespaces = namespaces.getParent();
   } catch (final SAXException ex) {
     throw new IOException(ex);
   }
 }
示例#24
0
 /**
  * Write the xml for a {@link Property}.
  *
  * @param property
  * @param contentHandler
  * @throws SAXException
  */
 protected static void generateXML(
     Property property, ContentHandler contentHandler, boolean isScrPrivateFile)
     throws SAXException {
   final AttributesImpl ai = new AttributesImpl();
   IOUtils.addAttribute(ai, "name", property.getName());
   IOUtils.addAttribute(ai, "type", property.getType());
   IOUtils.addAttribute(ai, "value", property.getValue());
   // we have to write more information if this is our scr private file
   if (isScrPrivateFile) {
     IOUtils.addAttribute(ai, "private", String.valueOf(property.isPrivate()));
     if (property.getLabel() != null) {
       IOUtils.addAttribute(ai, "label", String.valueOf(property.getLabel()));
     }
     if (property.getDescription() != null) {
       IOUtils.addAttribute(ai, "description", String.valueOf(property.getDescription()));
     }
     if (property.getCardinality() != null) {
       IOUtils.addAttribute(ai, "cardinality", String.valueOf(property.getCardinality()));
     }
   }
   IOUtils.indent(contentHandler, 2);
   contentHandler.startElement(
       INNER_NAMESPACE_URI,
       ComponentDescriptorIO.PROPERTY,
       ComponentDescriptorIO.PROPERTY_QNAME,
       ai);
   if (property.getMultiValue() != null && property.getMultiValue().length > 0) {
     // generate a new line first
     IOUtils.text(contentHandler, "\n");
     for (int i = 0; i < property.getMultiValue().length; i++) {
       IOUtils.indent(contentHandler, 3);
       IOUtils.text(contentHandler, property.getMultiValue()[i]);
       IOUtils.newline(contentHandler);
     }
     IOUtils.indent(contentHandler, 2);
   }
   contentHandler.endElement(
       INNER_NAMESPACE_URI, ComponentDescriptorIO.PROPERTY, ComponentDescriptorIO.PROPERTY_QNAME);
   IOUtils.newline(contentHandler);
 }
示例#25
0
  /**
   * This will invoke the <code>ContentHandler.startPrefixMapping</code> callback when a new
   * namespace is encountered in the <code>Document</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   * @return <code>Attributes</code> declaring the namespaces local to <code>element</code> or
   *     <code>null</code>.
   */
  private Attributes startPrefixMapping(Element element, NamespaceStack namespaces)
      throws JDOMException {
    AttributesImpl nsAtts = null; // The namespaces as xmlns attributes

    Namespace ns = element.getNamespace();
    if (ns != Namespace.XML_NAMESPACE) {
      String prefix = ns.getPrefix();
      String uri = namespaces.getURI(prefix);
      if (!ns.getURI().equals(uri)) {
        namespaces.push(ns);
        nsAtts = this.addNsAttribute(nsAtts, ns);
        try {
          contentHandler.startPrefixMapping(prefix, ns.getURI());
        } catch (SAXException se) {
          throw new JDOMException("Exception in startPrefixMapping", se);
        }
      }
    }

    // Fire additional namespace declarations
    List additionalNamespaces = element.getAdditionalNamespaces();
    if (additionalNamespaces != null) {
      Iterator itr = additionalNamespaces.iterator();
      while (itr.hasNext()) {
        ns = (Namespace) itr.next();
        String prefix = ns.getPrefix();
        String uri = namespaces.getURI(prefix);
        if (!ns.getURI().equals(uri)) {
          namespaces.push(ns);
          nsAtts = this.addNsAttribute(nsAtts, ns);
          try {
            contentHandler.startPrefixMapping(prefix, ns.getURI());
          } catch (SAXException se) {
            throw new JDOMException("Exception in startPrefixMapping", se);
          }
        }
      }
    }
    return nsAtts;
  }
示例#26
0
  /**
   * Write the xml for a {@link Reference}.
   *
   * @param reference
   * @param contentHandler
   * @throws SAXException
   */
  protected static void generateXML(
      final String namespace,
      Reference reference,
      ContentHandler contentHandler,
      boolean isScrPrivateFile)
      throws SAXException {
    final AttributesImpl ai = new AttributesImpl();
    IOUtils.addAttribute(ai, "name", reference.getName());
    IOUtils.addAttribute(ai, "interface", reference.getInterfacename());
    IOUtils.addAttribute(ai, "cardinality", reference.getCardinality());
    IOUtils.addAttribute(ai, "policy", reference.getPolicy());
    IOUtils.addAttribute(ai, "target", reference.getTarget());
    IOUtils.addAttribute(ai, "bind", reference.getBind());
    IOUtils.addAttribute(ai, "unbind", reference.getUnbind());

    // attributes new in 1.1-felix (FELIX-1893)
    if (NAMESPACE_URI_1_1_FELIX.equals(namespace)) {
      IOUtils.addAttribute(ai, "updated", reference.getUpdated());
    }

    if (isScrPrivateFile) {
      IOUtils.addAttribute(ai, "checked", String.valueOf(reference.isChecked()));
      IOUtils.addAttribute(ai, "strategy", reference.getStrategy());
    }
    IOUtils.indent(contentHandler, 2);
    contentHandler.startElement(
        INNER_NAMESPACE_URI,
        ComponentDescriptorIO.REFERENCE,
        ComponentDescriptorIO.REFERENCE_QNAME,
        ai);
    contentHandler.endElement(
        INNER_NAMESPACE_URI,
        ComponentDescriptorIO.REFERENCE,
        ComponentDescriptorIO.REFERENCE_QNAME);
    IOUtils.newline(contentHandler);
  }
示例#27
0
 public static void streamNullDocument(ContentHandler contentHandler) throws SAXException {
   contentHandler.startDocument();
   contentHandler.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI);
   final AttributesImpl attributes = new AttributesImpl();
   attributes.addAttribute(XMLConstants.XSI_URI, "nil", "xsi:nil", "CDATA", "true");
   contentHandler.startElement("", "null", "null", attributes);
   contentHandler.endElement("", "null", "null");
   contentHandler.endPrefixMapping(XMLConstants.XSI_PREFIX);
   contentHandler.endDocument();
 }
示例#28
0
  /**
   * This method tells you the line of the XML file being parsed. For an in-memory document, it's
   * meaningless. The location is only valid for the current parsing lifecycle, but the document has
   * already been parsed. Therefore, it returns -1 for both line and column numbers.
   *
   * @param document JDOM <code>Document</code>.
   */
  private void documentLocator(Document document) {
    locator = new JDOMLocator();
    String publicID = null;
    String systemID = null;

    if (document != null) {
      DocType docType = document.getDocType();
      if (docType != null) {
        publicID = docType.getPublicID();
        systemID = docType.getSystemID();
      }
    }
    locator.setPublicId(publicID);
    locator.setSystemId(systemID);
    locator.setLineNumber(-1);
    locator.setColumnNumber(-1);

    contentHandler.setDocumentLocator(locator);
  }
示例#29
0
  @Override
  protected void finishOpen() throws IOException {
    try {
      final AttributesImpl attrs = new AttributesImpl();
      final int as = attributes.size();
      for (int a = 0; a < as; a++) {
        final byte[] name = attributes.name(a);
        final String uri = string(namespaces.get(prefix(name)));
        final String lname = string(local(name));
        final String rname = string(name);
        final String value = string(attributes.value(a));
        attrs.addAttribute(uri, lname, rname, null, value);
      }

      final String uri = string(namespaces.get(elem.prefix()));
      final String lname = string(elem.local());
      final String rname = string(elem.string());
      contentHandler.startElement(uri, lname, rname, attrs);

    } catch (final SAXException ex) {
      throw new IOException(ex);
    }
  }
示例#30
0
  /**
   * Stream processing of JSON text.
   *
   * @see ContentHandler
   * @param in
   * @param contentHandler
   * @param isResume - Indicates if it continues previous parsing operation. If set to true, resume
   *     parsing the old stream, and parameter 'in' will be ignored. If this method is called for
   *     the first time in this instance, isResume will be ignored.
   * @throws IOException
   * @throws ParseException
   */
  public void parse(Reader in, ContentHandler contentHandler, boolean isResume)
      throws IOException, ParseException {
    if (!isResume) {
      reset(in);
      handlerStatusStack = new LinkedList();
    } else {
      if (handlerStatusStack == null) {
        isResume = false;
        reset(in);
        handlerStatusStack = new LinkedList();
      }
    }

    LinkedList statusStack = handlerStatusStack;

    try {
      do {
        switch (status) {
          case S_INIT:
            contentHandler.startJSON();
            nextToken();
            switch (token.type) {
              case Yytoken.TYPE_VALUE:
                status = S_IN_FINISHED_VALUE;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.primitive(token.value)) return;
                break;
              case Yytoken.TYPE_LEFT_BRACE:
                status = S_IN_OBJECT;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startObject()) return;
                break;
              case Yytoken.TYPE_LEFT_SQUARE:
                status = S_IN_ARRAY;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startArray()) return;
                break;
              default:
                status = S_IN_ERROR; // inner switch
            }
            break;

          case S_IN_FINISHED_VALUE:
            nextToken();
            if (token.type == Yytoken.TYPE_EOF) {
              contentHandler.endJSON();
              status = S_END;
              return;
            } else {
              status = S_IN_ERROR;
              throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
            }

          case S_IN_OBJECT:
            nextToken();
            switch (token.type) {
              case Yytoken.TYPE_COMMA:
                break;
              case Yytoken.TYPE_VALUE:
                if (token.value instanceof String) {
                  String key = (String) token.value;
                  status = S_PASSED_PAIR_KEY;
                  statusStack.addFirst(new Integer(status));
                  if (!contentHandler.startObjectEntry(key)) return;
                } else {
                  status = S_IN_ERROR;
                }
                break;
              case Yytoken.TYPE_RIGHT_BRACE:
                if (statusStack.size() > 1) {
                  statusStack.removeFirst();
                  status = peekStatus(statusStack);
                } else {
                  status = S_IN_FINISHED_VALUE;
                }
                if (!contentHandler.endObject()) return;
                break;
              default:
                status = S_IN_ERROR;
                break; // inner switch
            }
            break;

          case S_PASSED_PAIR_KEY:
            nextToken();
            switch (token.type) {
              case Yytoken.TYPE_COLON:
                break;
              case Yytoken.TYPE_VALUE:
                statusStack.removeFirst();
                status = peekStatus(statusStack);
                if (!contentHandler.primitive(token.value)) return;
                if (!contentHandler.endObjectEntry()) return;
                break;
              case Yytoken.TYPE_LEFT_SQUARE:
                statusStack.removeFirst();
                statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
                status = S_IN_ARRAY;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startArray()) return;
                break;
              case Yytoken.TYPE_LEFT_BRACE:
                statusStack.removeFirst();
                statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
                status = S_IN_OBJECT;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startObject()) return;
                break;
              default:
                status = S_IN_ERROR;
            }
            break;

          case S_IN_PAIR_VALUE:
            statusStack.removeFirst();
            status = peekStatus(statusStack);
            if (!contentHandler.endObjectEntry()) return;
            break;
            /*
             * S_IN_PAIR_VALUE is just a marker to indicate the end of an object entry, it doesn't proccess any token,
             * therefore delay consuming token until next round.
             */

          case S_IN_ARRAY:
            nextToken();
            switch (token.type) {
              case Yytoken.TYPE_COMMA:
                break;
              case Yytoken.TYPE_VALUE:
                if (!contentHandler.primitive(token.value)) return;
                break;
              case Yytoken.TYPE_RIGHT_SQUARE:
                if (statusStack.size() > 1) {
                  statusStack.removeFirst();
                  status = peekStatus(statusStack);
                } else {
                  status = S_IN_FINISHED_VALUE;
                }
                if (!contentHandler.endArray()) return;
                break;
              case Yytoken.TYPE_LEFT_BRACE:
                status = S_IN_OBJECT;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startObject()) return;
                break;
              case Yytoken.TYPE_LEFT_SQUARE:
                status = S_IN_ARRAY;
                statusStack.addFirst(new Integer(status));
                if (!contentHandler.startArray()) return;
                break;
              default:
                status = S_IN_ERROR; // inner switch
            }
            break;

          case S_END:
            return;

          case S_IN_ERROR:
            throw new ParseException(
                getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); // switch
        }
        if (status == S_IN_ERROR) {
          throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
        }
      } while (token.type != Yytoken.TYPE_EOF);
    } catch (IOException ie) {
      status = S_IN_ERROR;
      throw ie;
    } catch (ParseException pe) {
      status = S_IN_ERROR;
      throw pe;
    } catch (RuntimeException re) {
      status = S_IN_ERROR;
      throw re;
    } catch (Error e) {
      status = S_IN_ERROR;
      throw e;
    }

    status = S_IN_ERROR;
    throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
  }