public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
      throw new IllegalArgumentException(Messages.format(Messages.NULL_READER));
    }

    int eventType = reader.getEventType();
    if (eventType != XMLStreamConstants.START_ELEMENT
        && eventType != XMLStreamConstants.START_DOCUMENT) {
      // TODO: convert eventType into event name
      throw new IllegalStateException(Messages.format(Messages.ILLEGAL_READER_STATE, eventType));
    }

    XmlVisitor h = createUnmarshallerHandler(null, false, expectedType);
    StAXConnector connector = StAXStreamConnector.create(reader, h);

    try {
      connector.bridge();
    } catch (XMLStreamException e) {
      throw handleStreamException(e);
    }

    Object retVal = h.getContext().getResult();
    h.getContext().clearResult();
    return retVal;
  }
Exemplo n.º 2
0
  private Object unmarshal0(XMLEventReader reader, JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
      throw new IllegalArgumentException(Messages.format(Messages.NULL_READER));
    }

    try {
      XMLEvent event = reader.peek();

      if (!event.isStartElement() && !event.isStartDocument()) {
        // TODO: convert event into event name
        throw new IllegalStateException(
            Messages.format(Messages.ILLEGAL_READER_STATE, event.getEventType()));
      }

      // Quick hack until SJSXP fixes 6270116
      boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.stream.XMLReaderImpl");
      XmlVisitor h = createUnmarshallerHandler(null, false, expectedType);
      if (!isZephyr) {
        h = new InterningXmlVisitor(h);
      }
      new StAXEventConnector(reader, h).bridge();
      return h.getContext().getResult();
    } catch (XMLStreamException e) {
      throw handleStreamException(e);
    }
  }
Exemplo n.º 3
0
 public UnmarshallingContext getContext() {
   return next.getContext();
 }
Exemplo n.º 4
0
 /**
  * @param externalLocator If the caller is producing SAX events from sources other than Unicode
  *     and angle brackets, the caller can override the default SAX {@link Locator} object by this
  *     object to provide better location information.
  */
 public SAXConnector(XmlVisitor next, LocatorEx externalLocator) {
   this.next = next;
   this.context = next.getContext();
   this.predictor = next.getPredictor();
   this.loc = externalLocator;
 }