You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/01/17 09:48:56 UTC

svn commit: r1059813 [4/10] - in /incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets: ./ actcoll/typeof/ actions/ actions/choices/ actions/debug/ actions/debug/annotation/ actions/defaults/ actions/describedas/ acti...

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForContextFacetNone.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForContextFacetNone.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForContextFacetNone.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForContextFacetNone.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class DisableForContextFacetNone extends DisableForContextFacetAbstract {
+
+    public DisableForContextFacetNone(final FacetHolder holder) {
+        super(holder);
+    }
+
+    /**
+     * Always returns <tt>null</tt>.
+     */
+    public String disabledReason(final ObjectAdapter target) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacet.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacet.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacet.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.interactions.DisablingInteractionAdvisor;
+
+/**
+ * Disable a property, collection or action based on the current session.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to invoking the <tt>disableXxx(UserMemento)</tt> support
+ * method for the member.
+ */
+public interface DisableForSessionFacet extends Facet, DisablingInteractionAdvisor {
+
+    /**
+     * The reason this is disabled, or <tt>null</tt> if not.
+     */
+    public String disabledReason(AuthenticationSession session);
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetAbstract.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetAbstract.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetAbstract.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.applib.events.UsabilityEvent;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.UsabilityContext;
+
+
+public abstract class DisableForSessionFacetAbstract extends FacetAbstract implements DisableForSessionFacet {
+
+    public static Class<? extends Facet> type() {
+        return DisableForSessionFacet.class;
+    }
+
+    public DisableForSessionFacetAbstract(final FacetHolder holder) {
+        super(type(), holder, false);
+    }
+
+    public String disables(final UsabilityContext<? extends UsabilityEvent> ic) {
+        final AuthenticationSession session = ic.getSession();
+        return disabledReason(session);
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetNone.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetNone.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetNone.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisableForSessionFacetNone.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class DisableForSessionFacetNone extends DisableForSessionFacetAbstract {
+
+    public DisableForSessionFacetNone(final FacetHolder holder) {
+        super(holder);
+    }
+
+    public String disabledReason(final AuthenticationSession session) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacet.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacet.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacet.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.SingleWhenValueFacet;
+import org.apache.isis.core.metamodel.interactions.DisablingInteractionAdvisor;
+
+/**
+ * Disable a property, collection or action.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to annotating the member with <tt>@Disabled</tt>.
+ */
+public interface DisabledFacet extends SingleWhenValueFacet, DisablingInteractionAdvisor {
+
+    /**
+     * The reason why the (feature of the) target object is currently disabled, or <tt>null</tt> if enabled.
+     */
+    public String disabledReason(ObjectAdapter target);
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetAbstract.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetAbstract.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetAbstract.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.applib.events.UsabilityEvent;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.SingleWhenValueFacetAbstract;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.metamodel.interactions.UsabilityContext;
+
+
+public abstract class DisabledFacetAbstract extends SingleWhenValueFacetAbstract implements DisabledFacet {
+
+    public static Class<? extends Facet> type() {
+        return DisabledFacet.class;
+    }
+
+    public DisabledFacetAbstract(final When value, final FacetHolder holder) {
+        super(type(), holder, value);
+    }
+
+    public String disables(final UsabilityContext<? extends UsabilityEvent> ic) {
+        final ObjectAdapter target = ic.getTarget();
+        String disabledReason = disabledReason(target);
+        if (disabledReason != null) {
+        	return disabledReason;
+        }
+        if (getUnderlyingFacet() != null) {
+        	DisabledFacet underlyingFacet = (DisabledFacet) getUnderlyingFacet();
+        	return underlyingFacet.disabledReason(target);
+        }
+        return null;
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetImpl.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetImpl.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetImpl.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+
+
+public class DisabledFacetImpl extends DisabledFacetAbstract {
+
+    public DisabledFacetImpl(final When value, final FacetHolder holder) {
+        super(value, holder);
+    }
+
+    public String disabledReason(final ObjectAdapter targetAdapter) {
+        if (value() == When.ALWAYS) {
+            return "Always disabled";
+        } else if (value() == When.NEVER) {
+            return null;
+        }
+
+        // remaining tests depend upon the actual target in question
+        if (targetAdapter == null) {
+            return null;
+        }
+
+        if (value() == When.UNTIL_PERSISTED) {
+            return targetAdapter.isTransient() ? "Disabled until persisted" : null;
+        } else if (value() == When.ONCE_PERSISTED) {
+            return targetAdapter.isPersistent() ? "Disabled once persisted" : null;
+        }
+        return null;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetNever.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetNever.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetNever.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/DisabledFacetNever.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+
+
+public class DisabledFacetNever extends DisabledFacetAbstract {
+
+    public DisabledFacetNever(final FacetHolder holder) {
+        super(When.NEVER, holder);
+    }
+
+    /**
+     * Always returns <tt>null</tt>.
+     */
+    public String disabledReason(final ObjectAdapter target) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledAnnotationFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledAnnotationFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledAnnotationFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledAnnotationFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable.annotation;
+
+
+import org.apache.isis.applib.annotation.Disabled;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.AnnotationBasedFacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.progmodel.facets.members.disable.DisabledFacet;
+
+
+public class DisabledAnnotationFacetFactory extends AnnotationBasedFacetFactoryAbstract {
+
+    public DisabledAnnotationFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS);
+    }
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        final Disabled annotation = getAnnotation(processMethodContext.getMethod(), Disabled.class);
+        FacetUtil.addFacet(create(annotation, processMethodContext.getFacetHolder()));
+    }
+
+    private DisabledFacet create(final Disabled annotation, final FacetHolder holder) {
+        return annotation == null ? null : new DisabledFacetAnnotation(When.decode(annotation.value()), holder);
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledFacetAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledFacetAnnotation.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledFacetAnnotation.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/annotation/DisabledFacetAnnotation.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable.annotation;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.progmodel.facets.members.disable.DisabledFacetImpl;
+
+
+public class DisabledFacetAnnotation extends DisabledFacetImpl {
+
+    public DisabledFacetAnnotation(final When value, final FacetHolder holder) {
+        super(value, holder);
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisableForSessionFacetViaMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisableForSessionFacetViaMethod.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisableForSessionFacetViaMethod.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisableForSessionFacetViaMethod.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable.forsession;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.util.InvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.progmodel.authentication.AuthenticationSessionUtils;
+import org.apache.isis.core.progmodel.facets.members.disable.DisableForSessionFacetAbstract;
+
+
+public class DisableForSessionFacetViaMethod extends DisableForSessionFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public DisableForSessionFacetViaMethod(
+    		final Method method, 
+    		final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the constructor. 
+     */
+    public List<Method> getMethods() {
+    	return Collections.singletonList(method);
+    }
+
+	public boolean impliesResolve() {
+		return true;
+	}
+
+	public boolean impliesObjectChanged() {
+		return false;
+	}
+
+    /**
+     * Will only check provided that a {@link AuthenticationSession} has been provided.
+     */
+    public String disabledReason(final AuthenticationSession session) {
+        if (session == null) {
+            return null;
+        }
+        final int len = method.getParameterTypes().length;
+        final Object[] parameters = new Object[len];
+        parameters[0] = AuthenticationSessionUtils.createUserMemento(session);
+        // TODO: need to change to pick up as non-static rather than static
+        return (String) InvokeUtils.invokeStatic(method, parameters);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisabledFacetViaDisableForSessionMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisabledFacetViaDisableForSessionMethodFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisabledFacetViaDisableForSessionMethodFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/forsession/DisabledFacetViaDisableForSessionMethodFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,79 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.disable.forsession;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.security.UserMemento;
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class DisabledFacetViaDisableForSessionMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.DISABLE_PREFIX };
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from noa-architecture (where they exist)
+     */
+    public DisabledFacetViaDisableForSessionMethodFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        attachDisableFacetIfDisableMethodForSessionIsFound(processMethodContext);
+    }
+
+    public static void attachDisableFacetIfDisableMethodForSessionIsFound(
+        final ProcessMethodContext processMethodContext) {
+
+        final Method method = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(method.getName());
+
+        Class<?> cls = processMethodContext.getCls();
+        Method disableForSessionMethod =
+            MethodFinderUtils.findMethod(cls, MethodScope.CLASS,
+                MethodPrefixConstants.DISABLE_PREFIX + capitalizedName, String.class,
+                new Class[] { UserMemento.class });
+
+        if (disableForSessionMethod == null) {
+            return;
+        }
+
+        processMethodContext.removeMethod(disableForSessionMethod);
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new DisableForSessionFacetViaMethod(disableForSessionMethod, facetedMethod));
+    }
+
+
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisableForContextFacetViaMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisableForContextFacetViaMethod.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisableForContextFacetViaMethod.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisableForContextFacetViaMethod.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,73 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable.method;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.progmodel.facets.members.disable.DisableForContextFacetAbstract;
+
+
+public class DisableForContextFacetViaMethod extends DisableForContextFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public DisableForContextFacetViaMethod(
+    		final Method method, 
+    		final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the constructor. 
+     */
+    public List<Method> getMethods() {
+    	return Collections.singletonList(method);
+    }
+
+	public boolean impliesResolve() {
+		return true;
+	}
+
+	public boolean impliesObjectChanged() {
+		return false;
+	}
+
+    public String disabledReason(final ObjectAdapter owningAdapter) {
+        if (owningAdapter == null) {
+            return null;
+        }
+        return (String) AdapterInvokeUtils.invoke(method, owningAdapter);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisabledFacetViaDisableMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisabledFacetViaDisableMethodFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisabledFacetViaDisableMethodFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/method/DisabledFacetViaDisableMethodFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.disable.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.map.AdapterMap;
+import org.apache.isis.core.metamodel.adapter.map.AdapterMapAware;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class DisabledFacetViaDisableMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterMapAware {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.DISABLE_PREFIX };
+
+    private AdapterMap adapterMap;
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from noa-architecture (where they exist)
+     */
+    public DisabledFacetViaDisableMethodFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        attachDisabledFacetIfDisabledMethodIsFound(processMethodContext);
+    }
+
+    public static void attachDisabledFacetIfDisabledMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+        final Method method = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(method.getName());
+
+        Class<?> cls = processMethodContext.getCls();
+        Method disableMethod =
+            MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.DISABLE_PREFIX
+                + capitalizedName, String.class, new Class[] {});
+        if (disableMethod == null) {
+            return;
+        }
+
+        processMethodContext.removeMethod(disableMethod);
+        
+        final FacetHolder facetHolder = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new DisableForContextFacetViaMethod(disableMethod, facetHolder));
+    }
+
+
+
+    // ///////////////////////////////////////////////////////////////
+    // Dependencies
+    // ///////////////////////////////////////////////////////////////
+
+    @Override
+    public void setAdapterMap(AdapterMap adapterMap) {
+        this.adapterMap = adapterMap;
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetAlways.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetAlways.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetAlways.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetAlways.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.disable.staticmethod;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.progmodel.facets.members.disable.DisabledFacetAbstract;
+
+
+public class DisabledFacetAlways extends DisabledFacetAbstract {
+
+    public DisabledFacetAlways(final FacetHolder holder) {
+        super(When.ALWAYS, holder);
+    }
+
+    /**
+     * Always returns <i>Always disabled</i>.
+     */
+    public String disabledReason(final ObjectAdapter target) {
+        return "Always disabled";
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetViaProtectMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetViaProtectMethodFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetViaProtectMethodFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/disable/staticmethod/DisabledFacetViaProtectMethodFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,97 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.disable.staticmethod;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.util.InvokeUtils;
+import org.apache.isis.core.metamodel.exceptions.MetaModelException;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class DisabledFacetViaProtectMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.PROTECT_PREFIX };
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from noa-architecture (where they exist)
+     */
+    public DisabledFacetViaProtectMethodFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        attachDisabledFacetIfProtectMethodIsFound(processMethodContext);
+    }
+
+
+    public static void attachDisabledFacetIfProtectMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+        final Class<?>[] paramTypes = new Class[] {};
+
+        Class<?> type = processMethodContext.getCls();
+        final Method method = processMethodContext.getMethod();
+
+        final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(method.getName());
+
+        final Method protectMethod =
+            MethodFinderUtils.findMethodWithOrWithoutParameters(type, MethodScope.CLASS,
+                MethodPrefixConstants.PROTECT_PREFIX + capitalizedName, boolean.class, paramTypes);
+        if (protectMethod == null) {
+            return;
+        }
+
+        processMethodContext.removeMethod(protectMethod);
+
+        Boolean protectMethodReturnValue = invokeProtectMethod(protectMethod);
+        if (!protectMethodReturnValue.booleanValue()) {
+            return;
+        }
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new DisabledFacetAlways(facetedMethod));
+    }
+
+    private static Boolean invokeProtectMethod(final Method protectMethod) {
+        Boolean protectMethodReturnValue = null;
+        try {
+            protectMethodReturnValue = (Boolean) InvokeUtils.invokeStatic(protectMethod);
+        } catch (ClassCastException ex) {
+            // ignore
+        }
+        if(protectMethodReturnValue == null) {
+            throw new MetaModelException("method " + protectMethod + "must return a boolean");
+        }
+        return protectMethodReturnValue;
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetAbstract.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetAbstract.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetAbstract.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.applib.events.VisibilityEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.SingleWhenValueFacetAbstract;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.metamodel.facets.hide.HiddenFacet;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+
+
+public abstract class HiddenFacetAbstract extends SingleWhenValueFacetAbstract implements HiddenFacet {
+
+    public static Class<? extends Facet> type() {
+        return HiddenFacet.class;
+    }
+
+    public HiddenFacetAbstract(final When value, final FacetHolder holder) {
+        super(type(), holder, value);
+    }
+
+    public String hides(final VisibilityContext<? extends VisibilityEvent> ic) {
+        return hiddenReason(ic.getTarget());
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetImpl.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetImpl.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetImpl.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+
+
+public class HiddenFacetImpl extends HiddenFacetAbstract {
+
+    public HiddenFacetImpl(final When value, final FacetHolder holder) {
+        super(value, holder);
+    }
+
+    public String hiddenReason(final ObjectAdapter targetAdapter) {
+        if (value() == When.ALWAYS) {
+            return "Always hidden";
+        } else if (value() == When.NEVER) {
+            return null;
+        }
+
+        // remaining tests depend on target in question.
+        if (targetAdapter == null) {
+            return null;
+        }
+
+        if (value() == When.UNTIL_PERSISTED) {
+            return targetAdapter.isTransient() ? "Hidden until persisted" : null;
+        } else if (value() == When.ONCE_PERSISTED) {
+            return targetAdapter.isPersistent() ? "Hidden once persisted" : null;
+        }
+        return null;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetNever.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetNever.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetNever.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HiddenFacetNever.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+
+
+public class HiddenFacetNever extends HiddenFacetAbstract {
+
+    public HiddenFacetNever(final FacetHolder holder) {
+        super(When.NEVER, holder);
+    }
+
+    /**
+     * Always returns <tt>null</tt>.
+     */
+    public String hiddenReason(final ObjectAdapter target) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacet.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacet.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacet.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.interactions.HidingInteractionAdvisor;
+
+/**
+ * Hide a property, collection or action based on the state of the target {@link ObjectAdapter object}.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to invoking the <tt>hideXxx</tt> support method for the
+ * member.
+ */
+public interface HideForContextFacet extends Facet, HidingInteractionAdvisor {
+
+    public String hiddenReason(ObjectAdapter object);
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetAbstract.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetAbstract.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetAbstract.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.applib.events.VisibilityEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+
+
+public abstract class HideForContextFacetAbstract extends FacetAbstract implements HideForContextFacet {
+
+    public static Class<? extends Facet> type() {
+        return HideForContextFacet.class;
+    }
+
+    public HideForContextFacetAbstract(final FacetHolder holder) {
+        super(type(), holder, false);
+    }
+
+    public String hides(final VisibilityContext<? extends VisibilityEvent> ic) {
+        return hiddenReason(ic.getTarget());
+    }
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetNone.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetNone.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetNone.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForContextFacetNone.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class HideForContextFacetNone extends HideForContextFacetAbstract {
+
+    public HideForContextFacetNone(final FacetHolder holder) {
+        super(holder);
+    }
+
+    /**
+     * Always returns <tt>null</tt>.
+     */
+    public String hiddenReason(final ObjectAdapter object) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacet.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacet.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacet.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.interactions.HidingInteractionAdvisor;
+
+/**
+ * Hide a property, collection or action based on the current session.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to invoking the <tt>hideXxx(UserMemento)</tt> support
+ * method for the member.
+ */
+public interface HideForSessionFacet extends Facet, HidingInteractionAdvisor {
+
+    public String hiddenReason(AuthenticationSession session);
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetAbstract.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetAbstract.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetAbstract.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.applib.events.VisibilityEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+
+/**
+ * Hide a property, collection or action based on the current session.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to invoking the <tt>hideXxx(UserMemento)</tt> support
+ * method for the member.
+ */
+public abstract class HideForSessionFacetAbstract extends FacetAbstract implements HideForSessionFacet {
+
+    public static Class<? extends Facet> type() {
+        return HideForSessionFacet.class;
+    }
+
+    public HideForSessionFacetAbstract(final FacetHolder holder) {
+        super(type(), holder, false);
+    }
+
+    @Override
+    public String hides(final VisibilityContext<? extends VisibilityEvent> ic) {
+        return hiddenReason(ic.getSession());
+    }
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetNone.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetNone.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetNone.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/HideForSessionFacetNone.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class HideForSessionFacetNone extends HideForSessionFacetAbstract {
+
+    public HideForSessionFacetNone(final FacetHolder holder) {
+        super(holder);
+    }
+
+    /**
+     * Always returns <tt>null</tt>.
+     */
+    public String hiddenReason(final AuthenticationSession session) {
+        return null;
+    }
+
+    @Override
+    public boolean isNoop() {
+        return true;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenAnnotationFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenAnnotationFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenAnnotationFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenAnnotationFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide.annotation;
+
+
+import org.apache.isis.applib.annotation.Hidden;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.AnnotationBasedFacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.metamodel.facets.hide.HiddenFacet;
+
+
+public class HiddenAnnotationFacetFactory extends AnnotationBasedFacetFactoryAbstract {
+
+    public HiddenAnnotationFacetFactory() {
+        super(FeatureType.EVERYTHING_BUT_PARAMETERS);
+    }
+
+    
+    @Override
+    public void process(ProcessClassContext processClassContaxt) {
+        final Hidden annotation = getAnnotation(processClassContaxt.getCls(), Hidden.class);
+        FacetUtil.addFacet(create(annotation, processClassContaxt.getFacetHolder()));
+    }
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        final Hidden annotation = getAnnotation(processMethodContext.getMethod(), Hidden.class);
+        FacetUtil.addFacet(create(annotation, processMethodContext.getFacetHolder()));
+    }
+
+    private HiddenFacet create(final Hidden annotation, final FacetHolder holder) {
+        return annotation == null ? null : new HiddenFacetAnnotation(When.decode(annotation.value()), holder);
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenFacetAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenFacetAnnotation.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenFacetAnnotation.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/annotation/HiddenFacetAnnotation.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide.annotation;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.When;
+import org.apache.isis.core.progmodel.facets.members.hide.HiddenFacetImpl;
+
+
+public class HiddenFacetAnnotation extends HiddenFacetImpl {
+
+    public HiddenFacetAnnotation(final When value, final FacetHolder holder) {
+        super(value, holder);
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HiddenFacetViaHideForSessionMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HiddenFacetViaHideForSessionMethodFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HiddenFacetViaHideForSessionMethodFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HiddenFacetViaHideForSessionMethodFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,80 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.hide.forsession;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.security.UserMemento;
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class HiddenFacetViaHideForSessionMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.HIDE_PREFIX };
+
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from noa-architecture (where they exist)
+     */
+    public HiddenFacetViaHideForSessionMethodFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        // hideXxx(UserMemento)
+        attachHideFacetIfHideMethodForSessionIsFound(processMethodContext);
+
+    }
+
+    public static void attachHideFacetIfHideMethodForSessionIsFound(final ProcessMethodContext processMethodContext) {
+
+        final Method method = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(method.getName());
+
+        Class<?> cls = processMethodContext.getCls();
+        Method hideForSessionMethod =
+            MethodFinderUtils.findMethod(cls, MethodScope.CLASS,
+                MethodPrefixConstants.HIDE_PREFIX + capitalizedName, boolean.class,
+                new Class[] { UserMemento.class });
+
+        if (hideForSessionMethod == null) {
+            return;
+        }
+
+        processMethodContext.removeMethod(hideForSessionMethod);
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new HideForSessionFacetViaMethod(hideForSessionMethod, facetedMethod));
+    }
+
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HideForSessionFacetViaMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HideForSessionFacetViaMethod.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HideForSessionFacetViaMethod.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/forsession/HideForSessionFacetViaMethod.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide.forsession;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.util.InvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.progmodel.authentication.AuthenticationSessionUtils;
+import org.apache.isis.core.progmodel.facets.members.hide.HideForSessionFacetAbstract;
+
+
+public class HideForSessionFacetViaMethod extends HideForSessionFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public HideForSessionFacetViaMethod(
+    		final Method method, 
+    		final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the constructor. 
+     */
+    public List<Method> getMethods() {
+    	return Collections.singletonList(method);
+    }
+
+	public boolean impliesResolve() {
+		return true;
+	}
+
+	public boolean impliesObjectChanged() {
+		return false;
+	}
+
+    /**
+     * Will only check provided that a {@link AuthenticationSession} has been provided.
+     */
+    public String hiddenReason(final AuthenticationSession session) {
+        if (session == null) {
+            return null;
+        }
+        final int len = method.getParameterTypes().length;
+        final Object[] parameters = new Object[len];
+        parameters[0] = AuthenticationSessionUtils.createUserMemento(session);
+        // TODO: need to change to pick up as non-static rather than static
+        final Boolean isHidden = (Boolean) InvokeUtils.invokeStatic(method, parameters);
+        return isHidden.booleanValue() ? "Hidden" : null;
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}
+

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HiddenFacetViaHideMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HiddenFacetViaHideMethodFacetFactory.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HiddenFacetViaHideMethodFacetFactory.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HiddenFacetViaHideMethodFacetFactory.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,73 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.members.hide.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class HiddenFacetViaHideMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.HIDE_PREFIX };
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from noa-architecture (where they exist)
+     */
+    public HiddenFacetViaHideMethodFacetFactory() {
+        super(FeatureType.PROPERTIES_COLLECTIONS_AND_ACTIONS, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(ProcessMethodContext processMethodContext) {
+        attachHideFacetIfHideMethodIsFound(processMethodContext);
+    }
+
+    public static void attachHideFacetIfHideMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+        final Method getMethod = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(getMethod.getName());
+
+        Class<?> cls = processMethodContext.getCls();
+        Method hideMethod =
+            MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.HIDE_PREFIX + capitalizedName,
+                boolean.class, new Class[] {});
+        if (hideMethod == null) {
+            return;
+        }
+
+        processMethodContext.removeMethod(hideMethod);
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new HideForContextFacetViaMethod(hideMethod, facetedMethod));
+    }
+
+}

Added: incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HideForContextFacetViaMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HideForContextFacetViaMethod.java?rev=1059813&view=auto
==============================================================================
--- incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HideForContextFacetViaMethod.java (added)
+++ incubator/isis/trunk/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/members/hide/method/HideForContextFacetViaMethod.java Mon Jan 17 08:48:40 2011
@@ -0,0 +1,74 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.apache.isis.core.progmodel.facets.members.hide.method;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.progmodel.facets.members.hide.HideForContextFacetAbstract;
+
+
+public class HideForContextFacetViaMethod extends HideForContextFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public HideForContextFacetViaMethod(
+    		final Method method, 
+    		final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the constructor. 
+     */
+    public List<Method> getMethods() {
+    	return Collections.singletonList(method);
+    }
+
+	public boolean impliesResolve() {
+		return true;
+	}
+
+	public boolean impliesObjectChanged() {
+		return false;
+	}
+
+    public String hiddenReason(final ObjectAdapter owningAdapter) {
+        if (owningAdapter == null) {
+            return null;
+        }
+        final Boolean isHidden = (Boolean) AdapterInvokeUtils.invoke(method, owningAdapter);
+        return isHidden.booleanValue() ? "Hidden" : null;
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}
+