use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo in project midpoint by Evolveum.
the class ProcessorUtils method hasAnnotation.
private static BIDeclaration hasAnnotation(XSAnnotation annotation, QName qname) {
if (annotation == null) {
return null;
}
Object object = annotation.getAnnotation();
if (!(object instanceof BindInfo)) {
return null;
}
BindInfo info = (BindInfo) object;
BIDeclaration[] declarations = info.getDecls();
if (declarations == null) {
return null;
}
for (BIDeclaration declaration : declarations) {
if (qname.equals(declaration.getName())) {
return declaration;
}
}
return null;
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo in project jaxb-ri by eclipse-ee4j.
the class SimpleTypeBuilder method checkRefererCustomization.
/**
* Checks if the referer has a conversion customization or not.
* If it does, use it to bind this simple type. Otherwise
* return null;
*/
private TypeUse checkRefererCustomization(XSSimpleType type) {
// assertion check. referer must be set properly
// before the build method is called.
// since the handling of the simple type point-of-reference
// customization is very error prone, it deserves a strict
// assertion check.
// UGLY CODE WARNING
XSComponent top = getReferer();
if (top instanceof XSElementDecl) {
// if the parent is element type, its content type must be us.
XSElementDecl eref = (XSElementDecl) top;
assert eref.getType() == type;
// for elements, you can't use <property>,
// so we allow javaType to appear directly.
BindInfo info = builder.getBindInfo(top);
BIConversion conv = info.get(BIConversion.class);
if (conv != null) {
conv.markAsAcknowledged();
// the conversion is given.
return conv.getTypeUse(type);
}
detectJavaTypeCustomization();
} else if (top instanceof XSAttributeDecl) {
XSAttributeDecl aref = (XSAttributeDecl) top;
assert aref.getType() == type;
detectJavaTypeCustomization();
} else if (top instanceof XSComplexType) {
XSComplexType tref = (XSComplexType) top;
assert tref.getBaseType() == type || tref.getContentType() == type;
detectJavaTypeCustomization();
} else if (top == type) {
// this means the simple type is built by itself and
// not because it's referenced by something.
} else
// unexpected referer type.
assert false;
// now we are certain that the referer is OK.
// see if it has a conversion customization.
BIConversion conv = getRefererCustomization();
if (conv != null) {
conv.markAsAcknowledged();
// the conversion is given.
return conv.getTypeUse(type);
} else
// not found
return null;
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo in project jaxb-ri by eclipse-ee4j.
the class SimpleTypeBuilder method find.
/**
* Checks if there's any binding available on the given type.
*
* @return
* null if not (which causes the {@link #compose(XSSimpleType)} method
* to do ascending.
*/
private TypeUse find(XSSimpleType type) {
TypeUse r;
boolean noAutoEnum = false;
// check for user specified conversion
BindInfo info = builder.getBindInfo(type);
BIConversion conv = info.get(BIConversion.class);
if (conv != null) {
// a conversion was found
conv.markAsAcknowledged();
return conv.getTypeUse(type);
}
// look for enum customization, which is another user specified conversion
BIEnum en = info.get(BIEnum.class);
if (en != null) {
en.markAsAcknowledged();
if (!en.isMapped()) {
noAutoEnum = true;
} else {
// the type is OK
if (!canBeMappedToTypeSafeEnum(type)) {
getErrorReporter().error(en.getLocation(), Messages.ERR_CANNOT_BE_TYPE_SAFE_ENUM);
getErrorReporter().error(type.getLocator(), Messages.ERR_CANNOT_BE_TYPE_SAFE_ENUM_LOCATION);
// recover by ignoring this customization
return null;
}
// reference?
if (en.ref != null) {
if (!JJavaName.isFullyQualifiedClassName(en.ref)) {
Ring.get(ErrorReceiver.class).error(en.getLocation(), Messages.format(Messages.ERR_INCORRECT_CLASS_NAME, en.ref));
// recover by ignoring @ref
return null;
}
return new CClassRef(model, type, en, info.toCustomizationList());
}
// so in this stage we can safely cast it to XSRestrictionSimpleType
return bindToTypeSafeEnum((XSRestrictionSimpleType) type, en.className, en.javadoc, en.members, getEnumMemberMode().getModeWithEnum(), en.getLocation());
}
}
// if the type is built in, look for the default binding
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(type.getTargetNamespace())) {
String name = type.getName();
if (name != null) {
r = lookupBuiltin(name);
if (r != null)
return r;
}
}
// also check for swaRef
if (type.getTargetNamespace().equals(WellKnownNamespace.SWA_URI)) {
String name = type.getName();
if (name != null && name.equals("swaRef"))
return CBuiltinLeafInfo.STRING.makeAdapted(SwaRefAdapterMarker.class, false);
}
// if so, built a EnumXDucer from it and return it.
if (type.isRestriction() && !noAutoEnum) {
XSRestrictionSimpleType rst = type.asRestriction();
if (shouldBeMappedToTypeSafeEnumByDefault(rst)) {
r = bindToTypeSafeEnum(rst, null, null, Collections.emptyMap(), getEnumMemberMode(), null);
if (r != null)
return r;
}
}
return (CNonElement) getClassSelector()._bindToClass(type, null, false);
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo in project jaxb-ri by eclipse-ee4j.
the class SimpleTypeBuilder method getRefererCustomization.
/**
* Returns a javaType customization specified to the referer, if present.
* @return can be null.
*/
private BIConversion getRefererCustomization() {
BindInfo info = builder.getBindInfo(getReferer());
BIProperty prop = info.get(BIProperty.class);
if (prop == null)
return null;
return prop.getConv();
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo in project jaxb-ri by eclipse-ee4j.
the class BGMBuilder method checkMultipleSchemaBindings.
/**
* Reports an error if there are more than one jaxb:schemaBindings customization.
*/
private void checkMultipleSchemaBindings(XSSchema schema) {
ArrayList<Locator> locations = new ArrayList<>();
BindInfo bi = getBindInfo(schema);
for (BIDeclaration bid : bi) {
if (bid.getName() == BISchemaBinding.NAME)
locations.add(bid.getLocation());
}
// OK
if (locations.size() <= 1)
return;
// error
getErrorReporter().error(locations.get(0), Messages.ERR_MULTIPLE_SCHEMA_BINDINGS, schema.getTargetNamespace());
for (int i = 1; i < locations.size(); i++) getErrorReporter().error(locations.get(i), Messages.ERR_MULTIPLE_SCHEMA_BINDINGS_LOCATION);
}
Aggregations