OK, silly me... I didn't "svn up" properly.
Anyway, looking at your code, the reason it isn't working is that you are
installing the facet onto the object, rather than each of the members.
In the processClassContext(), the problem is that facetHolder is going to
relate to the ObjectSpecification:
@Override
public void process(final ProcessClassContext processClassContext) {
final Class<?> cls = processClassContext.getCls();
final FacetHolder facetHolder =
processClassContext.getFacetHolder();
final Method method =
MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
DISABLED_PREFIX, String.class, NO_PARAMETERS_TYPES);
if (method != null) {
FacetUtil.addFacet(new
DisabledObjectFacetViaDisabledMethod(method, *facetHolder*)); <<<<<<<
HERE'S THE PROBLEM
processClassContext.removeMethod(method);
}
}
Instead, you're going to have to hack it a little, by looping through the
members and installing the facet on each. It'll be something like:
ObjectSpecification objectSpec =
getSpecificationLoader().loadSpecification(processClassContext.getCls());
final Method method =
MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, DISABLED_PREFIX,
String.class, NO_PARAMETERS_TYPES);
for(ObjectMember member: objectSpec.getMembers()) {
FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
member);
}
processClassContext.removeMethod(method);
~~~
As for your hidden() facet, you'll probably need to do something similar.
It shouldn't be necessary to hack individual viewers. It also isn't
necessary to manually create an InteractionContext; that is done for you.
A good place to put a break point in order to see the stacktrace is in the
InteractionUtils class.
HTH
Dan
On 2 December 2011 17:10, Kevin Meyer - KMZ <[email protected]> wrote:
> Hi Dan,
>
> I've (mostly) implemented an equivalent hidden() on object, and I
> discovered that I was missing adding my HiddenMethodFact from the
> metamodel.
>
> Now I got the hidden() method working in the htmlviewer, but it could
> be a bit of a kludge, as this approach would need each viewer to be
> handled specifically.
>
> Anyway - using this knowledge, I went back to the disabled() method,
> and realised that I am probably looking at hooking into the isVetoed
> and equivalent methods in the metamodel, but I can't find where the
> Context is setup and appropriate Facets interrogated.
>
> Where else do I need to add my DisabledObjectFacet so that the
> metamodel picks it up?
>
> Regards,
> Kevin
>
>
> On 30 Nov 2011 at 17:53, Kevin Meyer - KMZ wrote:
>
> > Hi Dan,
> >
> > I remember discussing something like this with you at the Knockree
> > retreat - I've implemented the various classes to support a
> > String disabled(){..};
> > method on an object, to runtime prevent a user from editting any of the
> > properties.
> >
> > The problem is, it doesn't work! :)
> >
> > Following the examples of the Immutable facet and the "validate"
> > method facet, I have:
> >
> > public class DisabledObjectFacetViaDisabledMethod extends
> DisabledObjectFacetAbstract implements ImperativeFacet
> >
> > where
> >
> > public abstract class DisabledObjectFacetAbstract extends FacetAbstract
> implements DisabledObjectFacet
> >
> > and
> >
> > public interface DisabledObjectFacet extends Facet,
> DisablingInteractionAdvisor
> >
> > The factory is registered in ProgrammingModelFacetsJava5:
> > addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
> >
> > But when I load an object with the "disabled()" method, I can still edit
> it.
> > The "disabled" method is not visible, so it's being picked up...
> >
> > This tells me that the "DisablingInteractionAdvisor " is not doing what I
> > expect..
> >
> > What am I missing?
> >
> >
> > Since the unit test passes, I'll check in the code, associated with
> > ISIS-142
> >
> > Regards,
> > Kevin
> >
>
>
> --
> Kevin Meyer, PhD, Pr.Sci.Nat
> KMZ P.O. Box 9822, Sharon Park, South Africa.
> Tel: +27 11 363 2001 Cell: +27 83 346 3045
>
>
>