You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ke...@apache.org on 2011/11/30 17:11:24 UTC
svn commit: r1208481 - in /incubator/isis/trunk/framework/core/progmodel/src:
main/java/org/apache/isis/core/progmodel/facets/object/disabled/
main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/
test/java/org/apache/isis/core/progmo...
Author: kevin
Date: Wed Nov 30 16:11:23 2011
New Revision: 1208481
URL: http://svn.apache.org/viewvc?rev=1208481&view=rev
Log:
ISIS-142: Add "String disabled()" method to objects to disable entire object at runtime.
Added:
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledFacetViaDisabledMethodFacetFactory.java
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java (with props)
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java (with props)
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java (with props)
incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java (with props)
incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/
incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java (with props)
Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledFacetViaDisabledMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledFacetViaDisabledMethodFacetFactory.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledFacetViaDisabledMethodFacetFactory.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledFacetViaDisabledMethodFacetFactory.java Wed Nov 30 16:11:23 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.object.disabled;
+
+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;
+import org.apache.isis.core.progmodel.facets.members.disable.method.DisableForContextFacetViaMethod;
+
+public class DisabledFacetViaDisabledMethodFacetFactory 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 DisabledFacetViaDisabledMethodFacetFactory() {
+ super(FeatureType.MEMBERS, PREFIXES);
+ }
+
+ // ///////////////////////////////////////////////////////
+ // Actions
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+ attachDisabledFacetIfDisabledMethodIsFound(processMethodContext);
+ }
+
+ public static void attachDisabledFacetIfDisabledMethodIsFound(final ProcessMethodContext processMethodContext) {
+
+ final Method method = processMethodContext.getMethod();
+ final String capitalizedName = NameUtils.javaBaseNameStripAccessorPrefixIfRequired(method.getName());
+
+ final Class<?> cls = processMethodContext.getCls();
+ final 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(final AdapterMap adapterMap) {
+ this.adapterMap = adapterMap;
+ }
+
+}
Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java Wed Nov 30 16:11:23 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.object.disabled;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.object.immutable.ImmutableFacet;
+import org.apache.isis.core.metamodel.interactions.DisablingInteractionAdvisor;
+
+/**
+ * Mechanism for determining whether this object is should be disabled.
+ *
+ * <p>
+ * Even though all the properties of an object may themselves be enabled, there could be reasons to disable the object.
+ *
+ * <p>
+ * In the standard Apache Isis Programming Model, typically corresponds to the <tt>disabled</tt> method.
+ *
+ * @see ImmutableFacet
+ */
+public interface DisabledObjectFacet extends Facet, DisablingInteractionAdvisor {
+
+ /**
+ * The reason the object is disabled.
+ *
+ * <p>
+ * . If the object is actually enabled, should return <tt>null</tt>.
+ */
+ public String disabledReason(ObjectAdapter adapter);
+
+}
Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacet.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java Wed Nov 30 16:11:23 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.object.disabled;
+
+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.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.UsabilityContext;
+
+public abstract class DisabledObjectFacetAbstract extends FacetAbstract implements DisabledObjectFacet {
+
+ public static Class<? extends Facet> type() {
+ return DisabledObjectFacet.class;
+ }
+
+ public DisabledObjectFacetAbstract(final FacetHolder holder) {
+ super(type(), holder, false);
+ }
+
+ @Override
+ public String disables(final UsabilityContext<? extends UsabilityEvent> ic) {
+ if (!(ic instanceof UsabilityContext)) {
+ return null;
+ }
+ final ObjectAdapter toValidate = ic.getTarget();
+ return toValidate != null ? disabledReason(toValidate) : null;
+ }
+
+}
Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/DisabledObjectFacetAbstract.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java Wed Nov 30 16:11:23 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.object.disabled.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.object.disabled.DisabledObjectFacetAbstract;
+
+public class DisabledObjectFacetViaDisabledMethod extends DisabledObjectFacetAbstract implements ImperativeFacet {
+
+ private final Method method;
+
+ public DisabledObjectFacetViaDisabledMethod(final Method method, final FacetHolder holder) {
+ super(holder);
+ this.method = method;
+ }
+
+ @Override
+ public List<Method> getMethods() {
+ return Collections.singletonList(method);
+ }
+
+ @Override
+ public boolean impliesResolve() {
+ return true;
+ }
+
+ @Override
+ public boolean impliesObjectChanged() {
+ return false;
+ }
+
+ @Override
+ public String disabledReason(final ObjectAdapter owningAdapter) {
+ return (String) AdapterInvokeUtils.invoke(method, owningAdapter);
+ }
+
+ @Override
+ protected String toStringValues() {
+ return "method=" + method;
+ }
+}
Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectFacetViaDisabledMethod.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java Wed Nov 30 16:11:23 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.object.disabled.method;
+
+import java.lang.reflect.Method;
+
+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;
+
+public class DisabledObjectViaDisabledMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+ private static final String DISABLED_PREFIX = "disabled";
+
+ private static final String[] PREFIXES = { DISABLED_PREFIX, };
+
+ public DisabledObjectViaDisabledMethodFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY, PREFIXES);
+ }
+
+ @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));
+ processClassContext.removeMethod(method);
+ }
+ }
+}
Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java?rev=1208481&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java (added)
+++ incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java Wed Nov 30 16:11:23 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.object.disabled;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessClassContext;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.object.disabled.method.DisabledObjectFacetViaDisabledMethod;
+import org.apache.isis.core.progmodel.facets.object.disabled.method.DisabledObjectViaDisabledMethodFacetFactory;
+
+public class ObjectDisabledMethodFacetFactoryTest extends AbstractFacetFactoryTest {
+
+ private DisabledObjectViaDisabledMethodFacetFactory facetFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ facetFactory = new DisabledObjectViaDisabledMethodFacetFactory();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ facetFactory = null;
+ super.tearDown();
+ }
+
+ public void testDisabledMethodPickedUpAndMethodRemoved() {
+ class Customer {
+ @SuppressWarnings("unused")
+ public String disabled() {
+ return null;
+ }
+ }
+ final Method disabledMethod = findMethod(Customer.class, "disabled");
+
+ final ProcessClassContext processClassContext =
+ new ProcessClassContext(Customer.class, methodRemover, facetHolder);
+ facetFactory.process(processClassContext);
+
+ final Facet facet = facetHolder.getFacet(DisabledObjectFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof DisabledObjectFacetViaDisabledMethod);
+
+ assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(disabledMethod));
+ }
+
+}
Propchange: incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/disabled/ObjectDisabledMethodFacetFactoryTest.java
------------------------------------------------------------------------------
svn:executable = *