Java Code Examples for javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal()

The following examples show how to use javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeUseImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 2
Source File: JAXBUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Object useAdapter(Object obj,
                                XmlJavaTypeAdapter typeAdapter,
                                boolean marshal,
                                Object defaultValue) {
    if (typeAdapter != null) {
        try {
            @SuppressWarnings("rawtypes")
            XmlAdapter xmlAdapter = typeAdapter.value().newInstance();
            if (marshal) {
                return xmlAdapter.marshal(obj);
            }
            return xmlAdapter.unmarshal(obj);
        } catch (Exception ex) {
            LOG.log(Level.INFO, "(un)marshalling failed, using defaultValue", ex);
        }
    }
    return defaultValue;
}
 
Example 3
Source File: TypeUseImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 4
Source File: TypeUseImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 5
Source File: TypeUseImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 6
Source File: TypeUseImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 7
Source File: TypeUseImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 8
Source File: TypeUseImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 9
Source File: TypeUseImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
Example 10
Source File: BridgeAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 11
Source File: BridgeAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 12
Source File: BridgeAdapter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 13
Source File: BridgeAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 14
Source File: BridgeAdapter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 15
Source File: BridgeAdapter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 16
Source File: BridgeAdapter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}
 
Example 17
Source File: DefaultTypeUse.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JExpression createConstant(Outline outline, XmlString lexical) {
	if (isCollection())
		return null;

	if (adapter == null)
		return coreType.createConstant(outline, lexical);

	// [RESULT] new Adapter().unmarshal(CONSTANT);
	JExpression cons = coreType.createConstant(outline, lexical);
	@SuppressWarnings("unchecked")
	Class<? extends XmlAdapter<?, ?>> atype = (Class<? extends XmlAdapter<?, ?>>) adapter
			.getAdapterIfKnown();

	// try to run the adapter now rather than later.
	if (cons instanceof JStringLiteral && atype != null) {
		JStringLiteral scons = (JStringLiteral) cons;
		@SuppressWarnings("unchecked")
		XmlAdapter<Object, String> a = (XmlAdapter<Object, String>) ClassFactory
				.create(atype);
		try {
			Object value = a.unmarshal(scons.str);
			if (value instanceof String) {
				return JExpr.lit((String) value);
			}
		} catch (Exception e) {
			// assume that we can't eagerly bind this
		}
	}

	return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal")
			.arg(cons);
}
 
Example 18
Source File: XmlAdapterUtils.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <ValueType, BoundType> BoundType unmarshall(
		Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass,
		ValueType v) {
	try {
		final XmlAdapter<ValueType, BoundType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
		return xmlAdapter.unmarshal(v);
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 19
Source File: XmlAdapterUtils.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <ValueType, BoundType> ValueType unmarshallJAXBElement(
		Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass,
		JAXBElement<? extends BoundType> v) {
	try {
		if (v == null) {
			return null;
		} else {
			final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
			return xmlAdapter.unmarshal(v.getValue());
		}
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 20
Source File: BridgeAdapter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private @NotNull InMemory adaptU(Unmarshaller _u, OnWire v) throws JAXBException {
    UnmarshallerImpl u = (UnmarshallerImpl) _u;
    XmlAdapter<OnWire,InMemory> a = u.coordinator.getAdapter(adapter);
    u.coordinator.pushCoordinator();
    try {
        return a.unmarshal(v);
    } catch (Exception e) {
        throw new UnmarshalException(e);
    } finally {
        u.coordinator.popCoordinator();
    }
}