/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
public class MemberOrderAnnotationFacetFactory 
        extends AnnotationBasedFacetFactoryAbstract {
    public MemberOrderAnnotationFacetFactory() {
        super(
            NakedObjectFeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS);
    }
    @Override
    public boolean process(
            final Class<?> cls,
            final Method method, final MethodRemover methodRemover, 
            final FacetHolder holder) {
        Class<MemberOrder> annotationClass = MemberOrder.class;
        final MemberOrder annotation = 
            getAnnotation(method, annotationClass);
        return FacetUtil.addFacet(create(annotation, holder));
    }
    private MemberOrderFacet create(
            final MemberOrder annotation, final FacetHolder holder) {
        return annotation == null ? null : 
            new MemberOrderFacetAnnotation(
                    annotation.name(), annotation.sequence(), holder);
    }
}

