Exemplo n.º 1
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);
    }
  }
  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.º 3
0
 public void endElement(String uri, String localName, String qName) throws SAXException {
   processText(false);
   tagName.uri = uri;
   tagName.local = localName;
   tagName.qname = qName;
   next.endElement(tagName);
 }
Exemplo n.º 4
0
 public void startElement(TagName tagName) throws SAXException {
   if (tagName.local.equals("Include") && tagName.uri.equals(WellKnownNamespace.XOP)) {
     // found xop:Include
     String href = tagName.atts.getValue("href");
     DataHandler attachment = au.getAttachmentAsDataHandler(href);
     if (attachment == null) {
       // report an error and ignore
       parent.getEventHandler().handleEvent(null);
       // TODO
     }
     base64data.set(attachment);
     next.text(base64data);
     inXopInclude = true;
     followXop = true;
   } else next.startElement(tagName);
 }
 public void startElement(TagName tagName) throws SAXException {
   attributes.setAttributes(tagName.atts);
   tagName.atts = attributes;
   tagName.uri = intern(tagName.uri);
   tagName.local = intern(tagName.local);
   next.startElement(tagName);
 }
Exemplo n.º 6
0
 public void endElement(TagName tagName) throws SAXException {
   if (inXopInclude) {
     // consume </xop:Include> by ourselves.
     inXopInclude = false;
     followXop = true;
     return;
   }
   next.endElement(tagName);
 }
Exemplo n.º 7
0
  public void startElement(String uri, String local, String qname, Attributes atts)
      throws SAXException {
    // work gracefully with misconfigured parsers that don't support namespaces
    if (uri == null || uri.length() == 0) uri = "";
    if (local == null || local.length() == 0) local = qname;
    if (qname == null || qname.length() == 0) qname = local;

    boolean ignorable = true;
    StructureLoader sl;

    // not null only if element content is processed (StructureLoader is used)
    // ugly
    if ((sl = this.context.getStructureLoader()) != null) {
      ignorable = ((ClassBeanInfoImpl) sl.getBeanInfo()).hasElementOnlyContentModel();
    }

    processText(ignorable);

    tagName.uri = uri;
    tagName.local = local;
    tagName.qname = qname;
    tagName.atts = atts;
    next.startElement(tagName);
  }
Exemplo n.º 8
0
 public void startDocument() throws SAXException {
   next.startDocument(loc, null);
 }
 public void startPrefixMapping(String prefix, String nsUri) throws SAXException {
   next.startPrefixMapping(intern(prefix), intern(nsUri));
 }
Exemplo n.º 10
0
 public void endDocument() throws SAXException {
   next.endDocument();
 }
Exemplo n.º 11
0
 public void startDocument(LocatorEx loc, NamespaceContext nsContext) throws SAXException {
   next.startDocument(loc, nsContext);
 }
Exemplo n.º 12
0
 public TextPredictor getPredictor() {
   return next.getPredictor();
 }
Exemplo n.º 13
0
 public UnmarshallingContext getContext() {
   return next.getContext();
 }
Exemplo n.º 14
0
 public void text(CharSequence pcdata) throws SAXException {
   if (!followXop) next.text(pcdata);
   else followXop = false;
 }
Exemplo n.º 15
0
 public void endPrefixMapping(String prefix) throws SAXException {
   next.endPrefixMapping(prefix);
 }
Exemplo n.º 16
0
 public void startPrefixMapping(String prefix, String nsUri) throws SAXException {
   next.startPrefixMapping(prefix, nsUri);
 }
 public void endElement(TagName tagName) throws SAXException {
   tagName.uri = intern(tagName.uri);
   tagName.local = intern(tagName.local);
   next.endElement(tagName);
 }
Exemplo n.º 18
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;
 }
Exemplo n.º 19
0
 private void processText(boolean ignorable) throws SAXException {
   if (predictor.expectText() && (!ignorable || !WhiteSpaceProcessor.isWhiteSpace(buffer)))
     next.text(buffer);
   buffer.setLength(0);
 }
 public void text(CharSequence pcdata) throws SAXException {
   next.text(pcdata);
 }