use of jakarta.xml.bind.annotation.XmlSchemaType in project jaxb-ri by eclipse-ee4j.
the class EnumLeafInfoImpl method calcConstants.
/**
* Build {@link EnumConstant}s and discover/report any error in it.
*/
protected void calcConstants() {
EnumConstantImpl<T, C, F, M> last = null;
// first check if we represent xs:token derived type
Collection<? extends F> fields = nav().getDeclaredFields(clazz);
for (F f : fields) {
if (nav().isSameType(nav().getFieldType(f), nav().ref(String.class))) {
XmlSchemaType schemaTypeAnnotation = builder.reader.getFieldAnnotation(XmlSchemaType.class, f, this);
if (schemaTypeAnnotation != null) {
if ("token".equals(schemaTypeAnnotation.name())) {
tokenStringType = true;
break;
}
}
}
}
F[] constants = nav().getEnumConstants(clazz);
for (int i = constants.length - 1; i >= 0; i--) {
F constant = constants[i];
String name = nav().getFieldName(constant);
XmlEnumValue xev = builder.reader.getFieldAnnotation(XmlEnumValue.class, constant, this);
String literal;
if (xev == null)
literal = name;
else
literal = xev.value();
last = createEnumConstant(name, literal, constant, last);
}
this.firstConstant = last;
}
use of jakarta.xml.bind.annotation.XmlSchemaType in project jaxb-ri by eclipse-ee4j.
the class Util method calcSchemaType.
static <T, C, F, M> QName calcSchemaType(AnnotationReader<T, C, F, M> reader, AnnotationSource primarySource, C enclosingClass, T individualType, Locatable src) {
XmlSchemaType xst = primarySource.readAnnotation(XmlSchemaType.class);
if (xst != null) {
return new QName(xst.namespace(), xst.name());
}
// check the defaulted annotation
XmlSchemaTypes xsts = reader.getPackageAnnotation(XmlSchemaTypes.class, enclosingClass, src);
XmlSchemaType[] values = null;
if (xsts != null)
values = xsts.value();
else {
xst = reader.getPackageAnnotation(XmlSchemaType.class, enclosingClass, src);
if (xst != null) {
values = new XmlSchemaType[1];
values[0] = xst;
}
}
if (values != null) {
for (XmlSchemaType item : values) {
if (reader.getClassValue(item, "type").equals(individualType)) {
return new QName(item.namespace(), item.name());
}
}
}
return null;
}
use of jakarta.xml.bind.annotation.XmlSchemaType in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processPropertyAnnotations.
private void processPropertyAnnotations(TypeInfo info, JavaClass cls, JavaHasAnnotations propertyElement, Property property) {
// Check for mixed context
if (helper.isAnnotationPresent(propertyElement, XmlMixed.class)) {
info.setMixed(true);
property.setMixedContent(true);
findAndProcessObjectFactory(cls);
}
if (helper.isAnnotationPresent(propertyElement, XmlInverseReference.class)) {
XmlInverseReference inverseReference = (XmlInverseReference) helper.getAnnotation(propertyElement, XmlInverseReference.class);
property.setInverseReferencePropertyName(inverseReference.mappedBy());
TypeInfo targetInfo = this.getTypeInfos().get(property.getActualType().getName());
if (targetInfo != null && targetInfo.getXmlAccessType() == XmlAccessType.PROPERTY) {
String propName = property.getPropertyName();
propName = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
property.setInverseReferencePropertyGetMethodName(GET_STR + propName);
property.setInverseReferencePropertySetMethodName(SET_STR + propName);
}
property.setInverseReference(true, helper.isAnnotationPresent(propertyElement, XmlElement.class));
}
processXmlJavaTypeAdapter(property, info, cls);
if (helper.isAnnotationPresent(propertyElement, XmlAttachmentRef.class) && areEquals(property.getActualType(), JAVAX_ACTIVATION_DATAHANDLER)) {
property.setIsSwaAttachmentRef(true);
property.setSchemaType(Constants.SWA_REF_QNAME);
}
processXmlElement(property, info);
// JavaClass ptype = property.getActualType();
if (!(property.isSwaAttachmentRef()) && isMtomAttachment(property)) {
property.setIsMtomAttachment(true);
property.setSchemaType(Constants.BASE_64_BINARY_QNAME);
}
if (helper.isAnnotationPresent(propertyElement, XmlMimeType.class)) {
property.setMimeType(((XmlMimeType) helper.getAnnotation(propertyElement, XmlMimeType.class)).value());
}
// non-binary data type won't have any affect
if (helper.isAnnotationPresent(propertyElement, XmlInlineBinaryData.class) || info.isBinaryDataToBeInlined()) {
property.setisInlineBinaryData(true);
}
// later use:
if (helper.isAnnotationPresent(propertyElement, XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(propertyElement, XmlSchemaType.class);
QName schemaTypeQname = new QName(schemaType.namespace(), schemaType.name());
property.setSchemaType(schemaTypeQname);
}
if (helper.isAnnotationPresent(propertyElement, XmlAttribute.class)) {
property.setIsAttribute(true);
property.setIsRequired(((XmlAttribute) helper.getAnnotation(propertyElement, XmlAttribute.class)).required());
}
if (helper.isAnnotationPresent(propertyElement, XmlAnyAttribute.class)) {
if (info.isSetAnyAttributePropertyName() && !info.getAnyAttributePropertyName().equals(property.getPropertyName())) {
throw org.eclipse.persistence.exceptions.JAXBException.multipleAnyAttributeMapping(cls.getName());
}
if (!helper.isMapType(property.getType())) {
throw org.eclipse.persistence.exceptions.JAXBException.anyAttributeOnNonMap(property.getPropertyName());
}
property.setIsAnyAttribute(true);
info.setAnyAttributePropertyName(property.getPropertyName());
}
// Make sure XmlElementWrapper annotation is on a collection or array
if (helper.isAnnotationPresent(propertyElement, XmlElementWrapper.class)) {
XmlElementWrapper wrapper = (XmlElementWrapper) helper.getAnnotation(propertyElement, XmlElementWrapper.class);
org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper xmlEltWrapper = new org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper();
String wrapperName = wrapper.name();
if (wrapperName.equals(XMLProcessor.DEFAULT)) {
wrapperName = info.getXmlNameTransformer().transformElementName(property.getPropertyName());
}
xmlEltWrapper.setName(wrapperName);
xmlEltWrapper.setNamespace(wrapper.namespace());
xmlEltWrapper.setNillable(wrapper.nillable());
xmlEltWrapper.setRequired(wrapper.required());
property.setXmlElementWrapper(xmlEltWrapper);
}
if (helper.isAnnotationPresent(propertyElement, XmlList.class)) {
// Make sure XmlList annotation is on a collection or array
if (!helper.isCollectionType(property.getType()) && !property.getType().isArray()) {
throw JAXBException.invalidList(property.getPropertyName());
}
property.setIsXmlList(true);
}
if (helper.isAnnotationPresent(propertyElement, XmlValue.class)) {
property.setIsXmlValue(true);
info.setXmlValueProperty(property);
}
if (helper.isAnnotationPresent(propertyElement, XmlReadOnly.class)) {
property.setReadOnly(true);
}
if (helper.isAnnotationPresent(propertyElement, XmlWriteOnly.class)) {
property.setWriteOnly(true);
}
if (helper.isAnnotationPresent(propertyElement, XmlCDATA.class)) {
property.setCdata(true);
}
if (helper.isAnnotationPresent(propertyElement, XmlAccessMethods.class)) {
XmlAccessMethods accessMethods = (XmlAccessMethods) helper.getAnnotation(propertyElement, XmlAccessMethods.class);
if (!(accessMethods.getMethodName().equals(EMPTY_STRING))) {
property.setGetMethodName(accessMethods.getMethodName());
}
if (!(accessMethods.setMethodName().equals(EMPTY_STRING))) {
property.setSetMethodName(accessMethods.setMethodName());
}
if (!(property.isMethodProperty())) {
property.setMethodProperty(true);
}
}
// handle user properties
if (helper.isAnnotationPresent(propertyElement, XmlProperties.class)) {
XmlProperties xmlProperties = (XmlProperties) helper.getAnnotation(propertyElement, XmlProperties.class);
Map<Object, Object> propertiesMap = createUserPropertiesMap(xmlProperties.value());
property.setUserProperties(propertiesMap);
} else if (helper.isAnnotationPresent(propertyElement, XmlProperty.class)) {
XmlProperty xmlProperty = (XmlProperty) helper.getAnnotation(propertyElement, XmlProperty.class);
Map<Object, Object> propertiesMap = createUserPropertiesMap(new XmlProperty[] { xmlProperty });
property.setUserProperties(propertiesMap);
}
// handle XmlKey
if (helper.isAnnotationPresent(propertyElement, XmlKey.class)) {
info.addXmlKeyProperty(property);
}
// handle XmlJoinNode(s)
processXmlJoinNodes(property);
processXmlNullPolicy(property, cls, info);
// Handle XmlLocation
JavaHasAnnotations elem = propertyElement;
if (helper.isAnnotationPresent(elem, XmlLocation.class) || helper.isAnnotationPresent(elem, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.OLD_XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS)) {
if (!helper.getJavaClass(Constants.LOCATOR_CLASS).isAssignableFrom(property.getType())) {
throw JAXBException.invalidXmlLocation(property.getPropertyName(), property.getType().getName());
}
property.setXmlLocation(true);
}
}
use of jakarta.xml.bind.annotation.XmlSchemaType in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processSchemaTypes.
/**
* Process any @XmlSchemaType(s).
*/
private void processSchemaTypes(JavaClass javaClass, TypeInfo info) {
JavaPackage pack = javaClass.getPackage();
if (helper.isAnnotationPresent(pack, XmlSchemaTypes.class)) {
XmlSchemaTypes types = (XmlSchemaTypes) helper.getAnnotation(pack, XmlSchemaTypes.class);
XmlSchemaType[] typeArray = types.value();
for (XmlSchemaType next : typeArray) {
processSchemaType(next);
}
} else if (helper.isAnnotationPresent(pack, XmlSchemaType.class)) {
processSchemaType((XmlSchemaType) helper.getAnnotation(pack, XmlSchemaType.class));
}
}
use of jakarta.xml.bind.annotation.XmlSchemaType in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addSchemaComponents.
public void addSchemaComponents(JavaClass myClass) {
// first check for type
String myClassName = myClass.getQualifiedName();
Element rootElement = null;
TypeInfo info = typeInfo.get(myClassName);
if (info.isTransient() || info.getClassNamespace().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
return;
}
SchemaTypeInfo schemaTypeInfo = new SchemaTypeInfo();
schemaTypeInfo.setSchemaTypeName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
this.schemaTypeInfo.put(myClass.getQualifiedName(), schemaTypeInfo);
NamespaceInfo namespaceInfo = this.packageToPackageInfoMappings.get(myClass.getPackageName()).getNamespaceInfo();
if (namespaceInfo.getLocation() != null && !namespaceInfo.getLocation().equals(GENERATE)) {
return;
}
Schema schema = getSchemaForNamespace(info.getClassNamespace(), myClass.getPackageName());
info.setSchema(schema);
String typeName = info.getSchemaTypeName();
String pfx = EMPTY_STRING;
Property valueField = null;
if (info.isSetXmlRootElement()) {
// Create the root element and add it to the schema
org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement xmlRE = info.getXmlRootElement();
rootElement = new Element();
String elementName = xmlRE.getName();
if (elementName.equals(XMLProcessor.DEFAULT) || elementName.equals(EMPTY_STRING)) {
try {
elementName = info.getXmlNameTransformer().transformRootElementName(myClassName);
} catch (Exception ex) {
throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(myClassName, info.getXmlNameTransformer().getClass().getName(), ex);
}
}
rootElement.setName(elementName);
String rootNamespace = xmlRE.getNamespace();
if (rootNamespace.equals(XMLProcessor.DEFAULT)) {
Schema rootElementSchema = getSchemaForNamespace(namespaceInfo.getNamespace());
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(namespaceInfo.getNamespace(), rootNamespace));
rootNamespace = namespaceInfo.getNamespace();
} else {
Schema rootElementSchema = getSchemaForNamespace(rootNamespace);
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(rootNamespace, elementName));
}
// handle root-level imports/includes [schema = the type's schema]
Schema rootSchema = getSchemaForNamespace(rootNamespace);
addImportIfRequired(rootSchema, schema, schema.getTargetNamespace());
// setup a prefix, if necessary
if (rootSchema != null && !info.getClassNamespace().equals(EMPTY_STRING)) {
pfx = getOrGeneratePrefixForNamespace(info.getClassNamespace(), rootSchema);
pfx += COLON;
}
}
if (CompilerHelper.isSimpleType(info)) {
SimpleType type = new SimpleType();
// simple type case, we just need the name and namespace info
if (typeName.equals(EMPTY_STRING)) {
// A root elem or locally defined whenever used
if (rootElement != null) {
rootElement.setSimpleType(type);
}
} else {
type.setName(typeName);
schema.addTopLevelSimpleTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
// Figure out schema type and set it as Restriction
QName restrictionType = null;
Restriction restriction = new Restriction();
if (info.isEnumerationType()) {
restrictionType = ((EnumTypeInfo) info).getRestrictionBase();
restriction.setEnumerationFacets(this.getEnumerationFacetsFor((EnumTypeInfo) info));
String prefix = null;
if (restrictionType.getNamespaceURI() != null && !EMPTY_STRING.equals(restrictionType.getNamespaceURI())) {
if (javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(restrictionType.getNamespaceURI())) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, restrictionType.getNamespaceURI());
}
}
String extensionTypeName = restrictionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
restriction.setBaseType(extensionTypeName);
type.setRestriction(restriction);
} else {
valueField = info.getXmlValueProperty();
JavaClass javaType = valueField.getActualType();
QName baseType = getSchemaTypeFor(javaType);
String prefix = null;
if (baseType.getNamespaceURI() != null && !baseType.getNamespaceURI().equals(EMPTY_STRING)) {
if (baseType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, baseType.getNamespaceURI());
}
}
String baseTypeName = baseType.getLocalPart();
if (prefix != null) {
baseTypeName = prefix + COLON + baseTypeName;
}
if (valueField.isXmlList() || (valueField.getGenericType() != null)) {
// generate a list instead of a restriction
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
list.setItemType(baseTypeName);
type.setList(list);
} else {
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
// TODO: This assignment seems like a bug, probably this should be "baseTypeName" ?
baseType = new QName(schemaType.namespace(), schemaType.name());
}
restriction.setBaseType(baseTypeName);
type.setRestriction(restriction);
}
}
info.setSimpleType(type);
} else if ((valueField = this.getXmlValueFieldForSimpleContent(info)) != null) {
ComplexType type = new ComplexType();
SimpleContent content = new SimpleContent();
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
} else {
type.setName(typeName);
schema.addTopLevelComplexTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
QName extensionType = getSchemaTypeFor(valueField.getType());
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
extensionType = new QName(schemaType.namespace(), schemaType.name());
}
String prefix = null;
if (extensionType.getNamespaceURI() != null && !extensionType.getNamespaceURI().equals(EMPTY_STRING)) {
if (extensionType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, extensionType.getNamespaceURI());
}
}
String extensionTypeName = extensionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
Extension extension = new Extension();
extension.setBaseType(extensionTypeName);
content.setExtension(extension);
type.setSimpleContent(content);
info.setComplexType(type);
} else {
ComplexType type = createComplexTypeForClass(myClass, info);
TypeDefParticle compositor = null;
if (type.getComplexContent() != null && type.getComplexContent().getExtension() != null) {
compositor = type.getComplexContent().getExtension().getTypeDefParticle();
} else {
compositor = type.getTypeDefParticle();
}
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
info.setCompositor(compositor);
} else {
type.setName(typeName);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
schema.addTopLevelComplexTypes(type);
info.setComplexType(type);
info.setCompositor(compositor);
}
}
}
Aggregations