private void invokeUnmarshallCallback(Method m, Object child, UnmarshallerImpl unm, Object parent) throws SAXException { try { m.invoke(child,unm,parent); } catch (IllegalAccessException e) { UnmarshallingContext.getInstance().handleError(e, false); } catch (InvocationTargetException e) { UnmarshallingContext.getInstance().handleError(e, false); } }
public URI parse(CharSequence text) throws SAXException { try { return new URI(text.toString()); } catch (URISyntaxException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public QName parse(CharSequence text) throws SAXException { try { return DatatypeConverterImpl._parseQName(text.toString(),UnmarshallingContext.getInstance()); } catch (IllegalArgumentException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public URI parse(CharSequence text) throws SAXException { try { return new URI(text.toString()); } catch (URISyntaxException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public Object createInstance() throws SAXException { try { return method.invoke(factorInstance); } catch (IllegalAccessException e) { getInstance().handleError(e,false); } catch (InvocationTargetException e) { getInstance().handleError(e,false); } return null; // can never be executed } }
public XMLGregorianCalendar parse(CharSequence lexical) throws SAXException { try { return DatatypeConverterImpl.getDatatypeFactory() .newXMLGregorianCalendar(lexical.toString().trim()); // (.trim() - issue 396) } catch (Exception e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public Class parse(CharSequence text) throws SAXException { TODO.checkSpec("JSR222 Issue #42"); try { String name = WhiteSpaceProcessor.trim(text).toString(); ClassLoader cl = UnmarshallingContext.getInstance().classLoader; if(cl==null) cl = Thread.currentThread().getContextClassLoader(); if(cl!=null) return cl.loadClass(name); else return Class.forName(name); } catch (ClassNotFoundException e) { UnmarshallingContext.getInstance().handleError(e); return null; } } public String print(Class v) {
public DataHandler unmarshal(String cid) { AttachmentUnmarshaller au = UnmarshallingContext.getInstance().parent.getAttachmentUnmarshaller(); // TODO: error check return au.getAttachmentAsDataHandler(cid); }
public UUID parse(CharSequence text) throws SAXException { TODO.checkSpec("JSR222 Issue #42"); try { return UUID.fromString(WhiteSpaceProcessor.trim(text).toString()); } catch (IllegalArgumentException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public URL parse(CharSequence text) throws SAXException { TODO.checkSpec("JSR222 Issue #42"); try { return new URL(WhiteSpaceProcessor.trim(text).toString()); } catch (MalformedURLException e) { UnmarshallingContext.getInstance().handleError(e); return null; } } public String print(URL v) {
public Image parse(CharSequence text) throws SAXException { try { InputStream is; if(text instanceof Base64Data) is = ((Base64Data)text).getInputStream(); else is = new ByteArrayInputStream(decodeBase64(text)); // TODO: buffering is inefficient // technically we should check the MIME type here, but // normally images can be content-sniffed. // so the MIME type check will only make us slower and draconian, both of which // JAXB 2.0 isn't interested. try { return ImageIO.read(is); } finally { is.close(); } } catch (IOException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
@Override public Collection<QName> getExpectedChildElements() { return getInstance().getJAXBContext().getValidRootNames(); }
@Override public ValueT parse(CharSequence lexical) throws AccessorException, SAXException { String value = WhiteSpaceProcessor.trim(lexical).toString(); UnmarshallingContext.getInstance().addToIdTable(value); return core.parse(value); } }
public DataHandler parse(CharSequence text) { if(text instanceof Base64Data) return ((Base64Data)text).getDataHandler(); else return new DataHandler(new ByteArrayDataSource(decodeBase64(text), UnmarshallingContext.getInstance().getXMIMEContentType())); }
public BeanT parse(CharSequence lexical) throws AccessorException, SAXException { UnmarshallingContext ctxt = UnmarshallingContext.getInstance(); BeanT inst; if(ctxt!=null) inst = (BeanT)ctxt.createInstance(ownerClass); else // when this runs for parsing enum constants, // there's no UnmarshallingContext. inst = ClassFactory.create(ownerClass); xacc.parse(inst,lexical); return inst; }
public Source parse(CharSequence text) throws SAXException { try { if(text instanceof Base64Data) return new DataSourceSource( ((Base64Data)text).getDataHandler() ); else return new DataSourceSource(new ByteArrayDataSource(decodeBase64(text), UnmarshallingContext.getInstance().getXMIMEContentType())); } catch (MimeTypeParseException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public static void reportError(String msg, Exception nested, boolean canRecover) throws SAXException { UnmarshallingContext context = UnmarshallingContext.getInstance(); context.handleEvent( new ValidationEventImpl( canRecover? ValidationEvent.ERROR : ValidationEvent.FATAL_ERROR, msg, context.getLocator().getLocation(), nested ), canRecover ); }
@SuppressWarnings({"StringEquality"}) protected final void reportUnexpectedChildElement(TagName ea, boolean canRecover) throws SAXException { if (canRecover) { // this error happens particurly often (when input documents contain a lot of unexpected elements to be ignored), // so don't bother computing all the messages and etc if we know that // there's no event handler to receive the error in the end. See #286 UnmarshallingContext context = UnmarshallingContext.getInstance(); if (!context.parent.hasEventHandler() // is somebody listening? || !context.shouldErrorBeReported()) // should we report error? return; } if(ea.uri!=ea.uri.intern() || ea.local!=ea.local.intern()) reportError(Messages.UNINTERNED_STRINGS.format(), canRecover ); else reportError(Messages.UNEXPECTED_ELEMENT.format(ea.uri,ea.local,computeExpectedElements()), canRecover ); }
public void parse(final BeanT bean, CharSequence lexical) throws AccessorException, SAXException { final String idref = WhiteSpaceProcessor.trim(lexical).toString(); final UnmarshallingContext context = UnmarshallingContext.getInstance();
@Override public Collection<QName> getExpectedElements() { try { return UnmarshallingContext.getInstance().getCurrentExpectedElements(); } catch (NullPointerException npe) { // TODO: need to check what could be done in JAXB in order to prevent the npe // thrown from com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext#1206 } // something went wrong - return empty list return Collections.emptyList(); }