use of com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue in project enunciate by stoicflame.
the class QNameEnumUtil method createQNameMap.
private static <Q extends Enum<Q>> Map<? extends Enum, QName> createQNameMap(Class<Q> clazz) {
EnumMap<Q, QName> enumQNameEnumMap = new EnumMap<Q, QName>(clazz);
XmlQNameEnum enumInfo = clazz.getAnnotation(XmlQNameEnum.class);
if (enumInfo == null) {
throw new IllegalArgumentException("Class " + clazz.getName() + " isn't a QName enum.");
}
String namespace = enumInfo.namespace();
if ("##default".equals(namespace)) {
Package pkg = clazz.getPackage();
if (pkg != null) {
XmlSchema schemaInfo = pkg.getAnnotation(XmlSchema.class);
namespace = schemaInfo.namespace();
}
}
Field[] fields = clazz.getDeclaredFields();
for (Q e : clazz.getEnumConstants()) {
for (Field field : fields) {
if (field.isEnumConstant() && field.getName().equals(e.name())) {
if (field.getAnnotation(XmlUnknownQNameEnumValue.class) != null) {
enumQNameEnumMap.put(e, UNKNOWN_QNAME_ENUM);
break;
}
XmlQNameEnumValue enumValueInfo = field.getAnnotation(XmlQNameEnumValue.class);
String ns = namespace;
String localPart = field.getName();
if (enumValueInfo != null) {
if (enumValueInfo.exclude()) {
enumQNameEnumMap.put(e, EXCLUDED_QNAME_ENUM);
break;
} else {
if (!"##default".equals(enumValueInfo.namespace())) {
ns = enumValueInfo.namespace();
}
if (!"##default".equals(enumValueInfo.localPart())) {
localPart = enumValueInfo.localPart();
}
}
}
enumQNameEnumMap.put(e, new QName(ns, localPart));
}
}
}
return enumQNameEnumMap;
}
use of com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue in project enunciate by stoicflame.
the class QNameEnumTypeDefinition method loadEnumValues.
@Override
protected List<EnumValue> loadEnumValues() {
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
VariableElement unknownQNameConstant = null;
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
XmlUnknownQNameEnumValue unknownQNameEnumValue = enumConstant.getAnnotation(XmlUnknownQNameEnumValue.class);
if (unknownQNameEnumValue != null) {
if (unknownQNameConstant != null) {
throw new EnunciateException(getQualifiedName() + ": no more than two constants can be annotated with @XmlUnknownQNameEnumValue.");
}
unknownQNameConstant = enumConstant;
continue;
}
String ns = this.namespace;
String localPart = enumConstant.getSimpleName().toString();
XmlQNameEnumValue enumValueInfo = enumConstant.getAnnotation(XmlQNameEnumValue.class);
if (enumValueInfo != null) {
if (enumValueInfo.exclude()) {
continue;
}
if (!"##default".equals(enumValueInfo.namespace())) {
ns = enumValueInfo.namespace();
}
if (!"##default".equals(enumValueInfo.localPart())) {
localPart = enumValueInfo.localPart();
}
}
String uri = ns + localPart;
if (!enumValues.add(uri)) {
throw new EnunciateException(getQualifiedName() + ": duplicate qname enum value: " + uri);
}
enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), uri));
}
if (unknownQNameConstant != null) {
// enter the unknown qname constant as a null qname.
enumValueMap.add(new EnumValue(this, unknownQNameConstant, unknownQNameConstant.getSimpleName().toString(), null));
}
return enumValueMap;
}
use of com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue in project enunciate by stoicflame.
the class QNameEnumTypeDefinition method loadEnumValues.
@Override
protected List<EnumValue> loadEnumValues() {
String namespace = getPackage().getNamespace();
XmlQNameEnum xmlQNameEnum = getAnnotation(XmlQNameEnum.class);
if (xmlQNameEnum != null && !"##default".equals(xmlQNameEnum.namespace())) {
namespace = xmlQNameEnum.namespace();
}
if (namespace == null) {
namespace = "";
}
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValues = new ArrayList<EnumValue>();
HashSet<QName> enumValueValues = new HashSet<QName>(enumConstants.size());
VariableElement unknownQNameConstant = null;
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
XmlUnknownQNameEnumValue unknownQNameEnumValue = enumConstant.getAnnotation(XmlUnknownQNameEnumValue.class);
if (unknownQNameEnumValue != null) {
if (unknownQNameConstant != null) {
throw new EnunciateException(getQualifiedName() + ": no more than two constants can be annotated with @XmlUnknownQNameEnumValue.");
}
unknownQNameConstant = enumConstant;
continue;
}
String ns = namespace;
String localPart = enumConstant.getSimpleName().toString();
XmlQNameEnumValue enumValueInfo = enumConstant.getAnnotation(XmlQNameEnumValue.class);
if (enumValueInfo != null) {
if (enumValueInfo.exclude()) {
continue;
}
if (!"##default".equals(enumValueInfo.namespace())) {
ns = enumValueInfo.namespace();
}
if (!"##default".equals(enumValueInfo.localPart())) {
localPart = enumValueInfo.localPart();
}
}
QName qname = new QName(ns, localPart);
if (!enumValueValues.add(qname)) {
throw new EnunciateException(getQualifiedName() + ": duplicate qname enum value: " + qname);
}
enumValues.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), qname));
}
if (unknownQNameConstant != null) {
// enter the unknown qname constant as a null qname.
enumValues.add(new EnumValue(this, unknownQNameConstant, unknownQNameConstant.getSimpleName().toString(), null));
}
return enumValues;
}
use of com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue in project enunciate by stoicflame.
the class QNameEnumTypeDefinition method loadEnumValues.
@Override
protected List<EnumValue> loadEnumValues() {
List<VariableElement> enumConstants = enumValues();
List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
VariableElement unknownQNameConstant = null;
for (VariableElement enumConstant : enumConstants) {
if (isIgnored(enumConstant)) {
continue;
}
XmlUnknownQNameEnumValue unknownQNameEnumValue = enumConstant.getAnnotation(XmlUnknownQNameEnumValue.class);
if (unknownQNameEnumValue != null) {
if (unknownQNameConstant != null) {
throw new EnunciateException(getQualifiedName() + ": no more than two constants can be annotated with @XmlUnknownQNameEnumValue.");
}
unknownQNameConstant = enumConstant;
continue;
}
String ns = this.namespace;
String localPart = enumConstant.getSimpleName().toString();
XmlQNameEnumValue enumValueInfo = enumConstant.getAnnotation(XmlQNameEnumValue.class);
if (enumValueInfo != null) {
if (enumValueInfo.exclude()) {
continue;
}
if (!"##default".equals(enumValueInfo.namespace())) {
ns = enumValueInfo.namespace();
}
if (!"##default".equals(enumValueInfo.localPart())) {
localPart = enumValueInfo.localPart();
}
}
String uri = ns + localPart;
if (!enumValues.add(uri)) {
throw new EnunciateException(getQualifiedName() + ": duplicate qname enum value: " + uri);
}
enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), uri));
}
if (unknownQNameConstant != null) {
// enter the unknown qname constant as a null qname.
enumValueMap.add(new EnumValue(this, unknownQNameConstant, unknownQNameConstant.getSimpleName().toString(), null));
}
return enumValueMap;
}
Aggregations