本文整理汇总了Java中javax.xml.bind.annotation.adapters.XmlAdapter.marshal方法的典型用法代码示例。如果您正苦于以下问题:Java XmlAdapter.marshal方法的具体用法?Java XmlAdapter.marshal怎么用?Java XmlAdapter.marshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.annotation.adapters.XmlAdapter
的用法示例。
在下文中一共展示了XmlAdapter.marshal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _adaptM
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
private OnWire _adaptM(XMLSerializer serializer, InMemory v) throws MarshalException {
XmlAdapter<OnWire,InMemory> a = serializer.getAdapter(adapter);
try {
return a.marshal(v);
} catch (Exception e) {
serializer.handleError(e,v,null);
throw new MarshalException(e);
}
}
示例2: get
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
public OnWireValueT get(BeanT bean) throws AccessorException {
InMemValueT v = core.get(bean);
XmlAdapter<OnWireValueT,InMemValueT> a = getAdapter();
try {
return a.marshal(v);
} catch (Exception e) {
throw new AccessorException(e);
}
}
示例3: validateField
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
/**
* Validate a field setting.
* <p>
* This method inspects the field annotation for an XmlTypeValidator. If found
* then the XmlTypeValidator is instantiated and called against the provided
* field value.
* <p>
* If no XmlTypeValidator annotation is found then the field value is assumed
* to be valid.
* <p>
* If the field value is null then NO VALIDATION is done.
*
*
* @param field the class field
* @param fieldValue the class field configured value
* @throws Exception the XmlTypeValidator marshal error, thrown ONLY if the
* field value is not valid
*/
private static void validateField(Field field, Object fieldValue) throws Exception {
/**
* Do not validate fields with null values.
*/
if (fieldValue == null) {
return;
}
/**
* Scan the field annotations looking for an XmlJavaTypeAdapter instance.
*/
for (Annotation annotation : field.getAnnotations()) {
if (annotation instanceof XmlJavaTypeAdapter) {
/**
* If an XmlJavaTypeAdapter annotation is found then instantiate the
* XmlAdapter class referred to in the "value" field and attempt to
* marshal the field value. This action will complete silently if the
* field value is valid and throw an exception if the field value is not
* valid (as determined by the marshal method).
*/
try {
XmlAdapter<Object, Object> adapterInstance = ((XmlJavaTypeAdapter) annotation).value().getConstructor().newInstance();
adapterInstance.marshal(fieldValue);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) {
logger.log(Level.WARNING, "XmlJavaTypeAdapter failed to instantiate: {0}", ex.getMessage());
logger.log(Level.SEVERE, null, ex);
}
}
}
}
示例4: marshall
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
public static <ValueType, BoundType> ValueType marshall(
Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass,
BoundType v) {
try {
final XmlAdapter<ValueType, BoundType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
return xmlAdapter.marshal(v);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例5: marshallJAXBElement
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
public static <ValueType, BoundType> JAXBElement<BoundType> marshallJAXBElement(
Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass,
Class<BoundType> declaredType, QName name, Class<?> scope, ValueType v) {
try {
if (v == null) {
return null;
} else {
final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
return new JAXBElement<BoundType>(name, declaredType, scope,
xmlAdapter.marshal(v));
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例6: uncheckedMarshal
import javax.xml.bind.annotation.adapters.XmlAdapter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Object uncheckedMarshal(MutableLocatable<?> object, XmlAdapter<?, T> xmlAdapter)
throws Exception {
return xmlAdapter.marshal((T) object);
}