public <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) throws JAXBException { return context.getBeanInfo(clazz,true); }
public ValueListBeanInfoImpl(JAXBContextImpl owner, Class arrayType) throws JAXBException { super(owner, null, arrayType, false, true, false); this.itemType = jaxbType.getComponentType(); this.xducer = owner.getBeanInfo(arrayType.getComponentType(),true).getTransducer(); assert xducer!=null; }
/** * Gets the ID value from an identifiable object. */ private String getIdFromObject(Object identifiableObject) throws SAXException, JAXBException { return grammar.getBeanInfo(identifiableObject,true).getId(identifiableObject,this); }
/** * Gets the {@link JaxBeanInfo} object that can handle * the given JAXB-bound class. * * @param fatal * if true, the failure to look up will throw an exception. * Otherwise it will just return null. */ public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz,boolean fatal) throws JAXBException { JaxBeanInfo<T> bi = getBeanInfo(clazz); if(bi!=null) return bi; if(fatal) throw new JAXBException(clazz.getName()+" is not known to this context"); return null; }
public QName getElementName(Class o) throws JAXBException { JaxBeanInfo bi = getBeanInfo(o,true); if(!bi.isElement()) return null; return new QName(bi.getElementNamespaceURI(o),bi.getElementLocalName(o)); }
public QName getElementName(Object o) throws JAXBException { JaxBeanInfo bi = getBeanInfo(o,true); if(!bi.isElement()) return null; return new QName(bi.getElementNamespaceURI(o),bi.getElementLocalName(o)); }
public XmlNode updateXML(Object jaxbObject, XmlNode xmlNode) throws JAXBException { if(jaxbObject==null || xmlNode==null) throw new IllegalArgumentException(); // TODO // for now just marshal // TODO: object model independenc Element e = (Element)xmlNode; Node ns = e.getNextSibling(); Node p = e.getParentNode(); p.removeChild(e); // if the type object is passed, the following step is necessary to make // the marshalling successful. JaxBeanInfo bi = context.getBeanInfo(jaxbObject, true); if(!bi.isElement()) jaxbObject = new JAXBElement(new QName(e.getNamespaceURI(),e.getLocalName()),bi.jaxbType,jaxbObject); getMarshaller().marshal(jaxbObject,p); Node newNode = p.getLastChild(); p.removeChild(newNode); p.insertBefore(newNode,ns); return (XmlNode)newNode; }
public String next() throws SAXException, JAXBException { last = i.next(); String id = context.grammar.getBeanInfo(last,true).getId(last,context); if(id==null) { context.errorMissingId(last); } return id; } }
/** * Gets the {@link JaxBeanInfo} object that can handle * the given JAXB-bound object. * * @param fatal * if true, the failure to look up will throw an exception. * Otherwise it will just return null. */ public final JaxBeanInfo getBeanInfo(Object o,boolean fatal) throws JAXBException { JaxBeanInfo bi = getBeanInfo(o); if(bi!=null) return bi; if(fatal) { if(o instanceof Document) throw new JAXBException(Messages.ELEMENT_NEEDED_BUT_FOUND_DOCUMENT.format(o.getClass())); throw new JAXBException(Messages.UNKNOWN_CLASS.format(o.getClass())); } return null; }
/** * Gets the value of the xmime:contentType attribute on the given object, or null * if for some reason it couldn't be found, including any error. */ public String getXMIMEContentType( Object o ) { JaxBeanInfo bi = getBeanInfo(o); if(!(bi instanceof ClassBeanInfoImpl)) return null; ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; for (Property p : cb.properties) { if (p instanceof AttributeProperty) { AttributeProperty ap = (AttributeProperty) p; if(ap.attName.equals(WellKnownNamespace.XML_MIME_URI,"contentType")) try { return (String)ap.xacc.print(o); } catch (AccessorException e) { return null; } catch (SAXException e) { return null; } catch (ClassCastException e) { return null; } } } return null; }
public RawAccessor getElementPropertyAccessor(Class wrapperBean, String nsUri, String localName) throws JAXBException { JaxBeanInfo bi = getBeanInfo(wrapperBean,true); if(!(bi instanceof ClassBeanInfoImpl)) throw new JAXBException(wrapperBean+" is not a bean"); for( ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; cb!=null; cb=cb.superClazz) { for (Property p : cb.properties) { final Accessor acc = p.getElementPropertyAccessor(nsUri,localName); if(acc!=null) return new RawAccessor() { // Accessor.set/get are designed for unmarshaller/marshaller, and hence // they go through an adapter behind the scene. // this isn't desirable for JAX-WS, which essentially uses this method // just as a reflection library. So use the "unadapted" version to // achieve the desired semantics public Object get(Object bean) throws AccessorException { return acc.getUnadapted(bean); } public void set(Object bean, Object value) throws AccessorException { acc.setUnadapted(bean,value); } }; } } throw new JAXBException(new QName(nsUri,localName)+" is not a valid property on "+wrapperBean); }
w.childAsXsiType(v,fieldName,w.grammar.getBeanInfo(Object.class), addNilDecl && nillable); } else { w.startElement(tt.tagName,null);
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { ValueT v = acc.get(o); if(v!=null) { try { JaxBeanInfo bi = w.grammar.getBeanInfo(v,true); if(bi.jaxbType==Object.class && domHandler!=null) // even if 'v' is a DOM node, it always derive from Object, // so the getBeanInfo returns BeanInfo for Object w.writeDom(v,domHandler,o,fieldName); else bi.serializeRoot(v,w); } catch (JAXBException e) { w.reportError(fieldName,e); // recover by ignoring this property } } }
public String print(BeanT bean) throws AccessorException, SAXException { TargetT target = acc.get(bean); if(target==null) return null; XMLSerializer w = XMLSerializer.getInstance(); try { String id = w.grammar.getBeanInfo(target,true).getId(target,w); if(id==null) w.errorMissingId(target); return id; } catch (JAXBException e) { w.reportError(null,e); return null; } }
protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException { ListIterator<ItemT> itr = lister.iterator(list, w); while(itr.hasNext()) { try { ItemT item = itr.next(); if (item != null) { if(isMixed && item.getClass()==String.class) { w.text((String)item,null); } else { JaxBeanInfo bi = w.grammar.getBeanInfo(item,true); if(bi.jaxbType==Object.class && domHandler!=null) // even if 'v' is a DOM node, it always derive from Object, // so the getBeanInfo returns BeanInfo for Object w.writeDom(item,domHandler,o,fieldName); else bi.serializeRoot(item,w); } } } catch (JAXBException e) { w.reportError(fieldName,e); // recover by ignoring this item } } }
public void childAsRoot(Object obj) throws JAXBException, IOException, SAXException, XMLStreamException { final JaxBeanInfo beanInfo = grammar.getBeanInfo(obj, true); // since the same object will be reported to childAsRoot or // childAsXsiType, don't make it a part of the collision check. // but we do need to push it so that getXMIMEContentType will work. cycleDetectionStack.pushNocheck(obj); final boolean lookForLifecycleMethods = beanInfo.lookForLifecycleMethods(); if (lookForLifecycleMethods) { fireBeforeMarshalEvents(beanInfo, obj); } beanInfo.serializeRoot(obj,this); if (lookForLifecycleMethods) { fireAfterMarshalEvents(beanInfo, obj); } cycleDetectionStack.pop(); }
tbi = grammar.getBeanInfo(e.getDeclaredType(),true); } catch (JAXBException x) {
private Object associativeUnmarshal(XmlNode xmlNode, boolean inplace, Class expectedType) throws JAXBException { if (xmlNode == null) throw new IllegalArgumentException(); JaxBeanInfo bi = null; if(expectedType!=null) bi = context.getBeanInfo(expectedType, true); InterningXmlVisitor handler = new InterningXmlVisitor( getUnmarshaller().createUnmarshallerHandler(scanner,inplace,bi)); scanner.setContentHandler(new SAXConnector(handler,scanner.getLocator())); try { scanner.scan(xmlNode); } catch( SAXException e ) { throw unmarshaller.createUnmarshalException(e); } return handler.getContext().getResult(); }
/** * On top of {@link JAXBContextImpl#selectRootLoader(State, TagName)}, * this method also consults {@link ClassResolver}. * * @throws SAXException * if {@link ValidationEventHandler} reported a failure. */ public Loader selectRootLoader(State state, TagName tag) throws SAXException { try { Loader l = getJAXBContext().selectRootLoader(state, tag); if(l!=null) return l; if(classResolver!=null) { Class<?> clazz = classResolver.resolveElementName(tag.uri, tag.local); if(clazz!=null) { JAXBContextImpl enhanced = getJAXBContext().createAugmented(clazz); JaxBeanInfo<?> bi = enhanced.getBeanInfo(clazz); return bi.getLoader(enhanced,true); } } } catch (RuntimeException e) { throw e; } catch (Exception e) { handleError(e); } return null; }
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }