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 MandatoryFacetExplicitForProperty) {
// do not replace this facet;
// an explicit @Mandatory annotation cannot be overridden by @Column annotation
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);
}
}