@Override protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) { try { UnmarshallingContext unmarshallingContext = (UnmarshallingContext) createUnmarshallingContext(); IXMLReader xmlReader = new StAXReaderWrapper(streamReader, null, true); unmarshallingContext.setDocument(xmlReader); return unmarshallingContext.unmarshalElement(); } catch (JiBXException ex) { throw convertJibxException(ex, false); } }
String uri = m_unmarshalContext.getNamespace(); String prefix = m_unmarshalContext.getPrefix(); String name = m_unmarshalContext.getName(); if (prefix != null) { name = prefix + ':' + name; int ncount = m_unmarshalContext.getNamespaceCount(); for (int i = 0; i < ncount; i++) { prefix = m_unmarshalContext.getNamespacePrefix(i); uri = m_unmarshalContext.getNamespaceUri(i); if (prefix == null) { element.setAttributeNS(XMLNS_NAMESPACE, "xmlns", uri); int acount = m_unmarshalContext.getAttributeCount(); for (int i = 0; i < acount; i++) { prefix = m_unmarshalContext.getAttributePrefix(i); uri = m_unmarshalContext.getAttributeNamespace(i); name = m_unmarshalContext.getAttributeName(i); if (prefix != null) { name = prefix + ':' + name; String value = m_unmarshalContext.getAttributeValue(i); element.setAttributeNS(uri, name, value); int event = m_unmarshalContext.nextToken(); if (event != IXMLReader.END_TAG) { unmarshalContent(element); m_unmarshalContext.nextToken();
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { return null; } else { // check for reference to existing ID String id = ctx.attributeText(null, getAttributeName(), null); if (id == null) { // no ID value supplied, unmarshal full definition obj = ctx.unmarshalElement(); } else { // find object based on ID obj = ctx.findID(id, 0); ctx.parsePastEndTag(m_uri, m_name); if (obj == null) { ctx.throwStartTagException("Reference to undefined ID " + id); } } } return obj; } }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { ctx.throwStartTagNameError(m_uri, m_name); } // create new hashmap if needed int size = ctx.attributeInt(m_uri, getSizeAttributeName(), DEFAULT_SIZE); Map map = (Map)obj; if (map == null) { map = new HashMap(size); } // process all entries present in document ctx.parsePastStartTag(m_uri, m_name); while (ctx.isAt(m_uri, getEntryElementName())) { Object key = ctx.attributeText(m_uri, getKeyAttributeName(), null); ctx.parsePastStartTag(m_uri, getEntryElementName()); Object value = ctx.unmarshalElement(); map.put(key, value); ctx.parsePastEndTag(m_uri, getEntryElementName()); } ctx.parsePastEndTag(m_uri, m_name); return map; } }
if (ctx.isAt(m_uri, m_name)) { ctx.parsePastStartTag(m_uri, m_name); } else { return null; while (!ctx.isEnd()) { Object item = ctx.unmarshalElement(); m_holder.add(item); ctx.parsePastEndTag(m_uri, m_name);
if (!ctx.isAt(m_uri, m_name)) { ctx.throwStartTagNameError(m_uri, m_name); int nscnt = ctx.getActiveNamespaceCount(); String xsdlead = null; for (int i = nscnt-1; i >= 0; i--) { String uri = ctx.getActiveNamespaceUri(i); if (XSD_NAMESPACE_URI.equals(uri)) { String prefix = ctx.getActiveNamespacePrefix(i); if (!"".equals(prefix)) { xsdlead = prefix + ':'; int size = ctx.attributeInt(m_uri, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE); Map map = (Map)obj; if (map == null) { ctx.parsePastStartTag(m_uri, m_name); String tdflt = xsdlead + "string"; while (ctx.isAt(m_uri, ENTRY_ELEMENT_NAME)) { Object key = ctx.attributeText(m_uri, KEY_ATTRIBUTE_NAME); String tname = ctx.attributeText(XSI_NAMESPACE_URI, TYPE_ATTRIBUTE_NAME, tdflt); String text = ctx.parseElementText(m_uri, ENTRY_ELEMENT_NAME); Object value = null; switch (type) { ctx.parsePastEndTag(m_uri, m_name);
ctx.parseToStartTag(null, m_name); obj = createInstance(ctx.attributeText(null, "class", null), ctx); if (obj != null) { for (int i = 0; i < ctx.getAttributeCount(); i++) { String name = ctx.getAttributeName(i); String value = ctx.getAttributeValue(i); if (ctx.getAttributeNamespace(i).length() == 0) { if (!"class".equals(name)) { map.put(name, value); ctx.skipElement(); return obj;
ctx.parseToStartTag(null, ELEMENT_NAME); String check = ctx.attributeText(null, "check-method", null); String dser = ctx.attributeText(null, "deserializer", null); String format = ctx.attributeText(null, "format-name", null); String jclas = ctx.attributeText(null, "java-class", null); String ser = ctx.attributeText(null, "serializer", null); String stype = ctx.attributeText(null, "type-name"); boolean valid = true; if (jclas == null && format == null) { vctx.addError("'java-class' attribute is required unless 'format-name' is used", ctx.getStackTop()); valid = false; vctx.addError('\'' + format + "' is not a valid built-in format name", ctx.getStackTop()); valid = false; } else { for (int i = 0; i < ctx.getAttributeCount(); i++) { String name = ctx.getAttributeName(i); if (ctx.getAttributeNamespace(i).length() == 0) { if (s_allowedAttributes.indexOf(name) < 0) { vctx.addWarning("Undefined attribute " + name, ctx.getStackTop()); ctx.skipElement(); if (valid) { return new JavaType(stype, null, jclas, format, ser, dser, check);
m_context.toStart(); String version = m_context.attributeText(m_attributeUri, m_attributeName, m_versionTexts[0]); context.setFromContext(m_context); return context.unmarshalElement();
public Object read(MessagePartInfo part, XMLStreamReader input) { Class<?> type = part.getTypeClass(); try { UnmarshallingContext ctx = getUnmarshallingContext(input, type); if (JibxSimpleTypes.isSimpleType(type)) { QName stype = part.getTypeQName(); QName ctype = part.getConcreteName(); if (ctx.isAt(ctype.getNamespaceURI(), ctype.getLocalPart())) { String text = ctx.parseElementText(ctype.getNamespaceURI(), ctype.getLocalPart()); return JibxSimpleTypes.toObject(text, stype); } else { throw new RuntimeException("Missing required element [" + ctype + "]"); } } else { return ctx.unmarshalElement(part.getTypeClass()); } } catch (JiBXException e) { throw new RuntimeException(e); } }
while (ctx.isStart()) { String element = ctx.getName(); if (PackageCustom.ELEMENT_NAME.equals(element)) { unmarshalPackage(global, null, ctx); unmarshalClass(global, null, ctx); } else { global.internalAddExtensionChild(ctx.unmarshalElement());
/** * Validate attributes of element from schema namespace. This allows any number of attributes from other namespaces * on the element. * * @param ictx unmarshalling context * @param attrs attributes array * @exception JiBXException on unmarshalling error */ protected void validateAttributes(IUnmarshallingContext ictx, StringArray attrs) throws JiBXException { // handle basic validation readNamespaces(ictx); validateAttributes(ictx, true, attrs); // loop through all attributes of current element UnmarshallingContext uctx = (UnmarshallingContext)ictx; clearExtraAttributes(); for (int i = 0; i < uctx.getAttributeCount(); i++) { // collect attributes from non-schema namespaces String ns = uctx.getAttributeNamespace(i); if (ns != null && ns.length() > 0 && !getNamespace().equals(ns)) { addExtraAttribute(uctx.getAttributeName(i), ns, uctx.getAttributeValue(i)); } } } }
public Object read(QName elementQName, XMLStreamReader input, Class<?> type) { try { UnmarshallingContext ctx = getUnmarshallingContext(input, type); return ctx.unmarshalElement(type); } catch (JiBXException e) { throw new RuntimeException(e); } }
private static UnmarshallingContext getUnmarshallingContext(XMLStreamReader reader, Class jtype) throws JiBXException { IBindingFactory factory; if (JibxSimpleTypes.isSimpleType(jtype)) { factory = JibxNullBindingFactory.getFactory(); } else { factory = BindingDirectory.getFactory(jtype); } UnmarshallingContext ctx = (UnmarshallingContext)factory.createUnmarshallingContext(); StAXReaderWrapper wrapper = new StAXReaderWrapper(reader, "Data-element", true); ctx.setDocument(wrapper); ctx.toTag(); return ctx; }
/** * Validate attributes of element. This is designed to be called during unmarshalling as part of the pre-set method * processing when a subclass instance is being created. * * @param ictx unmarshalling context * @param attrs attributes array */ protected void validateAttributes(IUnmarshallingContext ictx, StringArray attrs) { // setup for attribute access ValidationContext vctx = (ValidationContext)ictx.getUserContext(); UnmarshallingContext uctx = (UnmarshallingContext)ictx; // loop through all attributes of current element for (int i = 0; i < uctx.getAttributeCount(); i++) { // check if nonamespace attribute is in the allowed set String name = uctx.getAttributeName(i); if (uctx.getAttributeNamespace(i).length() == 0) { if (attrs.indexOf(name) < 0) { vctx.addWarning("Undefined attribute " + name, this); } } } }
for (int i = 0; i < uctx.getAttributeCount(); i++) { String name = uctx.getAttributeName(i); String ns = uctx.getAttributeNamespace(i); if (ns == null || ns.length() == 0) { String qname = UnmarshallingContext.buildNameString(ns, name); vctx.addWarning("Non-WSDL attribute not allowed " + qname, ictx.getStackTop());
/** * Parameter value unmarshalling factory. This gets the containing element and the name so that the standard * constructor can be used. * * @param ictx * @return created instance * @throws JiBXException */ private static FaultCustom throwsFactory(IUnmarshallingContext ictx) throws JiBXException { UnmarshallingContext uctx = (UnmarshallingContext)ictx; Object parent = uctx.getStackTop(); int depth = 0; if (parent instanceof Collection) { parent = uctx.getStackObject(++depth); } return new FaultCustom((OperationCustom)parent, uctx.attributeText(null, "class")); } }
/** * Build the fully-qualified name for a package or class by appending the supplied name attribute value to the * fully-qualified name of the containing package. * * @param contain * @param ctx * @throws JiBXException */ private String buildFullName(PackageCustom contain, UnmarshallingContext ctx) throws JiBXException { String lead = ""; if (contain != null) { lead = contain.getName() + '.'; } return lead + ctx.attributeText(null, "name"); }
String encoding = ((UnmarshallingContext)uctx).getInputEncoding(); if (!mclas.isInstance(obj)) { System.err.println("Unmarshalled result not expected type");
QName qname = QName.get(m_unmarshalContext.getName(), m_unmarshalContext.getPrefix(), m_unmarshalContext.getNamespace()); Element element = s_factory.createElement(qname); int ncount = m_unmarshalContext.getNamespaceCount(); for (int i = 0; i < ncount; i++) { String prefix = m_unmarshalContext.getNamespacePrefix(i); String uri = m_unmarshalContext.getNamespaceUri(i); element.addNamespace(prefix, uri); int acount = m_unmarshalContext.getAttributeCount(); for (int i = 0; i < acount; i++) { String prefix = m_unmarshalContext.getAttributePrefix(i); String uri = m_unmarshalContext.getAttributeNamespace(i); String name = m_unmarshalContext.getAttributeName(i); String value = m_unmarshalContext.getAttributeValue(i); qname = QName.get(name, prefix, uri); element.addAttribute(qname, value); int event = m_unmarshalContext.nextToken(); if (event != IXMLReader.END_TAG) { unmarshalContent(element.content()); m_unmarshalContext.nextToken(); return element;