// get the class to be used for class decorator instance
ValidationContext vctx = (ValidationContext)ictx.getUserContext();
UnmarshallingContext ctx = (UnmarshallingContext)ictx;
String cname = ctx.attributeText(null, "class", null);
if (cname == null) {
vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx));
} else {
try {
// make sure the class implements the required interface
Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
if (ClassDecorator.class.isAssignableFrom(clas)) {
vctx.addError("Class " + cname + " does not implement the required IClassDecorator interface",
new ProblemLocation(ictx));
} else {
try {
return (ClassDecorator)clas.newInstance();
} catch (InstantiationException e) {
vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(),
new ProblemLocation(ictx));
} catch (IllegalAccessException e) {
vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(),
new ProblemLocation(ictx));
}
}
} catch (ClassNotFoundException e) {
vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ictx));
}
}
return null;
}