本文整理汇总了Java中javax.xml.bind.annotation.XmlAccessorType.value方法的典型用法代码示例。如果您正苦于以下问题:Java XmlAccessorType.value方法的具体用法?Java XmlAccessorType.value怎么用?Java XmlAccessorType.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.annotation.XmlAccessorType
的用法示例。
在下文中一共展示了XmlAccessorType.value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAccessType
import javax.xml.bind.annotation.XmlAccessorType; //导入方法依赖的package包/类
/**
* Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
* annotations.
*/
private XmlAccessType getAccessType() {
XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
if(xat!=null)
return xat.value();
else
return XmlAccessType.PUBLIC_MEMBER;
}
示例2: marshallException
import javax.xml.bind.annotation.XmlAccessorType; //导入方法依赖的package包/类
public static void marshallException(Marshaller marshaller, Exception elValue,
MessagePartInfo part, Object source) {
XMLStreamWriter writer = getStreamWriter(source);
QName qn = part.getElementQName();
try {
writer.writeStartElement("ns1", qn.getLocalPart(), qn.getNamespaceURI());
Class<?> cls = part.getTypeClass();
XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
if (accessorType == null && cls.getPackage() != null) {
accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
}
XmlAccessType accessType = accessorType != null
? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
String namespace = part.getElementQName().getNamespaceURI();
SchemaInfo sch = part.getMessageInfo().getOperation().getInterface()
.getService().getSchema(namespace);
if (sch != null) {
if (!sch.isElementFormQualified()) {
namespace = null;
}
} else {
LOG.warning("Schema associated with " + namespace + " is null");
}
for (Field f : cls.getDeclaredFields()) {
if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
QName fname = new QName(namespace, f.getName());
f.setAccessible(true);
if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
writeArrayObject(marshaller, writer, fname, f.get(elValue));
} else {
writeObject(marshaller, writer, new JAXBElement(fname, String.class,
f.get(elValue)));
}
}
}
for (Method m : cls.getMethods()) {
if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
int idx = m.getName().startsWith("get") ? 3 : 2;
String name = m.getName().substring(idx);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
QName mname = new QName(namespace, name);
if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
} else {
writeObject(marshaller, writer, new JAXBElement(mname, String.class,
m.invoke(elValue)));
}
}
}
writer.writeEndElement();
writer.flush();
} catch (Exception e) {
throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
}
}