下面列出了怎么用javax.xml.bind.annotation.XmlElements的API类实例代码及写法,或者点击链接到github查看源代码。
static boolean supportsCriteriaValue(Class<? extends SingleValuedPredicate> simplePredicateClass, CriteriaValue<?> value) {
if (simplePredicateClass == null) {
throw new IllegalArgumentException("simplePredicateClass was null");
}
if (value == null) {
throw new IllegalArgumentException("valueClass was null");
}
XmlElements elementsAnnotation = CriteriaSupportUtils.findXmlElementsAnnotation(simplePredicateClass);
if (elementsAnnotation != null) {
XmlElement[] elements = elementsAnnotation.value();
for (XmlElement element : elements) {
if (value.getClass().equals(element.type())) {
return true;
}
}
}
return false;
}
/**
* Returns the text in a {@code <gco:CharacterString>}, {@code <gcx:FileName>} or {@code <gcx:MimeFileType>}
* element, or {@code null} if none. This method does not return anything for {@code Enum} or {@code CodeList}
* instances, as the later are handled by {@link #getCodeList()}.
*
* <p>This method is invoked by JAXB at marshalling time and should not need to be invoked directly.</p>
*/
@XmlElements({
@XmlElement(type = String.class, name = "CharacterString"),
@XmlElement(type = Anchor.class, name = "Anchor", namespace = Namespaces.GCX),
@XmlElement(type = FileName.class, name = "FileName", namespace = Namespaces.GCX),
@XmlElement(type = MimeFileType.class, name = "MimeFileType", namespace = Namespaces.GCX),
@XmlElement(type = GO_URL.class, name = "URL", namespace = LegacyNamespaces.GMD)
})
private Object getValue() {
switch (type) {
case 0: return StringAdapter.toString(text);
case URL: return new GO_URL(text.toString());
case FILENAME: return new FileName(text.toString());
case MIME_TYPE: return new MimeFileType(text.toString());
case ANCHOR: return text; // Shall be an instance of Anchor.
default: return null; // CodeList or Enum.
}
}
/**
* Invoked by JAXB at marshalling time for getting the actual element to write
* inside the {@code <gml:parameterValue>} XML element.
* This is the value or a copy of the value given in argument to the {@code wrap} method.
*
* @return the element to be marshalled.
*
* @see CC_GeneralOperationParameter#getElement()
*/
@XmlElements({ // We can not use @XmlElementRef because we have no public AbstractParameterValue parent class.
@XmlElement(name = "ParameterValue", type = DefaultParameterValue.class),
@XmlElement(name = "ParameterValueGroup", type = DefaultParameterValueGroup.class)
})
public GeneralParameterValue getElement() {
final GeneralParameterValue metadata = this.metadata;
if (metadata instanceof DefaultParameterValue<?>) {
return (DefaultParameterValue<?>) metadata;
}
if (metadata instanceof DefaultParameterValueGroup) {
return (DefaultParameterValueGroup) metadata;
}
if (metadata instanceof ParameterValue) {
return new DefaultParameterValue<>((ParameterValue<?>) metadata);
}
if (metadata instanceof ParameterValueGroup) {
return new DefaultParameterValueGroup((ParameterValueGroup) metadata);
}
return null; // Unknown types are currently not marshalled (we may revisit that in a future SIS version).
}
@XmlElements({
@XmlElement(name="foo", type=Foo.class),
@XmlElement(name="bar", type=Bar.class)
})
public List<Model> getElements() {
return Arrays.asList(new Foo("name1"), new Bar("title1"));
}
@XmlElements({
@XmlElement(name = "http",
type = HttpEndpoint.class)
})
public void setEndpoint(Endpoint endpoint) {
this.endpoint = endpoint;
}
@XmlElements({
@XmlElement(name = "call",
type = CallMediator.class),
@XmlElement(name = "respond",
type = RespondMediator.class),
@XmlElement(name = "payloadFactory",
type = PayloadFactoryMediator.class)
})
public void setMediator(Mediator mediator) {
this.mediatorList.add(mediator);
}
@XmlElements({
@XmlElement(name = "inSequence",
type = Sequence.class),
@XmlElement(name = "outSequence",
type = Sequence.class)
})
public void setSequence(Sequence sequence) {
this.sequenceList.add(sequence);
}
@XmlElements({
@XmlElement(name="foo", type=Foo.class),
@XmlElement(name="bar", type=Bar.class)
})
public List<Model> getElements() {
return Arrays.asList(new Foo("name1"), new Bar("title1"));
}
@XmlElements({
@XmlElement(name="activity"),
@XmlElement(name="activity-alias")
})
public void setActivites(List<Activity> activites) {
this.activites = activites;
}
@XmlElements({ @XmlElement(name = "resource") })
@XmlElementWrapper(name = "resources")
public final List<MCRIViewClientResource> getResources() {
return resources.entries()
.stream()
.map(entry -> new MCRIViewClientResource(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
@XmlElements({ @XmlElement(name = "property") })
@XmlElementWrapper(name = "properties")
public final List<MCRIViewClientProperty> getProperties() {
return properties.entrySet()
.stream()
.map(entry -> new MCRIViewClientProperty(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
@XmlElementWrapper(name = "external-variables")
@XmlElements({@XmlElement(name="property-list-variable", type=JaxbPropertyListVariable.class),
@XmlElement(name="relative-date-variable", type=JaxbRelativeDateVariable.class),
@XmlElement(name="property-variable", type=JaxbPropertyValueVariable.class),
@XmlElement(name="fulltext-variable", type=JaxbFullTextVariable.class)})
@Override
public List<ExternalVariable<?>> getExternalVariables() {
return externalVariables;
}
@XmlElementWrapper
@XmlElements({@XmlElement(name="expression-set", type=JaxbExpressionSet.class),
@XmlElement(name="fulltext", type=JaxbFullTextExpression.class),
@XmlElement(name="property", type=JaxbPropertyExpression.class),
@XmlElement(name="property-list", type=JaxbPropertyListExpression.class),
@XmlElement(name="property-range", type=JaxbPropertyRangeExpression.class),
@XmlElement(name="relative-date", type=JaxbRelativeDateExpression.class)})
public List<Expression> getExpressions() {
return expressions;
}
@XmlElementWrapper(name = "tasks", namespace = "urn:test")
@XmlElements( {
@XmlElement(name = "usertask", namespace = "urn:test", type = UserTask.class),
@XmlElement(name = "autotask", namespace = "urn:test", type = AutoTask.class) })
public Collection<Node> getNodes() {
return nodes;
}
@XmlElements({
@XmlElement(name="user", type=RESTInputUser.class),
@XmlElement(name="userGroup", type=RESTInputGroup.class),
@XmlElement(name="instance", type=RESTInputInstance.class),
@XmlElement(name="rule", type=RESTInputRule.class)
})
public AbstractRESTPayload getPayload() {
return payload;
}
/**
* Parse the annotations on the field to see if there is an XmlElements
* annotation on it. If so, we'll check this annotation to see if it
* refers to any classes that are external from our code schema compile.
* If we find any, then we'll add them to our visitor.
* @param outline root of the generated code
* @param field parses the xml annotations looking for an external class
* @param directClasses set of direct classes to append to
* @throws IllegalAccessException throw if there's an error introspecting the annotations
*/
private static void parseXmlAnnotations(Outline outline, FieldOutline field, Set<String> directClasses) throws IllegalAccessException {
if (field instanceof UntypedListField) {
JFieldVar jfv = (JFieldVar) FieldHack.listField.get(field);
for(JAnnotationUse jau : jfv.annotations()) {
JClass jc = jau.getAnnotationClass();
if (jc.fullName().equals(XmlElements.class.getName())) {
JAnnotationArrayMember value = (JAnnotationArrayMember) jau.getAnnotationMembers().get("value");
for(JAnnotationUse anno : value.annotations()) {
handleXmlElement(outline, directClasses, anno.getAnnotationMembers().get("type"));
}
}
}
}
}
/**
* Returns the coordinate system.
*
* @return the coordinate system.
*/
@Override
@XmlElements({
@XmlElement(name = "cartesianCS", type = DefaultCartesianCS.class),
@XmlElement(name = "affineCS", type = DefaultAffineCS.class),
@XmlElement(name = "cylindricalCS", type = DefaultCylindricalCS.class),
@XmlElement(name = "linearCS", type = DefaultLinearCS.class),
@XmlElement(name = "polarCS", type = DefaultPolarCS.class),
@XmlElement(name = "sphericalCS", type = DefaultSphericalCS.class),
@XmlElement(name = "userDefinedCS", type = DefaultUserDefinedCS.class)
})
public CoordinateSystem getCoordinateSystem() {
return super.getCoordinateSystem();
}
@XmlElementWrapper(name = "enterprise-beans")
@XmlElements({
@XmlElement(name = "message-driven", required = true, type = MessageDrivenBean.class),
@XmlElement(name = "session", required = true, type = SessionBean.class),
@XmlElement(name = "entity", required = true, type = EntityBean.class)})
public EnterpriseBean[] getEnterpriseBeans() {
return enterpriseBeans.values().toArray(new EnterpriseBean[enterpriseBeans.size()]);
}
@GET
@Path("testJaxbAnnotationTransfer")
public String testJaxbAnnotationTransfer() throws Exception {
// Test for fix to this bug: https://github.com/quarkusio/quarkus/issues/6021
// Ensure that any JAX-B annotations are properly moved to generated getters
Method m = JAXBEntity.class.getMethod("getNamedAnnotatedProp");
XmlAttribute anno = m.getAnnotation(XmlAttribute.class);
assertNotNull(anno);
assertEquals("Named", anno.name());
assertNull(m.getAnnotation(XmlTransient.class));
m = JAXBEntity.class.getMethod("getDefaultAnnotatedProp");
anno = m.getAnnotation(XmlAttribute.class);
assertNotNull(anno);
assertEquals("##default", anno.name());
assertNull(m.getAnnotation(XmlTransient.class));
m = JAXBEntity.class.getMethod("getUnAnnotatedProp");
assertNull(m.getAnnotation(XmlAttribute.class));
assertNull(m.getAnnotation(XmlTransient.class));
m = JAXBEntity.class.getMethod("getTransientProp");
assertNull(m.getAnnotation(XmlAttribute.class));
assertNotNull(m.getAnnotation(XmlTransient.class));
m = JAXBEntity.class.getMethod("getArrayAnnotatedProp");
assertNull(m.getAnnotation(XmlTransient.class));
XmlElements elementsAnno = m.getAnnotation(XmlElements.class);
assertNotNull(elementsAnno);
assertNotNull(elementsAnno.value());
assertEquals(2, elementsAnno.value().length);
assertEquals("array1", elementsAnno.value()[0].name());
assertEquals("array2", elementsAnno.value()[1].name());
// Ensure that all original fields were labeled @XmlTransient and had their original JAX-B annotations removed
ensureFieldSanitized("namedAnnotatedProp");
ensureFieldSanitized("transientProp");
ensureFieldSanitized("defaultAnnotatedProp");
ensureFieldSanitized("unAnnotatedProp");
ensureFieldSanitized("arrayAnnotatedProp");
return "OK";
}
@XmlElementWrapper
@XmlElements({@XmlElement(name="id-location", type=JaxbIdLocation.class),
@XmlElement(name="path-location", type=JaxbPathLocation.class)})
public List<Location> getLocations() {
return locations;
}
@XmlElementWrapper(name = "MetaDefinitions")
@XmlElements(value = {
@XmlElement(name = "ClassDefinition",
type = ClassDefinition.class),
@XmlElement(name = "PropertyDefinition",
type = PropertyDefinition.class),
@XmlElement(name = "PropertyAliasDefinition",
type = PropertyAliasDefinition.class),
@XmlElement(name = "TypeDefinitionCharacter",
type = CharacterTypeDefinition.class),
@XmlElement(name = "TypeDefinitionEnumeration",
type = EnumerationTypeDefinition.class),
@XmlElement(name = "TypeDefinitionExtendibleEnumeration",
type = ExtendibleEnumerationTypeDefinition.class),
@XmlElement(name = "TypeDefinitionFixedArray",
type = FixedArrayTypeDefinition.class),
@XmlElement(name = "TypeDefinitionIndirect",
type = IndirectTypeDefinition.class),
@XmlElement(name = "TypeDefinitionInteger",
type = IntegerTypeDefinition.class),
@XmlElement(name = "TypeDefinitionOpaque",
type = OpaqueTypeDefinition.class),
@XmlElement(name = "TypeDefinitionRecord",
type = RecordTypeDefinition.class),
@XmlElement(name = "TypeDefinitionRename",
type = RenameTypeDefinition.class),
@XmlElement(name = "TypeDefinitionSet",
type = SetTypeDefinition.class),
@XmlElement(name = "TypeDefinitionStream",
type = StreamTypeDefinition.class),
@XmlElement(name = "TypeDefinitionString",
type = StringTypeDefinition.class),
@XmlElement(name = "TypeDefinitionStrongObjectReference",
type = StrongReferenceTypeDefinition.class),
@XmlElement(name = "TypeDefinitionVariableArray",
type = VariableArrayTypeDefinition.class),
@XmlElement(name = "TypeDefinitionWeakObjectReference",
type = WeakReferenceTypeDefinition.class),
@XmlElement(name = "TypeDefinitionFloat",
type = FloatTypeDefinition.class),
@XmlElement(name = "TypeDefinitionLenseSerialFloat",
type = LensSerialFloatTypeDefinition.class)
})
public ArrayList<Definition> getDefinitions() {
return definitions;
}
@XmlElementWrapper(namespace = Stream.XMLNS, name = "features")
@XmlElements({ @XmlElement(name = Starttls.NAME, type = Starttls.class), @XmlElement(name = Mechanisms.NAME, type = Mechanisms.class), @XmlElement(name = Bind.NAME, type = Bind.class), @XmlElement(name = Session.NAME, type = Session.class), @XmlElement(name = Register.NAME, type = Register.class) })
public List<Feature> getFeatures() {
return this.features;
}
@XmlElements({ @XmlElement(name = "mechanism", type = String.class) })
public Set<String> getMechanism() {
return this.mechanism;
}
@XmlElements({ @XmlElement(name = Item.NAME, type = Item.class) })
public List<Item> getItem() {
return this.items;
}
@XmlElements({ @XmlElement(name = ItemStatus.NAME, type = ItemStatus.class) })
public Set<ItemStatus> getStatuses() {
return this.statuses == null ? this.statuses : this.statuses.contains(ItemStatus.parse("201")) ? creator : this.statuses;
}
@XmlElements({ @XmlElement(name = XVCardPhoto.NAME, type = XVCardPhoto.class), @XmlElement(name = XVCard.NAME, type = XVCard.class), @XmlElement(name = XMuc.NAME, type = XMuc.class), @XmlElement(name = XUser.NAME, type = XUser.class) })
public List<Field<?>> getFields() {
return this.fields() ? this.fields.getFields() : empty.getFields();
}
@XmlElements({ @XmlElement(name = XVCardPhoto.NAME, type = XVCardPhoto.class) })
public List<Field<?>> getFields() {
return this.vCardFields.getFields();
}
@XmlElements({ @XmlElement(name = UnExpectedRequest.NAME, type = UnExpectedRequest.class), @XmlElement(name = SubscriptionRequired.NAME, type = SubscriptionRequired.class), @XmlElement(name = RemoteServerTimeout.NAME, type = RemoteServerTimeout.class), @XmlElement(name = RemoteServerNotFound.NAME, type = RemoteServerNotFound.class), @XmlElement(name = RegistrationRequired.NAME, type = RegistrationRequired.class), @XmlElement(name = Redirect.NAME, type = Redirect.class), @XmlElement(name = RecipientUnavaliable.NAME, type = RecipientUnavaliable.class), @XmlElement(name = JIDMalformed.NAME, type = JIDMalformed.class), @XmlElement(name = ServiceUnavailable.NAME, type = ServiceUnavailable.class), @XmlElement(name = ItemNotFound.NAME, type = ItemNotFound.class), @XmlElement(name = Gone.NAME, type = Gone.class), @XmlElement(name = Forbidden.NAME, type = Forbidden.class), @XmlElement(name = FeatureNotImplemented.NAME, type = FeatureNotImplemented.class), @XmlElement(name = BadRequest.NAME, type = BadRequest.class), @XmlElement(name = NotAllowed.NAME, type = NotAllowed.class), @XmlElement(name = NotAcceptable.NAME, type = NotAcceptable.class), @XmlElement(name = UnSupportedVersion.NAME, type = UnSupportedVersion.class), @XmlElement(name = UnSupportedStanzaType.NAME, type = UnSupportedStanzaType.class), @XmlElement(name = UnSupportedFeature.NAME, type = UnSupportedFeature.class), @XmlElement(name = UnSupportedEncoding.NAME, type = UnSupportedEncoding.class), @XmlElement(name = SystemShutdown.NAME, type = SystemShutdown.class), @XmlElement(name = SeeOtherHost.NAME, type = SeeOtherHost.class), @XmlElement(name = RestrictedXml.NAME, type = RestrictedXml.class), @XmlElement(name = com.sissi.protocol.error.detail.ResourceConstraint.NAME, type = com.sissi.protocol.error.detail.ResourceConstraint.class), @XmlElement(name = Reset.NAME, type = Reset.class), @XmlElement(name = PolicyViolation.NAME, type = PolicyViolation.class),
@XmlElement(name = NotWellFormed.NAME, type = NotWellFormed.class), @XmlElement(name = InvalidXml.NAME, type = InvalidXml.class), @XmlElement(name = InvalidFrom.NAME, type = InvalidFrom.class), @XmlElement(name = InternalServerError.NAME, type = InternalServerError.class), @XmlElement(name = Conflict.NAME, type = Conflict.class), @XmlElement(name = BadNamespacePrefix.NAME, type = BadNamespacePrefix.class), @XmlElement(name = BadFormat.NAME, type = BadFormat.class), @XmlElement(name = HostGone.NAME, type = HostGone.class), @XmlElement(name = HostUnknown.NAME, type = HostUnknown.class), @XmlElement(name = InvaildNamespace.NAME, type = InvaildNamespace.class), @XmlElement(name = NotAuthorized.NAME, type = NotAuthorized.class), @XmlElement(name = ImproperAddressing.NAME, type = ImproperAddressing.class) })
public List<ErrorDetail> getDetails() {
return this.details;
}
@XmlElements({ @XmlElement(name = Search.NAME, type = Search.class), @XmlElement(name = Privated.NAME, type = Privated.class), @XmlElement(name = Unique.NAME, type = Unique.class), @XmlElement(name = Sharedgroup.NAME, type = Sharedgroup.class), @XmlElement(name = Owner.NAME, type = Owner.class), @XmlElement(name = XMucAdmin.NAME, type = XMucAdmin.class), @XmlElement(name = ServerAck.NAME, type = ServerAck.class), @XmlElement(name = Client.NAME, type = Client.class), @XmlElement(name = Time.NAME, type = Time.class), @XmlElement(name = Last.NAME, type = Last.class), @XmlElement(name = Last.NAME, type = LastSeconds.class), @XmlElement(name = Ping.NAME, type = Ping.class), @XmlElement(name = Si.NAME, type = Si.class), @XmlElement(name = VCard.NAME, type = VCard.class), @XmlElement(name = Bind.NAME, type = Bind.class), @XmlElement(name = Session.NAME, type = Session.class), @XmlElement(name = Roster.NAME, type = Roster.class), @XmlElement(name = Register.NAME, type = Register.class), @XmlElement(name = DiscoInfo.NAME, type = DiscoInfo.class), @XmlElement(name = DiscoItems.NAME, type = DiscoItems.class), @XmlElement(name = Bytestreams.NAME, type = Bytestreams.class), @XmlElement(name = Blocked.NAME, type = Blocked.class), @XmlElement(name = UnBlock.NAME, type = UnBlock.class), @XmlElement(name = BlockList.NAME, type = BlockList.class) })
public List<Protocol> getProtocols() {
return this.protocols;
}