public void process(final ProcessMethodContext processMethodContext) {
final Column annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Column.class);
final FacetedMethod holder = processMethodContext.getFacetHolder();
final MandatoryFacet existingFacet = holder.getFacet(MandatoryFacet.class);
if(existingFacet != null) {
if (existingFacet instanceof OptionalFacetDerivedFromJdoPrimaryKeyAnnotation) {
// do not replace this facet;
// we must keep an optional facet here for different reasons
return;
}
if (existingFacet instanceof MandatoryFacetOnPropertyMandatoryAnnotation) {
// do not replace this facet;
// an explicit @Mandatory annotation cannot be overridden by @Column annotation
return;
}
// TODO: this isn't really good enough; in theory there could be other implementations of view model
// rather than just implementing ViewModel. However, we can't do a lookup of the ObjectSpecification for 'cls'
// because we would (I think) go into an infinite loop...
final Class<?> cls = processMethodContext.getCls();
if(ViewModel.class.isAssignableFrom(cls)) {
return;
}
}
boolean required = whetherRequired(processMethodContext, annotation);
MandatoryFacet facet = annotation != null
? new MandatoryFacetDerivedFromJdoColumn(holder, required)
: new MandatoryFacetInferredFromAbsenceOfJdoColumn(holder, required);
// as a side-effect, will chain any existing facets.
// we'll exploit this fact for meta-model validation (see #refineMetaModelValidator(), below)
FacetUtil.addFacet(facet);
// however, if a @Column was explicitly provided, and the underlying facet
// was the simple MandatoryFacetDefault (from an absence of @Optional or @Mandatory),
// then don't chain, simply replace.
if(facet instanceof MandatoryFacetDerivedFromJdoColumn && facet.getUnderlyingFacet() instanceof MandatoryFacetDefault) {
facet.setUnderlyingFacet(null);
}
}