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/05/07 09:54:11 UTC
[1/4] git commit: ISIS-550: starting on PostsAddedToCollectionEvent
Repository: isis
Updated Branches:
refs/heads/ISIS-550 [created] 2637a0551
ISIS-550: starting on PostsAddedToCollectionEvent
This is Oscar's patch attached to ISIS-550 ticket on 6-may-2014.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/548cb14f
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/548cb14f
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/548cb14f
Branch: refs/heads/ISIS-550
Commit: 548cb14ff648c0099036a2e777b318e1f4d3daa0
Parents: 31acb0f
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed May 7 05:20:50 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed May 7 05:20:50 2014 +0100
----------------------------------------------------------------------
.../annotation/PostsAddedToCollectionEvent.java | 59 +++++++
.../PostsRemovedFromCollectionEvent.java | 59 +++++++
.../isis/applib/events/ActionArgumentEvent.java | 2 +-
.../eventbus/AddedToCollectionEvent.java | 55 +++++++
.../eventbus/RemovedFromCollectionEvent.java | 54 +++++++
.../event/PostsAddedToCollectionEventFacet.java | 34 ++++
.../PostsCollectionAddToEventFacetAbstract.java | 37 +++++
...lectionAddToEventAnnotationFacetFactory.java | 117 ++++++++++++++
...ostsCollectionAddToEventFacetAnnotation.java | 154 +++++++++++++++++++
...nAddedEventFacetAnnotationTest_newEvent.java | 41 +++++
10 files changed, 611 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
new file mode 100644
index 0000000..28fa7c2
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
@@ -0,0 +1,59 @@
+/*
+ * 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.applib.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
+
+/**
+ * Applies only to collections; any changes should be propagated as events to subscribers.
+ * Only posted after a successful validation.
+ *
+ * <p>For example:
+ * <pre>
+ * public static class DomainEntityAddedToCollectionEvent extends AddedToCollectionEvent {}
+ *
+ * @PostsAddedToCollectionEvent(DomainEntityAddedToCollectionEvent.class)
+ * public DomainEntity getDomainEntity() { ...}
+ * </pre>
+ *
+ * <p>
+ * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
+ * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
+ * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
+ * load them using a repository, and then to delegate to the event to them.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface PostsAddedToCollectionEvent {
+
+ /**
+ * The subclass of {@link AddedToCollectionEvent event} to be instantiated and posted.
+ *
+ * <p>
+ * This subclass must provide a no-arg constructor; the fields are set reflectively.
+ */
+ Class<? extends AddedToCollectionEvent<?,?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
new file mode 100644
index 0000000..4198ce6
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
@@ -0,0 +1,59 @@
+/*
+ * 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.applib.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.isis.applib.services.eventbus.RemovedFromCollectionEvent;
+
+/**
+ * Applies only to collections; any changes should be propagated as events to subscribers.
+ * Only posted after a successful validation.
+ *
+ * <p>For example:
+ * <pre>
+ * public static class DomainEntityRemovedFromCollectionEvent extends RemovedFromCollectionEvent {}
+ *
+ * @PostsRemovedFromCollectionEvent(DomainEntityRemovedFromCollectionEvent.class)
+ * public DomainEntity getDomainEntity() { ...}
+ * </pre>
+ *
+ * <p>
+ * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
+ * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
+ * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
+ * load them using a repository, and then to delegate to the event to them.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface PostsRemovedFromCollectionEvent {
+
+ /**
+ * The subclass of {@link RemovedFromCollectionEvent event} to be instantiated and posted.
+ *
+ * <p>
+ * This subclass must provide a no-arg constructor; the fields are set reflectively.
+ */
+ Class<? extends RemovedFromCollectionEvent<?,?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/applib/src/main/java/org/apache/isis/applib/events/ActionArgumentEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/events/ActionArgumentEvent.java b/core/applib/src/main/java/org/apache/isis/applib/events/ActionArgumentEvent.java
index e59ce18..7f1f5b0 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/events/ActionArgumentEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/events/ActionArgumentEvent.java
@@ -67,7 +67,7 @@ public class ActionArgumentEvent extends ValidityEvent {
@Override
public String getReasonMessage() {
- return String.format("%s. Position: %s. Proposed: %s", super.getReasonMessage(), this.getPosition(), this.getProposed());
+ return String.format("Invalid action argument. Position: %s. Proposed value: %s. Reason: %s", this.getPosition(), this.getProposed(), super.getReasonMessage());
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
new file mode 100644
index 0000000..6b6bb02
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.services.eventbus;
+
+import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
+import org.apache.isis.applib.util.ObjectContracts;
+
+public abstract class AddedToCollectionEvent<S,T> {
+ private final S source;
+ private final T addedValue;
+
+ /**
+ * To instantiate reflectively when the {@link PostsPropertyChangedEvent} annotation
+ * is used.
+ *
+ * <p>
+ * The fields ({@link #source} and {@link #addedValue} are then set reflectively.
+ */
+ public AddedToCollectionEvent() {
+ this(null, null);
+ }
+ public AddedToCollectionEvent(S source, T addedValue) {
+ this.source = source;
+ this.addedValue = addedValue;
+ }
+
+ public S getSource() {
+ return source;
+ }
+
+ public T getAddedValue() {
+ return addedValue;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectContracts.toString(this, "source,addedValue");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
new file mode 100644
index 0000000..e33ed95
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.applib.services.eventbus;
+
+import org.apache.isis.applib.util.ObjectContracts;
+
+public abstract class RemovedFromCollectionEvent<S,T> {
+ private final S source;
+ private final T removedValue;
+
+ /**
+ * To instantiate reflectively when the {@link PostsAddedToCollectionEvent} annotation
+ * is used.
+ *
+ * <p>
+ * The fields ({@link #source} and {@link #removedValue} are then set reflectively.
+ */
+ public RemovedFromCollectionEvent() {
+ this(null, null);
+ }
+ public RemovedFromCollectionEvent(S source, T removedValue) {
+ this.source = source;
+ this.removedValue = removedValue;
+ }
+
+ public S getSource() {
+ return source;
+ }
+
+ public T getRemovedValue() {
+ return removedValue;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectContracts.toString(this, "source,removedValue");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
new file mode 100644
index 0000000..b2f6c18
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
@@ -0,0 +1,34 @@
+/*
+ * 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.metamodel.facets.collections.event;
+
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.MultiTypedFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+
+/**
+ * Indicates that (the specified subclass of) {@link PropertyChangedEvent} should be posted to the
+ * {@link EventBusService}.
+ */
+public interface PostsAddedToCollectionEventFacet extends CollectionAddToFacet, MultiTypedFacet, Facet {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
new file mode 100644
index 0000000..44eec96
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.metamodel.facets.collections.event;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.collections.CollectionFacetAbstract;
+
+public abstract class PostsCollectionAddToEventFacetAbstract extends CollectionFacetAbstract implements PostsAddedToCollectionEventFacet {
+
+ public PostsCollectionAddToEventFacetAbstract(FacetHolder holder) {
+ super(holder);
+ }
+
+ public static Class<? extends Facet> type() {
+ return PostsAddedToCollectionEventFacet.class;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
new file mode 100644
index 0000000..e68b05c
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
@@ -0,0 +1,117 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.isis.applib.annotation.PostsAddedToCollectionEvent;
+import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.ServicesProviderAware;
+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.MetaModelValidatorRefiner;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.collections.sortedby.SortedByFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsAddedToCollectionEventFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorComposite;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
+import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
+
+public class PostsCollectionAddToEventAnnotationFacetFactory extends FacetFactoryAbstract implements ServicesProviderAware, MetaModelValidatorRefiner {
+
+ private ServicesProvider servicesProvider;
+
+ public PostsCollectionAddToEventAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+ final Method method = processMethodContext.getMethod();
+ FacetUtil.addFacet(create(method, processMethodContext.getFacetHolder()));
+ }
+
+ private PostsAddedToCollectionEventFacet create(Method method, final FacetHolder holder) {
+ final PostsAddedToCollectionEvent annotation = Annotations.getAnnotation(method, PostsAddedToCollectionEvent.class);
+ if(annotation == null) {
+ return null;
+ }
+ final PostsAddedToCollectionEventFacet postsAddedToCollectionEventFacet = holder.getFacet(PostsAddedToCollectionEventFacet.class);
+ if(postsAddedToCollectionEventFacet == null) {
+ return null;
+ }
+ final CollectionAddToFacet collectionAddToFacet = holder.getFacet(CollectionAddToFacet.class);
+ final CollectionFacet collectionFacet = holder.getFacet(CollectionFacet.class);
+ if(postsAddedToCollectionEventFacet != null) {
+ holder.removeFacet(postsAddedToCollectionEventFacet);
+ }
+ if(collectionAddToFacet != null) {
+ holder.removeFacet(collectionAddToFacet);
+ }
+ if(collectionFacet != null) {
+ holder.removeFacet(collectionFacet);
+ }
+ final Class<? extends AddedToCollectionEvent<?,?>> changedEventType = annotation.value();
+ return new PostsCollectionAddToEventFacetAnnotation(changedEventType, postsAddedToCollectionEventFacet, collectionAddToFacet, collectionFacet, servicesProvider, holder);
+ }
+
+ @Override
+ public void setServicesProvider(ServicesProvider servicesProvider) {
+ this.servicesProvider = servicesProvider;
+ }
+
+ @Override
+ public void refineMetaModelValidator(MetaModelValidatorComposite metaModelValidator, IsisConfiguration configuration) {
+ metaModelValidator.add(new MetaModelValidatorVisiting(newValidatorVisitor()));
+ }
+
+ protected Visitor newValidatorVisitor() {
+ return new MetaModelValidatorVisiting.Visitor() {
+
+ @Override
+ public boolean visit(ObjectSpecification objectSpec, ValidationFailures validationFailures) {
+ List<OneToManyAssociation> objectCollections = objectSpec.getCollections(Contributed.EXCLUDED);
+ for (OneToManyAssociation objectCollection : objectCollections) {
+ final SortedByFacet facet = objectCollection.getFacet(SortedByFacet.class);
+ if(facet != null) {
+ final Class<? extends Comparator<?>> cls = facet.value();
+ if(!Comparator.class.isAssignableFrom(cls)) {
+ validationFailures.add("%s#%s is annotated with @SortedBy, but the class specified '%s' is not a Comparator", objectSpec.getIdentifier().getClassName(), objectCollection.getId(), facet.value().getName());
+ }
+ }
+ }
+ return true;
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
new file mode 100644
index 0000000..6c59633
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
@@ -0,0 +1,154 @@
+/*
+ * 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 java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsAddedToCollectionEventFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsCollectionAddToEventFacetAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+
+public class PostsCollectionAddToEventFacetAnnotation extends
+ PostsCollectionAddToEventFacetAbstract {
+
+ private final CollectionAddToFacet collectionAddToFacet;
+ private final CollectionFacet collectionFacet;
+ private final ServicesProvider servicesProvider;
+
+ private EventBusService eventBusService;
+ private boolean searchedForEventBusService = false;
+ private Class<? extends AddedToCollectionEvent<?, ?>> addedToCollectionEventType;
+
+ public PostsCollectionAddToEventFacetAnnotation(
+ Class<? extends AddedToCollectionEvent<?, ?>> addedToCollectionEventType,
+ CollectionAddToFacet collectionAddToFacet,
+ CollectionFacet collectionFacet,
+ ServicesProvider servicesProvider, FacetHolder holder) {
+ super(holder);
+ this.addedToCollectionEventType = addedToCollectionEventType;
+ this.collectionAddToFacet = collectionAddToFacet;
+ this.collectionFacet = collectionFacet;
+ this.servicesProvider = servicesProvider;
+ }
+
+ @Override
+ public void add(ObjectAdapter inObject, ObjectAdapter value) {
+ if (this.collectionAddToFacet == null) {
+ return;
+ }
+ eventBusService = getEventBusService();
+ if (eventBusService == null) {
+ collectionAddToFacet.add(inObject, value);
+ return;
+ }
+
+ final Boolean previouslyExisting = this.collectionFacet.contains(
+ inObject, value);
+ if (!previouslyExisting) {
+ collectionAddToFacet.add(inObject, value);
+ postEvent(inObject, value);
+ }
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void postEvent(ObjectAdapter inObject,
+ final Object addedValue) {
+ final Object source = inObject.getObject();
+ try {
+ final Class type = addedToCollectionEventType;
+ final AddedToCollectionEvent<?, ?> event = newEvent(type, addedValue, source);
+
+ eventBusService.post(event);
+ } catch (Exception e) {
+ throw new FatalException(e);
+ }
+ }
+
+
+ static <S, T> AddedToCollectionEvent<S, T> newEvent(
+ final Class<? extends AddedToCollectionEvent<S, T>> type,
+ final T addedValue, final S source)
+ throws InstantiationException, IllegalAccessException,
+ NoSuchFieldException {
+ final AddedToCollectionEvent<S, T> event = type.newInstance();
+
+ setField("source", event, source);
+ setField("addedValue", event, addedValue);
+ return event;
+ }
+
+ private static void setField(final String name,
+ final AddedToCollectionEvent<?, ?> event, final Object sourceValue)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field sourceField = AddedToCollectionEvent.class
+ .getDeclaredField(name);
+ sourceField.setAccessible(true);
+ sourceField.set(event, sourceValue);
+ }
+
+ private EventBusService getEventBusService() {
+ if (!searchedForEventBusService) {
+ final List<ObjectAdapter> serviceAdapters = servicesProvider
+ .getServices();
+ for (ObjectAdapter serviceAdapter : serviceAdapters) {
+ final Object service = serviceAdapter.getObject();
+ if (service instanceof EventBusService) {
+ eventBusService = (EventBusService) service;
+ break;
+ }
+ }
+ }
+ searchedForEventBusService = true;
+ return eventBusService;
+ }
+
+ // //////////////////////////////////////
+ // MultiTypedFacet
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<? extends Facet>[] facetTypes() {
+ return Lists.newArrayList(PostsAddedToCollectionEventFacet.class,
+ CollectionAddToFacet.class).toArray(
+ new Class[] {});
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Facet> T getFacet(Class<T> facet) {
+ return (T) this;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/548cb14f/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
new file mode 100644
index 0000000..ab89c44
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.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.properties.event;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.joda.time.LocalDate;
+import org.junit.Test;
+
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+
+public class PostsCollectionAddedEventFacetAnnotationTest_newEvent {
+
+ public static class SomeDomainObject {}
+
+ public static class SomeDomainObjectCollectionAddedEvent extends AddToCollectionEvent<SomeDomainObject, SomeDomainObject> {}
+
+ @Test
+ public void test() throws Exception {
+ SomeDomainObject sdo = new SomeDomainObject();
+ final PropertyChangedEvent<SomeDomainObject, LocalDate> ev = PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, new SomeDomainObject(), sdo);
+ assertThat(ev.getSource(), is(sdo));
+ assertThat(ev.getNewValue(), is(new LocalDate(2013,4,1)));
+ }
+
+}
[2/4] git commit: ISIS-550: renaming classes
Posted by da...@apache.org.
ISIS-550: renaming classes
to be consistent with current convention..
* AddToCollectionEvent -> CollectionAddToEvent
* RemoveFromCollectionEvent -> CollectionRemoveFromEvent
etc.
Also commented out some unit test that was incomplete.
Also:
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/43c50c46
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/43c50c46
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/43c50c46
Branch: refs/heads/ISIS-550
Commit: 43c50c463b5d664f1558dfa92752c2483654e738
Parents: 548cb14
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed May 7 05:31:56 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed May 7 05:31:56 2014 +0100
----------------------------------------------------------------------
.../annotation/PostsAddedToCollectionEvent.java | 59 ------------------
.../annotation/PostsCollectionAddedToEvent.java | 63 ++++++++++++++++++++
.../PostsCollectionRemovedFromEvent.java | 63 ++++++++++++++++++++
.../PostsRemovedFromCollectionEvent.java | 59 ------------------
.../eventbus/AddedToCollectionEvent.java | 55 -----------------
.../eventbus/CollectionAddedToEvent.java | 55 +++++++++++++++++
.../eventbus/CollectionRemovedFromEvent.java | 54 +++++++++++++++++
.../eventbus/RemovedFromCollectionEvent.java | 54 -----------------
...lectionAddToEventAnnotationFacetFactory.java | 8 +--
...ostsCollectionAddToEventFacetAnnotation.java | 18 +++---
...nAddedEventFacetAnnotationTest_newEvent.java | 20 +++----
11 files changed, 258 insertions(+), 250 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
deleted file mode 100644
index 28fa7c2..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsAddedToCollectionEvent.java
+++ /dev/null
@@ -1,59 +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.applib.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
-
-/**
- * Applies only to collections; any changes should be propagated as events to subscribers.
- * Only posted after a successful validation.
- *
- * <p>For example:
- * <pre>
- * public static class DomainEntityAddedToCollectionEvent extends AddedToCollectionEvent {}
- *
- * @PostsAddedToCollectionEvent(DomainEntityAddedToCollectionEvent.class)
- * public DomainEntity getDomainEntity() { ...}
- * </pre>
- *
- * <p>
- * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
- * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
- * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
- * load them using a repository, and then to delegate to the event to them.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-public @interface PostsAddedToCollectionEvent {
-
- /**
- * The subclass of {@link AddedToCollectionEvent event} to be instantiated and posted.
- *
- * <p>
- * This subclass must provide a no-arg constructor; the fields are set reflectively.
- */
- Class<? extends AddedToCollectionEvent<?,?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
new file mode 100644
index 0000000..e67be7f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.applib.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+
+/**
+ * Applies only to collections; any changes should be propagated as events to subscribers.
+ * Only posted after a successful validation.
+ *
+ * <p>For example:
+ * <pre>
+ * public class Order {
+ * public static class OrderLineItemsAddedToEvent extends CollectionAddedToEvent {}
+ *
+ * @PostsCollectionAddedToEvent(OrderLineItemsAddedToEvent.class)
+ * public SortedSet<OrderLine> getLineItems() { ...}
+ * }
+ * </pre>
+ *
+ * <p>
+ * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
+ * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
+ * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
+ * load them using a repository, and then to delegate to the event to them.
+ *
+ * @see PostsCollectionRemovedFromEvent
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface PostsCollectionAddedToEvent {
+
+ /**
+ * The subclass of {@link CollectionAddedToEvent event} to be instantiated and posted.
+ *
+ * <p>
+ * This subclass must provide a no-arg constructor; the fields are set reflectively.
+ */
+ Class<? extends CollectionAddedToEvent<?,?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
new file mode 100644
index 0000000..f560434
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.applib.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.isis.applib.services.eventbus.CollectionRemovedFromEvent;
+
+/**
+ * Applies only to collections; any changes should be propagated as events to subscribers.
+ * Only posted after a successful validation.
+ *
+ * <p>For example:
+ * <pre>
+ * public class Order {
+ * public static class OrderLineItemsRemovedFromEvent extends CollectionRemovedFromEvent {}
+ *
+ * @PostsCollectionRemovedFromEvent(OrderLineItemsRemovedFromEvent.class)
+ * public SortedSet<OrderLine> getLineItems() { ...}
+ * }
+ * </pre>
+ *
+ * <p>
+ * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
+ * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
+ * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
+ * load them using a repository, and then to delegate to the event to them.
+ *
+ * @see PostsCollectionAddedToEvent
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface PostsCollectionRemovedFromEvent {
+
+ /**
+ * The subclass of {@link CollectionRemovedFromEvent event} to be instantiated and posted.
+ *
+ * <p>
+ * This subclass must provide a no-arg constructor; the fields are set reflectively.
+ */
+ Class<? extends CollectionRemovedFromEvent<?,?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
deleted file mode 100644
index 4198ce6..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsRemovedFromCollectionEvent.java
+++ /dev/null
@@ -1,59 +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.applib.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.apache.isis.applib.services.eventbus.RemovedFromCollectionEvent;
-
-/**
- * Applies only to collections; any changes should be propagated as events to subscribers.
- * Only posted after a successful validation.
- *
- * <p>For example:
- * <pre>
- * public static class DomainEntityRemovedFromCollectionEvent extends RemovedFromCollectionEvent {}
- *
- * @PostsRemovedFromCollectionEvent(DomainEntityRemovedFromCollectionEvent.class)
- * public DomainEntity getDomainEntity() { ...}
- * </pre>
- *
- * <p>
- * It is highly advisable that only domain services - not domain entities - are registered as subscribers.
- * Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true
- * of domain entities. The typical implementation of a domain service subscriber is to identify the impacted entities,
- * load them using a repository, and then to delegate to the event to them.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-public @interface PostsRemovedFromCollectionEvent {
-
- /**
- * The subclass of {@link RemovedFromCollectionEvent event} to be instantiated and posted.
- *
- * <p>
- * This subclass must provide a no-arg constructor; the fields are set reflectively.
- */
- Class<? extends RemovedFromCollectionEvent<?,?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
deleted file mode 100644
index 6b6bb02..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AddedToCollectionEvent.java
+++ /dev/null
@@ -1,55 +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.applib.services.eventbus;
-
-import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
-import org.apache.isis.applib.util.ObjectContracts;
-
-public abstract class AddedToCollectionEvent<S,T> {
- private final S source;
- private final T addedValue;
-
- /**
- * To instantiate reflectively when the {@link PostsPropertyChangedEvent} annotation
- * is used.
- *
- * <p>
- * The fields ({@link #source} and {@link #addedValue} are then set reflectively.
- */
- public AddedToCollectionEvent() {
- this(null, null);
- }
- public AddedToCollectionEvent(S source, T addedValue) {
- this.source = source;
- this.addedValue = addedValue;
- }
-
- public S getSource() {
- return source;
- }
-
- public T getAddedValue() {
- return addedValue;
- }
-
- @Override
- public String toString() {
- return ObjectContracts.toString(this, "source,addedValue");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
new file mode 100644
index 0000000..10229f7
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.services.eventbus;
+
+import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
+import org.apache.isis.applib.util.ObjectContracts;
+
+public abstract class CollectionAddedToEvent<S,T> {
+ private final S source;
+ private final T addedValue;
+
+ /**
+ * To instantiate reflectively when the {@link PostsPropertyChangedEvent} annotation
+ * is used.
+ *
+ * <p>
+ * The fields ({@link #source} and {@link #addedValue} are then set reflectively.
+ */
+ public CollectionAddedToEvent() {
+ this(null, null);
+ }
+ public CollectionAddedToEvent(S source, T addedValue) {
+ this.source = source;
+ this.addedValue = addedValue;
+ }
+
+ public S getSource() {
+ return source;
+ }
+
+ public T getAddedValue() {
+ return addedValue;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectContracts.toString(this, "source,addedValue");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
new file mode 100644
index 0000000..84289da
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.applib.services.eventbus;
+
+import org.apache.isis.applib.util.ObjectContracts;
+
+public abstract class CollectionRemovedFromEvent<S,T> {
+ private final S source;
+ private final T removedValue;
+
+ /**
+ * To instantiate reflectively when the {@link PostsCollectionAddedToEvent} annotation
+ * is used.
+ *
+ * <p>
+ * The fields ({@link #source} and {@link #removedValue} are then set reflectively.
+ */
+ public CollectionRemovedFromEvent() {
+ this(null, null);
+ }
+ public CollectionRemovedFromEvent(S source, T removedValue) {
+ this.source = source;
+ this.removedValue = removedValue;
+ }
+
+ public S getSource() {
+ return source;
+ }
+
+ public T getRemovedValue() {
+ return removedValue;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectContracts.toString(this, "source,removedValue");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
deleted file mode 100644
index e33ed95..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/RemovedFromCollectionEvent.java
+++ /dev/null
@@ -1,54 +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.applib.services.eventbus;
-
-import org.apache.isis.applib.util.ObjectContracts;
-
-public abstract class RemovedFromCollectionEvent<S,T> {
- private final S source;
- private final T removedValue;
-
- /**
- * To instantiate reflectively when the {@link PostsAddedToCollectionEvent} annotation
- * is used.
- *
- * <p>
- * The fields ({@link #source} and {@link #removedValue} are then set reflectively.
- */
- public RemovedFromCollectionEvent() {
- this(null, null);
- }
- public RemovedFromCollectionEvent(S source, T removedValue) {
- this.source = source;
- this.removedValue = removedValue;
- }
-
- public S getSource() {
- return source;
- }
-
- public T getRemovedValue() {
- return removedValue;
- }
-
- @Override
- public String toString() {
- return ObjectContracts.toString(this, "source,removedValue");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
index e68b05c..408a144 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
@@ -23,8 +23,8 @@ import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.List;
-import org.apache.isis.applib.annotation.PostsAddedToCollectionEvent;
-import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
+import org.apache.isis.applib.annotation.PostsCollectionAddedToEvent;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.metamodel.adapter.ServicesProvider;
import org.apache.isis.core.metamodel.adapter.ServicesProviderAware;
@@ -61,7 +61,7 @@ public class PostsCollectionAddToEventAnnotationFacetFactory extends FacetFactor
}
private PostsAddedToCollectionEventFacet create(Method method, final FacetHolder holder) {
- final PostsAddedToCollectionEvent annotation = Annotations.getAnnotation(method, PostsAddedToCollectionEvent.class);
+ final PostsCollectionAddedToEvent annotation = Annotations.getAnnotation(method, PostsCollectionAddedToEvent.class);
if(annotation == null) {
return null;
}
@@ -80,7 +80,7 @@ public class PostsCollectionAddToEventAnnotationFacetFactory extends FacetFactor
if(collectionFacet != null) {
holder.removeFacet(collectionFacet);
}
- final Class<? extends AddedToCollectionEvent<?,?>> changedEventType = annotation.value();
+ final Class<? extends CollectionAddedToEvent<?,?>> changedEventType = annotation.value();
return new PostsCollectionAddToEventFacetAnnotation(changedEventType, postsAddedToCollectionEventFacet, collectionAddToFacet, collectionFacet, servicesProvider, holder);
}
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
index 6c59633..8318cdb 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
@@ -26,7 +26,7 @@ import java.util.List;
import com.google.common.collect.Lists;
import org.apache.isis.applib.FatalException;
-import org.apache.isis.applib.services.eventbus.AddedToCollectionEvent;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
import org.apache.isis.applib.services.eventbus.EventBusService;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.adapter.ServicesProvider;
@@ -47,10 +47,10 @@ public class PostsCollectionAddToEventFacetAnnotation extends
private EventBusService eventBusService;
private boolean searchedForEventBusService = false;
- private Class<? extends AddedToCollectionEvent<?, ?>> addedToCollectionEventType;
+ private Class<? extends CollectionAddedToEvent<?, ?>> addedToCollectionEventType;
public PostsCollectionAddToEventFacetAnnotation(
- Class<? extends AddedToCollectionEvent<?, ?>> addedToCollectionEventType,
+ Class<? extends CollectionAddedToEvent<?, ?>> addedToCollectionEventType,
CollectionAddToFacet collectionAddToFacet,
CollectionFacet collectionFacet,
ServicesProvider servicesProvider, FacetHolder holder) {
@@ -86,7 +86,7 @@ public class PostsCollectionAddToEventFacetAnnotation extends
final Object source = inObject.getObject();
try {
final Class type = addedToCollectionEventType;
- final AddedToCollectionEvent<?, ?> event = newEvent(type, addedValue, source);
+ final CollectionAddedToEvent<?, ?> event = newEvent(type, addedValue, source);
eventBusService.post(event);
} catch (Exception e) {
@@ -95,12 +95,12 @@ public class PostsCollectionAddToEventFacetAnnotation extends
}
- static <S, T> AddedToCollectionEvent<S, T> newEvent(
- final Class<? extends AddedToCollectionEvent<S, T>> type,
+ static <S, T> CollectionAddedToEvent<S, T> newEvent(
+ final Class<? extends CollectionAddedToEvent<S, T>> type,
final T addedValue, final S source)
throws InstantiationException, IllegalAccessException,
NoSuchFieldException {
- final AddedToCollectionEvent<S, T> event = type.newInstance();
+ final CollectionAddedToEvent<S, T> event = type.newInstance();
setField("source", event, source);
setField("addedValue", event, addedValue);
@@ -108,9 +108,9 @@ public class PostsCollectionAddToEventFacetAnnotation extends
}
private static void setField(final String name,
- final AddedToCollectionEvent<?, ?> event, final Object sourceValue)
+ final CollectionAddedToEvent<?, ?> event, final Object sourceValue)
throws NoSuchFieldException, IllegalAccessException {
- final Field sourceField = AddedToCollectionEvent.class
+ final Field sourceField = CollectionAddedToEvent.class
.getDeclaredField(name);
sourceField.setAccessible(true);
sourceField.set(event, sourceValue);
http://git-wip-us.apache.org/repos/asf/isis/blob/43c50c46/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
index ab89c44..5f22cc4 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.isis.core.progmodel.facets.properties.event;
+package org.apache.isis.core.progmodel.facets.collections.event;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -28,14 +28,14 @@ public class PostsCollectionAddedEventFacetAnnotationTest_newEvent {
public static class SomeDomainObject {}
- public static class SomeDomainObjectCollectionAddedEvent extends AddToCollectionEvent<SomeDomainObject, SomeDomainObject> {}
-
- @Test
- public void test() throws Exception {
- SomeDomainObject sdo = new SomeDomainObject();
- final PropertyChangedEvent<SomeDomainObject, LocalDate> ev = PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, new SomeDomainObject(), sdo);
- assertThat(ev.getSource(), is(sdo));
- assertThat(ev.getNewValue(), is(new LocalDate(2013,4,1)));
- }
+// public static class SomeDomainObjectCollectionAddedEvent extends AddToCollectionEvent<SomeDomainObject, SomeDomainObject> {}
+//
+// @Test
+// public void test() throws Exception {
+// SomeDomainObject sdo = new SomeDomainObject();
+// final PropertyChangedEvent<SomeDomainObject, LocalDate> ev = PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, new SomeDomainObject(), sdo);
+// assertThat(ev.getSource(), is(sdo));
+// assertThat(ev.getNewValue(), is(new LocalDate(2013,4,1)));
+// }
}
[3/4] ISIS-550: PostsCollectionAddToEvent first-cut impl
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtilsTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtilsTest.java
index 23238d9..5efadc3 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtilsTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtilsTest.java
@@ -19,8 +19,15 @@
package org.apache.isis.core.metamodel.facets;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
import java.lang.reflect.Method;
+
import com.google.common.collect.Lists;
+
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -28,15 +35,12 @@ import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.apache.isis.applib.filter.Filter;
import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils.ImperativeFacetFlags;
import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
import org.apache.isis.core.unittestsupport.jmocking.JavassistImposteriser;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
-
@RunWith(JMock.class)
public class ImperativeFacetUtilsTest {
@@ -78,7 +82,7 @@ public class ImperativeFacetUtilsTest {
will(returnValue(Lists.newArrayList()));
}
});
- final ImperativeFacetFlags flags = ImperativeFacetUtils.getImperativeFacetFlags(mockObjectMember, method);
+ final ImperativeFacet.Flags flags = ImperativeFacetUtils.getImperativeFacetFlags(mockObjectMember, method);
assertThat(flags, is(not(nullValue())));
assertThat(flags.impliesResolve(), is(false));
assertThat(flags.impliesObjectChanged(), is(false));
@@ -94,7 +98,7 @@ public class ImperativeFacetUtilsTest {
will(returnValue(Lists.newArrayList((Facet) imperativeFacet)));
}
});
- final ImperativeFacetFlags flags = ImperativeFacetUtils.getImperativeFacetFlags(mockObjectMember, method);
+ final ImperativeFacet.Flags flags = ImperativeFacetUtils.getImperativeFacetFlags(mockObjectMember, method);
assertThat(flags, is(not(nullValue())));
// TODO: need more tests here, these don't go deep enough...
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
index 5f22cc4..c4f15c9 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedEventFacetAnnotationTest_newEvent.java
@@ -19,23 +19,33 @@ package org.apache.isis.core.progmodel.facets.collections.event;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import org.joda.time.LocalDate;
+import java.util.Set;
+
import org.junit.Test;
-import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
public class PostsCollectionAddedEventFacetAnnotationTest_newEvent {
- public static class SomeDomainObject {}
+ public static class SomeDomainObject {
+ public Set<SomeReferencedObject> getReferences() { return null; }
+ }
+ public static class SomeReferencedObject {}
+
+ public static class SomeDomainObjectCollectionAddedToEvent extends CollectionAddedToEvent<SomeDomainObject, SomeReferencedObject> {}
-// public static class SomeDomainObjectCollectionAddedEvent extends AddToCollectionEvent<SomeDomainObject, SomeDomainObject> {}
-//
-// @Test
-// public void test() throws Exception {
-// SomeDomainObject sdo = new SomeDomainObject();
-// final PropertyChangedEvent<SomeDomainObject, LocalDate> ev = PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, new SomeDomainObject(), sdo);
-// assertThat(ev.getSource(), is(sdo));
-// assertThat(ev.getNewValue(), is(new LocalDate(2013,4,1)));
-// }
+ @Test
+ public void test() throws Exception {
+ SomeDomainObject sdo = new SomeDomainObject();
+ SomeReferencedObject other = new SomeReferencedObject();
+ Identifier identifier = Identifier.propertyOrCollectionIdentifier(SomeDomainObject.class, "references");
+
+ final CollectionAddedToEvent<SomeDomainObject, SomeReferencedObject> ev = PostsCollectionAddedToEventFacetAnnotation.newEvent(
+ SomeDomainObjectCollectionAddedToEvent.class, sdo, identifier, other);
+ assertThat(ev.getSource(), is(sdo));
+ assertThat(ev.getIdentifier(), is(identifier));
+ assertThat(ev.getValue(), is(other));
+ }
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotationTest_newEvent.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotationTest_newEvent.java b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotationTest_newEvent.java
index 972aea6..f997473 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotationTest_newEvent.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotationTest_newEvent.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertThat;
import org.joda.time.LocalDate;
import org.junit.Test;
+import org.apache.isis.applib.Identifier;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
public class PostsPropertyChangedEventFacetAnnotationTest_newEvent {
@@ -32,11 +33,18 @@ public class PostsPropertyChangedEventFacetAnnotationTest_newEvent {
@Test
public void test() throws Exception {
+
SomeDomainObject sdo = new SomeDomainObject();
- final PropertyChangedEvent<SomeDomainObject, LocalDate> ev = PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, new LocalDate(2013,4,1), new LocalDate(2013,5,2), sdo);
+ Identifier identifier = Identifier.propertyOrCollectionIdentifier(SomeDomainObject.class, "someDateProperty");
+ LocalDate oldValue = new LocalDate(2013,4,1);
+ LocalDate newValue = new LocalDate(2013,5,2);
+
+ final PropertyChangedEvent<SomeDomainObject, LocalDate> ev =
+ PostsPropertyChangedEventFacetAnnotation.newEvent(SomeDatePropertyChangedEvent.class, sdo, identifier, oldValue, newValue);
assertThat(ev.getSource(), is(sdo));
- assertThat(ev.getOldValue(), is(new LocalDate(2013,4,1)));
- assertThat(ev.getNewValue(), is(new LocalDate(2013,5,2)));
+ assertThat(ev.getIdentifier(), is(identifier));
+ assertThat(ev.getOldValue(), is(oldValue));
+ assertThat(ev.getNewValue(), is(newValue));
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/AbstractCollectionInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/AbstractCollectionInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/AbstractCollectionInvocationHandler.java
index ab1e808..b8a4464 100644
--- a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/AbstractCollectionInvocationHandler.java
+++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/AbstractCollectionInvocationHandler.java
@@ -23,14 +23,17 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import com.google.common.collect.Lists;
+
import org.apache.isis.applib.events.CollectionMethodEvent;
import org.apache.isis.applib.events.InteractionEvent;
import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
abstract class AbstractCollectionInvocationHandler<T, C> extends DelegatingInvocationHandlerDefault<C> {
- private final List<Method> interceptedMethods = new ArrayList<Method>();
- private final List<Method> vetoedMethods = new ArrayList<Method>();
+ private final List<Method> interceptedMethods = Lists.newArrayList();
+ private final List<Method> vetoedMethods = Lists.newArrayList();
+
private final String collectionName;
private final OneToManyAssociation oneToManyAssociation;
private final T domainObject;
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
index 93b6d6b..1dc2293 100644
--- a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
+++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.applib.annotation.WrapperPolicy;
import org.apache.isis.applib.events.CollectionAccessEvent;
import org.apache.isis.applib.events.InteractionEvent;
import org.apache.isis.applib.events.ObjectTitleEvent;
@@ -40,8 +41,8 @@ import org.apache.isis.applib.services.wrapper.HiddenException;
import org.apache.isis.applib.services.wrapper.InteractionException;
import org.apache.isis.applib.services.wrapper.InvalidException;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
-import org.apache.isis.applib.services.wrapper.WrapperObject;
import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
+import org.apache.isis.applib.services.wrapper.WrapperObject;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -54,6 +55,7 @@ import org.apache.isis.core.metamodel.consent.InteractionResult;
import org.apache.isis.core.metamodel.facetapi.DecoratingFacet;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facets.ImperativeFacet;
+import org.apache.isis.core.metamodel.facets.PostsEventWithWrapperPolicy;
import org.apache.isis.core.metamodel.facets.accessor.PropertyOrCollectionAccessorFacet;
import org.apache.isis.core.metamodel.facets.actions.choices.ActionChoicesFacet;
import org.apache.isis.core.metamodel.facets.actions.defaults.ActionDefaultsFacet;
@@ -62,6 +64,7 @@ import org.apache.isis.core.metamodel.facets.collections.modify.CollectionRemove
import org.apache.isis.core.metamodel.facets.param.choices.ActionParameterChoicesFacet;
import org.apache.isis.core.metamodel.facets.properties.choices.PropertyChoicesFacet;
import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+import org.apache.isis.core.metamodel.facets.properties.modify.PropertyClearFacet;
import org.apache.isis.core.metamodel.facets.properties.modify.PropertyInitializationFacet;
import org.apache.isis.core.metamodel.facets.properties.modify.PropertySetterFacet;
import org.apache.isis.core.metamodel.interactions.ObjectTitleContext;
@@ -176,9 +179,6 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
return method.invoke(getDelegate(), args);
}
- // for all members, check visibility and usability
- checkVisibility(getAuthenticationSession(), targetAdapter, objectMember);
-
if (objectMember.isOneToOneAssociation()) {
if (instanceOf(imperativeFacets, PropertyValidateFacetViaMethod.class, PropertySetterFacetViaModifyMethod.class, PropertyClearFacetViaClearMethod.class)) {
@@ -186,11 +186,12 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
}
final OneToOneAssociation otoa = (OneToOneAssociation) objectMember;
+
if (instanceOf(imperativeFacets, PropertyOrCollectionAccessorFacet.class)) {
return handleGetterMethodOnProperty(args, targetAdapter, otoa, methodName);
}
+
if (instanceOf(imperativeFacets, PropertySetterFacet.class, PropertyInitializationFacet.class)) {
- checkUsability(getAuthenticationSession(), targetAdapter, objectMember);
return handleSetterMethodOnProperty(args, getAuthenticationSession(), targetAdapter, otoa, methodName);
}
}
@@ -200,16 +201,15 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method '%s'; use only collection accessor/mutator", memberName));
}
+
final OneToManyAssociation otma = (OneToManyAssociation) objectMember;
if (instanceOf(imperativeFacets, PropertyOrCollectionAccessorFacet.class)) {
return handleGetterMethodOnCollection(method, args, targetAdapter, otma, memberName);
}
if (instanceOf(imperativeFacets, CollectionAddToFacet.class)) {
- checkUsability(getAuthenticationSession(), targetAdapter, objectMember);
return handleCollectionAddToMethod(args, targetAdapter, otma, methodName);
}
if (instanceOf(imperativeFacets, CollectionRemoveFromFacet.class)) {
- checkUsability(getAuthenticationSession(), targetAdapter, objectMember);
return handleCollectionRemoveFromMethod(args, targetAdapter, otma, methodName);
}
}
@@ -230,6 +230,10 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
if (objectMember instanceof ObjectAction) {
+ // for all members, check visibility and usability
+ checkVisibility(getAuthenticationSession(), targetAdapter, objectMember);
+
+
if (instanceOf(imperativeFacets, ActionValidationFacetViaMethod.class)) {
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method '%s'; use only the 'invoke' method", memberName));
}
@@ -338,10 +342,13 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
// /////////////////////////////////////////////////////////////////
private Object handleGetterMethodOnProperty(final Object[] args, final ObjectAdapter targetAdapter, final OneToOneAssociation otoa, final String methodName) {
+
if (args.length != 0) {
throw new IllegalArgumentException("Invoking a 'get' should have no arguments");
}
+ checkVisibility(getAuthenticationSession(), targetAdapter, otoa);
+
resolveIfRequired(targetAdapter);
final ObjectAdapter currentReferencedAdapter = otoa.get(targetAdapter);
@@ -361,13 +368,23 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
throw new IllegalArgumentException("Invoking a setter should only have a single argument");
}
- resolveIfRequired(targetAdapter);
-
final Object argumentObj = underlying(args[0]);
+
+ final WrapperPolicy wrapperPolicy = determineWrapperPolicy(otoa, argumentObj);
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ checkVisibility(getAuthenticationSession(), targetAdapter, otoa);
+ checkUsability(getAuthenticationSession(), targetAdapter, otoa);
+ }
+
final ObjectAdapter argumentAdapter = argumentObj != null ? getAdapterManager().adapterFor(argumentObj) : null;
- final InteractionResult interactionResult = otoa.isAssociationValid(targetAdapter, argumentAdapter).getInteractionResult();
- notifyListenersAndVetoIfRequired(interactionResult);
+ resolveIfRequired(targetAdapter);
+
+
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ final InteractionResult interactionResult = otoa.isAssociationValid(targetAdapter, argumentAdapter).getInteractionResult();
+ notifyListenersAndVetoIfRequired(interactionResult);
+ }
if (getExecutionMode() == ExecutionMode.EXECUTE) {
otoa.set(targetAdapter, argumentAdapter);
@@ -378,15 +395,33 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
return null;
}
+ private static WrapperPolicy determineWrapperPolicy(final OneToOneAssociation otoa, final Object argumentObj) {
+ final PostsEventWithWrapperPolicy wrapperPolicyFacet;
+ if(argumentObj != null) {
+ final PropertySetterFacet setterFacet = otoa.getFacet(PropertySetterFacet.class);
+ wrapperPolicyFacet = PostsEventWithWrapperPolicy.Util.getWrapperPolicyFacet(setterFacet);
+ } else {
+ final PropertyClearFacet clearFacet = otoa.getFacet(PropertyClearFacet.class);
+ wrapperPolicyFacet = PostsEventWithWrapperPolicy.Util.getWrapperPolicyFacet(clearFacet);
+ }
+ return wrapperPolicyFacet != null ? wrapperPolicyFacet.getWrapperPolicy() : WrapperPolicy.ENFORCE_RULES;
+ }
+
+
+
// /////////////////////////////////////////////////////////////////
// collection - access
// /////////////////////////////////////////////////////////////////
private Object handleGetterMethodOnCollection(final Method method, final Object[] args, final ObjectAdapter targetAdapter, final OneToManyAssociation otma, final String memberName) {
+
+
if (args.length != 0) {
throw new IllegalArgumentException("Invoking a 'get' should have no arguments");
}
+ checkVisibility(getAuthenticationSession(), targetAdapter, otma);
+
resolveIfRequired(targetAdapter);
final ObjectAdapter currentReferencedAdapter = otma.get(targetAdapter);
@@ -445,6 +480,12 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
throw new IllegalArgumentException("Invoking a addTo should only have a single argument");
}
+ final WrapperPolicy wrapperPolicy = determineAddToWrapperPolicy(otma);
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ checkVisibility(getAuthenticationSession(), targetAdapter, otma);
+ checkUsability(getAuthenticationSession(), targetAdapter, otma);
+ }
+
resolveIfRequired(targetAdapter);
final Object argumentObj = underlying(args[0]);
@@ -453,8 +494,10 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
}
final ObjectAdapter argumentNO = getAdapterManager().adapterFor(argumentObj);
- final InteractionResult interactionResult = otma.isValidToAdd(targetAdapter, argumentNO).getInteractionResult();
- notifyListenersAndVetoIfRequired(interactionResult);
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ final InteractionResult interactionResult = otma.isValidToAdd(targetAdapter, argumentNO).getInteractionResult();
+ notifyListenersAndVetoIfRequired(interactionResult);
+ }
if (getExecutionMode() == ExecutionMode.EXECUTE) {
otma.addElement(targetAdapter, argumentNO);
@@ -465,6 +508,13 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
return null;
}
+ private static WrapperPolicy determineAddToWrapperPolicy(final OneToManyAssociation otma) {
+ final CollectionAddToFacet facet = otma.getFacet(CollectionAddToFacet.class);
+ final PostsEventWithWrapperPolicy wrapperPolicyFacet = PostsEventWithWrapperPolicy.Util.getWrapperPolicyFacet(facet);
+ return wrapperPolicyFacet != null ? wrapperPolicyFacet.getWrapperPolicy() : WrapperPolicy.ENFORCE_RULES;
+ }
+
+
// /////////////////////////////////////////////////////////////////
// collection - remove from
// /////////////////////////////////////////////////////////////////
@@ -474,6 +524,13 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
throw new IllegalArgumentException("Invoking a removeFrom should only have a single argument");
}
+ final WrapperPolicy wrapperPolicy = determineRemoveFromWrapperPolicy(otma);
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ checkVisibility(getAuthenticationSession(), targetAdapter, otma);
+ checkUsability(getAuthenticationSession(), targetAdapter, otma);
+ }
+
+
resolveIfRequired(targetAdapter);
final Object argumentObj = underlying(args[0]);
@@ -482,8 +539,10 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
}
final ObjectAdapter argumentAdapter = getAdapterManager().adapterFor(argumentObj);
- final InteractionResult interactionResult = otma.isValidToRemove(targetAdapter, argumentAdapter).getInteractionResult();
- notifyListenersAndVetoIfRequired(interactionResult);
+ if(wrapperPolicy == WrapperPolicy.ENFORCE_RULES) {
+ final InteractionResult interactionResult = otma.isValidToRemove(targetAdapter, argumentAdapter).getInteractionResult();
+ notifyListenersAndVetoIfRequired(interactionResult);
+ }
if (getExecutionMode() == ExecutionMode.EXECUTE) {
otma.removeElement(targetAdapter, argumentAdapter);
@@ -494,6 +553,13 @@ public class DomainObjectInvocationHandler<T> extends DelegatingInvocationHandle
return null;
}
+ private static WrapperPolicy determineRemoveFromWrapperPolicy(final OneToManyAssociation otma) {
+ final CollectionRemoveFromFacet removeFromFacet = otma.getFacet(CollectionRemoveFromFacet.class);
+
+ final PostsEventWithWrapperPolicy wrapperPolicyFacet = PostsEventWithWrapperPolicy.Util.getWrapperPolicyFacet(removeFromFacet);
+ return wrapperPolicyFacet != null ? wrapperPolicyFacet.getWrapperPolicy() : WrapperPolicy.ENFORCE_RULES;
+ }
+
// /////////////////////////////////////////////////////////////////
// action
// /////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
index c384a9c..5f9fc1d 100644
--- a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
+++ b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
@@ -22,13 +22,17 @@ import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
+
import javax.jdo.JDOHelper;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.VersionStrategy;
+
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Ordering;
+
import org.joda.time.LocalDate;
+
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.NonRecoverableException;
import org.apache.isis.applib.RecoverableException;
@@ -41,8 +45,11 @@ import org.apache.isis.applib.clock.Clock;
import org.apache.isis.applib.services.background.BackgroundService;
import org.apache.isis.applib.services.clock.ClockService;
import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
import org.apache.isis.applib.services.scratchpad.Scratchpad;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.applib.util.ObjectContracts;
import org.apache.isis.applib.util.TitleBuffer;
import org.apache.isis.applib.value.Blob;
@@ -410,6 +417,7 @@ public class ToDoItem implements Comparable<ToDoItem> {
private String notes;
@javax.jdo.annotations.Column(allowsNull="true", length=400)
+ @PostsPropertyChangedEvent()
public String getNotes() {
return notes;
}
@@ -479,6 +487,7 @@ public class ToDoItem implements Comparable<ToDoItem> {
@javax.jdo.annotations.Element(column="dependentId")
private SortedSet<ToDoItem> dependencies = new TreeSet<ToDoItem>();
+ @PostsCollectionAddedToEvent(wrapperPolicy=WrapperPolicy.SKIP_RULES)
@SortedBy(DependenciesComparator.class)
public SortedSet<ToDoItem> getDependencies() {
return dependencies;
@@ -487,13 +496,19 @@ public class ToDoItem implements Comparable<ToDoItem> {
public void setDependencies(final SortedSet<ToDoItem> dependencies) {
this.dependencies = dependencies;
}
-
+ public void addToDependencies(final ToDoItem toDoItem) {
+ getDependencies().add(toDoItem);
+ }
+ public void removeFromDependencies(final ToDoItem toDoItem) {
+ getDependencies().remove(toDoItem);
+ }
+
@PublishedAction
public ToDoItem add(
@TypicalLength(20)
final ToDoItem toDoItem) {
- getDependencies().add(toDoItem);
+ wrapperFactory.wrap(this).addToDependencies(toDoItem);
return this;
}
public List<ToDoItem> autoComplete0Add(final @MinLength(2) String search) {
@@ -523,7 +538,7 @@ public class ToDoItem implements Comparable<ToDoItem> {
public ToDoItem remove(
@TypicalLength(20)
final ToDoItem toDoItem) {
- getDependencies().remove(toDoItem);
+ this.removeFromDependencies(toDoItem);
return this;
}
// disable action dependent on state of object
@@ -733,6 +748,7 @@ public class ToDoItem implements Comparable<ToDoItem> {
// Events
// //////////////////////////////////////
+
public static abstract class AbstractEvent {
private final String eventDescription;
private final ToDoItem toDoItem;
@@ -899,6 +915,9 @@ public class ToDoItem implements Comparable<ToDoItem> {
this.eventBusService = eventBusService;
}
+ @javax.inject.Inject
+ private WrapperFactory wrapperFactory;
+
//endregion
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemSubscriptions.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemSubscriptions.java b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemSubscriptions.java
index c748e18..0a4b02f 100644
--- a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemSubscriptions.java
+++ b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItemSubscriptions.java
@@ -22,7 +22,9 @@ import com.google.common.eventbus.Subscribe;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
public class ToDoItemSubscriptions {
@@ -36,6 +38,18 @@ public class ToDoItemSubscriptions {
LOG.info(ev.getEventDescription() + ": " + container.titleOf(ev.getToDoItem()));
}
+ @Programmatic
+ @Subscribe
+ public void on(PropertyChangedEvent<?,?> ev) {
+ LOG.info(container.titleOf(ev.getSource()) + ", changed " + ev.getIdentifier().getMemberName() + " : " + ev.getOldValue() + " -> " + ev.getNewValue());
+ }
+
+ @Programmatic
+ @Subscribe
+ public void on(CollectionAddedToEvent<?,?> ev) {
+ LOG.info(container.titleOf(ev.getSource()) + ", added to " + ev.getIdentifier().getMemberName() + " : " + ev.getValue());
+ }
+
//region > injected services
// //////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/example/application/quickstart_wicket_restful_jdo/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/webapp/pom.xml b/example/application/quickstart_wicket_restful_jdo/webapp/pom.xml
index e415798..1381579 100644
--- a/example/application/quickstart_wicket_restful_jdo/webapp/pom.xml
+++ b/example/application/quickstart_wicket_restful_jdo/webapp/pom.xml
@@ -185,6 +185,10 @@
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-wrapper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-profilestore</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/example/application/quickstart_wicket_restful_jdo/webapp/src/main/webapp/WEB-INF/isis.properties
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/quickstart_wicket_restful_jdo/webapp/src/main/webapp/WEB-INF/isis.properties
index 87f1857..153f3f9 100644
--- a/example/application/quickstart_wicket_restful_jdo/webapp/src/main/webapp/WEB-INF/isis.properties
+++ b/example/application/quickstart_wicket_restful_jdo/webapp/src/main/webapp/WEB-INF/isis.properties
@@ -189,6 +189,7 @@ isis.services = \
org.apache.isis.applib.annotation.Bulk$InteractionContext,\
org.apache.isis.applib.services.scratchpad.Scratchpad,\
org.apache.isis.applib.services.queryresultscache.QueryResultsCache,\
+ org.apache.isis.core.wrapper.WrapperFactoryDefault,\
\
# JDO implementation of the EventBusService, \
org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo,\
[4/4] git commit: ISIS-550: PostsCollectionAddToEvent first-cut impl
Posted by da...@apache.org.
ISIS-550: PostsCollectionAddToEvent first-cut impl
... pretty much there.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/2637a055
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/2637a055
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/2637a055
Branch: refs/heads/ISIS-550
Commit: 2637a0551f49c2373154cd00b78791039c8d7dc0
Parents: 43c50c4
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed May 7 08:53:41 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed May 7 08:53:41 2014 +0100
----------------------------------------------------------------------
.../annotation/PostsCollectionAddedToEvent.java | 9 +-
.../PostsCollectionRemovedFromEvent.java | 9 +-
.../annotation/PostsPropertyChangedEvent.java | 9 +-
.../isis/applib/annotation/WrapperPolicy.java | 35 ++++
.../eventbus/CollectionAddedToEvent.java | 37 ++--
.../eventbus/CollectionRemovedFromEvent.java | 35 ++--
.../services/eventbus/PropertyChangedEvent.java | 23 ++-
.../applib/services/publish/EventPayload.java | 2 +-
.../ObjectResolveAndObjectChangedEnhancer.java | 4 +-
.../ObjectResolveAndObjectChangedEnhancer.java | 4 +-
.../core/metamodel/facets/ImperativeFacet.java | 85 +++++++++
.../metamodel/facets/ImperativeFacetUtils.java | 76 ++------
.../facets/PostsEventWithWrapperPolicy.java | 61 +++++++
.../event/PostsAddedToCollectionEventFacet.java | 34 ----
.../PostsCollectionAddToEventFacetAbstract.java | 37 ----
.../event/PostsCollectionAddedToEventFacet.java | 37 ++++
...ostsCollectionAddedToEventFacetAbstract.java | 55 ++++++
.../event/PostsPropertyChangedEventFacet.java | 3 +-
.../PostsPropertyChangedEventFacetAbstract.java | 17 +-
.../collection/CollectionFacetFactory.java | 6 +-
...lectionAddToEventAnnotationFacetFactory.java | 117 -------------
...ostsCollectionAddToEventFacetAnnotation.java | 154 -----------------
...ctionAddedToEventAnnotationFacetFactory.java | 78 +++++++++
...tsCollectionAddedToEventFacetAnnotation.java | 173 +++++++++++++++++++
...pertyChangedEventAnnotationFacetFactory.java | 11 +-
...ostsPropertyChangedEventFacetAnnotation.java | 64 ++++---
.../dflt/ProgrammingModelFacetsJava5.java | 4 +
.../facets/ImperativeFacetUtilsTest.java | 16 +-
...nAddedEventFacetAnnotationTest_newEvent.java | 34 ++--
...hangedEventFacetAnnotationTest_newEvent.java | 14 +-
.../AbstractCollectionInvocationHandler.java | 7 +-
.../handlers/DomainObjectInvocationHandler.java | 96 ++++++++--
.../dom/src/main/java/dom/todo/ToDoItem.java | 25 ++-
.../java/dom/todo/ToDoItemSubscriptions.java | 14 ++
.../webapp/pom.xml | 4 +
.../src/main/webapp/WEB-INF/isis.properties | 1 +
36 files changed, 884 insertions(+), 506 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
index e67be7f..04037b8 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionAddedToEvent.java
@@ -25,6 +25,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
/**
* Applies only to collections; any changes should be propagated as events to subscribers.
@@ -58,6 +59,12 @@ public @interface PostsCollectionAddedToEvent {
* <p>
* This subclass must provide a no-arg constructor; the fields are set reflectively.
*/
- Class<? extends CollectionAddedToEvent<?,?>> value();
+ Class<? extends CollectionAddedToEvent<?,?>> value() default CollectionAddedToEvent.Default.class;
+
+ /**
+ * If invoked through the {@link WrapperFactory}, whether business rules ("see it, use it, do it")
+ * should be enforced or not.
+ */
+ WrapperPolicy wrapperPolicy() default WrapperPolicy.ENFORCE_RULES;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
index f560434..f94851f 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsCollectionRemovedFromEvent.java
@@ -25,6 +25,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.isis.applib.services.eventbus.CollectionRemovedFromEvent;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
/**
* Applies only to collections; any changes should be propagated as events to subscribers.
@@ -58,6 +59,12 @@ public @interface PostsCollectionRemovedFromEvent {
* <p>
* This subclass must provide a no-arg constructor; the fields are set reflectively.
*/
- Class<? extends CollectionRemovedFromEvent<?,?>> value();
+ Class<? extends CollectionRemovedFromEvent<?,?>> value() default CollectionRemovedFromEvent.Default.class;
+
+ /**
+ * If invoked through the {@link WrapperFactory}, whether business rules ("see it, use it, do it")
+ * should be enforced or not.
+ */
+ WrapperPolicy wrapperPolicy() default WrapperPolicy.ENFORCE_RULES;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsPropertyChangedEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsPropertyChangedEvent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsPropertyChangedEvent.java
index f1d9491..b55c961 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsPropertyChangedEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PostsPropertyChangedEvent.java
@@ -25,6 +25,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
/**
* Applies only to properties; any changes should be propagated as events to subscribers.
@@ -54,6 +55,12 @@ public @interface PostsPropertyChangedEvent {
* <p>
* This subclass must provide a no-arg constructor; the fields are set reflectively.
*/
- Class<? extends PropertyChangedEvent<?,?>> value();
+ Class<? extends PropertyChangedEvent<?,?>> value() default PropertyChangedEvent.Default.class;
+
+ /**
+ * If invoked through the {@link WrapperFactory}, whether business rules ("see it, use it, do it")
+ * should be enforced or not.
+ */
+ WrapperPolicy wrapperPolicy() default WrapperPolicy.ENFORCE_RULES;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/annotation/WrapperPolicy.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/WrapperPolicy.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/WrapperPolicy.java
new file mode 100644
index 0000000..a69c817
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/WrapperPolicy.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.annotation;
+
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
+
+/**
+ * An attribute of {@link PostsPropertyChangedEvent}, {@link PostsCollectionAddedToEvent} and other related annotations;
+ * is a hint to indicate that if the object member is interacted with through a {@link WrapperFactory}, then whether
+ * business rules ("see it, use it, do it") should be enforced or not.
+ *
+ * <p>
+ * This provides a half-way house between strictly UI-interactions and fully programmatic interactions, so that an
+ * event can be fired programmatically even if the object is disabled in the UI.
+ */
+public enum WrapperPolicy {
+ ENFORCE_RULES,
+ SKIP_RULES
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
index 10229f7..7b2d8f1 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionAddedToEvent.java
@@ -18,38 +18,55 @@
*/
package org.apache.isis.applib.services.eventbus;
+import org.apache.isis.applib.Identifier;
import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
import org.apache.isis.applib.util.ObjectContracts;
public abstract class CollectionAddedToEvent<S,T> {
+
+ public static class Default extends CollectionAddedToEvent<Object, Object> {}
+
private final S source;
- private final T addedValue;
+ private final Identifier identifier;
+ private final T value;
/**
* To instantiate reflectively when the {@link PostsPropertyChangedEvent} annotation
* is used.
*
* <p>
- * The fields ({@link #source} and {@link #addedValue} are then set reflectively.
+ * The fields ({@link #source} and {@link #value} are then set reflectively.
*/
public CollectionAddedToEvent() {
- this(null, null);
+ this(null, null, null);
}
- public CollectionAddedToEvent(S source, T addedValue) {
- this.source = source;
- this.addedValue = addedValue;
+
+ /**
+ * @deprecated - use {@link #CollectionAddedToEvent(Object, Identifier, Object)}
+ */
+ @Deprecated
+ public CollectionAddedToEvent(S source, T value) {
+ this(source, null, value);
}
+ public CollectionAddedToEvent(S source, Identifier identifier, T value) {
+ this.source = source;
+ this.identifier = identifier;
+ this.value = value;
+ }
+
public S getSource() {
return source;
}
-
- public T getAddedValue() {
- return addedValue;
+ public Identifier getIdentifier() {
+ return identifier;
+ }
+ public T getValue() {
+ return value;
}
@Override
public String toString() {
- return ObjectContracts.toString(this, "source,addedValue");
+ return ObjectContracts.toString(this, "source,identifier,value");
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
index 84289da..17b8fed 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/CollectionRemovedFromEvent.java
@@ -18,37 +18,52 @@
*/
package org.apache.isis.applib.services.eventbus;
+import org.apache.isis.applib.Identifier;
import org.apache.isis.applib.util.ObjectContracts;
public abstract class CollectionRemovedFromEvent<S,T> {
+
+ public static class Default extends CollectionRemovedFromEvent<Object, Object> {}
+
private final S source;
- private final T removedValue;
+ private final Identifier identifier;
+ private final T value;
/**
- * To instantiate reflectively when the {@link PostsCollectionAddedToEvent} annotation
+ * To instantiate reflectively when the {@link PostsCollectionRemovedFromEvent} annotation
* is used.
*
* <p>
- * The fields ({@link #source} and {@link #removedValue} are then set reflectively.
+ * The fields ({@link #source} and {@link #value} are then set reflectively.
*/
public CollectionRemovedFromEvent() {
- this(null, null);
+ this(null, null, null);
}
- public CollectionRemovedFromEvent(S source, T removedValue) {
+ /**
+ * @deprecated - use {@link #CollectionRemovedFromEvent(Object, Identifier, Object)}
+ */
+ @Deprecated
+ public CollectionRemovedFromEvent(S source, T value) {
+ this(source, null, value);
+ }
+ public CollectionRemovedFromEvent(S source, Identifier identifier, T value) {
this.source = source;
- this.removedValue = removedValue;
+ this.identifier = identifier;
+ this.value = value;
}
public S getSource() {
return source;
}
-
- public T getRemovedValue() {
- return removedValue;
+ public Identifier getIdentifier() {
+ return identifier;
+ }
+ public T getValue() {
+ return value;
}
@Override
public String toString() {
- return ObjectContracts.toString(this, "source,removedValue");
+ return ObjectContracts.toString(this, "source,value");
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyChangedEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyChangedEvent.java b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyChangedEvent.java
index e528867..9ae0afe 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyChangedEvent.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/PropertyChangedEvent.java
@@ -18,11 +18,16 @@
*/
package org.apache.isis.applib.services.eventbus;
+import org.apache.isis.applib.Identifier;
import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
import org.apache.isis.applib.util.ObjectContracts;
public abstract class PropertyChangedEvent<S,T> {
+
+ public static class Default extends PropertyChangedEvent<Object, Object> {}
+
private final S source;
+ private final Identifier identifier;
private final T oldValue;
private final T newValue;
@@ -35,18 +40,30 @@ public abstract class PropertyChangedEvent<S,T> {
* then set reflectively.
*/
public PropertyChangedEvent() {
- this(null, null, null);
+ this(null, null, null, null);
}
+
+ /**
+ * @deprecated - use {@link #PropertyChangedEvent(Object, Identifier, Object, Object)}.
+ */
+ @Deprecated
public PropertyChangedEvent(S source, T oldValue, T newValue) {
+ this(source, null, oldValue, newValue);
+ }
+
+ public PropertyChangedEvent(S source, Identifier identifier, T oldValue, T newValue) {
this.source = source;
+ this.identifier = identifier;
this.oldValue = oldValue;
this.newValue = newValue;
}
-
+
public S getSource() {
return source;
}
-
+ public Identifier getIdentifier() {
+ return identifier;
+ }
public T getOldValue() {
return oldValue;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventPayload.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventPayload.java b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventPayload.java
index cbeb1fd..4dd96e1 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventPayload.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventPayload.java
@@ -32,7 +32,7 @@ import org.apache.isis.applib.annotation.Programmatic;
* This should be prepared in a way that can be processed by the {@link EventSerializer}. For example:
* <ul>
* <li>The {@link EventSerializer.Simple simple event serializer} simply invokes
- * {@link Object#toString() toString()} on the payload. Use the {@link Simple simple} implementation
+ * {@link Object#toString() toString()} on the payload. Use the {@link Default simple} implementation
* which simply wraps a string.
* </li>
* <li>The <tt>RestfulObjectsSpecEventSerializer</tt> event serializer expects a pojo domain object
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/bytecode-cglib/src/main/java/org/apache/isis/core/bytecode/cglib/ObjectResolveAndObjectChangedEnhancer.java
----------------------------------------------------------------------
diff --git a/core/bytecode-cglib/src/main/java/org/apache/isis/core/bytecode/cglib/ObjectResolveAndObjectChangedEnhancer.java b/core/bytecode-cglib/src/main/java/org/apache/isis/core/bytecode/cglib/ObjectResolveAndObjectChangedEnhancer.java
index 64ce728..d5c68a7 100644
--- a/core/bytecode-cglib/src/main/java/org/apache/isis/core/bytecode/cglib/ObjectResolveAndObjectChangedEnhancer.java
+++ b/core/bytecode-cglib/src/main/java/org/apache/isis/core/bytecode/cglib/ObjectResolveAndObjectChangedEnhancer.java
@@ -29,8 +29,8 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.apache.isis.core.commons.lang.ArrayExtensions;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils;
-import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils.ImperativeFacetFlags;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
import org.apache.isis.core.metamodel.specloader.classsubstitutor.CglibEnhanced;
@@ -62,7 +62,7 @@ public class ObjectResolveAndObjectChangedEnhancer extends ObjectResolveAndObjec
public Object intercept(final Object proxied, final Method proxiedMethod, final Object[] args, final MethodProxy proxyMethod) throws Throwable {
final boolean ignore = proxiedMethod.getDeclaringClass().equals(Object.class);
- ImperativeFacetFlags flags = null;
+ ImperativeFacet.Flags flags = null;
if (!ignore) {
final ObjectSpecificationDefault targetObjSpec = getJavaSpecificationOfOwningClass(proxiedMethod);
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java b/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
index df4ded0..b1103b0 100644
--- a/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
+++ b/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
@@ -28,8 +28,8 @@ import javassist.util.proxy.ProxyObject;
import org.apache.isis.core.commons.exceptions.IsisException;
import org.apache.isis.core.commons.lang.ArrayExtensions;
+import org.apache.isis.core.metamodel.facets.ImperativeFacet;
import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils;
-import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils.ImperativeFacetFlags;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
import org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault;
@@ -54,7 +54,7 @@ public class ObjectResolveAndObjectChangedEnhancer extends ObjectResolveAndObjec
public Object invoke(final Object proxied, final Method proxyMethod, final Method proxiedMethod, final Object[] args) throws Throwable {
final boolean ignore = proxyMethod.getDeclaringClass().equals(Object.class);
- ImperativeFacetFlags flags = null;
+ ImperativeFacet.Flags flags = null;
if (!ignore) {
final ObjectSpecificationDefault targetObjSpec = getJavaSpecificationOfOwningClass(proxiedMethod);
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacet.java
index f1f0e90..f702496 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacet.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacet.java
@@ -24,6 +24,9 @@ import java.util.List;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.filter.Filter;
+import org.apache.isis.applib.filter.Filters;
+import org.apache.isis.core.commons.lang.ObjectExtensions;
+import org.apache.isis.core.metamodel.facetapi.DecoratingFacet;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facetapi.FacetHolder;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -93,4 +96,86 @@ public interface ImperativeFacet {
*/
public boolean impliesObjectChanged();
+
+ // //////////////////////////////////////
+
+ public static class Util {
+ private Util(){}
+
+ /**
+ * Returns the provided {@link Facet facet} as an {@link ImperativeFacet} if
+ * it either is one or if it is a {@link DecoratingFacet} that in turn wraps
+ * an {@link ImperativeFacet}.
+ *
+ * <p>
+ * Otherwise, returns <tt>null</tt>.
+ */
+ public static ImperativeFacet getImperativeFacet(final Facet facet) {
+ if (facet instanceof ImperativeFacet) {
+ return (ImperativeFacet) facet;
+ }
+ if (facet.getUnderlyingFacet() instanceof ImperativeFacet) {
+ return (ImperativeFacet) facet.getUnderlyingFacet();
+ }
+ if (facet instanceof DecoratingFacet) {
+ final DecoratingFacet<?> decoratingFacet = ObjectExtensions.asT(facet);
+ return getImperativeFacet(decoratingFacet.getDecoratedFacet());
+ }
+ return null;
+ }
+
+ public static boolean isImperativeFacet(final Facet facet) {
+ return getImperativeFacet(facet) != null;
+ }
+
+ public static Flags getImperativeFacetFlags(final ObjectMember member, final Method method) {
+ final Flags flags = new Flags();
+ if (member == null) {
+ return flags;
+ }
+ final List<Facet> allFacets = member.getFacets(Filters.anyOfType(Facet.class));
+ for (final Facet facet : allFacets) {
+ final ImperativeFacet imperativeFacet = ImperativeFacetUtils.getImperativeFacet(facet);
+ if (imperativeFacet == null) {
+ continue;
+ }
+ final List<Method> methods = imperativeFacet.getMethods();
+ if (!methods.contains(method)) {
+ continue;
+ }
+ flags.apply(imperativeFacet);
+
+ // no need to search further
+ if (flags.bothSet()) {
+ break;
+ }
+ }
+ return flags;
+ }
+ }
+
+ public static class Flags {
+ private boolean impliesResolve;
+ private boolean impliesObjectChanged;
+
+ public void apply(final ImperativeFacet imperativeFacet) {
+ this.impliesResolve |= imperativeFacet.impliesResolve();
+ this.impliesObjectChanged |= imperativeFacet.impliesObjectChanged();
+ }
+
+ public boolean bothSet() {
+ return impliesResolve && impliesObjectChanged;
+ }
+
+ public boolean impliesResolve() {
+ return impliesResolve;
+ }
+
+ public boolean impliesObjectChanged() {
+ return impliesObjectChanged;
+ }
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtils.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtils.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtils.java
index b4e0beb..049ba3e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtils.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ImperativeFacetUtils.java
@@ -23,8 +23,6 @@ import java.lang.reflect.Method;
import java.util.List;
import org.apache.isis.applib.filter.Filters;
-import org.apache.isis.core.commons.lang.ObjectExtensions;
-import org.apache.isis.core.metamodel.facetapi.DecoratingFacet;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
@@ -34,73 +32,27 @@ public final class ImperativeFacetUtils {
}
/**
- * Returns the provided {@link Facet facet} as an {@link ImperativeFacet} if
- * it either is one or if it is a {@link DecoratingFacet} that in turn wraps
- * an {@link ImperativeFacet}.
- *
- * <p>
- * Otherwise, returns <tt>null</tt>.
+ * @deprecated - use {@link ImperativeFacet.Util#getImperativeFacet(Facet)}
*/
+ @Deprecated
public static ImperativeFacet getImperativeFacet(final Facet facet) {
- if (facet instanceof ImperativeFacet) {
- return (ImperativeFacet) facet;
- }
- if (facet instanceof DecoratingFacet) {
- final DecoratingFacet<?> decoratingFacet = ObjectExtensions.asT(facet);
- return getImperativeFacet(decoratingFacet.getDecoratedFacet());
- }
- return null;
+ return ImperativeFacet.Util.getImperativeFacet(facet);
}
+ /**
+ * @deprecated - use {@link ImperativeFacet.Util#isImperativeFacet(Facet)}
+ */
+ @Deprecated
public static boolean isImperativeFacet(final Facet facet) {
- return getImperativeFacet(facet) != null;
+ return ImperativeFacet.Util.isImperativeFacet(facet);
}
- public static class ImperativeFacetFlags {
- private boolean impliesResolve;
- private boolean impliesObjectChanged;
-
- public void apply(final ImperativeFacet imperativeFacet) {
- this.impliesResolve |= imperativeFacet.impliesResolve();
- this.impliesObjectChanged |= imperativeFacet.impliesObjectChanged();
- }
-
- public boolean bothSet() {
- return impliesResolve && impliesObjectChanged;
- }
-
- public boolean impliesResolve() {
- return impliesResolve;
- }
-
- public boolean impliesObjectChanged() {
- return impliesObjectChanged;
- }
- }
-
- public static ImperativeFacetFlags getImperativeFacetFlags(final ObjectMember member, final Method method) {
- final ImperativeFacetFlags flags = new ImperativeFacetFlags();
- if (member == null) {
- return flags;
- }
- final List<Facet> allFacets = member.getFacets(Filters.anyOfType(Facet.class));
- for (final Facet facet : allFacets) {
- final ImperativeFacet imperativeFacet = ImperativeFacetUtils.getImperativeFacet(facet);
- if (imperativeFacet == null) {
- continue;
- }
- final List<Method> methods = imperativeFacet.getMethods();
- if (!methods.contains(method)) {
- continue;
- }
- flags.apply(imperativeFacet);
-
- // no need to search further
- if (flags.bothSet()) {
- break;
- }
- }
- return flags;
+ /**
+ * @deprecated - use {@link ImperativeFacet.Util#getImperativeFacet(Facet)}
+ */
+ @Deprecated
+ public static ImperativeFacet.Flags getImperativeFacetFlags(final ObjectMember member, final Method method) {
+ return ImperativeFacet.Util.getImperativeFacetFlags(member, method);
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/PostsEventWithWrapperPolicy.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/PostsEventWithWrapperPolicy.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/PostsEventWithWrapperPolicy.java
new file mode 100644
index 0000000..0c12c1c
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/PostsEventWithWrapperPolicy.java
@@ -0,0 +1,61 @@
+/*
+ * 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.metamodel.facets;
+
+import org.apache.isis.applib.annotation.WrapperPolicy;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+import org.apache.isis.core.commons.lang.ObjectExtensions;
+import org.apache.isis.core.metamodel.facetapi.DecoratingFacet;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.MultiTypedFacet;
+import org.apache.isis.core.metamodel.facets.properties.modify.PropertyClearFacet;
+import org.apache.isis.core.metamodel.facets.properties.modify.PropertySetterFacet;
+
+public interface PostsEventWithWrapperPolicy {
+
+ WrapperPolicy getWrapperPolicy();
+
+ public static class Util {
+ private Util(){}
+
+ /**
+ * Returns the provided {@link Facet facet} as an {@link PostsEventWithWrapperPolicy} if
+ * it either is one or if it is a {@link DecoratingFacet} that in turn wraps
+ * an {@link PostsEventWithWrapperPolicy}.
+ *
+ * <p>
+ * Otherwise, returns <tt>null</tt>.
+ */
+ public static PostsEventWithWrapperPolicy getWrapperPolicyFacet(final Facet facet) {
+ if (facet instanceof PostsEventWithWrapperPolicy) {
+ return (PostsEventWithWrapperPolicy) facet;
+ }
+ if (facet.getUnderlyingFacet() instanceof PostsEventWithWrapperPolicy) {
+ return (PostsEventWithWrapperPolicy) facet.getUnderlyingFacet();
+ }
+ if (facet instanceof DecoratingFacet) {
+ final DecoratingFacet<?> decoratingFacet = ObjectExtensions.asT(facet);
+ return getWrapperPolicyFacet(decoratingFacet.getDecoratedFacet());
+ }
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
deleted file mode 100644
index b2f6c18..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsAddedToCollectionEventFacet.java
+++ /dev/null
@@ -1,34 +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.metamodel.facets.collections.event;
-
-import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.MultiTypedFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
-
-/**
- * Indicates that (the specified subclass of) {@link PropertyChangedEvent} should be posted to the
- * {@link EventBusService}.
- */
-public interface PostsAddedToCollectionEventFacet extends CollectionAddToFacet, MultiTypedFacet, Facet {
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
deleted file mode 100644
index 44eec96..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddToEventFacetAbstract.java
+++ /dev/null
@@ -1,37 +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.metamodel.facets.collections.event;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.collections.CollectionFacetAbstract;
-
-public abstract class PostsCollectionAddToEventFacetAbstract extends CollectionFacetAbstract implements PostsAddedToCollectionEventFacet {
-
- public PostsCollectionAddToEventFacetAbstract(FacetHolder holder) {
- super(holder);
- }
-
- public static Class<? extends Facet> type() {
- return PostsAddedToCollectionEventFacet.class;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacet.java
new file mode 100644
index 0000000..91d7d3c
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacet.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.metamodel.facets.collections.event;
+
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.MultiTypedFacet;
+import org.apache.isis.core.metamodel.facets.PostsEventWithWrapperPolicy;
+import org.apache.isis.core.metamodel.facets.SingleValueFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+
+/**
+ * Indicates that (the specified subclass of) {@link CollectionAddedToEvent} should be posted to the
+ * {@link EventBusService}.
+ */
+public interface PostsCollectionAddedToEventFacet extends SingleValueFacet<Class<? extends CollectionAddedToEvent<?,?>>>, CollectionAddToFacet, MultiTypedFacet, PostsEventWithWrapperPolicy {
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacetAbstract.java
new file mode 100644
index 0000000..4f89185
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/event/PostsCollectionAddedToEventFacetAbstract.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.metamodel.facets.collections.event;
+
+import org.apache.isis.applib.annotation.WrapperPolicy;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.SingleValueFacetAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+
+
+public abstract class PostsCollectionAddedToEventFacetAbstract
+ extends SingleValueFacetAbstract<Class<? extends CollectionAddedToEvent<?,?>>>
+ implements PostsCollectionAddedToEventFacet {
+
+ public static Class<? extends Facet> type() {
+
+ // the "primary" type is CollectionAddToFacet rather than PostsAddedToCollectionEventFacet
+ // so that this facet can wrap an existing (via setUnderlying).
+
+ //return PostsAddedToCollectionEventFacet.class;
+ return CollectionAddToFacet.class;
+ }
+
+ private final WrapperPolicy wrapperPolicy;
+
+ public PostsCollectionAddedToEventFacetAbstract(Class<? extends CollectionAddedToEvent<?, ?>> changedEventType, WrapperPolicy wrapperPolicy, FacetHolder holder) {
+ super(type(), changedEventType, holder);
+ this.wrapperPolicy = wrapperPolicy;
+ }
+
+ @Override
+ public WrapperPolicy getWrapperPolicy() {
+ return wrapperPolicy;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacet.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacet.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacet.java
index a01e7f4..e5c108f 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacet.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacet.java
@@ -22,6 +22,7 @@ package org.apache.isis.core.metamodel.facets.properties.event;
import org.apache.isis.applib.services.eventbus.EventBusService;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
import org.apache.isis.core.metamodel.facetapi.MultiTypedFacet;
+import org.apache.isis.core.metamodel.facets.PostsEventWithWrapperPolicy;
import org.apache.isis.core.metamodel.facets.SingleValueFacet;
import org.apache.isis.core.metamodel.facets.properties.modify.PropertyClearFacet;
import org.apache.isis.core.metamodel.facets.properties.modify.PropertySetterFacet;
@@ -30,6 +31,6 @@ import org.apache.isis.core.metamodel.facets.properties.modify.PropertySetterFac
* Indicates that (the specified subclass of) {@link PropertyChangedEvent} should be posted to the
* {@link EventBusService}.
*/
-public interface PostsPropertyChangedEventFacet extends SingleValueFacet<Class<? extends PropertyChangedEvent<?,?>>>, PropertyClearFacet, PropertySetterFacet, MultiTypedFacet {
+public interface PostsPropertyChangedEventFacet extends SingleValueFacet<Class<? extends PropertyChangedEvent<?,?>>>, PropertyClearFacet, PropertySetterFacet, MultiTypedFacet, PostsEventWithWrapperPolicy {
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacetAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacetAbstract.java
index 281438a..69ff6a0 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/event/PostsPropertyChangedEventFacetAbstract.java
@@ -19,19 +19,32 @@
package org.apache.isis.core.metamodel.facets.properties.event;
+import org.apache.isis.applib.annotation.WrapperPolicy;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facetapi.FacetHolder;
import org.apache.isis.core.metamodel.facets.SingleValueFacetAbstract;
-public abstract class PostsPropertyChangedEventFacetAbstract extends SingleValueFacetAbstract<Class<? extends PropertyChangedEvent<?,?>>> implements PostsPropertyChangedEventFacet {
+public abstract class PostsPropertyChangedEventFacetAbstract
+ extends SingleValueFacetAbstract<Class<? extends PropertyChangedEvent<?,?>>>
+ implements PostsPropertyChangedEventFacet {
public static Class<? extends Facet> type() {
+ // different implementation to PostsCollectionAddToEventFacet (for example) because this facet wraps
+ // multiple facets and so we cannot use the setUnderlyingFacet capability.
return PostsPropertyChangedEventFacet.class;
}
- public PostsPropertyChangedEventFacetAbstract(final Class<? extends PropertyChangedEvent<?,?>> changedEventType, final FacetHolder holder) {
+ private final WrapperPolicy wrapperPolicy;
+
+ public PostsPropertyChangedEventFacetAbstract(final Class<? extends PropertyChangedEvent<?,?>> changedEventType, final WrapperPolicy wrapperPolicy, final FacetHolder holder) {
super(type(), changedEventType, holder);
+ this.wrapperPolicy = wrapperPolicy;
+ }
+
+ @Override
+ public WrapperPolicy getWrapperPolicy() {
+ return wrapperPolicy;
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
index cbaa8f5..9b4b4a5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/collection/CollectionFacetFactory.java
@@ -51,11 +51,11 @@ public class CollectionFacetFactory extends FacetFactoryAbstract implements Coll
}
- private void processCollectionType(final ProcessClassContext processClassContaxt) {
- final FacetHolder facetHolder = processClassContaxt.getFacetHolder();
+ private void processCollectionType(final ProcessClassContext processClassContext) {
+ final FacetHolder facetHolder = processClassContext.getFacetHolder();
final TypeOfFacet typeOfFacet = facetHolder.getFacet(TypeOfFacet.class);
if (typeOfFacet == null) {
- final Class<?> collectionElementType = collectionElementType(processClassContaxt.getCls());
+ final Class<?> collectionElementType = collectionElementType(processClassContext.getCls());
facetHolder.addFacet(collectionElementType != Object.class ? new TypeOfFacetInferredFromGenerics(collectionElementType, facetHolder, getSpecificationLoader()) : new TypeOfFacetDefaultToObject(facetHolder, getSpecificationLoader()));
} else {
// nothing
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
deleted file mode 100644
index 408a144..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventAnnotationFacetFactory.java
+++ /dev/null
@@ -1,117 +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.collections.event;
-
-import java.lang.reflect.Method;
-import java.util.Comparator;
-import java.util.List;
-
-import org.apache.isis.applib.annotation.PostsCollectionAddedToEvent;
-import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.metamodel.adapter.ServicesProvider;
-import org.apache.isis.core.metamodel.adapter.ServicesProviderAware;
-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.MetaModelValidatorRefiner;
-import org.apache.isis.core.metamodel.facets.Annotations;
-import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.collections.sortedby.SortedByFacet;
-import org.apache.isis.core.metamodel.facets.collections.event.PostsAddedToCollectionEventFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorComposite;
-import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
-import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
-import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
-
-public class PostsCollectionAddToEventAnnotationFacetFactory extends FacetFactoryAbstract implements ServicesProviderAware, MetaModelValidatorRefiner {
-
- private ServicesProvider servicesProvider;
-
- public PostsCollectionAddToEventAnnotationFacetFactory() {
- super(FeatureType.PROPERTIES_ONLY);
- }
-
- @Override
- public void process(final ProcessMethodContext processMethodContext) {
- final Method method = processMethodContext.getMethod();
- FacetUtil.addFacet(create(method, processMethodContext.getFacetHolder()));
- }
-
- private PostsAddedToCollectionEventFacet create(Method method, final FacetHolder holder) {
- final PostsCollectionAddedToEvent annotation = Annotations.getAnnotation(method, PostsCollectionAddedToEvent.class);
- if(annotation == null) {
- return null;
- }
- final PostsAddedToCollectionEventFacet postsAddedToCollectionEventFacet = holder.getFacet(PostsAddedToCollectionEventFacet.class);
- if(postsAddedToCollectionEventFacet == null) {
- return null;
- }
- final CollectionAddToFacet collectionAddToFacet = holder.getFacet(CollectionAddToFacet.class);
- final CollectionFacet collectionFacet = holder.getFacet(CollectionFacet.class);
- if(postsAddedToCollectionEventFacet != null) {
- holder.removeFacet(postsAddedToCollectionEventFacet);
- }
- if(collectionAddToFacet != null) {
- holder.removeFacet(collectionAddToFacet);
- }
- if(collectionFacet != null) {
- holder.removeFacet(collectionFacet);
- }
- final Class<? extends CollectionAddedToEvent<?,?>> changedEventType = annotation.value();
- return new PostsCollectionAddToEventFacetAnnotation(changedEventType, postsAddedToCollectionEventFacet, collectionAddToFacet, collectionFacet, servicesProvider, holder);
- }
-
- @Override
- public void setServicesProvider(ServicesProvider servicesProvider) {
- this.servicesProvider = servicesProvider;
- }
-
- @Override
- public void refineMetaModelValidator(MetaModelValidatorComposite metaModelValidator, IsisConfiguration configuration) {
- metaModelValidator.add(new MetaModelValidatorVisiting(newValidatorVisitor()));
- }
-
- protected Visitor newValidatorVisitor() {
- return new MetaModelValidatorVisiting.Visitor() {
-
- @Override
- public boolean visit(ObjectSpecification objectSpec, ValidationFailures validationFailures) {
- List<OneToManyAssociation> objectCollections = objectSpec.getCollections(Contributed.EXCLUDED);
- for (OneToManyAssociation objectCollection : objectCollections) {
- final SortedByFacet facet = objectCollection.getFacet(SortedByFacet.class);
- if(facet != null) {
- final Class<? extends Comparator<?>> cls = facet.value();
- if(!Comparator.class.isAssignableFrom(cls)) {
- validationFailures.add("%s#%s is annotated with @SortedBy, but the class specified '%s' is not a Comparator", objectSpec.getIdentifier().getClassName(), objectCollection.getId(), facet.value().getName());
- }
- }
- }
- return true;
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
deleted file mode 100644
index 8318cdb..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddToEventFacetAnnotation.java
+++ /dev/null
@@ -1,154 +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.collections.event;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.applib.FatalException;
-import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
-import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.ServicesProvider;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.collections.event.PostsAddedToCollectionEventFacet;
-import org.apache.isis.core.metamodel.facets.collections.event.PostsCollectionAddToEventFacetAbstract;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-
-public class PostsCollectionAddToEventFacetAnnotation extends
- PostsCollectionAddToEventFacetAbstract {
-
- private final CollectionAddToFacet collectionAddToFacet;
- private final CollectionFacet collectionFacet;
- private final ServicesProvider servicesProvider;
-
- private EventBusService eventBusService;
- private boolean searchedForEventBusService = false;
- private Class<? extends CollectionAddedToEvent<?, ?>> addedToCollectionEventType;
-
- public PostsCollectionAddToEventFacetAnnotation(
- Class<? extends CollectionAddedToEvent<?, ?>> addedToCollectionEventType,
- CollectionAddToFacet collectionAddToFacet,
- CollectionFacet collectionFacet,
- ServicesProvider servicesProvider, FacetHolder holder) {
- super(holder);
- this.addedToCollectionEventType = addedToCollectionEventType;
- this.collectionAddToFacet = collectionAddToFacet;
- this.collectionFacet = collectionFacet;
- this.servicesProvider = servicesProvider;
- }
-
- @Override
- public void add(ObjectAdapter inObject, ObjectAdapter value) {
- if (this.collectionAddToFacet == null) {
- return;
- }
- eventBusService = getEventBusService();
- if (eventBusService == null) {
- collectionAddToFacet.add(inObject, value);
- return;
- }
-
- final Boolean previouslyExisting = this.collectionFacet.contains(
- inObject, value);
- if (!previouslyExisting) {
- collectionAddToFacet.add(inObject, value);
- postEvent(inObject, value);
- }
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private void postEvent(ObjectAdapter inObject,
- final Object addedValue) {
- final Object source = inObject.getObject();
- try {
- final Class type = addedToCollectionEventType;
- final CollectionAddedToEvent<?, ?> event = newEvent(type, addedValue, source);
-
- eventBusService.post(event);
- } catch (Exception e) {
- throw new FatalException(e);
- }
- }
-
-
- static <S, T> CollectionAddedToEvent<S, T> newEvent(
- final Class<? extends CollectionAddedToEvent<S, T>> type,
- final T addedValue, final S source)
- throws InstantiationException, IllegalAccessException,
- NoSuchFieldException {
- final CollectionAddedToEvent<S, T> event = type.newInstance();
-
- setField("source", event, source);
- setField("addedValue", event, addedValue);
- return event;
- }
-
- private static void setField(final String name,
- final CollectionAddedToEvent<?, ?> event, final Object sourceValue)
- throws NoSuchFieldException, IllegalAccessException {
- final Field sourceField = CollectionAddedToEvent.class
- .getDeclaredField(name);
- sourceField.setAccessible(true);
- sourceField.set(event, sourceValue);
- }
-
- private EventBusService getEventBusService() {
- if (!searchedForEventBusService) {
- final List<ObjectAdapter> serviceAdapters = servicesProvider
- .getServices();
- for (ObjectAdapter serviceAdapter : serviceAdapters) {
- final Object service = serviceAdapter.getObject();
- if (service instanceof EventBusService) {
- eventBusService = (EventBusService) service;
- break;
- }
- }
- }
- searchedForEventBusService = true;
- return eventBusService;
- }
-
- // //////////////////////////////////////
- // MultiTypedFacet
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<? extends Facet>[] facetTypes() {
- return Lists.newArrayList(PostsAddedToCollectionEventFacet.class,
- CollectionAddToFacet.class).toArray(
- new Class[] {});
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends Facet> T getFacet(Class<T> facet) {
- return (T) this;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventAnnotationFacetFactory.java
new file mode 100644
index 0000000..504dd64
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventAnnotationFacetFactory.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.collections.event;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.PostsCollectionAddedToEvent;
+import org.apache.isis.applib.annotation.WrapperPolicy;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.ServicesProviderAware;
+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.accessor.PropertyOrCollectionAccessorFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsCollectionAddedToEventFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+
+public class PostsCollectionAddedToEventAnnotationFacetFactory extends FacetFactoryAbstract implements ServicesProviderAware {
+
+ private ServicesProvider servicesProvider;
+
+ public PostsCollectionAddedToEventAnnotationFacetFactory() {
+ super(FeatureType.COLLECTIONS_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+ final Method method = processMethodContext.getMethod();
+ FacetUtil.addFacet(create(method, processMethodContext.getFacetHolder()));
+ }
+
+ private PostsCollectionAddedToEventFacet create(Method method, final FacetHolder holder) {
+ final PostsCollectionAddedToEvent annotation = Annotations.getAnnotation(method, PostsCollectionAddedToEvent.class);
+ if(annotation == null) {
+ return null;
+ }
+
+ final PropertyOrCollectionAccessorFacet getterFacet = holder.getFacet(PropertyOrCollectionAccessorFacet.class);
+ if(getterFacet == null) {
+ return null;
+ }
+ final CollectionAddToFacet collectionAddToFacet = holder.getFacet(CollectionAddToFacet.class);
+ if(collectionAddToFacet == null) {
+ return null;
+ }
+ // the collectionAddToFacet will end up as the underlying facet of the PostsCollectionAddedToEventFacetAnnotation
+
+ final Class<? extends CollectionAddedToEvent<?,?>> changedEventType = annotation.value();
+ final WrapperPolicy wrapperPolicy = annotation.wrapperPolicy();
+ return new PostsCollectionAddedToEventFacetAnnotation(changedEventType, wrapperPolicy, getterFacet, collectionAddToFacet, servicesProvider, holder);
+ }
+
+ @Override
+ public void setServicesProvider(ServicesProvider servicesProvider) {
+ this.servicesProvider = servicesProvider;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventFacetAnnotation.java
new file mode 100644
index 0000000..f1e30ec
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/collections/event/PostsCollectionAddedToEventFacetAnnotation.java
@@ -0,0 +1,173 @@
+/*
+ * 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 java.lang.reflect.Field;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.applib.annotation.WrapperPolicy;
+import org.apache.isis.applib.services.eventbus.CollectionAddedToEvent;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.util.AdapterUtils;
+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.facets.accessor.PropertyOrCollectionAccessorFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsCollectionAddedToEventFacet;
+import org.apache.isis.core.metamodel.facets.collections.event.PostsCollectionAddedToEventFacetAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+
+public class PostsCollectionAddedToEventFacetAnnotation
+ extends PostsCollectionAddedToEventFacetAbstract {
+
+ private final PropertyOrCollectionAccessorFacet getterFacet;
+ private final CollectionAddToFacet collectionAddToFacet;
+ private final ServicesProvider servicesProvider;
+
+ private EventBusService eventBusService;
+ private boolean searchedForEventBusService = false;
+
+ public PostsCollectionAddedToEventFacetAnnotation(
+ final Class<? extends CollectionAddedToEvent<?, ?>> eventType,
+ final WrapperPolicy wrapperPolicy,
+ final PropertyOrCollectionAccessorFacet getterFacet,
+ final CollectionAddToFacet collectionAddToFacet,
+ final ServicesProvider servicesProvider,
+ final FacetHolder holder) {
+ super(eventType, wrapperPolicy, holder);
+ this.getterFacet = getterFacet;
+ this.collectionAddToFacet = collectionAddToFacet;
+ this.servicesProvider = servicesProvider;
+ }
+
+ @Override
+ public void add(ObjectAdapter targetAdapter, ObjectAdapter referencedObjectAdapter) {
+ if (this.collectionAddToFacet == null) {
+ return;
+ }
+ eventBusService = getEventBusService();
+ if (eventBusService == null) {
+ collectionAddToFacet.add(targetAdapter, referencedObjectAdapter);
+ return;
+ }
+
+ final Object referencedObject = AdapterUtils.unwrap(referencedObjectAdapter);
+
+ // get hold of underlying collection
+ final Object collection = getterFacet.getProperty(targetAdapter);
+
+ // don't post event if has set semantics and contains object
+ if(collection instanceof Set) {
+ Set<?> set = (Set<?>) collection;
+ if(set.contains(referencedObject)) {
+ return;
+ }
+ }
+
+ // either doesn't contain object, or doesn't have set semantics, so post event
+ collectionAddToFacet.add(targetAdapter, referencedObjectAdapter);
+
+ postEvent(targetAdapter, getIdentified().getIdentifier(), referencedObject);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void postEvent(
+ final ObjectAdapter targetAdapter,
+ final Identifier identifier,
+ final Object addedReference) {
+
+ final Object source = targetAdapter.getObject();
+ try {
+ final Class type = value();
+ final CollectionAddedToEvent<?, ?> event = newEvent(type, source, identifier, addedReference);
+ eventBusService.post(event);
+ } catch (Exception e) {
+ throw new FatalException(e);
+ }
+ }
+
+ static <S, T> CollectionAddedToEvent<S, T> newEvent(
+ final Class<? extends CollectionAddedToEvent<S, T>> type,
+ final S source,
+ final Identifier identifier,
+ final T value)
+ throws InstantiationException, IllegalAccessException,
+ NoSuchFieldException {
+ final CollectionAddedToEvent<S, T> event = type.newInstance();
+
+ setField("source", event, source);
+ setField("identifier", event, identifier);
+ setField("value", event, value);
+ return event;
+ }
+
+ private static void setField(final String name,
+ final CollectionAddedToEvent<?, ?> event, final Object sourceValue)
+ throws NoSuchFieldException, IllegalAccessException {
+ final Field sourceField = CollectionAddedToEvent.class
+ .getDeclaredField(name);
+ sourceField.setAccessible(true);
+ sourceField.set(event, sourceValue);
+ }
+
+ private EventBusService getEventBusService() {
+ if (!searchedForEventBusService) {
+ final List<ObjectAdapter> serviceAdapters = servicesProvider
+ .getServices();
+ for (ObjectAdapter serviceAdapter : serviceAdapters) {
+ final Object service = serviceAdapter.getObject();
+ if (service instanceof EventBusService) {
+ eventBusService = (EventBusService) service;
+ break;
+ }
+ }
+ }
+ searchedForEventBusService = true;
+ return eventBusService;
+ }
+
+ // //////////////////////////////////////
+ // MultiTypedFacet
+ // //////////////////////////////////////
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<? extends Facet>[] facetTypes() {
+ return Lists.newArrayList(
+ type(), // ie CollectionAddedToFacet
+ PostsCollectionAddedToEventFacet.class
+ ).toArray(
+ new Class[] {});
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Facet> T getFacet(Class<T> facet) {
+ return (T) this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventAnnotationFacetFactory.java
index 3e87ff7..1a75d60 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventAnnotationFacetFactory.java
@@ -24,6 +24,7 @@ import java.util.Comparator;
import java.util.List;
import org.apache.isis.applib.annotation.PostsPropertyChangedEvent;
+import org.apache.isis.applib.annotation.WrapperPolicy;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.metamodel.adapter.ServicesProvider;
@@ -75,14 +76,22 @@ public class PostsPropertyChangedEventAnnotationFacetFactory extends FacetFactor
if (clearFacet == null && setterFacet == null) {
return null;
}
+
+
+ // REVIEW: I'm a bit uncertain about this; this facet is multi-valued, but the setUnderlying(...) stuff only
+ // works for single valued types.
+ // the wrapperFactory stuff looks for underlying to find the imperative method, I think this only works in this
+ // case because (by accident rather than design) there is also the PropertyInitializationFacet wrapping the setter.
if(setterFacet != null) {
holder.removeFacet(setterFacet);
}
if(clearFacet != null) {
holder.removeFacet(clearFacet);
}
+
final Class<? extends PropertyChangedEvent<?, ?>> changedEventType = annotation.value();
- return new PostsPropertyChangedEventFacetAnnotation(changedEventType, getterFacet, setterFacet, clearFacet, servicesProvider, holder);
+ final WrapperPolicy wrapperPolicy = annotation.wrapperPolicy();
+ return new PostsPropertyChangedEventFacetAnnotation(changedEventType, wrapperPolicy, getterFacet, setterFacet, clearFacet, servicesProvider, holder);
}
@Override
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotation.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotation.java
index 406ac36..afc96bb 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/properties/event/PostsPropertyChangedEventFacetAnnotation.java
@@ -26,7 +26,8 @@ import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import org.apache.isis.applib.FatalException;
-import org.apache.isis.applib.RecoverableException;
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.applib.annotation.WrapperPolicy;
import org.apache.isis.applib.services.eventbus.EventBusService;
import org.apache.isis.applib.services.eventbus.PropertyChangedEvent;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -50,13 +51,14 @@ public class PostsPropertyChangedEventFacetAnnotation extends PostsPropertyChang
private boolean searchedForEventBusService = false;
public PostsPropertyChangedEventFacetAnnotation(
- final Class<? extends PropertyChangedEvent<?, ?>> changedEventType,
+ final Class<? extends PropertyChangedEvent<?, ?>> eventType,
+ final WrapperPolicy wrapperPolicy,
final PropertyOrCollectionAccessorFacet getterFacet,
final PropertySetterFacet setterFacet,
final PropertyClearFacet clearFacet,
final ServicesProvider servicesProvider,
final FacetHolder holder) {
- super(changedEventType, holder);
+ super(eventType, wrapperPolicy, holder);
this.getterFacet = getterFacet;
this.setterFacet = setterFacet;
this.clearFacet = clearFacet;
@@ -64,50 +66,56 @@ public class PostsPropertyChangedEventFacetAnnotation extends PostsPropertyChang
}
@Override
- public void setProperty(ObjectAdapter inObject, ObjectAdapter value) {
- if(this.setterFacet == null) {
+ public void setProperty(ObjectAdapter targetAdapter, ObjectAdapter valueAdapter) {
+ if(setterFacet == null) {
return;
}
eventBusService = getEventBusService();
if(eventBusService == null) {
- setterFacet.setProperty(inObject, value);
+ setterFacet.setProperty(targetAdapter, valueAdapter);
return;
}
- final Object oldValue = this.getterFacet.getProperty(inObject);
- this.setterFacet.setProperty(inObject, value);
- final Object newValue = this.getterFacet.getProperty(inObject);
- postEventIfChanged(inObject, oldValue, newValue);
+ final Object oldValue = getterFacet.getProperty(targetAdapter);
+ setterFacet.setProperty(targetAdapter, valueAdapter);
+ final Object newValue = getterFacet.getProperty(targetAdapter);
+ postEventIfChanged(targetAdapter, getIdentified().getIdentifier(), oldValue, newValue);
}
@Override
- public void clearProperty(ObjectAdapter inObject) {
- if(this.clearFacet == null) {
+ public void clearProperty(ObjectAdapter targetAdapter) {
+ if(clearFacet == null) {
return;
}
eventBusService = getEventBusService();
if(eventBusService == null) {
- clearFacet.clearProperty(inObject);
+ clearFacet.clearProperty(targetAdapter);
return;
}
- final Object oldValue = this.getterFacet.getProperty(inObject);
- this.clearFacet.clearProperty(inObject);
- final Object newValue = this.getterFacet.getProperty(inObject);
- postEventIfChanged(inObject, oldValue, newValue);
+ final Object oldValue = getterFacet.getProperty(targetAdapter);
+ clearFacet.clearProperty(targetAdapter);
+ final Object newValue = getterFacet.getProperty(targetAdapter);
+
+ postEventIfChanged(targetAdapter, getIdentified().getIdentifier(), oldValue, newValue);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- private void postEventIfChanged(ObjectAdapter inObject, final Object oldValue, final Object newValue) {
+ private void postEventIfChanged(
+ final ObjectAdapter targetAdapter,
+ final Identifier identifier,
+ final Object oldValue,
+ final Object newValue) {
+
if(Objects.equal(oldValue, newValue)) {
// do nothing.
return;
}
- final Object source = inObject.getObject();
+ final Object source = targetAdapter.getObject();
try {
final Class type = value();
- final PropertyChangedEvent<?, ?> event = newEvent(type, oldValue, newValue, source);
+ final PropertyChangedEvent<?, ?> event = newEvent(type, source, identifier, oldValue, newValue);
eventBusService.post(event);
} catch (Exception e) {
@@ -115,10 +123,16 @@ public class PostsPropertyChangedEventFacetAnnotation extends PostsPropertyChang
}
}
- static <S,T> PropertyChangedEvent<S,T> newEvent(final Class<? extends PropertyChangedEvent<S, T>> type, final T oldValue, final T newValue, final S source) throws InstantiationException, IllegalAccessException, NoSuchFieldException {
+ static <S,T> PropertyChangedEvent<S,T> newEvent(
+ final Class<? extends PropertyChangedEvent<S, T>> type,
+ final S source,
+ final Identifier identifier,
+ final T oldValue,
+ final T newValue) throws InstantiationException, IllegalAccessException, NoSuchFieldException {
final PropertyChangedEvent<S, T> event = type.newInstance();
setField("source", event, source);
+ setField("identifier", event, identifier);
setField("oldValue", event, oldValue);
setField("newValue", event, newValue);
return event;
@@ -147,12 +161,16 @@ public class PostsPropertyChangedEventFacetAnnotation extends PostsPropertyChang
// //////////////////////////////////////
// MultiTypedFacet
-
+ // //////////////////////////////////////
@SuppressWarnings("unchecked")
@Override
public Class<? extends Facet>[] facetTypes() {
- return Lists.newArrayList(PostsPropertyChangedEventFacet.class, PropertySetterFacet.class, PropertyClearFacet.class).toArray(new Class[]{});
+ return Lists.newArrayList(
+ PostsPropertyChangedEventFacet.class,
+ PropertySetterFacet.class,
+ PropertyClearFacet.class
+ ).toArray(new Class[]{});
}
@SuppressWarnings("unchecked")
http://git-wip-us.apache.org/repos/asf/isis/blob/2637a055/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
index 69c6e70..1e4598c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
+++ b/core/metamodel/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
@@ -47,6 +47,7 @@ import org.apache.isis.core.progmodel.facets.collections.aggregated.ParentedSinc
import org.apache.isis.core.progmodel.facets.collections.clear.CollectionClearFacetFactory;
import org.apache.isis.core.progmodel.facets.collections.collection.CollectionFacetFactory;
import org.apache.isis.core.progmodel.facets.collections.disabled.fromimmutable.DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory;
+import org.apache.isis.core.progmodel.facets.collections.event.PostsCollectionAddedToEventAnnotationFacetFactory;
import org.apache.isis.core.progmodel.facets.collections.modify.CollectionAddRemoveAndValidateFacetFactory;
import org.apache.isis.core.progmodel.facets.collections.notpersisted.annotation.NotPersistedAnnotationForCollectionFacetFactory;
import org.apache.isis.core.progmodel.facets.collections.sortedby.SortedByAnnotationFacetFactory;
@@ -362,8 +363,11 @@ public final class ProgrammingModelFacetsJava5 extends ProgrammingModelAbstract
addFactory(DisabledFacetForPropertyDerivedFromImmutableTypeFacetFactory.class);
addFactory(DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.class);
+ // must come after the property/collection/action accessor+mutator facet factories
addFactory(PostsPropertyChangedEventAnnotationFacetFactory.class);
+ addFactory(PostsCollectionAddedToEventAnnotationFacetFactory.class);
+
addFactory(ImmutableMarkerInterfaceFacetFactory.class);
addFactory(ViewModelIntefaceFacetFactory.class);