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 2014/07/09 06:59:41 UTC

[6/8] ISIS-831: use of @InteractionWith{Action|Property|Collection} and {Action|Property|Collection}InteractionEvents

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetFactory.java
deleted file mode 100644
index 06a71b1..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetFactory.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- *  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.actions.invoke;
-
-import java.lang.reflect.Method;
-
-import org.apache.isis.core.commons.lang.StringExtensions;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
-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.facets.actions.debug.DebugFacet;
-import org.apache.isis.core.metamodel.facets.actions.exploration.ExplorationFacet;
-import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
-import org.apache.isis.core.metamodel.facets.named.NamedFacet;
-import org.apache.isis.core.metamodel.facets.named.NamedFacetInferred;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAware;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
-
-/**
- * Sets up {@link ActionInvocationFacet}, along with a number of supporting
- * facets that are based on the action's name.
- * 
- * <p>
- * The supporting methods are: {@link ExecutedFacet}, {@link ExplorationFacet}
- * and {@link DebugFacet}. In addition a {@link NamedFacet} is inferred from the
- * name (taking into account the above well-known prefixes).
- */
-public class ActionInvocationFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware, ServicesInjectorAware, RuntimeContextAware {
-
-    private static final String EXPLORATION_PREFIX = "Exploration";
-    private static final String DEBUG_PREFIX = "Debug";
-
-    private static final String[] PREFIXES = { EXPLORATION_PREFIX, DEBUG_PREFIX };
-
-    private AdapterManager adapterManager;
-    private ServicesInjector servicesInjector;
-    private RuntimeContext runtimeContext;
-
-    /**
-     * Note that the {@link Facet}s registered are the generic ones from
-     * noa-architecture (where they exist)
-     */
-    public ActionInvocationFacetFactory() {
-        super(FeatureType.ACTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
-    }
-
-    // ///////////////////////////////////////////////////////
-    // Actions
-    // ///////////////////////////////////////////////////////
-
-    @Override
-    public void process(final ProcessMethodContext processMethodContext) {
-
-        // InvocationFacet
-        attachInvocationFacet(processMethodContext);
-
-        // DebugFacet, ExplorationFacet
-        attachDebugFacetIfActionMethodNamePrefixed(processMethodContext);
-        attachExplorationFacetIfActionMethodNamePrefixed(processMethodContext);
-
-        // inferred name
-        // (must be called after the attachinvocationFacet methods)
-        attachNamedFacetInferredFromMethodName(processMethodContext); 
-    }
-
-    private void attachInvocationFacet(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-
-        try {
-            final Class<?> returnType = actionMethod.getReturnType();
-            final ObjectSpecification returnSpec = getSpecificationLoader().loadSpecification(returnType);
-            if (returnSpec == null) {
-                return;
-            }
-
-            final Class<?> cls = processMethodContext.getCls();
-            final ObjectSpecification typeSpec = getSpecificationLoader().loadSpecification(cls);
-            final FacetHolder holder = processMethodContext.getFacetHolder();
-
-            FacetUtil.addFacet(new ActionInvocationFacetViaMethod(actionMethod, typeSpec, returnSpec, holder, getRuntimeContext(), getAdapterManager(), getServicesInjector()));
-        } finally {
-            processMethodContext.removeMethod(actionMethod);
-        }
-    }
-
-    private void attachDebugFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
-        if (!capitalizedName.startsWith(DEBUG_PREFIX)) {
-            return;
-        }
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new DebugFacetViaNamingConvention(facetedMethod));
-    }
-
-    private void attachExplorationFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
-        if (!capitalizedName.startsWith(EXPLORATION_PREFIX)) {
-            return;
-        }
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new ExplorationFacetViaNamingConvention(facetedMethod));
-    }
-
-    /**
-     * Must be called after added the debug, exploration etc facets.
-     * 
-     * <p>
-     * TODO: remove this hack
-     */
-    private void attachNamedFacetInferredFromMethodName(final ProcessMethodContext processMethodContext) {
-
-        final Method method = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(method.getName());
-
-        // this is nasty...
-        String name = capitalizedName;
-        name = StringExtensions.removePrefix(name, DEBUG_PREFIX);
-        name = StringExtensions.removePrefix(name, EXPLORATION_PREFIX);
-        name = StringExtensions.asNaturalName2(name);
-
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new NamedFacetInferred(name, facetedMethod));
-    }
-
-    // ///////////////////////////////////////////////////////////////
-    // Dependencies
-    // ///////////////////////////////////////////////////////////////
-
-    @Override
-    public void setAdapterManager(final AdapterManager adapterManager) {
-        this.adapterManager = adapterManager;
-    }
-
-    private AdapterManager getAdapterManager() {
-        return adapterManager;
-    }
-
-    @Override
-    public void setServicesInjector(final ServicesInjector servicesInjector) {
-        this.servicesInjector = servicesInjector;
-    }
-
-    private ServicesInjector getServicesInjector() {
-        return servicesInjector;
-    }
-
-    private RuntimeContext getRuntimeContext() {
-        return runtimeContext;
-    }
-    
-    @Override
-    public void setRuntimeContext(RuntimeContext runtimeContext) {
-        this.runtimeContext = runtimeContext;
-    }
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
deleted file mode 100644
index 41541fc..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- *  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.actions.invoke;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.isis.applib.NonRecoverableException;
-import org.apache.isis.applib.RecoverableException;
-import org.apache.isis.applib.ViewModel;
-import org.apache.isis.applib.annotation.Bulk;
-import org.apache.isis.applib.annotation.Bulk.InteractionContext.InvokedAs;
-import org.apache.isis.applib.annotation.Command.ExecuteIn;
-import org.apache.isis.applib.annotation.Command.Persistence;
-import org.apache.isis.applib.clock.Clock;
-import org.apache.isis.applib.services.background.ActionInvocationMemento;
-import org.apache.isis.applib.services.background.BackgroundService;
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.command.Command;
-import org.apache.isis.applib.services.command.Command.Executor;
-import org.apache.isis.applib.services.command.CommandContext;
-import org.apache.isis.applib.services.command.spi.CommandService;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.lang.ThrowableExtensions;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.ImperativeFacet;
-import org.apache.isis.core.metamodel.facets.actions.command.CommandFacet;
-import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
-import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacetAbstract;
-import org.apache.isis.core.metamodel.facets.actions.publish.PublishedActionFacet;
-import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
-import org.apache.isis.core.metamodel.facets.typeof.ElementSpecificationProviderFromTypeOfFacet;
-import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.metamodel.specloader.ReflectiveActionException;
-import org.apache.isis.core.progmodel.facets.actions.bulk.BulkFacet;
-
-public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstract implements ImperativeFacet {
-
-    private final static Logger LOG = LoggerFactory.getLogger(ActionInvocationFacetViaMethod.class);
-
-    private final Method method;
-    private final ObjectSpecification onType;
-    private final ObjectSpecification returnType;
-
-    private final AdapterManager adapterManager;
-    private final ServicesInjector servicesInjector;
-    private final RuntimeContext runtimeContext;
-    
-    public ActionInvocationFacetViaMethod(
-            final Method method, 
-            final ObjectSpecification onType, 
-            final ObjectSpecification returnType, 
-            final FacetHolder holder, 
-            final RuntimeContext runtimeContext, 
-            final AdapterManager adapterManager, 
-            final ServicesInjector servicesInjector) {
-        super(holder);
-        this.method = method;
-        this.onType = onType;
-        this.returnType = returnType;
-        this.runtimeContext = runtimeContext;
-        this.adapterManager = adapterManager;
-        this.servicesInjector = servicesInjector;
-    }
-
-    /**
-     * Returns a singleton list of the {@link Method} provided in the
-     * constructor.
-     */
-    @Override
-    public List<Method> getMethods() {
-        return Collections.singletonList(method);
-    }
-
-    @Override
-    public Intent getIntent(final Method method) {
-        return Intent.EXECUTE;
-    }
-
-    @Override
-    public ObjectSpecification getReturnType() {
-        return returnType;
-    }
-
-    @Override
-    public ObjectSpecification getOnType() {
-        return onType;
-    }
-
-    @Override
-    public ObjectAdapter invoke(final ObjectAdapter targetAdapter, final ObjectAdapter[] argumentAdapters) {
-        return invoke(null, targetAdapter, argumentAdapters);
-    }
-    
-    @Override
-    public ObjectAdapter invoke(
-            final ObjectAction owningAction, 
-            final ObjectAdapter targetAdapter, 
-            final ObjectAdapter[] argumentAdapters) {
-    
-    	// Can return null both because the action finally was not invoked 
-    	// or because it returned null.
-    	return internalInvoke(owningAction, targetAdapter, argumentAdapters).getAdapter();
-    	
-    }
-
-    /**
-     * Introduced to disambiguate the meaning of <tt>null</tt> as a return value of
-     * {@link ActionInvocationFacetViaMethod#invoke(ObjectAdapter, ObjectAdapter[])}
-     */
-    public static class InvocationResult {
-
-        public static InvocationResult forActionThatReturned(final ObjectAdapter resultAdapter) {
-            return new InvocationResult(true, resultAdapter);
-        }
-
-        public static InvocationResult forActionNotInvoked() {
-            return new InvocationResult(false, null);
-        }
-
-    	private final boolean whetherInvoked;
-    	private final ObjectAdapter adapter;
-    	
-    	private InvocationResult(final boolean whetherInvoked, final ObjectAdapter result) {
-    		this.whetherInvoked = whetherInvoked;
-    		this.adapter = result;
-    	}
-
-		public boolean getWhetherInvoked() {
-			return whetherInvoked;
-		}
-
-		/**
-		 * Returns the result, or null if either the action invocation returned null or 
-		 * if the action was never invoked in the first place.
-		 * 
-		 * <p>
-		 * Use {@link #getWhetherInvoked()} to distinguish between these two cases.
-		 */
-		public ObjectAdapter getAdapter() {
-			return adapter;
-		}
-    }
-    
-    protected InvocationResult internalInvoke(
-            final ObjectAction owningAction, 
-            final ObjectAdapter targetAdapter, 
-            final ObjectAdapter[] arguments) {
-    	
-        final Bulk.InteractionContext bulkInteractionContext = getServicesInjector().lookupService(Bulk.InteractionContext.class);
-        final CommandContext commandContext = getServicesInjector().lookupService(CommandContext.class);
-        final Command command = commandContext != null ? commandContext.getCommand() : null;
-
-        try {
-            final Object[] executionParameters = new Object[arguments.length];
-            for (int i = 0; i < arguments.length; i++) {
-                executionParameters[i] = unwrap(arguments[i]);
-            }
-
-            final Object targetPojo = unwrap(targetAdapter);
-            
-            final BulkFacet bulkFacet = getFacetHolder().getFacet(BulkFacet.class);
-            if (bulkFacet != null && 
-                bulkInteractionContext != null &&
-                bulkInteractionContext.getInvokedAs() == null) {
-                
-                bulkInteractionContext.setInvokedAs(InvokedAs.REGULAR);
-                bulkInteractionContext.setDomainObjects(Collections.singletonList(targetPojo));
-            }
-
-            if(command != null && command.getExecutor() == Executor.USER && owningAction != null) {
-
-                if(command.getTarget() != null) {
-                    // already set up by a ObjectActionContributee;
-                    // don't overwrite
-                } else {
-                    command.setTargetClass(CommandUtil.targetClassNameFor(targetAdapter));
-                    command.setTargetAction(CommandUtil.targetActionNameFor(owningAction));
-                    command.setArguments(CommandUtil.argDescriptionFor(owningAction, arguments));
-                    
-                    final Bookmark targetBookmark = CommandUtil.bookmarkFor(targetAdapter);
-                    command.setTarget(targetBookmark);
-                }
-
-                command.setMemberIdentifier(CommandUtil.actionIdentifierFor(owningAction));
-
-                // the background service is used here merely as a means to capture an invocation memento
-                final BackgroundService backgroundService = getServicesInjector().lookupService(BackgroundService.class);
-                if(backgroundService != null) {
-                    final Object targetObject = unwrap(targetAdapter);
-                    final Object[] args = CommandUtil.objectsFor(arguments);
-                    ActionInvocationMemento aim = backgroundService.asActionInvocationMemento(method, targetObject, args);
-
-                    if(aim != null) {
-                        command.setMemento(aim.asMementoString());
-                    } else {
-                        throw new IsisException(
-                            "Unable to build memento for action " + 
-                            owningAction.getIdentifier().toClassAndNameIdentityString());
-                    }
-                }
-
-                // copy over the command execution 'context' (if available)
-                final CommandFacet commandFacet = getFacetHolder().getFacet(CommandFacet.class);
-                if(commandFacet != null && !commandFacet.isDisabled()) {
-                    command.setExecuteIn(commandFacet.executeIn());
-                    command.setPersistence(commandFacet.persistence());
-                } else {
-                    // if no facet, assume do want to execute right now, but only persist (eventually) if hinted.
-                    command.setExecuteIn(ExecuteIn.FOREGROUND);
-                    command.setPersistence(Persistence.IF_HINTED);
-                }
-            }
-            
-            
-            if( command != null && 
-                command.getExecutor() == Executor.USER && 
-                command.getExecuteIn() == ExecuteIn.BACKGROUND) {
-                
-                // persist command so can be this command can be in the 'background'
-                final CommandService commandService = getServicesInjector().lookupService(CommandService.class);
-                if(commandService.persistIfPossible(command)) {
-                    // force persistence, then return the command itself.
-                    final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
-                    return InvocationResult.forActionThatReturned(resultAdapter);
-                } else {
-                    throw new IsisException(
-                            "Unable to schedule action '"
-                            + owningAction.getIdentifier().toClassAndNameIdentityString() + "' to run in background: "
-                            + "CommandService does not support persistent commands " );
-                }
-            } else {
-                
-                // otherwise, go ahead and execute action in the 'foreground'
-
-                if(command != null) {
-                    command.setStartedAt(Clock.getTimeAsJavaSqlTimestamp());
-                }
-                
-                Object result = method.invoke(targetPojo, executionParameters);
-
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug(" action result " + result);
-                }
-                if (result == null) {
-                    if(targetAdapter.getSpecification().isViewModelCloneable(null)) {
-                        // if this was a void method on a ViewModel.Cloneable, then (to save boilerplate in the domain)
-                        // automatically do the clone and return the clone instead.
-                        final ViewModel.Cloneable cloneable = (ViewModel.Cloneable) targetAdapter.getObject();
-                        final Object clone = cloneable.clone();
-                        final ObjectAdapter clonedAdapter = getAdapterManager().adapterFor(clone);
-                        return InvocationResult.forActionThatReturned(clonedAdapter);
-                    }
-                	return InvocationResult.forActionThatReturned(null);
-                }
-
-                ObjectAdapter resultAdapter = getAdapterManager().adapterFor(result);
-
-                if(resultAdapter.getSpecification().isViewModelCloneable(resultAdapter)) {
-                    // if the object returned is a ViewModel.Cloneable, then
-                    // (to save boilerplate in the domain) automatically do the clone.
-                    final ViewModel.Cloneable cloneable = (ViewModel.Cloneable) result;
-                    result = cloneable.clone();
-                    resultAdapter = getAdapterManager().adapterFor(result);
-                }
-
-
-                // copy over TypeOfFacet if required
-                final TypeOfFacet typeOfFacet = getFacetHolder().getFacet(TypeOfFacet.class);
-                resultAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(typeOfFacet));
-
-                if(command != null) {
-                    if(!resultAdapter.getSpecification().containsDoOpFacet(ViewModelFacet.class)) {
-                        final Bookmark bookmark = CommandUtil.bookmarkFor(resultAdapter);
-                        command.setResult(bookmark);
-                    }
-                }
-                
-                final PublishedActionFacet publishedActionFacet = getIdentified().getFacet(PublishedActionFacet.class);
-                ActionInvocationFacet.currentInvocation.set(
-                        publishedActionFacet != null
-                            ? new CurrentInvocation(targetAdapter, getIdentified(), arguments, resultAdapter, command)
-                            :null);
-                
-                return InvocationResult.forActionThatReturned(resultAdapter);
-            }
-
-        } catch (final IllegalArgumentException e) {
-            throw e;
-        } catch (final InvocationTargetException e) {
-            final Throwable targetException = e.getTargetException();
-            if (targetException instanceof IllegalStateException) {
-                throw new ReflectiveActionException("IllegalStateException thrown while executing " + method + " " + targetException.getMessage(), targetException);
-            } 
-            if(targetException instanceof RecoverableException) {
-                if (!runtimeContext.getTransactionState().canCommit()) {
-                    // something severe has happened to the underlying transaction;
-                    // so escalate this exception to be non-recoverable
-                    final Throwable targetExceptionCause = targetException.getCause();
-                    Throwable nonRecoverableCause = targetExceptionCause != null? targetExceptionCause: targetException;
-                    throw new NonRecoverableException(nonRecoverableCause);
-                }
-            }
-
-            ThrowableExtensions.throwWithinIsisException(e, "Exception executing " + method);
-            
-            // Action was not invoked (an Exception was thrown)
-            return InvocationResult.forActionNotInvoked();
-        } catch (final IllegalAccessException e) {
-            throw new ReflectiveActionException("Illegal access of " + method, e);
-        }
-    }
-
-    private static Object unwrap(final ObjectAdapter adapter) {
-        return adapter == null ? null : adapter.getObject();
-    }
-
-    @Override
-    public boolean impliesResolve() {
-        return true;
-    }
-
-    @Override
-    public boolean impliesObjectChanged() {
-        return false;
-    }
-
-    @Override
-    protected String toStringValues() {
-        return "method=" + method;
-    }
-
-    // /////////////////////////////////////////////////////////
-    // Dependencies (from constructor)
-    // /////////////////////////////////////////////////////////
-
-    private AdapterManager getAdapterManager() {
-        return adapterManager;
-    }
-
-    private ServicesInjector getServicesInjector() {
-        return servicesInjector;
-    }
-
-    
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetAbstract.java
new file mode 100644
index 0000000..5135f8b
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetAbstract.java
@@ -0,0 +1,409 @@
+/*
+ *  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.actions.invoke.event;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.isis.applib.*;
+import org.apache.isis.applib.annotation.Bulk;
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.applib.services.background.ActionInvocationMemento;
+import org.apache.isis.applib.services.background.BackgroundService;
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.command.Command;
+import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.applib.services.command.spi.CommandService;
+import org.apache.isis.applib.services.eventbus.ActionInteractionEvent;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.lang.ThrowableExtensions;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.util.AdapterUtils;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.metamodel.facets.actions.command.CommandFacet;
+import org.apache.isis.core.metamodel.facets.actions.interaction.ActionInteractionFacet;
+import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
+import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacetAbstract;
+import org.apache.isis.core.metamodel.facets.actions.publish.PublishedActionFacet;
+import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
+import org.apache.isis.core.metamodel.facets.typeof.ElementSpecificationProviderFromTypeOfFacet;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.core.metamodel.specloader.ReflectiveActionException;
+import org.apache.isis.core.progmodel.facets.actions.bulk.BulkFacet;
+import org.apache.isis.core.progmodel.facets.actions.invoke.CommandUtil;
+
+public abstract class InteractionWithActionFacetAbstract
+        extends ActionInvocationFacetAbstract
+        implements ImperativeFacet, ActionInteractionFacet {
+
+    private final static Logger LOG = LoggerFactory.getLogger(InteractionWithActionFacetAbstract.class);
+
+    private final Method method;
+    private final ObjectSpecification onType;
+    private final ObjectSpecification returnType;
+
+    private final AdapterManager adapterManager;
+    private final ServicesInjector servicesInjector;
+    private final RuntimeContext runtimeContext;
+
+    private final Class<? extends ActionInteractionEvent<?>> eventType;
+
+    public InteractionWithActionFacetAbstract(
+            final Method method,
+            final ObjectSpecification onType,
+            final ObjectSpecification returnType,
+            final FacetHolder holder,
+            final RuntimeContext runtimeContext,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final Class<? extends ActionInteractionEvent<?>> eventType) {
+        super(holder);
+        this.method = method;
+        this.onType = onType;
+        this.returnType = returnType;
+        this.runtimeContext = runtimeContext;
+        this.adapterManager = adapterManager;
+        this.servicesInjector = servicesInjector;
+        this.eventType = eventType;
+    }
+
+    /**
+     * Returns a singleton list of the {@link java.lang.reflect.Method} provided in the
+     * constructor.
+     */
+    @Override
+    public List<Method> getMethods() {
+        return Collections.singletonList(method);
+    }
+
+    @Override
+    public Intent getIntent(final Method method) {
+        return Intent.EXECUTE;
+    }
+
+    @Override
+    public ObjectSpecification getReturnType() {
+        return returnType;
+    }
+
+    @Override
+    public ObjectSpecification getOnType() {
+        return onType;
+    }
+
+    /**
+     * Introduced to disambiguate the meaning of <tt>null</tt> as a return value of
+     * {@link #invoke(org.apache.isis.core.metamodel.adapter.ObjectAdapter, org.apache.isis.core.metamodel.adapter.ObjectAdapter[])}
+     */
+    public static class InvocationResult {
+
+        public static InvocationResult forActionThatReturned(final ObjectAdapter resultAdapter) {
+            return new InvocationResult(true, resultAdapter);
+        }
+
+        public static InvocationResult forActionNotInvoked() {
+            return new InvocationResult(false, null);
+        }
+
+        private final boolean whetherInvoked;
+        private final ObjectAdapter adapter;
+
+        private InvocationResult(final boolean whetherInvoked, final ObjectAdapter result) {
+            this.whetherInvoked = whetherInvoked;
+            this.adapter = result;
+        }
+
+        public boolean getWhetherInvoked() {
+            return whetherInvoked;
+        }
+
+        /**
+         * Returns the result, or null if either the action invocation returned null or
+         * if the action was never invoked in the first place.
+         *
+         * <p>
+         * Use {@link #getWhetherInvoked()} to distinguish between these two cases.
+         */
+        public ObjectAdapter getAdapter() {
+            return adapter;
+        }
+    }
+
+    @Override
+    public ObjectAdapter invoke(final ObjectAdapter targetAdapter, final ObjectAdapter[] argumentAdapters) {
+        return invoke(null, targetAdapter, argumentAdapters);
+    }
+
+    @Override
+    public ObjectAdapter invoke(
+            final ObjectAction owningAction,
+            final ObjectAdapter targetAdapter,
+            final ObjectAdapter[] arguments) {
+
+        final InvocationResult invocationResult = internalInvoke(owningAction, targetAdapter, arguments);
+
+        // Perhaps the Action was not properly invoked (i.e. an exception was raised).
+        if (invocationResult.getWhetherInvoked()) {
+            // If invoked, then send the ActionInteractionEvent to the EventBus.
+            postEvent(owningAction, targetAdapter, arguments);
+        }
+
+        return invocationResult.getAdapter();
+    }
+
+    protected InvocationResult internalInvoke(
+            final ObjectAction owningAction,
+            final ObjectAdapter targetAdapter,
+            final ObjectAdapter[] arguments) {
+
+        final Bulk.InteractionContext bulkInteractionContext = getServicesInjector().lookupService(Bulk.InteractionContext.class);
+        final CommandContext commandContext = getServicesInjector().lookupService(CommandContext.class);
+        final Command command = commandContext != null ? commandContext.getCommand() : null;
+
+        try {
+            final Object[] executionParameters = new Object[arguments.length];
+            for (int i = 0; i < arguments.length; i++) {
+                executionParameters[i] = unwrap(arguments[i]);
+            }
+
+            final Object targetPojo = unwrap(targetAdapter);
+
+            final BulkFacet bulkFacet = getFacetHolder().getFacet(BulkFacet.class);
+            if (bulkFacet != null &&
+                    bulkInteractionContext != null &&
+                    bulkInteractionContext.getInvokedAs() == null) {
+
+                bulkInteractionContext.setInvokedAs(Bulk.InteractionContext.InvokedAs.REGULAR);
+                bulkInteractionContext.setDomainObjects(Collections.singletonList(targetPojo));
+            }
+
+            if(command != null && command.getExecutor() == Command.Executor.USER && owningAction != null) {
+
+                if(command.getTarget() != null) {
+                    // already set up by a ObjectActionContributee;
+                    // don't overwrite
+                } else {
+                    command.setTargetClass(CommandUtil.targetClassNameFor(targetAdapter));
+                    command.setTargetAction(CommandUtil.targetActionNameFor(owningAction));
+                    command.setArguments(CommandUtil.argDescriptionFor(owningAction, arguments));
+
+                    final Bookmark targetBookmark = CommandUtil.bookmarkFor(targetAdapter);
+                    command.setTarget(targetBookmark);
+                }
+
+                command.setMemberIdentifier(CommandUtil.actionIdentifierFor(owningAction));
+
+                // the background service is used here merely as a means to capture an invocation memento
+                final BackgroundService backgroundService = getServicesInjector().lookupService(BackgroundService.class);
+                if(backgroundService != null) {
+                    final Object targetObject = unwrap(targetAdapter);
+                    final Object[] args = CommandUtil.objectsFor(arguments);
+                    ActionInvocationMemento aim = backgroundService.asActionInvocationMemento(method, targetObject, args);
+
+                    if(aim != null) {
+                        command.setMemento(aim.asMementoString());
+                    } else {
+                        throw new IsisException(
+                                "Unable to build memento for action " +
+                                        owningAction.getIdentifier().toClassAndNameIdentityString());
+                    }
+                }
+
+                // copy over the command execution 'context' (if available)
+                final CommandFacet commandFacet = getFacetHolder().getFacet(CommandFacet.class);
+                if(commandFacet != null && !commandFacet.isDisabled()) {
+                    command.setExecuteIn(commandFacet.executeIn());
+                    command.setPersistence(commandFacet.persistence());
+                } else {
+                    // if no facet, assume do want to execute right now, but only persist (eventually) if hinted.
+                    command.setExecuteIn(org.apache.isis.applib.annotation.Command.ExecuteIn.FOREGROUND);
+                    command.setPersistence(org.apache.isis.applib.annotation.Command.Persistence.IF_HINTED);
+                }
+            }
+
+
+            if( command != null &&
+                    command.getExecutor() == Command.Executor.USER &&
+                    command.getExecuteIn() == org.apache.isis.applib.annotation.Command.ExecuteIn.BACKGROUND) {
+
+                // persist command so can be this command can be in the 'background'
+                final CommandService commandService = getServicesInjector().lookupService(CommandService.class);
+                if(commandService.persistIfPossible(command)) {
+                    // force persistence, then return the command itself.
+                    final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
+                    return InvocationResult.forActionThatReturned(resultAdapter);
+                } else {
+                    throw new IsisException(
+                            "Unable to schedule action '"
+                                    + owningAction.getIdentifier().toClassAndNameIdentityString() + "' to run in background: "
+                                    + "CommandService does not support persistent commands " );
+                }
+            } else {
+
+                // otherwise, go ahead and execute action in the 'foreground'
+
+                if(command != null) {
+                    command.setStartedAt(Clock.getTimeAsJavaSqlTimestamp());
+                }
+
+                Object result = method.invoke(targetPojo, executionParameters);
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug(" action result " + result);
+                }
+                if (result == null) {
+                    if(targetAdapter.getSpecification().isViewModelCloneable(null)) {
+                        // if this was a void method on a ViewModel.Cloneable, then (to save boilerplate in the domain)
+                        // automatically do the clone and return the clone instead.
+                        final ViewModel.Cloneable cloneable = (ViewModel.Cloneable) targetAdapter.getObject();
+                        final Object clone = cloneable.clone();
+                        final ObjectAdapter clonedAdapter = getAdapterManager().adapterFor(clone);
+                        return InvocationResult.forActionThatReturned(clonedAdapter);
+                    }
+                    return InvocationResult.forActionThatReturned(null);
+                }
+
+                ObjectAdapter resultAdapter = getAdapterManager().adapterFor(result);
+
+                if(resultAdapter.getSpecification().isViewModelCloneable(resultAdapter)) {
+                    // if the object returned is a ViewModel.Cloneable, then
+                    // (to save boilerplate in the domain) automatically do the clone.
+                    final ViewModel.Cloneable cloneable = (ViewModel.Cloneable) result;
+                    result = cloneable.clone();
+                    resultAdapter = getAdapterManager().adapterFor(result);
+                }
+
+
+                // copy over TypeOfFacet if required
+                final TypeOfFacet typeOfFacet = getFacetHolder().getFacet(TypeOfFacet.class);
+                resultAdapter.setElementSpecificationProvider(ElementSpecificationProviderFromTypeOfFacet.createFrom(typeOfFacet));
+
+                if(command != null) {
+                    if(!resultAdapter.getSpecification().containsDoOpFacet(ViewModelFacet.class)) {
+                        final Bookmark bookmark = CommandUtil.bookmarkFor(resultAdapter);
+                        command.setResult(bookmark);
+                    }
+                }
+
+                final PublishedActionFacet publishedActionFacet = getIdentified().getFacet(PublishedActionFacet.class);
+                ActionInvocationFacet.currentInvocation.set(
+                        publishedActionFacet != null
+                                ? new CurrentInvocation(targetAdapter, getIdentified(), arguments, resultAdapter, command)
+                                :null);
+
+                return InvocationResult.forActionThatReturned(resultAdapter);
+            }
+
+        } catch (final IllegalArgumentException e) {
+            throw e;
+        } catch (final InvocationTargetException e) {
+            final Throwable targetException = e.getTargetException();
+            if (targetException instanceof IllegalStateException) {
+                throw new ReflectiveActionException("IllegalStateException thrown while executing " + method + " " + targetException.getMessage(), targetException);
+            }
+            if(targetException instanceof RecoverableException) {
+                if (!runtimeContext.getTransactionState().canCommit()) {
+                    // something severe has happened to the underlying transaction;
+                    // so escalate this exception to be non-recoverable
+                    final Throwable targetExceptionCause = targetException.getCause();
+                    Throwable nonRecoverableCause = targetExceptionCause != null? targetExceptionCause: targetException;
+                    throw new NonRecoverableException(nonRecoverableCause);
+                }
+            }
+
+            ThrowableExtensions.throwWithinIsisException(e, "Exception executing " + method);
+
+            // Action was not invoked (an Exception was thrown)
+            return InvocationResult.forActionNotInvoked();
+        } catch (final IllegalAccessException e) {
+            throw new ReflectiveActionException("Illegal access of " + method, e);
+        }
+    }
+
+    @SuppressWarnings({ "rawtypes" })
+    private void postEvent(
+            final ObjectAction owningAction,
+            final ObjectAdapter targetAdapter,
+            final ObjectAdapter[] argumentAdapters) {
+
+        try {
+            final Class type = eventType;
+            Identifier actionIdentifier = owningAction.getIdentifier();
+            final Object source = AdapterUtils.unwrap(targetAdapter);
+            final Object[] arguments = AdapterUtils.unwrap(argumentAdapters);
+            @SuppressWarnings("unchecked")
+            final ActionInteractionEvent<?> event = ActionInteractionFacet.Util.newEvent(type, source, actionIdentifier, arguments);
+            getEventBusService().post(event);
+        } catch (Exception e) {
+            throw new FatalException(e);
+        }
+    }
+
+
+    private static Object unwrap(final ObjectAdapter adapter) {
+        return adapter == null ? null : adapter.getObject();
+    }
+
+    @Override
+    public boolean impliesResolve() {
+        return true;
+    }
+
+    @Override
+    public boolean impliesObjectChanged() {
+        return false;
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+
+    // /////////////////////////////////////////////////////////
+    // Dependencies (from lookup)
+    // /////////////////////////////////////////////////////////
+
+    private EventBusService getEventBusService() {
+        return this.servicesInjector.lookupService(EventBusService.class);
+    }
+
+    // /////////////////////////////////////////////////////////
+    // Dependencies (from constructor)
+    // /////////////////////////////////////////////////////////
+
+    private AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+    private ServicesInjector getServicesInjector() {
+        return servicesInjector;
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetDefault.java
new file mode 100644
index 0000000..16a6b7e
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetDefault.java
@@ -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.actions.invoke.event;
+
+import java.lang.reflect.Method;
+import org.apache.isis.applib.services.eventbus.ActionInteractionEvent;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class InteractionWithActionFacetDefault
+        extends InteractionWithActionFacetAbstract {
+
+    public InteractionWithActionFacetDefault(
+            final Method method,
+            final ObjectSpecification onType,
+            final ObjectSpecification returnType,
+            final FacetHolder holder,
+            final RuntimeContext runtimeContext,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final Class<? extends ActionInteractionEvent<?>> eventType) {
+        super(method, onType, returnType, holder, runtimeContext, adapterManager, servicesInjector, eventType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetFactory.java
new file mode 100644
index 0000000..799a5e1
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetFactory.java
@@ -0,0 +1,200 @@
+/*
+ *  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.actions.invoke.event;
+
+import java.lang.reflect.Method;
+import org.apache.isis.applib.annotation.InteractionWithAction;
+import org.apache.isis.applib.annotation.PostsActionInvokedEvent;
+import org.apache.isis.applib.services.eventbus.ActionInteractionEvent;
+import org.apache.isis.core.commons.lang.StringExtensions;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+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.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.actions.debug.DebugFacet;
+import org.apache.isis.core.metamodel.facets.actions.exploration.ExplorationFacet;
+import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
+import org.apache.isis.core.metamodel.facets.named.NamedFacet;
+import org.apache.isis.core.metamodel.facets.named.NamedFacetInferred;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAware;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.actions.invoke.DebugFacetViaNamingConvention;
+import org.apache.isis.core.progmodel.facets.actions.invoke.ExplorationFacetViaNamingConvention;
+
+/**
+ * Sets up {@link ActionInvocationFacet}, along with a number of supporting
+ * facets that are based on the action's name.
+ * 
+ * <p>
+ * The supporting methods are: {@link ExecutedFacet}, {@link ExplorationFacet}
+ * and {@link DebugFacet}. In addition a {@link NamedFacet} is inferred from the
+ * name (taking into account the above well-known prefixes).
+ */
+public class InteractionWithActionFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware, ServicesInjectorAware, RuntimeContextAware {
+
+    private static final String EXPLORATION_PREFIX = "Exploration";
+    private static final String DEBUG_PREFIX = "Debug";
+
+    private static final String[] PREFIXES = { EXPLORATION_PREFIX, DEBUG_PREFIX };
+
+    private AdapterManager adapterManager;
+    private ServicesInjector servicesInjector;
+    private RuntimeContext runtimeContext;
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from
+     * noa-architecture (where they exist)
+     */
+    public InteractionWithActionFacetFactory() {
+        super(FeatureType.ACTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+
+        // InvocationFacet
+        attachInvocationFacet(processMethodContext);
+
+        // DebugFacet, ExplorationFacet
+        attachDebugFacetIfActionMethodNamePrefixed(processMethodContext);
+        attachExplorationFacetIfActionMethodNamePrefixed(processMethodContext);
+
+        // inferred name
+        // (must be called after the attachinvocationFacet methods)
+        attachNamedFacetInferredFromMethodName(processMethodContext); 
+    }
+
+    private void attachInvocationFacet(final ProcessMethodContext processMethodContext) {
+
+        final Method actionMethod = processMethodContext.getMethod();
+
+        try {
+            final Class<?> returnType = actionMethod.getReturnType();
+            final ObjectSpecification returnSpec = getSpecificationLoader().loadSpecification(returnType);
+            if (returnSpec == null) {
+                return;
+            }
+
+            final Class<?> cls = processMethodContext.getCls();
+            final ObjectSpecification typeSpec = getSpecificationLoader().loadSpecification(cls);
+            final FacetHolder holder = processMethodContext.getFacetHolder();
+
+            final InteractionWithAction interactionWithAction =Annotations.getAnnotation(actionMethod, InteractionWithAction.class);
+            final PostsActionInvokedEvent postsActionInvokedEvent = Annotations.getAnnotation(actionMethod, PostsActionInvokedEvent.class);
+
+            if (interactionWithAction != null) {
+                Class<? extends ActionInteractionEvent<?>> eventType = interactionWithAction.value();
+                FacetUtil.addFacet(new InteractionWithActionFacetForAnnotation(actionMethod, typeSpec, returnSpec, holder, getRuntimeContext(), getAdapterManager(), getServicesInjector(), eventType));
+            } else if (postsActionInvokedEvent != null) {
+                Class<? extends ActionInteractionEvent<?>> eventType = postsActionInvokedEvent.value();
+                FacetUtil.addFacet(new InteractionWithActionFacetForPostsActionInvokedEventAnnotation(actionMethod, typeSpec, returnSpec, holder, getRuntimeContext(), getAdapterManager(), getServicesInjector(), eventType));
+            } else {
+                Class<? extends ActionInteractionEvent<?>> eventType = ActionInteractionEvent.Default.class;
+                FacetUtil.addFacet(new InteractionWithActionFacetDefault(actionMethod, typeSpec, returnSpec, holder, getRuntimeContext(), getAdapterManager(), getServicesInjector(), eventType));
+            }
+        } finally {
+            processMethodContext.removeMethod(actionMethod);
+        }
+    }
+
+    private void attachDebugFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
+        final Method actionMethod = processMethodContext.getMethod();
+        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
+        if (!capitalizedName.startsWith(DEBUG_PREFIX)) {
+            return;
+        }
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new DebugFacetViaNamingConvention(facetedMethod));
+    }
+
+    private void attachExplorationFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
+
+        final Method actionMethod = processMethodContext.getMethod();
+        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
+        if (!capitalizedName.startsWith(EXPLORATION_PREFIX)) {
+            return;
+        }
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new ExplorationFacetViaNamingConvention(facetedMethod));
+    }
+
+    /**
+     * Must be called after added the debug, exploration etc facets.
+     * 
+     * <p>
+     * TODO: remove this hack
+     */
+    private void attachNamedFacetInferredFromMethodName(final ProcessMethodContext processMethodContext) {
+
+        final Method method = processMethodContext.getMethod();
+        final String capitalizedName = StringExtensions.asCapitalizedName(method.getName());
+
+        // this is nasty...
+        String name = capitalizedName;
+        name = StringExtensions.removePrefix(name, DEBUG_PREFIX);
+        name = StringExtensions.removePrefix(name, EXPLORATION_PREFIX);
+        name = StringExtensions.asNaturalName2(name);
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new NamedFacetInferred(name, facetedMethod));
+    }
+
+    // ///////////////////////////////////////////////////////////////
+    // Dependencies
+    // ///////////////////////////////////////////////////////////////
+
+    @Override
+    public void setAdapterManager(final AdapterManager adapterManager) {
+        this.adapterManager = adapterManager;
+    }
+
+    private AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+    @Override
+    public void setServicesInjector(final ServicesInjector servicesInjector) {
+        this.servicesInjector = servicesInjector;
+    }
+
+    private ServicesInjector getServicesInjector() {
+        return servicesInjector;
+    }
+
+    private RuntimeContext getRuntimeContext() {
+        return runtimeContext;
+    }
+    
+    @Override
+    public void setRuntimeContext(RuntimeContext runtimeContext) {
+        this.runtimeContext = runtimeContext;
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForAnnotation.java
new file mode 100644
index 0000000..ca66e74
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForAnnotation.java
@@ -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.actions.invoke.event;
+
+import java.lang.reflect.Method;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.isis.applib.services.eventbus.ActionInteractionEvent;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class InteractionWithActionFacetForAnnotation
+        extends InteractionWithActionFacetAbstract {
+
+    public InteractionWithActionFacetForAnnotation(
+            final Method method,
+            final ObjectSpecification onType,
+            final ObjectSpecification returnType,
+            final FacetHolder holder,
+            final RuntimeContext runtimeContext,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final Class<? extends ActionInteractionEvent<?>> eventType) {
+        super(method, onType, returnType, holder, runtimeContext, adapterManager, servicesInjector, eventType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForPostsActionInvokedEventAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForPostsActionInvokedEventAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForPostsActionInvokedEventAnnotation.java
new file mode 100644
index 0000000..fa10a22
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/InteractionWithActionFacetForPostsActionInvokedEventAnnotation.java
@@ -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.actions.invoke.event;
+
+import java.lang.reflect.Method;
+import org.apache.isis.applib.services.eventbus.ActionInteractionEvent;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public class InteractionWithActionFacetForPostsActionInvokedEventAnnotation
+        extends InteractionWithActionFacetAbstract {
+
+    public InteractionWithActionFacetForPostsActionInvokedEventAnnotation(
+            final Method method,
+            final ObjectSpecification onType,
+            final ObjectSpecification returnType,
+            final FacetHolder holder,
+            final RuntimeContext runtimeContext,
+            final AdapterManager adapterManager,
+            final ServicesInjector servicesInjector,
+            final Class<? extends ActionInteractionEvent<?>> eventType) {
+        super(method, onType, returnType, holder, runtimeContext, adapterManager, servicesInjector, eventType);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetAnnotation.java
deleted file mode 100644
index 1406c44..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetAnnotation.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- *  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.actions.invoke.event;
-
-import java.lang.reflect.Method;
-import org.apache.isis.applib.FatalException;
-import org.apache.isis.applib.Identifier;
-import org.apache.isis.applib.services.eventbus.ActionInvokedEvent;
-import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.util.AdapterUtils;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.ImperativeFacet;
-import org.apache.isis.core.metamodel.facets.actions.event.PostsActionInvokedEventFacet;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.progmodel.facets.actions.invoke.ActionInvocationFacetViaMethod;
-
-public class PostsActionInvokedEventFacetAnnotation 
-        extends ActionInvocationFacetViaMethod 
-        implements ImperativeFacet, PostsActionInvokedEventFacet {
-	
-	private ServicesInjector servicesInjector;
-	private Class<? extends ActionInvokedEvent<?>> eventType;
-
-    public PostsActionInvokedEventFacetAnnotation(
-            final Method method, 
-            final ObjectSpecification onType, 
-            final ObjectSpecification returnType, 
-            final FacetHolder holder, 
-            final RuntimeContext runtimeContext, 
-            final AdapterManager adapterManager, 
-            final ServicesInjector servicesInjector,
-			final Class<? extends ActionInvokedEvent<?>> eventType) {
-        super(method, onType, returnType, holder, runtimeContext, adapterManager, servicesInjector);
-        
-        this.servicesInjector = servicesInjector;
-        this.eventType = eventType;
-    }
-
-    @Override
-    public ObjectAdapter invoke(
-            final ObjectAction owningAction, 
-            final ObjectAdapter targetAdapter, 
-            final ObjectAdapter[] arguments) {
-
-    	final InvocationResult invocationResult = this.internalInvoke(owningAction, targetAdapter, arguments);
-    	
-    	// Perhaps the Action was not properly invoked (i.e. an exception was raised).
-    	if (invocationResult.getWhetherInvoked()) {
-    		// If invoked, then send the ActionInvokedEvent to the EventBus.
-    		postEvent(owningAction, targetAdapter, arguments);
-    	}
-    	
-    	return invocationResult.getAdapter();
-    }
-    
-	@SuppressWarnings({ "rawtypes" })
-	private void postEvent(
-            final ObjectAction owningAction, 
-            final ObjectAdapter targetAdapter, 
-            final ObjectAdapter[] argumentAdapters) {
-	    
-		try {
-			final Class type = eventType;
-			Identifier actionIdentifier = owningAction.getIdentifier();
-	        final Object source = AdapterUtils.unwrap(targetAdapter);
-			final Object[] arguments = AdapterUtils.unwrap(argumentAdapters);
-            @SuppressWarnings("unchecked")
-            final ActionInvokedEvent<?> event = org.apache.isis.core.metamodel.facets.actions.event.PostsActionInvokedEventFacet.Util.newEvent(type, source, actionIdentifier, arguments);
-			getEventBusService().post(event);
-		} catch (Exception e) {
-			throw new FatalException(e);
-		}
-	}
-
-	private EventBusService getEventBusService() {
-        return this.servicesInjector.lookupService(EventBusService.class);
-	}
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetFactory.java
deleted file mode 100644
index d52b55a..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetFactory.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- *  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.actions.invoke.event;
-
-import java.lang.reflect.Method;
-
-import org.apache.isis.applib.annotation.PostsActionInvokedEvent;
-import org.apache.isis.applib.annotation.PostsCollectionAddedToEvent;
-import org.apache.isis.applib.services.eventbus.ActionInvokedEvent;
-import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
-import org.apache.isis.core.commons.lang.StringExtensions;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
-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.facets.Annotations;
-import org.apache.isis.core.metamodel.facets.actions.debug.DebugFacet;
-import org.apache.isis.core.metamodel.facets.actions.exploration.ExplorationFacet;
-import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
-import org.apache.isis.core.metamodel.facets.named.NamedFacet;
-import org.apache.isis.core.metamodel.facets.named.NamedFacetInferred;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAware;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
-import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
-import org.apache.isis.core.progmodel.facets.actions.invoke.DebugFacetViaNamingConvention;
-import org.apache.isis.core.progmodel.facets.actions.invoke.ExplorationFacetViaNamingConvention;
-
-/**
- * Sets up {@link ActionInvocationFacet}, along with a number of supporting
- * facets that are based on the action's name.
- * 
- * <p>
- * The supporting methods are: {@link ExecutedFacet}, {@link ExplorationFacet}
- * and {@link DebugFacet}. In addition a {@link NamedFacet} is inferred from the
- * name (taking into account the above well-known prefixes).
- */
-public class PostsActionInvokedEventFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware, ServicesInjectorAware, RuntimeContextAware {
-
-    private static final String EXPLORATION_PREFIX = "Exploration";
-    private static final String DEBUG_PREFIX = "Debug";
-
-    private static final String[] PREFIXES = { EXPLORATION_PREFIX, DEBUG_PREFIX };
-
-    private AdapterManager adapterManager;
-    private ServicesInjector servicesInjector;
-    private RuntimeContext runtimeContext;
-
-    /**
-     * Note that the {@link Facet}s registered are the generic ones from
-     * noa-architecture (where they exist)
-     */
-    public PostsActionInvokedEventFacetFactory() {
-        super(FeatureType.ACTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
-    }
-
-    // ///////////////////////////////////////////////////////
-    // Actions
-    // ///////////////////////////////////////////////////////
-
-    @Override
-    public void process(final ProcessMethodContext processMethodContext) {
-
-        // InvocationFacet
-        attachInvocationFacet(processMethodContext);
-
-        // DebugFacet, ExplorationFacet
-        attachDebugFacetIfActionMethodNamePrefixed(processMethodContext);
-        attachExplorationFacetIfActionMethodNamePrefixed(processMethodContext);
-
-        // inferred name
-        // (must be called after the attachinvocationFacet methods)
-        attachNamedFacetInferredFromMethodName(processMethodContext); 
-    }
-
-    private void attachInvocationFacet(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-
-        try {
-            final PostsActionInvokedEvent annotation = Annotations.getAnnotation(actionMethod, PostsActionInvokedEvent.class);
-            if(annotation == null) {
-                return;
-            }
-        	
-            final Class<?> returnType = actionMethod.getReturnType();
-            final ObjectSpecification returnSpec = getSpecificationLoader().loadSpecification(returnType);
-            if (returnSpec == null) {
-                return;
-            }
-
-            final Class<?> cls = processMethodContext.getCls();
-            final ObjectSpecification typeSpec = getSpecificationLoader().loadSpecification(cls);
-            final FacetHolder holder = processMethodContext.getFacetHolder();
-            
-            final Class<? extends ActionInvokedEvent<?>> changedEventType = annotation.value();
-
-            FacetUtil.addFacet(new PostsActionInvokedEventFacetAnnotation(actionMethod, typeSpec, returnSpec, holder, getRuntimeContext(), getAdapterManager(), getServicesInjector(), changedEventType));
-        } finally {
-            processMethodContext.removeMethod(actionMethod);
-        }
-    }
-
-    private void attachDebugFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
-        if (!capitalizedName.startsWith(DEBUG_PREFIX)) {
-            return;
-        }
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new DebugFacetViaNamingConvention(facetedMethod));
-    }
-
-    private void attachExplorationFacetIfActionMethodNamePrefixed(final ProcessMethodContext processMethodContext) {
-
-        final Method actionMethod = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(actionMethod.getName());
-        if (!capitalizedName.startsWith(EXPLORATION_PREFIX)) {
-            return;
-        }
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new ExplorationFacetViaNamingConvention(facetedMethod));
-    }
-
-    /**
-     * Must be called after added the debug, exploration etc facets.
-     * 
-     * <p>
-     * TODO: remove this hack
-     */
-    private void attachNamedFacetInferredFromMethodName(final ProcessMethodContext processMethodContext) {
-
-        final Method method = processMethodContext.getMethod();
-        final String capitalizedName = StringExtensions.asCapitalizedName(method.getName());
-
-        // this is nasty...
-        String name = capitalizedName;
-        name = StringExtensions.removePrefix(name, DEBUG_PREFIX);
-        name = StringExtensions.removePrefix(name, EXPLORATION_PREFIX);
-        name = StringExtensions.asNaturalName2(name);
-
-        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
-        FacetUtil.addFacet(new NamedFacetInferred(name, facetedMethod));
-    }
-
-    // ///////////////////////////////////////////////////////////////
-    // Dependencies
-    // ///////////////////////////////////////////////////////////////
-
-    @Override
-    public void setAdapterManager(final AdapterManager adapterManager) {
-        this.adapterManager = adapterManager;
-    }
-
-    private AdapterManager getAdapterManager() {
-        return adapterManager;
-    }
-
-    @Override
-    public void setServicesInjector(final ServicesInjector servicesInjector) {
-        this.servicesInjector = servicesInjector;
-    }
-
-    private ServicesInjector getServicesInjector() {
-        return servicesInjector;
-    }
-
-    private RuntimeContext getRuntimeContext() {
-        return runtimeContext;
-    }
-    
-    @Override
-    public void setRuntimeContext(RuntimeContext runtimeContext) {
-        this.runtimeContext = runtimeContext;
-    }
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddDefault.java
new file mode 100644
index 0000000..6eb8fc4
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddDefault.java
@@ -0,0 +1,42 @@
+/*
+ *  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.collections.event;
+
+import org.apache.isis.applib.services.eventbus.CollectionInteractionEvent;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.accessor.PropertyOrCollectionAccessorFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.InteractionWithCollectionFacetAddAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+
+public class InteractionWithCollectionFacetAddDefault
+        extends InteractionWithCollectionFacetAddAbstract {
+
+	public InteractionWithCollectionFacetAddDefault(
+            final Class<? extends CollectionInteractionEvent<?, ?>> eventType,
+            final PropertyOrCollectionAccessorFacet getterFacet,
+            final CollectionAddToFacet collectionAddToFacet,
+            final ServicesInjector servicesInjector,
+            final FacetHolder holder) {
+		super(eventType, getterFacet, collectionAddToFacet, servicesInjector, holder);
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddForAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddForAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddForAnnotation.java
new file mode 100644
index 0000000..806030a
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddForAnnotation.java
@@ -0,0 +1,42 @@
+/*
+ *  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.collections.event;
+
+import org.apache.isis.applib.services.eventbus.CollectionInteractionEvent;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.accessor.PropertyOrCollectionAccessorFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.InteractionWithCollectionFacetAddAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+
+public class InteractionWithCollectionFacetAddForAnnotation
+        extends InteractionWithCollectionFacetAddAbstract {
+
+	public InteractionWithCollectionFacetAddForAnnotation(
+            final Class<? extends CollectionInteractionEvent<?, ?>> eventType,
+            final PropertyOrCollectionAccessorFacet getterFacet,
+            final CollectionAddToFacet collectionAddToFacet,
+            final ServicesInjector servicesInjector,
+            final FacetHolder holder) {
+		super(eventType, getterFacet, collectionAddToFacet, servicesInjector, holder);
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9dd104af/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation.java
new file mode 100644
index 0000000..8132928
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation.java
@@ -0,0 +1,41 @@
+/*
+ *  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.collections.event;
+
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.accessor.PropertyOrCollectionAccessorFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.InteractionWithCollectionFacetAddAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+
+public class InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation
+        extends InteractionWithCollectionFacetAddAbstract {
+
+	public InteractionWithCollectionFacetAddPostsCollectionAddedToEventAnnotation(
+            final Class<? extends CollectionAddedToEvent<?, ?>> eventType,
+            final PropertyOrCollectionAccessorFacet getterFacet,
+            final CollectionAddToFacet collectionAddToFacet,
+            final ServicesInjector servicesInjector,
+            final FacetHolder holder) {
+		super(eventType, getterFacet, collectionAddToFacet, servicesInjector, holder);
+	}
+
+}