@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); } }
public Object unmarshal(Object arg0, IUnmarshallingContext arg1) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext) arg1; if (!ctx.isAt(m_uri, m_name)) { ctx.throwStartTagNameError(m_uri, m_name); } ctx.parseToStartTag(m_uri, m_name); String type = ctx.attributeText(m_uri, TYPE); ctx.parsePastStartTag(m_uri, m_name); String text = ctx.parseContentText(); ctx.parsePastEndTag(m_uri, m_name); Object obj = null; if (type.equals(FLOAT)) obj = new Float((String) text); else if (type.equals(COLOR)) obj = colorConverter.fromString(text); else if (type.equals(VECTOR)) obj = vectorConverter.fromString(text); else if (type.equals(POINT)) obj = pointConverter.fromString(text); 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(this.uri, this.name)) { ctx.throwStartTagNameError(this.uri, this.name); } String unitString = ctx.attributeText(null, "unit"); Unit<?> unit = null; try { unit = (Unit<?>) (UnitFormat.getInstance().parseObject(unitString)); } catch (ParseException ex) { throw new JiBXException("Unable to parse unit element", ex); } // unit.asType(Length.class); ctx.parsePastStartTag(this.uri, this.name); String value = ctx.parseContentText(); ctx.parsePastEndTag(this.uri, this.name); return KnittingMeasure.valueOf(value, unit); }