use of jakarta.xml.bind.annotation.XmlElementDecl in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processObjectFactory.
public JavaClass[] processObjectFactory(JavaClass objectFactoryClass, List<JavaClass> classes) {
String className = objectFactoryClass.getName();
if (objectFactoryClassNames.contains(className)) {
return new JavaClass[0];
}
objectFactoryClassNames.add(className);
// if there is an xml-registry from XML for this JavaClass, create a map
// of method names to XmlElementDecl objects to simplify processing
// later on in this method
Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl> elemDecls = new HashMap<>();
org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry xmlReg = xmlRegistries.get(objectFactoryClass.getQualifiedName());
if (xmlReg != null) {
// process xml-element-decl entries
for (org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl xmlElementDecl : xmlReg.getXmlElementDecl()) {
// key each element-decl on method name
elemDecls.put(xmlElementDecl.getJavaMethod(), xmlElementDecl);
}
}
Collection methods = objectFactoryClass.getDeclaredMethods();
Iterator methodsIter = methods.iterator();
PackageInfo packageInfo = getPackageInfoForPackage(objectFactoryClass);
while (methodsIter.hasNext()) {
JavaMethod next = (JavaMethod) methodsIter.next();
if (next.getName().startsWith(CREATE)) {
JavaClass type = next.getReturnType();
if (JAVAX_XML_BIND_JAXBELEMENT.equals(type.getName())) {
Object[] actualTypeArguments = type.getActualTypeArguments().toArray();
if (actualTypeArguments.length == 0) {
type = helper.getObjectClass();
} else {
type = (JavaClass) actualTypeArguments[0];
}
type = processXmlElementDecl(type, next, packageInfo, elemDecls);
} else if (helper.getJaxbElementClass().isAssignableFrom(type)) {
this.factoryMethods.put(type.getRawName(), next);
type = processXmlElementDecl(type, next, packageInfo, elemDecls);
} else {
this.factoryMethods.put(type.getRawName(), next);
}
if (!helper.isBuiltInJavaType(type) && !helper.classExistsInArray(type, classes)) {
classes.add(type);
}
}
}
if (classes.size() > 0) {
classesToProcessPropertyTypes.addAll(classes);
return classes.toArray(new JavaClass[classes.size()]);
} else {
return new JavaClass[0];
}
}
use of jakarta.xml.bind.annotation.XmlElementDecl in project eclipselink by eclipse-ee4j.
the class ObjectFactory method createTask.
@XmlElementDecl(name = "task")
public JAXBElement<Task> createTask(Task t) {
JAXBElement<Task> task = new JAXBElement<Employee.Task>(new QName("task"), Task.class, t);
task.setNil(true);
return task;
}
use of jakarta.xml.bind.annotation.XmlElementDecl in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processXmlElementDecl.
private JavaClass processXmlElementDecl(JavaClass type, JavaMethod next, PackageInfo packageInfo, Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl> elemDecls) {
JavaClass returnType = type;
// if there's an XmlElementDecl for this method from XML, use it
// - otherwise look for an annotation
org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl xmlEltDecl = elemDecls.get(next.getName());
if ((xmlEltDecl != null) || helper.isAnnotationPresent(next, XmlElementDecl.class)) {
QName qname;
QName substitutionHead = null;
String url;
String localName;
String defaultValue = null;
Class<?> scopeClass = jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class;
if (xmlEltDecl != null) {
url = xmlEltDecl.getNamespace();
localName = xmlEltDecl.getName();
String scopeClassName = xmlEltDecl.getScope();
if (!scopeClassName.equals(ELEMENT_DECL_GLOBAL)) {
JavaClass jScopeClass = helper.getJavaClass(scopeClassName);
if (jScopeClass != null) {
scopeClass = helper.getClassForJavaClass(jScopeClass);
if (scopeClass == null) {
scopeClass = jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class;
}
}
}
if (!xmlEltDecl.getSubstitutionHeadName().equals(EMPTY_STRING)) {
String subHeadLocal = xmlEltDecl.getSubstitutionHeadName();
String subHeadNamespace = xmlEltDecl.getSubstitutionHeadNamespace();
if (subHeadNamespace.equals(XMLProcessor.DEFAULT)) {
subHeadNamespace = packageInfo.getNamespace();
}
substitutionHead = new QName(subHeadNamespace, subHeadLocal);
}
if (!(xmlEltDecl.getDefaultValue().length() == 1 && xmlEltDecl.getDefaultValue().startsWith(ELEMENT_DECL_DEFAULT))) {
defaultValue = xmlEltDecl.getDefaultValue();
}
} else {
// there was no xml-element-decl for this method in XML,
// so use the annotation
XmlElementDecl elementDecl = (XmlElementDecl) helper.getAnnotation(next, XmlElementDecl.class);
url = elementDecl.namespace();
localName = elementDecl.name();
scopeClass = elementDecl.scope();
if (!elementDecl.substitutionHeadName().equals(EMPTY_STRING)) {
String subHeadLocal = elementDecl.substitutionHeadName();
String subHeadNamespace = elementDecl.substitutionHeadNamespace();
if (subHeadNamespace.equals(XMLProcessor.DEFAULT)) {
subHeadNamespace = packageInfo.getNamespace();
}
substitutionHead = new QName(subHeadNamespace, subHeadLocal);
}
if (!(elementDecl.defaultValue().length() == 1 && elementDecl.defaultValue().startsWith(ELEMENT_DECL_DEFAULT))) {
defaultValue = elementDecl.defaultValue();
}
}
if (XMLProcessor.DEFAULT.equals(url)) {
url = packageInfo.getNamespace();
}
if (Constants.EMPTY_STRING.equals(url)) {
isDefaultNamespaceAllowed = false;
qname = new QName(localName);
} else {
qname = new QName(url, localName);
}
boolean isList = false;
if (JAVA_UTIL_LIST.equals(type.getName())) {
isList = true;
Collection args = type.getActualTypeArguments();
if (args.size() > 0) {
type = (JavaClass) args.iterator().next();
}
}
ElementDeclaration declaration = new ElementDeclaration(qname, type, type.getQualifiedName(), isList, scopeClass);
if (substitutionHead != null) {
declaration.setSubstitutionHead(substitutionHead);
}
if (defaultValue != null) {
declaration.setDefaultValue(defaultValue);
}
if (helper.isAnnotationPresent(next, XmlJavaTypeAdapter.class)) {
XmlJavaTypeAdapter typeAdapter = (XmlJavaTypeAdapter) helper.getAnnotation(next, XmlJavaTypeAdapter.class);
Class<? extends XmlAdapter> typeAdapterClass = typeAdapter.value();
declaration.setJavaTypeAdapterClass(typeAdapterClass);
Class<?> declJavaType = CompilerHelper.getTypeFromAdapterClass(typeAdapterClass);
JavaClass adaptedType = helper.getJavaClass(declJavaType);
declaration.setJavaType(adaptedType);
declaration.setAdaptedJavaType(type);
returnType = adaptedType;
}
if (helper.isAnnotationPresent(next, XmlMimeType.class)) {
XmlMimeType mimeType = (XmlMimeType) helper.getAnnotation(next, XmlMimeType.class);
declaration.setXmlMimeType(mimeType.value());
}
if (helper.isAnnotationPresent(next, XmlAttachmentRef.class)) {
declaration.setXmlAttachmentRef(true);
}
Map<QName, ElementDeclaration> elements = getElementDeclarationsForScope(scopeClass.getName());
if (elements == null) {
elements = new HashMap<>();
this.elementDeclarations.put(scopeClass.getName(), elements);
}
if (elements.containsKey(qname)) {
throw JAXBException.duplicateElementName(qname);
}
elements.put(qname, declaration);
}
return returnType;
}
use of jakarta.xml.bind.annotation.XmlElementDecl in project eclipselink by eclipse-ee4j.
the class ObjectFactory method createAddress.
@XmlElementDecl(name = "address")
public JAXBElement<Address> createAddress(Address a) {
JAXBElement<Address> address = new JAXBElement<Address>(new QName("address"), Address.class, a);
address.setNil(true);
return address;
}
Aggregations