use of jakarta.xml.bind.annotation.XmlAnyAttribute in project glassfish-hk2 by eclipse-ee4j.
the class GeneratorUtilities method getXmlNameMap.
public static NameInformation getXmlNameMap(AltClass convertMe) {
Map<String, XmlElementData> xmlNameMap = new LinkedHashMap<String, XmlElementData>();
Set<String> unmappedNames = new LinkedHashSet<String>();
Map<String, String> addMethodToVariableMap = new LinkedHashMap<String, String>();
Map<String, String> removeMethodToVariableMap = new LinkedHashMap<String, String>();
Map<String, String> lookupMethodToVariableMap = new LinkedHashMap<String, String>();
Set<String> referenceSet = new LinkedHashSet<String>();
Map<String, List<XmlElementData>> aliasMap = new LinkedHashMap<String, List<XmlElementData>>();
XmlElementData valueData = null;
XmlElementData xmlAnyAttributeData = null;
boolean hasAnElement = false;
for (AltMethod originalMethod : convertMe.getMethods()) {
String originalMethodName = originalMethod.getName();
String setterVariable = Utilities.isSetter(originalMethod);
if (setterVariable == null) {
setterVariable = Utilities.isGetter(originalMethod);
if (setterVariable == null)
continue;
}
if (isSpecifiedReference(originalMethod)) {
referenceSet.add(setterVariable);
}
AltAnnotation pluralOf = null;
AltAnnotation xmlElement = originalMethod.getAnnotation(XmlElement.class.getName());
AltAnnotation xmlElements = originalMethod.getAnnotation(XmlElements.class.getName());
AltAnnotation xmlElementWrapper = originalMethod.getAnnotation(XmlElementWrapper.class.getName());
AltAnnotation xmlAttribute = originalMethod.getAnnotation(XmlAttribute.class.getName());
AltAnnotation xmlValue = originalMethod.getAnnotation(XmlValue.class.getName());
AltAnnotation xmlAnyAttribute = originalMethod.getAnnotation(XmlAnyAttribute.class.getName());
String xmlElementWrapperName = (xmlElementWrapper == null) ? null : xmlElementWrapper.getStringValue("name");
if (xmlElementWrapperName != null && xmlElementWrapperName.isEmpty()) {
xmlElementWrapperName = setterVariable;
}
checkOnlyOne(convertMe, originalMethod, xmlElement, xmlElements);
checkOnlyOne(convertMe, originalMethod, xmlElement, xmlAttribute);
checkOnlyOne(convertMe, originalMethod, xmlElements, xmlAttribute);
checkOnlyOne(convertMe, originalMethod, xmlElement, xmlValue);
checkOnlyOne(convertMe, originalMethod, xmlElements, xmlValue);
checkOnlyOne(convertMe, originalMethod, xmlAttribute, xmlValue);
checkOnlyOne(convertMe, originalMethod, xmlElement, xmlAnyAttribute);
checkOnlyOne(convertMe, originalMethod, xmlElements, xmlAnyAttribute);
checkOnlyOne(convertMe, originalMethod, xmlAttribute, xmlAnyAttribute);
checkOnlyOne(convertMe, originalMethod, xmlValue, xmlAnyAttribute);
if (xmlElements != null) {
hasAnElement = true;
// First add the actual method so it is known to the system
pluralOf = originalMethod.getAnnotation(PluralOf.class.getName());
String defaultValue = Generator.JAXB_DEFAULT_DEFAULT;
xmlNameMap.put(setterVariable, new XmlElementData("", setterVariable, setterVariable, defaultValue, Format.ELEMENT, null, true, xmlElementWrapperName, false, originalMethodName));
String aliasName = setterVariable;
AltAnnotation[] allXmlElements = xmlElements.getAnnotationArrayValue("value");
List<XmlElementData> aliases = new ArrayList<XmlElementData>(allXmlElements.length);
aliasMap.put(setterVariable, aliases);
for (AltAnnotation allXmlElement : allXmlElements) {
defaultValue = allXmlElement.getStringValue("defaultValue");
String allXmlElementNamespace = allXmlElement.getStringValue("namespace");
String allXmlElementName = allXmlElement.getStringValue("name");
boolean allXmlElementRequired = allXmlElement.getBooleanValue("required");
AltClass allXmlElementType = (AltClass) allXmlElement.getAnnotationValues().get("type");
String allXmlElementTypeName = (allXmlElementType == null) ? null : allXmlElementType.getName();
boolean allXmlElementTypeInterface = (allXmlElementType == null) ? true : allXmlElementType.isInterface();
if (Generator.JAXB_DEFAULT_STRING.equals(allXmlElementName)) {
throw new IllegalArgumentException("The name field of an XmlElement inside an XmlElements must have a specified name");
} else {
aliases.add(new XmlElementData(allXmlElementNamespace, allXmlElementName, aliasName, defaultValue, Format.ELEMENT, allXmlElementTypeName, allXmlElementTypeInterface, xmlElementWrapperName, allXmlElementRequired, originalMethodName));
}
}
} else if (xmlElement != null) {
hasAnElement = true;
// Get the pluralOf from the method
pluralOf = originalMethod.getAnnotation(PluralOf.class.getName());
String defaultValue = xmlElement.getStringValue("defaultValue");
String namespace = xmlElement.getStringValue("namespace");
String name = xmlElement.getStringValue("name");
boolean required = xmlElement.getBooleanValue("required");
if (Generator.JAXB_DEFAULT_STRING.equals(name)) {
xmlNameMap.put(setterVariable, new XmlElementData(namespace, setterVariable, setterVariable, defaultValue, Format.ELEMENT, null, true, xmlElementWrapperName, required, originalMethodName));
} else {
xmlNameMap.put(setterVariable, new XmlElementData(namespace, name, name, defaultValue, Format.ELEMENT, null, true, xmlElementWrapperName, required, originalMethodName));
}
} else if (xmlAttribute != null) {
String namespace = xmlAttribute.getStringValue("namespace");
String name = xmlAttribute.getStringValue("name");
boolean required = xmlAttribute.getBooleanValue("required");
if (Generator.JAXB_DEFAULT_STRING.equals(name)) {
xmlNameMap.put(setterVariable, new XmlElementData(namespace, setterVariable, setterVariable, Generator.JAXB_DEFAULT_DEFAULT, Format.ATTRIBUTE, null, true, xmlElementWrapperName, required, originalMethodName));
} else {
xmlNameMap.put(setterVariable, new XmlElementData(namespace, name, name, Generator.JAXB_DEFAULT_DEFAULT, Format.ATTRIBUTE, null, true, xmlElementWrapperName, required, originalMethodName));
}
} else if (xmlValue != null) {
if (valueData != null) {
throw new IllegalArgumentException("There may be only one XmlValue method on " + convertMe);
}
valueData = new XmlElementData(XmlService.DEFAULT_NAMESPACE, XML_VALUE_LOCAL_PART, XML_VALUE_LOCAL_PART, null, Format.VALUE, null, false, xmlElementWrapperName, true, originalMethodName);
xmlNameMap.put(setterVariable, valueData);
} else if (xmlAnyAttribute != null) {
if (xmlAnyAttributeData != null) {
throw new IllegalArgumentException("There may be only one XmlAnyAttribute method on " + convertMe);
}
xmlAnyAttributeData = new XmlElementData(XmlService.DEFAULT_NAMESPACE, XML_ANY_ATTRIBUTE_LOCAL_PART, XML_ANY_ATTRIBUTE_LOCAL_PART, null, Format.ATTRIBUTE, null, false, xmlElementWrapperName, false, originalMethodName);
xmlNameMap.put(setterVariable, xmlAnyAttributeData);
} else {
unmappedNames.add(setterVariable);
}
if (pluralOf == null)
pluralOf = new AnnotationAltAnnotationImpl(new PluralOfDefault(), null);
String unDecapitalizedVariable = originalMethod.getName().substring(3);
addMethodToVariableMap.put(getMethodName(MethodType.ADD, unDecapitalizedVariable, pluralOf), setterVariable);
removeMethodToVariableMap.put(getMethodName(MethodType.REMOVE, unDecapitalizedVariable, pluralOf), setterVariable);
lookupMethodToVariableMap.put(getMethodName(MethodType.LOOKUP, unDecapitalizedVariable, pluralOf), setterVariable);
}
if (valueData != null && hasAnElement) {
throw new IllegalArgumentException("A bean cannot both have XmlElements and XmlValue methods in " + convertMe);
}
Set<String> noXmlElementNames = new LinkedHashSet<String>();
for (String unmappedName : unmappedNames) {
if (!xmlNameMap.containsKey(unmappedName)) {
noXmlElementNames.add(unmappedName);
}
}
return new NameInformation(xmlNameMap, noXmlElementNames, addMethodToVariableMap, removeMethodToVariableMap, lookupMethodToVariableMap, referenceSet, aliasMap, valueData);
}
Aggregations