本文整理匯總了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);
}