/** <p>Creates a constructor with protected access and a single argument,
* the backing object.</p>
*/
protected JavaConstructor getConstructor(JavaSource pJs, InterfaceDescription[] pInterfaces) {
JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PROTECTED);
jcon.addParam(Object.class, "o");
jcon.addIf("o == null");
jcon.addThrowNew(NullPointerException.class,
JavaSource.getQuoted("The supplied object must not be null."));
jcon.addEndIf();
for (int i = 0; i < pInterfaces.length; i++) {
if (pInterfaces[i].isMandatory) {
jcon.addIf("!(o instanceof ", pInterfaces[i].getInterface(), ")");
jcon.addThrowNew(ClassCastException.class,
JavaSource.getQuoted("The supplied instance of "),
" + o.getClass().getName() + ",
JavaSource.getQuoted(" is not implementing "),
" + ", pInterfaces[i].getInterface(), ".class.getName()");
jcon.addEndIf();
}
}
jcon.addLine("backingObject = o;");
return jcon;
}