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 2012/12/05 00:41:09 UTC

[18/52] [partial] ISIS-188: consolidating isis-core

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentAnnotationFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentAnnotationFacetFactory.java
new file mode 100644
index 0000000..3d86776
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentAnnotationFacetFactory.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.semantics;
+
+import org.apache.isis.applib.annotation.Idempotent;
+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.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.actions.semantics.ActionSemanticsFacet;
+
+public class IdempotentAnnotationFacetFactory extends FacetFactoryAbstract {
+
+    public IdempotentAnnotationFacetFactory() {
+        super(FeatureType.ACTIONS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+        final Idempotent annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Idempotent.class);
+        FacetUtil.addFacet(create(annotation, processMethodContext.getFacetHolder()));
+    }
+
+    private ActionSemanticsFacet create(final Idempotent annotation, final FacetHolder holder) {
+        return annotation == null ? null : new IdempotentFacetAnnotation(holder);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentFacetAnnotation.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentFacetAnnotation.java
new file mode 100644
index 0000000..5b5e8db
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/IdempotentFacetAnnotation.java
@@ -0,0 +1,32 @@
+/*
+ *  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.semantics;
+
+import org.apache.isis.applib.annotation.ActionSemantics;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.actions.semantics.ActionSemanticsFacetAbstract;
+
+public class IdempotentFacetAnnotation extends ActionSemanticsFacetAbstract {
+
+    public IdempotentFacetAnnotation(final FacetHolder holder) {
+        super(ActionSemantics.Of.IDEMPOTENT, holder);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyAnnotationFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyAnnotationFacetFactory.java
new file mode 100644
index 0000000..7a2379a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyAnnotationFacetFactory.java
@@ -0,0 +1,45 @@
+/*
+ *  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.semantics;
+
+import org.apache.isis.applib.annotation.QueryOnly;
+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.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+
+public class QueryOnlyAnnotationFacetFactory extends FacetFactoryAbstract {
+
+    public QueryOnlyAnnotationFacetFactory() {
+        super(FeatureType.ACTIONS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+        final QueryOnly annotation = Annotations.getAnnotation(processMethodContext.getMethod(), QueryOnly.class);
+        if (annotation == null) {
+            return;
+        }
+        final FacetedMethod facetHolder = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new QueryOnlyFacetAnnotation(facetHolder));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyFacetAnnotation.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyFacetAnnotation.java
new file mode 100644
index 0000000..3b0c72d
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/semantics/QueryOnlyFacetAnnotation.java
@@ -0,0 +1,31 @@
+/*
+ *  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.semantics;
+
+import org.apache.isis.applib.annotation.ActionSemantics;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.actions.semantics.ActionSemanticsFacetAbstract;
+
+public class QueryOnlyFacetAnnotation extends ActionSemanticsFacetAbstract {
+
+    public QueryOnlyFacetAnnotation(final FacetHolder holder) {
+        super(ActionSemantics.Of.SAFE, holder);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfAnnotationForActionsFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfAnnotationForActionsFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfAnnotationForActionsFacetFactory.java
new file mode 100644
index 0000000..fb050bf
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfAnnotationForActionsFacetFactory.java
@@ -0,0 +1,96 @@
+/*
+ *  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.typeof.annotation;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+
+import org.apache.isis.applib.annotation.TypeOf;
+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.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetInferredFromArray;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetInferredFromGenerics;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistryAware;
+
+public class TypeOfAnnotationForActionsFacetFactory extends FacetFactoryAbstract implements CollectionTypeRegistryAware {
+    private CollectionTypeRegistry collectionTypeRegistry;
+
+    public TypeOfAnnotationForActionsFacetFactory() {
+        super(FeatureType.ACTIONS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+
+        final TypeOf annotation = Annotations.getAnnotation(processMethodContext.getMethod(), TypeOf.class);
+
+        final Class<?> methodReturnType = processMethodContext.getMethod().getReturnType();
+        if (!collectionTypeRegistry.isCollectionType(methodReturnType) && !collectionTypeRegistry.isArrayType(methodReturnType)) {
+            return;
+        }
+
+        final Class<?> returnType = processMethodContext.getMethod().getReturnType();
+        if (returnType.isArray()) {
+            final Class<?> componentType = returnType.getComponentType();
+            FacetUtil.addFacet(new TypeOfFacetInferredFromArray(componentType, processMethodContext.getFacetHolder(), getSpecificationLoader()));
+            return;
+        }
+
+        if (annotation != null) {
+            FacetUtil.addFacet(new TypeOfFacetAnnotationForAction(annotation.value(), processMethodContext.getFacetHolder(), getSpecificationLoader()));
+            return;
+        }
+
+        final Type type = processMethodContext.getMethod().getGenericReturnType();
+        if (!(type instanceof ParameterizedType)) {
+            return;
+        }
+
+        final ParameterizedType parameterizedType = (ParameterizedType) type;
+        final Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
+        if (actualTypeArguments.length == 0) {
+            return;
+        }
+
+        final Object actualTypeArgument = actualTypeArguments[0];
+        if (actualTypeArgument instanceof Class) {
+            final Class<?> actualType = (Class<?>) actualTypeArgument;
+            FacetUtil.addFacet(new TypeOfFacetInferredFromGenerics(actualType, processMethodContext.getFacetHolder(), getSpecificationLoader()));
+            return;
+        }
+
+        if (actualTypeArgument instanceof TypeVariable) {
+
+            // TODO: what to do here?
+            return;
+        }
+
+    }
+
+    @Override
+    public void setCollectionTypeRegistry(final CollectionTypeRegistry collectionTypeRegistry) {
+        this.collectionTypeRegistry = collectionTypeRegistry;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfFacetAnnotationForAction.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfFacetAnnotationForAction.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfFacetAnnotationForAction.java
new file mode 100644
index 0000000..9f34bd4
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/typeof/annotation/TypeOfFacetAnnotationForAction.java
@@ -0,0 +1,32 @@
+/*
+ *  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.typeof.annotation;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetAbstract;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+
+public class TypeOfFacetAnnotationForAction extends TypeOfFacetAbstract {
+
+    public TypeOfFacetAnnotationForAction(final Class<?> type, final FacetHolder holder, final SpecificationLoader specificationLookup) {
+        super(type, holder, specificationLookup);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacet.java
new file mode 100644
index 0000000..1872aff
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacet.java
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.actions.validate;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
+import org.apache.isis.core.metamodel.interactions.ValidatingInteractionAdvisor;
+
+/**
+ * The mechanism by which the set of parameters of the action can be validated
+ * before the action itself is invoked.
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, corresponds to invoking the
+ * <tt>validateXxx</tt> support method for an action.
+ * 
+ * <p>
+ * Note that the parameters may be validated independently first (eg a range
+ * check on a numeric parameter).
+ * 
+ * @see ActionInvocationFacet
+ */
+public interface ActionValidationFacet extends Facet, ValidatingInteractionAdvisor {
+
+    /**
+     * Reason why the validation has failed, or <tt>null</tt> if okay.
+     */
+    public String invalidReason(ObjectAdapter target, ObjectAdapter[] arguments);
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacetAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacetAbstract.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacetAbstract.java
new file mode 100644
index 0000000..858e5e6
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/ActionValidationFacetAbstract.java
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.actions.validate;
+
+import org.apache.isis.applib.events.ValidityEvent;
+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.ActionInvocationContext;
+import org.apache.isis.core.metamodel.interactions.ValidityContext;
+
+public abstract class ActionValidationFacetAbstract extends FacetAbstract implements ActionValidationFacet {
+
+    public static Class<? extends Facet> type() {
+        return ActionValidationFacet.class;
+    }
+
+    public ActionValidationFacetAbstract(final FacetHolder holder) {
+        super(type(), holder, Derivation.NOT_DERIVED);
+    }
+
+    @Override
+    public String invalidates(final ValidityContext<? extends ValidityEvent> context) {
+        if (!(context instanceof ActionInvocationContext)) {
+            return null;
+        }
+        final ActionInvocationContext actionInvocationContext = (ActionInvocationContext) context;
+        return invalidReason(actionInvocationContext.getTarget(), actionInvocationContext.getArgs());
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaMethod.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaMethod.java
new file mode 100644
index 0000000..4c63bc1
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaMethod.java
@@ -0,0 +1,70 @@
+/*
+ *  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.validate.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.actions.validate.ActionValidationFacetAbstract;
+
+public class ActionValidationFacetViaMethod extends ActionValidationFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public ActionValidationFacetViaMethod(final Method method, final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the
+     * constructor.
+     */
+    @Override
+    public List<Method> getMethods() {
+        return Collections.singletonList(method);
+    }
+
+    @Override
+    public boolean impliesResolve() {
+        return true;
+    }
+
+    @Override
+    public boolean impliesObjectChanged() {
+        return false;
+    }
+
+    @Override
+    public String invalidReason(final ObjectAdapter owningAdapter, final ObjectAdapter[] proposedArgumentAdapters) {
+        return (String) AdapterInvokeUtils.invoke(method, owningAdapter, proposedArgumentAdapters);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaValidateMethodFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaValidateMethodFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaValidateMethodFacetFactory.java
new file mode 100644
index 0000000..41346ef
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/validate/method/ActionValidationFacetViaValidateMethodFacetFactory.java
@@ -0,0 +1,78 @@
+/*
+ *  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.validate.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+import org.apache.isis.core.progmodel.facets.actions.validate.ActionValidationFacet;
+
+/**
+ * Sets up {@link ActionValidationFacet}.
+ */
+public class ActionValidationFacetViaValidateMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.VALIDATE_PREFIX };
+
+    /**
+     * Note that the {@link Facet}s registered are the generic ones from
+     * noa-architecture (where they exist)
+     */
+    public ActionValidationFacetViaValidateMethodFacetFactory() {
+        super(FeatureType.ACTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Actions
+    // ///////////////////////////////////////////////////////
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+        attachValidatingAdvisorFacetForValidateMethodIfFound(processMethodContext);
+    }
+
+    private void attachValidatingAdvisorFacetForValidateMethodIfFound(final ProcessMethodContext processMethodContext) {
+
+        final Class<?> cls = processMethodContext.getCls();
+        final Method actionMethod = processMethodContext.getMethod();
+
+        final String capitalizedName = NameUtils.capitalizeName(actionMethod.getName());
+        final Class<?>[] paramTypes = actionMethod.getParameterTypes();
+        final MethodScope onClass = MethodScope.scopeFor(actionMethod);
+
+        final Method validateMethod = MethodFinderUtils.findMethod(cls, onClass, MethodPrefixConstants.VALIDATE_PREFIX + capitalizedName, String.class, paramTypes);
+        if (validateMethod == null) {
+            return;
+        }
+        processMethodContext.removeMethod(validateMethod);
+
+        final FacetHolder facetedMethod = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new ActionValidationFacetViaMethod(validateMethod, facetedMethod));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetFactory.java
new file mode 100644
index 0000000..6696c26
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetFactory.java
@@ -0,0 +1,106 @@
+/*
+ *  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.accessor;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+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.facetapi.MethodRemover;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+import org.apache.isis.core.progmodel.facets.PropertyOrCollectionIdentifyingFacetFactoryAbstract;
+
+public class CollectionAccessorFacetFactory extends PropertyOrCollectionIdentifyingFacetFactoryAbstract {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.GET_PREFIX };
+
+    public CollectionAccessorFacetFactory() {
+        super(FeatureType.COLLECTIONS_ONLY, PREFIXES);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+
+        attachAccessorFacetForAccessorMethod(processMethodContext);
+    }
+
+    private void attachAccessorFacetForAccessorMethod(final ProcessMethodContext processMethodContext) {
+        final Method accessorMethod = processMethodContext.getMethod();
+        processMethodContext.removeMethod(accessorMethod);
+
+        final FacetHolder holder = processMethodContext.getFacetHolder();
+        final Facet facet = new CollectionAccessorFacetViaAccessor(accessorMethod, holder);
+        FacetUtil.addFacet(facet);
+    }
+
+    // ///////////////////////////////////////////////////////////////
+    // PropertyOrCollectionIdentifyingFacetFactory impl.
+    // ///////////////////////////////////////////////////////////////
+
+    @Override
+    public boolean isPropertyOrCollectionAccessorCandidate(final Method method) {
+        return method.getName().startsWith(MethodPrefixConstants.GET_PREFIX);
+    }
+
+    @Override
+    public boolean isCollectionAccessor(final Method method) {
+        if (!isPropertyOrCollectionAccessorCandidate(method)) {
+            return false;
+        }
+        final Class<?> methodReturnType = method.getReturnType();
+        return isCollectionOrArray(methodReturnType);
+    }
+
+    /**
+     * The method way well represent a reference property, but this facet
+     * factory does not have any opinion on the matter.
+     */
+    @Override
+    public boolean isPropertyAccessor(final Method method) {
+        return false;
+    }
+
+    /**
+     * The method way well represent a value property, but this facet factory
+     * does not have any opinion on the matter.
+     */
+    public boolean isValuePropertyAccessor(final Method method) {
+        return false;
+    }
+
+    @Override
+    public void findAndRemoveCollectionAccessors(final MethodRemover methodRemover, final List<Method> methodListToAppendTo) {
+        final Class<?>[] collectionClasses = getCollectionTypeRepository().getCollectionType();
+        for (final Class<?> returnType : collectionClasses) {
+            final List<Method> list = methodRemover.removeMethods(MethodScope.OBJECT, MethodPrefixConstants.GET_PREFIX, returnType, false, 0);
+            methodListToAppendTo.addAll(list);
+        }
+    }
+
+    @Override
+    public void findAndRemovePropertyAccessors(final MethodRemover methodRemover, final List<Method> methodListToAppendTo) {
+        // does nothing
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetViaAccessor.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetViaAccessor.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetViaAccessor.java
new file mode 100644
index 0000000..e0d9c2d
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/accessor/CollectionAccessorFacetViaAccessor.java
@@ -0,0 +1,77 @@
+/*
+ *  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.accessor;
+
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.applib.DomainObjectContainer;
+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.metamodel.facets.accessor.PropertyOrCollectionAccessorFacetAbstract;
+
+public class CollectionAccessorFacetViaAccessor extends PropertyOrCollectionAccessorFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public CollectionAccessorFacetViaAccessor(final Method method, final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the
+     * constructor.
+     */
+    @Override
+    public List<Method> getMethods() {
+        return Collections.singletonList(method);
+    }
+
+    @Override
+    public boolean impliesResolve() {
+        return true;
+    }
+
+    /**
+     * Bytecode cannot automatically call
+     * {@link DomainObjectContainer#objectChanged(Object)} because cannot
+     * distinguish whether interacting with accessor to read it or to modify its
+     * contents.
+     */
+    @Override
+    public boolean impliesObjectChanged() {
+        return false;
+    }
+
+    @Override
+    public Object getProperty(final ObjectAdapter owningAdapter) {
+        return AdapterInvokeUtils.invoke(method, owningAdapter);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedFacetSinceCollection.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedFacetSinceCollection.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedFacetSinceCollection.java
new file mode 100644
index 0000000..4b002fe
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedFacetSinceCollection.java
@@ -0,0 +1,31 @@
+/*
+ *  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.aggregated;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.aggregated.ParentedFacetAbstract;
+
+public class ParentedFacetSinceCollection extends ParentedFacetAbstract {
+
+    public ParentedFacetSinceCollection(final FacetHolder holder) {
+        super(holder);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedSinceCollectionFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedSinceCollectionFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedSinceCollectionFacetFactory.java
new file mode 100644
index 0000000..001f50f
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/aggregated/ParentedSinceCollectionFacetFactory.java
@@ -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.collections.aggregated;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.object.aggregated.ParentedFacet;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.progmodel.facets.collections.collection.CollectionFacetFactory;
+
+/**
+ * All {@link CollectionTypeRegistry collection types} are intrinsically
+ * {@link ParentedFacet parented}.
+ * 
+ * <p> 
+ * Must be registered in the {@link ProgrammingModel} after
+ * {@link CollectionFacetFactory}.
+ */
+public class ParentedSinceCollectionFacetFactory extends FacetFactoryAbstract {
+
+    public ParentedSinceCollectionFacetFactory() {
+        super(FeatureType.OBJECTS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessClassContext processClassContaxt) {
+        if (!processClassContaxt.getFacetHolder().containsFacet(CollectionFacet.class)) {
+            return;
+        }
+        FacetUtil.addFacet(new ParentedFacetSinceCollection(processClassContaxt.getFacetHolder()));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetFactory.java
new file mode 100644
index 0000000..f03c784
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetFactory.java
@@ -0,0 +1,98 @@
+/*
+ *  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.clear;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtier;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtierAware;
+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.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionClearFacet;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.MethodPrefixConstants;
+
+public class CollectionClearFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements AdapterManagerAware, ObjectDirtierAware {
+
+    private static final String[] PREFIXES = { MethodPrefixConstants.CLEAR_PREFIX };
+
+    private AdapterManager adapterManager;
+    private ObjectDirtier objectDirtier;
+
+    public CollectionClearFacetFactory() {
+        super(FeatureType.COLLECTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+        attachCollectionClearFacets(processMethodContext);
+
+    }
+
+    private void attachCollectionClearFacets(final ProcessMethodContext processMethodContext) {
+
+        final Method getMethod = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseName(getMethod.getName());
+
+        final Class<?> cls = processMethodContext.getCls();
+        final Method method = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.CLEAR_PREFIX + capitalizedName, void.class, null);
+        processMethodContext.removeMethod(method);
+
+        final FacetHolder collection = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(createCollectionClearFacet(method, getMethod, collection));
+    }
+
+    private CollectionClearFacet createCollectionClearFacet(final Method clearMethodIfAny, final Method accessorMethod, final FacetHolder collection) {
+        if (clearMethodIfAny != null) {
+            return new CollectionClearFacetViaMethod(clearMethodIfAny, collection);
+        } else {
+            return new CollectionClearFacetViaAccessor(accessorMethod, collection, getAdapterManager(), getObjectDirtier());
+        }
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Dependencies (injected)
+    // ///////////////////////////////////////////////////////
+
+    protected AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+    @Override
+    public void setAdapterManager(final AdapterManager adapterManager) {
+        this.adapterManager = adapterManager;
+    }
+
+    protected ObjectDirtier getObjectDirtier() {
+        return objectDirtier;
+    }
+
+    @Override
+    public void setObjectDirtier(final ObjectDirtier objectDirtier) {
+        this.objectDirtier = objectDirtier;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaAccessor.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaAccessor.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaAccessor.java
new file mode 100644
index 0000000..7f4fd80
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaAccessor.java
@@ -0,0 +1,99 @@
+/*
+ *  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.clear;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtier;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+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.metamodel.facets.collections.modify.CollectionClearFacetAbstract;
+
+public class CollectionClearFacetViaAccessor extends CollectionClearFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+    private final AdapterManager adapterManager;
+    private final ObjectDirtier objectDirtier;
+
+    public CollectionClearFacetViaAccessor(final Method method, final FacetHolder holder, final AdapterManager adapterManager, final ObjectDirtier objectDirtier) {
+        super(holder);
+        this.method = method;
+        this.adapterManager = adapterManager;
+        this.objectDirtier = objectDirtier;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the
+     * constructor.
+     */
+    @Override
+    public List<Method> getMethods() {
+        return Collections.singletonList(method);
+    }
+
+    @Override
+    public boolean impliesResolve() {
+        return true;
+    }
+
+    /**
+     * Bytecode cannot automatically call
+     * {@link DomainObjectContainer#objectChanged(Object)} because cannot
+     * distinguish whether interacting with accessor to read it or to modify its
+     * contents.
+     */
+    @Override
+    public boolean impliesObjectChanged() {
+        return false;
+    }
+
+    @Override
+    public void clear(final ObjectAdapter owningAdapter) {
+        final Collection<?> collection = (Collection<?>) AdapterInvokeUtils.invoke(method, owningAdapter);
+        collection.clear();
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(owningAdapter);
+        getObjectDirtier().objectChanged(adapter);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+    // /////////////////////////////////////////////////////////
+    // Dependencies (from constructor)
+    // /////////////////////////////////////////////////////////
+
+    protected AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+    protected ObjectDirtier getObjectDirtier() {
+        return objectDirtier;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaMethod.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaMethod.java
new file mode 100644
index 0000000..9bb2e5a
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/clear/CollectionClearFacetViaMethod.java
@@ -0,0 +1,70 @@
+/*
+ *  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.clear;
+
+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.metamodel.facets.collections.modify.CollectionClearFacetAbstract;
+
+public class CollectionClearFacetViaMethod extends CollectionClearFacetAbstract implements ImperativeFacet {
+
+    private final Method method;
+
+    public CollectionClearFacetViaMethod(final Method method, final FacetHolder holder) {
+        super(holder);
+        this.method = method;
+    }
+
+    /**
+     * Returns a singleton list of the {@link Method} provided in the
+     * constructor.
+     */
+    @Override
+    public List<Method> getMethods() {
+        return Collections.singletonList(method);
+    }
+
+    @Override
+    public boolean impliesResolve() {
+        return true;
+    }
+
+    @Override
+    public boolean impliesObjectChanged() {
+        return true;
+    }
+
+    @Override
+    public void clear(final ObjectAdapter owningAdapter) {
+        AdapterInvokeUtils.invoke(method, owningAdapter);
+    }
+
+    @Override
+    protected String toStringValues() {
+        return "method=" + method;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
new file mode 100644
index 0000000..cbaa8f5
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
@@ -0,0 +1,98 @@
+/*
+ *  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.collection;
+
+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.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetDefaultToObject;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetInferredFromArray;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetInferredFromGenerics;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistryAware;
+
+public class CollectionFacetFactory extends FacetFactoryAbstract implements CollectionTypeRegistryAware, AdapterManagerAware {
+
+    private CollectionTypeRegistry collectionTypeRegistry;
+    private AdapterManager adapterManager;
+
+    public CollectionFacetFactory() {
+        super(FeatureType.OBJECTS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessClassContext processClassContaxt) {
+
+        if (collectionTypeRegistry.isCollectionType(processClassContaxt.getCls())) {
+            processCollectionType(processClassContaxt);
+        } else if (collectionTypeRegistry.isArrayType(processClassContaxt.getCls())) {
+            processAsArrayType(processClassContaxt);
+        }
+
+    }
+
+    private void processCollectionType(final ProcessClassContext processClassContaxt) {
+        final FacetHolder facetHolder = processClassContaxt.getFacetHolder();
+        final TypeOfFacet typeOfFacet = facetHolder.getFacet(TypeOfFacet.class);
+        if (typeOfFacet == null) {
+            final Class<?> collectionElementType = collectionElementType(processClassContaxt.getCls());
+            facetHolder.addFacet(collectionElementType != Object.class ? new TypeOfFacetInferredFromGenerics(collectionElementType, facetHolder, getSpecificationLoader()) : new TypeOfFacetDefaultToObject(facetHolder, getSpecificationLoader()));
+        } else {
+            // nothing
+        }
+        facetHolder.addFacet(new JavaCollectionFacet(facetHolder, getAdapterManager()));
+        return;
+    }
+
+    private void processAsArrayType(final ProcessClassContext processClassContaxt) {
+        final FacetHolder facetHolder = processClassContaxt.getFacetHolder();
+        facetHolder.addFacet(new JavaArrayFacet(facetHolder, getAdapterManager()));
+        facetHolder.addFacet(new TypeOfFacetInferredFromArray(processClassContaxt.getCls().getComponentType(), facetHolder, getSpecificationLoader()));
+    }
+
+    private Class<?> collectionElementType(final Class<?> cls) {
+        return Object.class;
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // Dependencies (injected)
+    // //////////////////////////////////////////////////////////////
+
+    /**
+     * Injected since {@link CollectionTypeRegistryAware}.
+     */
+    @Override
+    public void setCollectionTypeRegistry(final CollectionTypeRegistry collectionTypeRegistry) {
+        this.collectionTypeRegistry = collectionTypeRegistry;
+    }
+
+    public AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+    @Override
+    public void setAdapterManager(final AdapterManager adapterManager) {
+        this.adapterManager = adapterManager;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaArrayFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaArrayFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaArrayFacet.java
new file mode 100644
index 0000000..2cf11a1
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaArrayFacet.java
@@ -0,0 +1,95 @@
+/*
+ *  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.collection;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+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.collections.CollectionFacetAbstract;
+
+public class JavaArrayFacet extends CollectionFacetAbstract {
+
+    private final AdapterManager adapterManager;
+
+    public JavaArrayFacet(final FacetHolder holder, final AdapterManager adapterManager) {
+        super(holder);
+        this.adapterManager = adapterManager;
+    }
+
+    /**
+     * Expected to be called with a {@link ObjectAdapter} wrapping an array.
+     */
+    @Override
+    public void init(final ObjectAdapter collectionAdapter, final ObjectAdapter[] initData) {
+        final int length = initData.length;
+        final Object[] array = new Object[length];
+        for (int i = 0; i < length; i++) {
+            array[i] = initData[i].getObject();
+        }
+        collectionAdapter.replacePojo(array);
+    }
+
+    /**
+     * Expected to be called with a {@link ObjectAdapter} wrapping an array.
+     */
+    @Override
+    public Collection<ObjectAdapter> collection(final ObjectAdapter collectionAdapter) {
+        final Object[] array = array(collectionAdapter);
+        final ArrayList<ObjectAdapter> objectCollection = new ArrayList<ObjectAdapter>(array.length);
+        for (final Object element2 : array) {
+            final ObjectAdapter element = getAdapterManager().getAdapterFor(element2);
+            objectCollection.add(element);
+        }
+        return objectCollection;
+    }
+
+    /**
+     * Expected to be called with a {@link ObjectAdapter} wrapping an array.
+     */
+    @Override
+    public ObjectAdapter firstElement(final ObjectAdapter collectionAdapter) {
+        final Object[] array = array(collectionAdapter);
+        return array.length > 0 ? getAdapterManager().getAdapterFor(array[0]) : null;
+    }
+
+    /**
+     * Expected to be called with a {@link ObjectAdapter} wrapping an array.
+     */
+    @Override
+    public int size(final ObjectAdapter collectionAdapter) {
+        return array(collectionAdapter).length;
+    }
+
+    private Object[] array(final ObjectAdapter collectionAdapter) {
+        return (Object[]) collectionAdapter.getObject();
+    }
+
+    // /////////////////////////////////////////////////////
+    // Dependencies (from constructor)
+    // /////////////////////////////////////////////////////
+
+    private AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaCollectionFacet.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaCollectionFacet.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaCollectionFacet.java
new file mode 100644
index 0000000..0010415
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/JavaCollectionFacet.java
@@ -0,0 +1,85 @@
+/*
+ *  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.collection;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.collections.CollectionUtils;
+
+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.collections.CollectionFacetAbstract;
+
+public class JavaCollectionFacet extends CollectionFacetAbstract {
+
+    private final AdapterManager adapterManager;
+
+    public JavaCollectionFacet(final FacetHolder holder, final AdapterManager adapterManager) {
+        super(holder);
+        this.adapterManager = adapterManager;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public Collection<ObjectAdapter> collection(final ObjectAdapter wrappedCollection) {
+        final Collection<?> collectionOfUnderlying = collectionOfUnderlying(wrappedCollection);
+        return CollectionUtils.collect(collectionOfUnderlying, new ObjectToAdapterTransformer(getAdapterManager()));
+    }
+
+    @Override
+    public ObjectAdapter firstElement(final ObjectAdapter collection) {
+        final Iterator<ObjectAdapter> iterator = iterator(collection);
+        return iterator.hasNext() ? iterator.next() : null;
+    }
+
+    @Override
+    public int size(final ObjectAdapter collection) {
+        return collectionOfUnderlying(collection).size();
+    }
+
+    @Override
+    public void init(final ObjectAdapter collection, final ObjectAdapter[] initData) {
+        final Collection<? super Object> javaCollection = collectionOfUnderlying(collection);
+        javaCollection.clear();
+        for (final ObjectAdapter element : initData) {
+            final Object pojo = element.getObject();
+            javaCollection.add(pojo);
+        }
+    }
+
+    /**
+     * The underlying collection of objects (not {@link ObjectAdapter}s).
+     */
+    @SuppressWarnings("unchecked")
+    private Collection<? super Object> collectionOfUnderlying(final ObjectAdapter wrappedCollection) {
+        return (Collection<? super Object>) wrappedCollection.getObject();
+    }
+
+    // //////////////////////////////////////////////////////////////////////
+    // Dependencies (from constructor)
+    // //////////////////////////////////////////////////////////////////////
+
+    private AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/ObjectToAdapterTransformer.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/ObjectToAdapterTransformer.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/ObjectToAdapterTransformer.java
new file mode 100644
index 0000000..442a24d
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/ObjectToAdapterTransformer.java
@@ -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.collections.collection;
+
+import org.apache.commons.collections.Transformer;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+
+/**
+ * Uses the Commons Collection API to transform {@link Object}s into
+ * {@link ObjectAdapter} adapters.
+ * 
+ */
+public final class ObjectToAdapterTransformer implements Transformer {
+
+    private final AdapterManager adapterManager;
+
+    public ObjectToAdapterTransformer(final AdapterManager adapterManager) {
+        this.adapterManager = adapterManager;
+    }
+
+    @Override
+    public Object transform(final Object object) {
+        return getAdapterManager().adapterFor(object);
+    }
+
+    // //////////////////////////////////////////////////////////////////
+    // Dependencies (from constructor)
+    // //////////////////////////////////////////////////////////////////
+
+    public AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutable.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutable.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutable.java
new file mode 100644
index 0000000..2bf1924
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutable.java
@@ -0,0 +1,39 @@
+/*
+ *  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.disabled.fromimmutable;
+
+import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.immutable.ImmutableFacet;
+import org.apache.isis.core.progmodel.facets.members.disabled.DisabledFacetAbstract;
+
+public class DisabledFacetForCollectionDerivedFromImmutable extends DisabledFacetAbstract {
+
+    public DisabledFacetForCollectionDerivedFromImmutable(final ImmutableFacet immutableFacet, final FacetHolder holder) {
+        super(immutableFacet.when(), Where.ANYWHERE, holder);
+    }
+
+    @Override
+    public String disabledReason(final ObjectAdapter target) {
+        return when().appliesTo(target) ? "Immutable" : null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.java
new file mode 100644
index 0000000..5bf55c9
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/disabled/fromimmutable/DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.java
@@ -0,0 +1,51 @@
+/*
+ *  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.disabled.fromimmutable;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactory;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.object.immutable.ImmutableFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+/**
+ * REVIEW: I'm not sure this {@link FacetFactory} actually makes sense. Just
+ * because a type is immutable, doesn't imply that the property can't change the
+ * instance that it refers to?
+ */
+public class DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory extends FacetFactoryAbstract {
+
+    public DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory() {
+        super(FeatureType.COLLECTIONS_ONLY);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+        final ObjectSpecification spec = getSpecificationLoader().loadSpecification(processMethodContext.getMethod().getDeclaringClass());
+        if (spec.containsDoOpFacet(ImmutableFacet.class)) {
+            final ImmutableFacet immutableFacet = spec.getFacet(ImmutableFacet.class);
+            final FacetedMethod facetHolder = processMethodContext.getFacetHolder();
+            FacetUtil.addFacet(new DisabledFacetForCollectionDerivedFromImmutable(immutableFacet, facetHolder));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/modify/CollectionAddRemoveAndValidateFacetFactory.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/modify/CollectionAddRemoveAndValidateFacetFactory.java b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/modify/CollectionAddRemoveAndValidateFacetFactory.java
new file mode 100644
index 0000000..f428d09
--- /dev/null
+++ b/framework/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/modify/CollectionAddRemoveAndValidateFacetFactory.java
@@ -0,0 +1,185 @@
+/*
+ *  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.modify;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.commons.lang.NameUtils;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtier;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtierAware;
+import org.apache.isis.core.metamodel.exceptions.MetaModelException;
+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.FacetFactory;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionRemoveFromFacet;
+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.collections.validate.CollectionValidateAddToFacetViaMethod;
+import org.apache.isis.core.progmodel.facets.collections.validate.CollectionValidateRemoveFromFacetViaMethod;
+
+/**
+ * TODO: should probably split out into two {@link FacetFactory}s, one for
+ * <tt>addTo()</tt>/<tt>removeFrom()</tt> and one for <tt>validateAddTo()</tt>/
+ * <tt>validateRemoveFrom()</tt>.
+ */
+public class CollectionAddRemoveAndValidateFacetFactory extends MethodPrefixBasedFacetFactoryAbstract implements ObjectDirtierAware {
+
+    private static final String[] PREFIXES = {};
+
+    private ObjectDirtier objectDirtier;
+
+    public CollectionAddRemoveAndValidateFacetFactory() {
+        super(FeatureType.COLLECTIONS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
+    }
+
+    @Override
+    public void process(final ProcessMethodContext processMethodContext) {
+
+        final Class<?> collectionType = attachAddToFacetAndRemoveFromFacet(processMethodContext);
+        attachValidateAddToAndRemoveFromFacetIfMethodsFound(processMethodContext, collectionType);
+    }
+
+    private Class<?> attachAddToFacetAndRemoveFromFacet(final ProcessMethodContext processMethodContext) {
+
+        final Method accessorMethod = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseName(accessorMethod.getName());
+
+        final Class<?> cls = processMethodContext.getCls();
+
+        // add
+        final Method addToMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.ADD_TO_PREFIX + capitalizedName, void.class);
+        processMethodContext.removeMethod(addToMethod);
+
+        // remove
+        final Method removeFromMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.REMOVE_FROM_PREFIX + capitalizedName, void.class);
+        processMethodContext.removeMethod(removeFromMethod);
+
+        // add facets
+        final FacetHolder collection = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(createAddToFacet(addToMethod, accessorMethod, collection));
+        FacetUtil.addFacet(createRemoveFromFacet(removeFromMethod, accessorMethod, collection));
+
+        // infer typ
+        final Class<?> addToType = ((addToMethod == null || addToMethod.getParameterTypes().length != 1) ? null : addToMethod.getParameterTypes()[0]);
+        final Class<?> removeFromType = ((removeFromMethod == null || removeFromMethod.getParameterTypes().length != 1) ? null : removeFromMethod.getParameterTypes()[0]);
+
+        return inferTypeOfIfPossible(accessorMethod, addToType, removeFromType, collection);
+    }
+
+    /**
+     * TODO need to distinguish between Java collections, arrays and other
+     * collections!
+     */
+    private CollectionAddToFacet createAddToFacet(final Method addToMethodIfAny, final Method accessorMethod, final FacetHolder holder) {
+        if (addToMethodIfAny != null) {
+            return new CollectionAddToFacetViaMethod(addToMethodIfAny, holder);
+        } else {
+            return new CollectionAddToFacetViaAccessor(accessorMethod, holder, getObjectDirtier());
+        }
+    }
+
+    /**
+     * TODO need to distinguish between Java collections, arrays and other
+     * collections!
+     */
+    private CollectionRemoveFromFacet createRemoveFromFacet(final Method removeFromMethodIfAny, final Method accessorMethod, final FacetHolder holder) {
+        if (removeFromMethodIfAny != null) {
+            return new CollectionRemoveFromFacetViaMethod(removeFromMethodIfAny, holder);
+        } else {
+            return new CollectionRemoveFromFacetViaAccessor(accessorMethod, holder, getObjectDirtier());
+        }
+    }
+
+    private Class<?> inferTypeOfIfPossible(final Method getMethod, final Class<?> addType, final Class<?> removeType, final FacetHolder collection) {
+
+        if (addType != null && removeType != null && addType != removeType) {
+            throw new MetaModelException("The addTo/removeFrom methods for " + getMethod.getDeclaringClass() + " must " + "both deal with same type of object: " + addType + "; " + removeType);
+        }
+
+        final Class<?> type = addType != null ? addType : removeType;
+        if (type != null) {
+            FacetUtil.addFacet(new TypeOfFacetInferredFromSupportingMethods(type, collection, getSpecificationLoader()));
+        }
+        return type;
+    }
+
+    private void attachValidateAddToAndRemoveFromFacetIfMethodsFound(final ProcessMethodContext processMethodContext, final Class<?> collectionType) {
+        attachValidateAddToFacetIfValidateAddToMethodIsFound(processMethodContext, collectionType);
+        attachValidateRemoveFacetIfValidateRemoveFromMethodIsFound(processMethodContext, collectionType);
+    }
+
+    private void attachValidateAddToFacetIfValidateAddToMethodIsFound(final ProcessMethodContext processMethodContext, final Class<?> collectionType) {
+
+        final Method getMethod = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseName(getMethod.getName());
+
+        final Class<?> cls = processMethodContext.getCls();
+        final Class<?>[] paramTypes = MethodFinderUtils.paramTypesOrNull(collectionType);
+        Method validateAddToMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.VALIDATE_ADD_TO_PREFIX + capitalizedName, String.class, paramTypes);
+        if (validateAddToMethod == null) {
+            validateAddToMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.VALIDATE_ADD_TO_PREFIX_2 + capitalizedName, String.class, MethodFinderUtils.paramTypesOrNull(collectionType));
+        }
+        if (validateAddToMethod == null) {
+            return;
+        }
+        processMethodContext.removeMethod(validateAddToMethod);
+
+        final FacetHolder collection = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new CollectionValidateAddToFacetViaMethod(validateAddToMethod, collection));
+    }
+
+    private void attachValidateRemoveFacetIfValidateRemoveFromMethodIsFound(final ProcessMethodContext processMethodContext, final Class<?> collectionType) {
+
+        final Method getMethod = processMethodContext.getMethod();
+        final String capitalizedName = NameUtils.javaBaseName(getMethod.getName());
+
+        final Class<?> cls = processMethodContext.getCls();
+        final Class<?>[] paramTypes = MethodFinderUtils.paramTypesOrNull(collectionType);
+        Method validateRemoveFromMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.VALIDATE_REMOVE_FROM_PREFIX + capitalizedName, String.class, paramTypes);
+        if (validateRemoveFromMethod == null) {
+            validateRemoveFromMethod = MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, MethodPrefixConstants.VALIDATE_REMOVE_FROM_PREFIX_2 + capitalizedName, String.class, MethodFinderUtils.paramTypesOrNull(collectionType));
+        }
+        if (validateRemoveFromMethod == null) {
+            return;
+        }
+        processMethodContext.removeMethod(validateRemoveFromMethod);
+
+        final FacetHolder collection = processMethodContext.getFacetHolder();
+        FacetUtil.addFacet(new CollectionValidateRemoveFromFacetViaMethod(validateRemoveFromMethod, collection));
+    }
+
+    // ///////////////////////////////////////////////////////
+    // Dependencies (injected)
+    // ///////////////////////////////////////////////////////
+
+    protected ObjectDirtier getObjectDirtier() {
+        return objectDirtier;
+    }
+
+    @Override
+    public void setObjectDirtier(final ObjectDirtier objectDirtier) {
+        this.objectDirtier = objectDirtier;
+    }
+
+}