You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/04/26 20:24:13 UTC
svn commit: r1096837 [3/14] - in /incubator/isis/trunk:
core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/
core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/map/
core/metamodel/src/main/java/org/apache/isis/core/meta...
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/Version.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/Version.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/Version.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/Version.java Tue Apr 26 18:24:05 2011
@@ -17,51 +17,49 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.adapter.version;
-package org.apache.isis.core.metamodel.adapter.version;
-
import java.io.Serializable;
import java.util.Date;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-
-
-/**
- * An instance of this class is held by each {@link ObjectAdapter} and is used to represent
- * a particular version (at a point in time) of domain object wrapped by that adapter.
- *
- * <p>
- * This is normally done using some form of incrementing number or timestamp, which would be held within the
- * implementing class. The numbers, timestamps, etc should change for each changed object, and the different()
- * method should indicate that the two Version objects are different.
- *
- * <p>
- * The user's name and a timestamp should alos be kept so that when an message is passed to the user it can be
- * of the form "user has change object at time"
- */
-public interface Version extends Serializable {
-
- /**
- * Compares this version against the specified version and returns true if they are different versions.
- *
- * <p>
- * This is use for optimistic checking, where the existence of a different version will normally cause a
- * concurrency exception.
- */
- boolean different(Version version);
-
- /**
- * Returns the user who made the last change.
- */
- String getUser();
-
- /**
- * Returns the time of the last change.
- */
- Date getTime();
-
- /**
- * Returns the sequence for printing/display
- */
- String sequence();
-}
+
+/**
+ * An instance of this class is held by each {@link ObjectAdapter} and is used to represent a particular version (at a
+ * point in time) of domain object wrapped by that adapter.
+ *
+ * <p>
+ * This is normally done using some form of incrementing number or timestamp, which would be held within the
+ * implementing class. The numbers, timestamps, etc should change for each changed object, and the different() method
+ * should indicate that the two Version objects are different.
+ *
+ * <p>
+ * The user's name and a timestamp should alos be kept so that when an message is passed to the user it can be of the
+ * form "user has change object at time"
+ */
+public interface Version extends Serializable {
+
+ /**
+ * Compares this version against the specified version and returns true if they are different versions.
+ *
+ * <p>
+ * This is use for optimistic checking, where the existence of a different version will normally cause a concurrency
+ * exception.
+ */
+ boolean different(Version version);
+
+ /**
+ * Returns the user who made the last change.
+ */
+ String getUser();
+
+ /**
+ * Returns the time of the last change.
+ */
+ Date getTime();
+
+ /**
+ * Returns the sequence for printing/display
+ */
+ String sequence();
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAbstract.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAbstract.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAbstract.java Tue Apr 26 18:24:05 2011
@@ -17,45 +17,44 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.adapter.version;
-package org.apache.isis.core.metamodel.adapter.version;
-
import java.io.IOException;
import org.apache.isis.core.commons.encoding.DataInputExtended;
import org.apache.isis.core.commons.encoding.DataOutputExtended;
import org.apache.isis.core.commons.encoding.Encodable;
-
-
-
-public abstract class VersionUserAbstract implements Version, Encodable {
- private final String user;
-
- public VersionUserAbstract(final String user) {
- this.user = user;
- initialized();
- }
-
- public VersionUserAbstract(DataInputExtended input) throws IOException {
- this.user = input.readUTF();
- initialized();
- }
-
- public void encode(final DataOutputExtended output) throws IOException {
- output.writeUTF(user);
- }
-
- private void initialized() {
- // nothing to do
- }
-
- /////////////////////////////////////////////////////////
- //
- /////////////////////////////////////////////////////////
-
-
- public String getUser() {
- return user;
- }
-
-}
+
+public abstract class VersionUserAbstract implements Version, Encodable {
+ private static final long serialVersionUID = 1L;
+ private final String user;
+
+ public VersionUserAbstract(final String user) {
+ this.user = user;
+ initialized();
+ }
+
+ public VersionUserAbstract(final DataInputExtended input) throws IOException {
+ this.user = input.readUTF();
+ initialized();
+ }
+
+ @Override
+ public void encode(final DataOutputExtended output) throws IOException {
+ output.writeUTF(user);
+ }
+
+ private void initialized() {
+ // nothing to do
+ }
+
+ // ///////////////////////////////////////////////////////
+ //
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public String getUser() {
+ return user;
+ }
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAndTimeAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAndTimeAbstract.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAndTimeAbstract.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/version/VersionUserAndTimeAbstract.java Tue Apr 26 18:24:05 2011
@@ -17,50 +17,47 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.adapter.version;
-package org.apache.isis.core.metamodel.adapter.version;
-
import java.io.IOException;
import java.util.Date;
import org.apache.isis.core.commons.encoding.DataInputExtended;
import org.apache.isis.core.commons.encoding.DataOutputExtended;
-
-
-
-public abstract class VersionUserAndTimeAbstract extends VersionUserAbstract {
- private final Date time;
-
- public VersionUserAndTimeAbstract(final String user, final Date time) {
- super(user);
- this.time = time;
- initialized();
- }
-
- public VersionUserAndTimeAbstract(DataInputExtended input) throws IOException {
- super(input);
- this.time = new Date(input.readLong());
- initialized();
- }
-
- @Override
- public void encode(final DataOutputExtended output) throws IOException {
- super.encode(output);
- output.writeLong(time.getTime());
- }
-
- private void initialized() {
- // nothing to do
- }
-
- /////////////////////////////////////////////////////////
- //
- /////////////////////////////////////////////////////////
-
-
- public Date getTime() {
- return time;
- }
-
-
-}
+
+public abstract class VersionUserAndTimeAbstract extends VersionUserAbstract {
+ private static final long serialVersionUID = 1L;
+ private final Date time;
+
+ public VersionUserAndTimeAbstract(final String user, final Date time) {
+ super(user);
+ this.time = time;
+ initialized();
+ }
+
+ public VersionUserAndTimeAbstract(final DataInputExtended input) throws IOException {
+ super(input);
+ this.time = new Date(input.readLong());
+ initialized();
+ }
+
+ @Override
+ public void encode(final DataOutputExtended output) throws IOException {
+ super.encode(output);
+ output.writeLong(time.getTime());
+ }
+
+ private void initialized() {
+ // nothing to do
+ }
+
+ // ///////////////////////////////////////////////////////
+ //
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public Date getTime() {
+ return time;
+ }
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Allow.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Allow.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Allow.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Allow.java Tue Apr 26 18:24:05 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.metamodel.consent;
import org.apache.isis.core.metamodel.facetapi.Facet;
-
/**
* An instance of this type is used to allow something.
*/
@@ -37,14 +35,15 @@ public class Allow extends ConsentAbstra
}
/**
- * Called by DnD viewer; we should instead find a way to put the calling logic into {@link Facet}s so that
- * it is available for use by other viewers.
+ * Called by DnD viewer; we should instead find a way to put the calling logic into {@link Facet}s so that it is
+ * available for use by other viewers.
*
* @see Veto
* @deprecated
* @param reasonVeteod
* @param advisorClass
*/
+ @Deprecated
public Allow(final String description) {
super(description, null);
}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Consent.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Consent.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Consent.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Consent.java Tue Apr 26 18:24:05 2011
@@ -17,11 +17,8 @@
* under the License.
*/
-
package org.apache.isis.core.metamodel.consent;
-
-
public interface Consent {
/**
@@ -38,8 +35,8 @@ public interface Consent {
* Why consent is being vetoed.
*
* <p>
- * Will be non-<tt>null</tt> and non-empty if vetoed. Will be <tt>null</tt>
- * (<i>not</i> the empty string) if this is consent is is allowed.
+ * Will be non-<tt>null</tt> and non-empty if vetoed. Will be <tt>null</tt> (<i>not</i> the empty string) if this is
+ * consent is is allowed.
*
* <p>
* Will correspond to the {@link InteractionResult#getReason() reason} in the contained
@@ -54,11 +51,9 @@ public interface Consent {
* May be <tt>null</tt>.
*/
String getDescription();
-
/**
- * Allows the description of the interaction to which this consent relates to be
- * specified or refined.
+ * Allows the description of the interaction to which this consent relates to be specified or refined.
*
* @param description
* @return this consent
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/ConsentAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/ConsentAbstract.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/ConsentAbstract.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/ConsentAbstract.java Tue Apr 26 18:24:05 2011
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.isis.core.metamodel.consent;
import static org.apache.isis.core.commons.matchers.IsisMatchers.nonEmptyStringOrNull;
@@ -38,19 +37,18 @@ public abstract class ConsentAbstract im
* Factory method.
*
* <p>
- * Used extensively by the DnD viewer.
+ * Used extensively by the DnD viewer.
*/
public static Consent allowIf(final boolean allowed) {
return allowed ? Allow.DEFAULT : Veto.DEFAULT;
}
-
+
private final InteractionResult interactionResult;
private final String reason;
-
+
/**
- * Can be subsequently {@link #setDescription(String) modified}, but is only a
- * description of the event to which this consent applies and does not change
- * whether the Consent represents an allow or a veto.
+ * Can be subsequently {@link #setDescription(String) modified}, but is only a description of the event to which
+ * this consent applies and does not change whether the Consent represents an allow or a veto.
*/
private String description;
@@ -61,7 +59,6 @@ public abstract class ConsentAbstract im
return interactionResult.getReason();
}
-
/**
*
* @param interactionResult
@@ -72,45 +69,47 @@ public abstract class ConsentAbstract im
}
/**
- * Enable legacy {@link Consent}s (not created using an {@link InteractionResult}) to
- * create an {@link Consent}, specifying a {@link #getDescription() description} of the
- * event and the {@link #getReason() reason} (if any) that the consent is vetoed.
- *
- * @param description - a description of the event to which this consent relates
- * @param reason - if not <tt>null</tt> and not empty, is the reason this consent is vetoed.
+ * Enable legacy {@link Consent}s (not created using an {@link InteractionResult}) to create an {@link Consent},
+ * specifying a {@link #getDescription() description} of the event and the {@link #getReason() reason} (if any) that
+ * the consent is vetoed.
+ *
+ * @param description
+ * - a description of the event to which this consent relates
+ * @param reason
+ * - if not <tt>null</tt> and not empty, is the reason this consent is vetoed.
*/
protected ConsentAbstract(final String description, final String reason) {
this(null, description, reason);
}
- private ConsentAbstract(
- final InteractionResult interactionResult,
- final String description,
- final String reason) {
+ private ConsentAbstract(final InteractionResult interactionResult, final String description, final String reason) {
this.interactionResult = interactionResult;
this.description = description;
Ensure.ensureThatArg(reason, is(nonEmptyStringOrNull()));
this.reason = reason;
- }
+ }
/**
* The reason why this has been vetoed.
*/
+ @Override
public String getReason() {
- return isVetoed()? this.reason: null;
+ return isVetoed() ? this.reason : null;
}
+ @Override
public Consent setDescription(final String description) {
this.description = description;
return this;
}
/**
- * Returns <tt>true</tt> if this object is giving permission
- * (if the {@link #getReason() reason} is <tt>null</tt> or empty.
+ * Returns <tt>true</tt> if this object is giving permission (if the {@link #getReason() reason} is <tt>null</tt> or
+ * empty.
*
* @see #getReason()
*/
+ @Override
public boolean isAllowed() {
return this.reason == null || this.reason.equals("");
}
@@ -120,15 +119,16 @@ public abstract class ConsentAbstract im
*
* @see #isAllowed()
*/
+ @Override
public boolean isVetoed() {
return !isAllowed();
}
/**
- * Underlying {@link InteractionResult} that created this {@link Consent}
- * (may be <tt>null</tt>).
+ * Underlying {@link InteractionResult} that created this {@link Consent} (may be <tt>null</tt>).
*
*/
+ @Override
public InteractionResult getInteractionResult() {
return interactionResult;
}
@@ -137,16 +137,17 @@ public abstract class ConsentAbstract im
* Description of the action allowed by this event.
*
* <p>
- * (Previously, {@link Allow} consents overloaded the {@link #getReason() reason} property with
- * a description of the event. This has now been changed so that a non-<tt>null</tt> reason
- * always implies a {@link Veto}. This property captures the description.
+ * (Previously, {@link Allow} consents overloaded the {@link #getReason() reason} property with a description of the
+ * event. This has now been changed so that a non-<tt>null</tt> reason always implies a {@link Veto}. This property
+ * captures the description.
*
* @return
*/
+ @Override
public String getDescription() {
return description;
}
-
+
@Override
public String toString() {
return (isVetoed() ? "VETOED" : "ALLOWED") + ", reason=" + reason;
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionAdvisor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionAdvisor.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionAdvisor.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionAdvisor.java Tue Apr 26 18:24:05 2011
@@ -17,23 +17,22 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.consent;
-package org.apache.isis.core.metamodel.consent;
-
import org.apache.isis.core.metamodel.facetapi.Facet;
-
-
-/**
- * Marker interface for implementations (specifically, {@link Facet}s) that can advise as to whether a member
- * should be disabled.
- *
- * Used within {@link Allow} and {@link Veto}.
- */
-public interface InteractionAdvisor {
-
- /**
- * For testing purposes only.
- */
- public static InteractionAdvisor NOOP = new InteractionAdvisor() {};
-
-}
+
+/**
+ * Marker interface for implementations (specifically, {@link Facet}s) that can advise as to whether a member should be
+ * disabled.
+ *
+ * Used within {@link Allow} and {@link Veto}.
+ */
+public interface InteractionAdvisor {
+
+ /**
+ * For testing purposes only.
+ */
+ public static InteractionAdvisor NOOP = new InteractionAdvisor() {
+ };
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionContextType.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionContextType.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionContextType.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionContextType.java Tue Apr 26 18:24:05 2011
@@ -17,102 +17,97 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.consent;
-package org.apache.isis.core.metamodel.consent;
-
import org.apache.isis.core.metamodel.interactions.InteractionContext;
-
-/**
- * Powertype for the {@link InteractionContext} hierarchy.
- *
- */
-public enum InteractionContextType {
-
- /**
- * Persisting the object.
- */
- OBJECT_VALIDATE("Saving or updating object"),
- /**
- * Accessing the object's title.
- */
- OBJECT_TITLE("Reading object's title"),
- /**
- * Determining whether the property of the object is visible (or has been hidden).
- */
- PROPERTY_VISIBLE("View property"),
- /**
- * Determining whether the property of the object is either readable or modifiable (or has been disabled).
- */
- PROPERTY_USABLE("Use property"),
- /**
- * Reading the current value of the property of the object.
- */
- PROPERTY_READ("Read property"),
- /**
- * Modifying (or attempting to modify) the value of a property.
- */
- PROPERTY_MODIFY("Modify property"),
- /**
- * Determining whether the collection of the object is visible (or has been hidden).
- */
- COLLECTION_VISIBLE("View collection"),
- /**
- * Determining whether the collection of the object is either readable or modifiable (or has been
- * disabled).
- */
- COLLECTION_USABLE("Use collection"),
- /**
- * Reading the contents of the collection.
- */
- COLLECTION_READ("Read contents of collection"),
- /**
- * Adding to (or attempting to add to) a collection.
- */
- COLLECTION_ADD_TO("Add to collection"),
- /**
- * Removing from (or attempting to remove from) a collection.
- */
- COLLECTION_REMOVE_FROM("Remove from collection"),
- /**
- * Whether the action of the object is visible (or has been hidden).
- */
- ACTION_VISIBLE("View action"),
- /**
- * Whether the action of the object is usable (or has been disabled).
- */
- ACTION_USABLE("Use action"),
- /**
- * Whether this particular proposed argument for an action invocation is valid (or if it is in fact
- * invalid).
- *
- * <p>
- * For example, ensuring that a regular expression match or number range is correct.
- */
- ACTION_PROPOSED_ARGUMENT("Proposed argument"),
- /**
- * Invoking (or attempting to invoke) an action.
- *
- * <p>
- * Even if each of the {@link #ACTION_PROPOSED_ARGUMENT proposed arguments} are valid, it may not be
- * possible to invoke the action if there the arguments together are invalid (for example,
- * <tt>startDate > endDate</tt>).
- */
- ACTION_INVOKE("Invoke action"),
-
- /**
- * Parsing a value (could be an property or an action argument).
- */
- PARSE_VALUE("Parsing value");
-
- private final String description;
-
- private InteractionContextType(final String description) {
- this.description = description;
- }
-
- public String getDescription() {
- return description;
- }
-
-}
-
+
+/**
+ * Powertype for the {@link InteractionContext} hierarchy.
+ *
+ */
+public enum InteractionContextType {
+
+ /**
+ * Persisting the object.
+ */
+ OBJECT_VALIDATE("Saving or updating object"),
+ /**
+ * Accessing the object's title.
+ */
+ OBJECT_TITLE("Reading object's title"),
+ /**
+ * Determining whether the property of the object is visible (or has been hidden).
+ */
+ PROPERTY_VISIBLE("View property"),
+ /**
+ * Determining whether the property of the object is either readable or modifiable (or has been disabled).
+ */
+ PROPERTY_USABLE("Use property"),
+ /**
+ * Reading the current value of the property of the object.
+ */
+ PROPERTY_READ("Read property"),
+ /**
+ * Modifying (or attempting to modify) the value of a property.
+ */
+ PROPERTY_MODIFY("Modify property"),
+ /**
+ * Determining whether the collection of the object is visible (or has been hidden).
+ */
+ COLLECTION_VISIBLE("View collection"),
+ /**
+ * Determining whether the collection of the object is either readable or modifiable (or has been disabled).
+ */
+ COLLECTION_USABLE("Use collection"),
+ /**
+ * Reading the contents of the collection.
+ */
+ COLLECTION_READ("Read contents of collection"),
+ /**
+ * Adding to (or attempting to add to) a collection.
+ */
+ COLLECTION_ADD_TO("Add to collection"),
+ /**
+ * Removing from (or attempting to remove from) a collection.
+ */
+ COLLECTION_REMOVE_FROM("Remove from collection"),
+ /**
+ * Whether the action of the object is visible (or has been hidden).
+ */
+ ACTION_VISIBLE("View action"),
+ /**
+ * Whether the action of the object is usable (or has been disabled).
+ */
+ ACTION_USABLE("Use action"),
+ /**
+ * Whether this particular proposed argument for an action invocation is valid (or if it is in fact invalid).
+ *
+ * <p>
+ * For example, ensuring that a regular expression match or number range is correct.
+ */
+ ACTION_PROPOSED_ARGUMENT("Proposed argument"),
+ /**
+ * Invoking (or attempting to invoke) an action.
+ *
+ * <p>
+ * Even if each of the {@link #ACTION_PROPOSED_ARGUMENT proposed arguments} are valid, it may not be possible to
+ * invoke the action if there the arguments together are invalid (for example, <tt>startDate > endDate</tt>).
+ */
+ ACTION_INVOKE("Invoke action"),
+
+ /**
+ * Parsing a value (could be an property or an action argument).
+ */
+ PARSE_VALUE("Parsing value");
+
+ private final String description;
+
+ private InteractionContextType(final String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionInvocationMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionInvocationMethod.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionInvocationMethod.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionInvocationMethod.java Tue Apr 26 18:24:05 2011
@@ -17,25 +17,24 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.consent;
-package org.apache.isis.core.metamodel.consent;
-
import org.apache.isis.core.metamodel.interactions.InteractionContext;
-
-/**
- * Whether an {@link InteractionContext} was invoked by the user, or is programmatic.
- */
-public enum InteractionInvocationMethod {
-
- BY_USER("By user"), PROGRAMMATIC("Programmatic");
-
- private final String description;
-
- private InteractionInvocationMethod(final String description) {
- this.description = description;
- }
-
- public String getDescription() {
- return description;
- }
-}
+
+/**
+ * Whether an {@link InteractionContext} was invoked by the user, or is programmatic.
+ */
+public enum InteractionInvocationMethod {
+
+ BY_USER("By user"), PROGRAMMATIC("Programmatic");
+
+ private final String description;
+
+ private InteractionInvocationMethod(final String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResult.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResult.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResult.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResult.java Tue Apr 26 18:24:05 2011
@@ -17,136 +17,132 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.consent;
-package org.apache.isis.core.metamodel.consent;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.isis.applib.events.InteractionEvent;
-
-
-public class InteractionResult {
-
- /**
- * Initially {@link #ADVISING}; when call {@link InteractionResult#getInteractionEvent()}, flips over into
- * {@link #ADVISED}.
- *
- * <p>
- * Subsequent attempts to {@link InteractionResult#advise(String, InteractionAdvisor)} will then be
- * disallowed.
- */
- enum State {
- ADVISING, ADVISED
- }
-
- private final InteractionEvent interactionEvent;
- private final StringBuilder reasonBuf = new StringBuilder();
- private final List<InteractionAdvisor> advisors = new ArrayList<InteractionAdvisor>();
-
- private State state = State.ADVISING;
-
- public InteractionResult(final InteractionEvent interactionEvent) {
- this.interactionEvent = interactionEvent;
- }
-
- /**
- * Returns the contained {@link InteractionEvent}, if necessary updated with the
- * {@link #advise(String, InteractionAdvisor) advice} of the interactions.
- *
- * <p>
- * That is, if still {@link State#ADVISING advising}, then copies over the details from this result into
- * the contained {@link InteractionEvent}, and flips into {@link State#ADVISED advised (done)}.
- *
- * @return
- */
- public InteractionEvent getInteractionEvent() {
- if (state == State.ADVISING) {
- interactionEvent.advised(getReason(), getAdvisorClass());
- state = State.ADVISED;
- }
- return interactionEvent;
- }
-
- private Class<?> getAdvisorClass() {
- final InteractionAdvisor advisor = getAdvisor();
- return advisor != null ? advisor.getClass() : null;
- }
-
- public void advise(final String reason, final InteractionAdvisor facet) {
- if (state == State.ADVISED) {
- throw new IllegalStateException("Cannot append since have called getInteractionEvent");
- }
- if (reason == null) {
- return;
- }
- if (isVetoing()) {
- reasonBuf.append("; ");
- }
- advisors.add(facet);
- reasonBuf.append(reason);
- }
-
- public boolean isVetoing() {
- return !isNotVetoing();
- }
-
- public boolean isNotVetoing() {
- return reasonBuf.length() == 0;
- }
-
- /**
- * Returns the first of the {@link #getAdvisors()} that has been
- * {@link #advise(String, InteractionAdvisor) advised}, or <tt>null</tt> if none yet.
- *
- * @see #getAdvisorFacets()
- */
- public InteractionAdvisor getAdvisor() {
- return advisors.size() >= 1 ? advisors.get(0) : null;
- }
-
- /**
- * Returns all {@link InteractionAdvisor advisor} (facet)s that have
- * {@link #advise(String, InteractionAdvisor) append}ed reasons to the buffer.
- *
- * @see #getAdvisor()
- */
- public List<InteractionAdvisor> getAdvisorFacets() {
- return Collections.unmodifiableList(advisors);
- }
-
- public Consent createConsent() {
- if (isNotVetoing()) {
- return new Allow(this);
- } else {
- return new Veto(this);
- }
- }
-
- /**
- * Gets the reason as currently known, but does not change the state.
- *
- * <p>
- * If {@link #isNotVetoing()}, then returns <tt>null</tt>. Otherwise will be a non-empty string.
- */
- public String getReason() {
- return isNotVetoing()? null : reasonBuf.toString();
- }
-
- @Override
- public String toString() {
- return String.format("%s: %s: %s (%d facets advised)", interactionEvent, state, toStringInterpret(reasonBuf), advisors
- .size());
- }
-
- private String toStringInterpret(final StringBuilder reasonBuf) {
- if (getReason().length() == 0) {
- return "allowed";
- } else {
- return "vetoed";
- }
- }
-
-}
-
+
+public class InteractionResult {
+
+ /**
+ * Initially {@link #ADVISING}; when call {@link InteractionResult#getInteractionEvent()}, flips over into
+ * {@link #ADVISED}.
+ *
+ * <p>
+ * Subsequent attempts to {@link InteractionResult#advise(String, InteractionAdvisor)} will then be disallowed.
+ */
+ enum State {
+ ADVISING, ADVISED
+ }
+
+ private final InteractionEvent interactionEvent;
+ private final StringBuilder reasonBuf = new StringBuilder();
+ private final List<InteractionAdvisor> advisors = new ArrayList<InteractionAdvisor>();
+
+ private State state = State.ADVISING;
+
+ public InteractionResult(final InteractionEvent interactionEvent) {
+ this.interactionEvent = interactionEvent;
+ }
+
+ /**
+ * Returns the contained {@link InteractionEvent}, if necessary updated with the
+ * {@link #advise(String, InteractionAdvisor) advice} of the interactions.
+ *
+ * <p>
+ * That is, if still {@link State#ADVISING advising}, then copies over the details from this result into the
+ * contained {@link InteractionEvent}, and flips into {@link State#ADVISED advised (done)}.
+ *
+ * @return
+ */
+ public InteractionEvent getInteractionEvent() {
+ if (state == State.ADVISING) {
+ interactionEvent.advised(getReason(), getAdvisorClass());
+ state = State.ADVISED;
+ }
+ return interactionEvent;
+ }
+
+ private Class<?> getAdvisorClass() {
+ final InteractionAdvisor advisor = getAdvisor();
+ return advisor != null ? advisor.getClass() : null;
+ }
+
+ public void advise(final String reason, final InteractionAdvisor facet) {
+ if (state == State.ADVISED) {
+ throw new IllegalStateException("Cannot append since have called getInteractionEvent");
+ }
+ if (reason == null) {
+ return;
+ }
+ if (isVetoing()) {
+ reasonBuf.append("; ");
+ }
+ advisors.add(facet);
+ reasonBuf.append(reason);
+ }
+
+ public boolean isVetoing() {
+ return !isNotVetoing();
+ }
+
+ public boolean isNotVetoing() {
+ return reasonBuf.length() == 0;
+ }
+
+ /**
+ * Returns the first of the {@link #getAdvisors()} that has been {@link #advise(String, InteractionAdvisor) advised}
+ * , or <tt>null</tt> if none yet.
+ *
+ * @see #getAdvisorFacets()
+ */
+ public InteractionAdvisor getAdvisor() {
+ return advisors.size() >= 1 ? advisors.get(0) : null;
+ }
+
+ /**
+ * Returns all {@link InteractionAdvisor advisor} (facet)s that have {@link #advise(String, InteractionAdvisor)
+ * append}ed reasons to the buffer.
+ *
+ * @see #getAdvisor()
+ */
+ public List<InteractionAdvisor> getAdvisorFacets() {
+ return Collections.unmodifiableList(advisors);
+ }
+
+ public Consent createConsent() {
+ if (isNotVetoing()) {
+ return new Allow(this);
+ } else {
+ return new Veto(this);
+ }
+ }
+
+ /**
+ * Gets the reason as currently known, but does not change the state.
+ *
+ * <p>
+ * If {@link #isNotVetoing()}, then returns <tt>null</tt>. Otherwise will be a non-empty string.
+ */
+ public String getReason() {
+ return isNotVetoing() ? null : reasonBuf.toString();
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s: %s: %s (%d facets advised)", interactionEvent, state, toStringInterpret(reasonBuf),
+ advisors.size());
+ }
+
+ private String toStringInterpret(final StringBuilder reasonBuf) {
+ if (getReason().length() == 0) {
+ return "allowed";
+ } else {
+ return "vetoed";
+ }
+ }
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResultSet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResultSet.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResultSet.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/InteractionResultSet.java Tue Apr 26 18:24:05 2011
@@ -17,87 +17,84 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.consent;
-package org.apache.isis.core.metamodel.consent;
-
import java.util.ArrayList;
import java.util.List;
-
-
-
-public class InteractionResultSet {
-
- private final List<InteractionResult> results = new ArrayList<InteractionResult>();
- private InteractionResult firstResult = null;
-
- public InteractionResultSet() {}
-
- public InteractionResultSet add(final InteractionResult result) {
- if (firstResult == null) {
- firstResult = result;
- }
- this.results.add(result);
- return this;
- }
-
- /**
- * Empty only if all the {@link #add(InteractionResult) contained} {@link InteractionResult}s are also
- * {@link InteractionResult#isNotVetoing() empty}.
- */
- public boolean isAllowed() {
- return !isVetoed();
- }
-
- /**
- * Vetoed if any of the {@link #add(InteractionResult) contained} {@link InteractionResult}s are also
- * {@link InteractionResult#isVetoing() not empty}.
- *
- * @return
- */
- public boolean isVetoed() {
- for (final InteractionResult result : results) {
- if (result.isVetoing()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns the {@link Consent} corresponding to {@link #getInteractionResult()}, or an {@link Allow} if
- * there have been no {@link InteractionResult}s {@link #add(InteractionResult) added}.
- *
- * @return
- */
- public Consent createConsent() {
- final InteractionResult interactionResult = getInteractionResult();
- if (interactionResult == null) {
- return Allow.DEFAULT;
- }
- return interactionResult.createConsent();
- }
-
- /**
- * Returns the "best" contained {@link InteractionResult}.
- *
- * <p>
- * This will be the first {@link InteractionResult} that has vetoed the interaction, or the first
- * {@link InteractionResult} {@link #add(InteractionResult) added} if none have vetoed.
- *
- * @return
- */
- public InteractionResult getInteractionResult() {
- for (final InteractionResult result : results) {
- if (!result.isNotVetoing()) {
- return result;
- }
- }
- return firstResult != null ? firstResult : null;
- }
-
- @Override
- public String toString() {
- return super.toString();
- }
-}
-
+
+public class InteractionResultSet {
+
+ private final List<InteractionResult> results = new ArrayList<InteractionResult>();
+ private InteractionResult firstResult = null;
+
+ public InteractionResultSet() {
+ }
+
+ public InteractionResultSet add(final InteractionResult result) {
+ if (firstResult == null) {
+ firstResult = result;
+ }
+ this.results.add(result);
+ return this;
+ }
+
+ /**
+ * Empty only if all the {@link #add(InteractionResult) contained} {@link InteractionResult}s are also
+ * {@link InteractionResult#isNotVetoing() empty}.
+ */
+ public boolean isAllowed() {
+ return !isVetoed();
+ }
+
+ /**
+ * Vetoed if any of the {@link #add(InteractionResult) contained} {@link InteractionResult}s are also
+ * {@link InteractionResult#isVetoing() not empty}.
+ *
+ * @return
+ */
+ public boolean isVetoed() {
+ for (final InteractionResult result : results) {
+ if (result.isVetoing()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the {@link Consent} corresponding to {@link #getInteractionResult()}, or an {@link Allow} if there have
+ * been no {@link InteractionResult}s {@link #add(InteractionResult) added}.
+ *
+ * @return
+ */
+ public Consent createConsent() {
+ final InteractionResult interactionResult = getInteractionResult();
+ if (interactionResult == null) {
+ return Allow.DEFAULT;
+ }
+ return interactionResult.createConsent();
+ }
+
+ /**
+ * Returns the "best" contained {@link InteractionResult}.
+ *
+ * <p>
+ * This will be the first {@link InteractionResult} that has vetoed the interaction, or the first
+ * {@link InteractionResult} {@link #add(InteractionResult) added} if none have vetoed.
+ *
+ * @return
+ */
+ public InteractionResult getInteractionResult() {
+ for (final InteractionResult result : results) {
+ if (!result.isNotVetoing()) {
+ return result;
+ }
+ }
+ return firstResult != null ? firstResult : null;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString();
+ }
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Veto.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Veto.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Veto.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/consent/Veto.java Tue Apr 26 18:24:05 2011
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.isis.core.metamodel.consent;
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
@@ -32,10 +31,11 @@ public class Veto extends ConsentAbstrac
public static Veto DEFAULT = new Veto("Vetoed by default");
/**
- * Called by DnD viewer; we should instead find a way to put the calling logic into {@link Facet}s so that
- * it is available for use by other viewers.
+ * Called by DnD viewer; we should instead find a way to put the calling logic into {@link Facet}s so that it is
+ * available for use by other viewers.
*
- * @param reasonVeteod - must not be <tt>null</tt>
+ * @param reasonVeteod
+ * - must not be <tt>null</tt>
*/
public Veto(final String reasonVetoed) {
super(null, ensureThatArg(reasonVetoed, nonEmptyString()));
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/exceptions/MetaModelException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/exceptions/MetaModelException.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/exceptions/MetaModelException.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/exceptions/MetaModelException.java Tue Apr 26 18:24:05 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.metamodel.exceptions;
import org.apache.isis.core.commons.exceptions.IsisException;
-
public class MetaModelException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/DecoratingFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/DecoratingFacet.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/DecoratingFacet.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/DecoratingFacet.java Tue Apr 26 18:24:05 2011
@@ -17,20 +17,18 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
+/**
+ * Provides access to underlying facet that has been decorated.
+ *
+ * <p>
+ * Originally introduced as a means to allow filtering of facets to get at the underlying facet (eg to locate those that
+ * are imperative, that is, abstract a method call to an <tt>addToXxx</tt>).
+ *
+ * @param <T>
+ */
+public interface DecoratingFacet<T extends Facet> {
-
-/**
- * Provides access to underlying facet that has been decorated.
- *
- * <p>
- * Originally introduced as a means to allow filtering of facets to get at the underlying facet (eg to locate
- * those that are imperative, that is, abstract a method call to an <tt>addToXxx</tt>).
- *
- * @param <T>
- */
-public interface DecoratingFacet<T extends Facet> {
-
- T getDecoratedFacet();
-}
+ T getDecoratedFacet();
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/Facet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/Facet.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/Facet.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/Facet.java Tue Apr 26 18:24:05 2011
@@ -17,79 +17,75 @@
* under the License.
*/
-
-package org.apache.isis.core.metamodel.facetapi;
+package org.apache.isis.core.metamodel.facetapi;
import org.apache.isis.core.metamodel.facets.actions.invoke.ActionInvocationFacet;
-
-public interface Facet {
-
- /**
- * The {@link FacetHolder holder} of this facet.
- *
- * @return
- */
- FacetHolder getFacetHolder();
-
- /**
- * Allows reparenting of Facet.
- *
- * <p>
- * Used by Facet decorators.
- *
- * @param facetHolder
- */
- public void setFacetHolder(FacetHolder facetHolder);
-
-
- /**
- * Underlying {@link Facet} of the same {@link #facetType() type}, if any.
- */
- public Facet getUnderlyingFacet();
- /**
- * Sets underlying {@link Facet}, that is, creating a chain.
- *
- * <p>
- * Must be of the same {@link #facetType() type}.
- */
- public void setUnderlyingFacet(Facet underlyingFacet);
-
-
- /**
- * Determines the type of this facet to be stored under.
- *
- * <p>
- * The framework looks for {@link Facet}s of certain well-known facet types. Each facet implementation
- * must specify which type of facet it corresponds to. This therefore allows the (rules of the)
- * programming model to be varied without impacting the rest of the framework.
- *
- * <p>
- * For example, the <tt>ActionInvocationFacet</tt> specifies the facet to invoke an action. The typical
- * implementation of this wraps a <tt>public</tt> method. However, a different facet factory could be
- * installed that creates facet also of type {@link ActionInvocationFacet} but that have some other rule,
- * such as requiring an <i>action</i> prefix, or that decorate the interaction by logging it, for example.
- */
- Class<? extends Facet> facetType();
-
- /**
- * Whether this facet implementation is derived (as opposed to explicit); used to determine
- * precedence.
- *
- * <p>
- * For example, we might derive the typical length of a property based on its type; but if the
- * typical length has been explicitly specified using an annotation then that should take precedence.
- */
- public boolean isDerived();
-
- /**
- * Whether this facet implementation is a no-op.
- */
- public boolean isNoop();
-
- /**
- * Whether this facet implementation should replace existing (none-noop) implementations.
- */
- public boolean alwaysReplace();
-
-
-}
+
+public interface Facet {
+
+ /**
+ * The {@link FacetHolder holder} of this facet.
+ *
+ * @return
+ */
+ FacetHolder getFacetHolder();
+
+ /**
+ * Allows reparenting of Facet.
+ *
+ * <p>
+ * Used by Facet decorators.
+ *
+ * @param facetHolder
+ */
+ public void setFacetHolder(FacetHolder facetHolder);
+
+ /**
+ * Underlying {@link Facet} of the same {@link #facetType() type}, if any.
+ */
+ public Facet getUnderlyingFacet();
+
+ /**
+ * Sets underlying {@link Facet}, that is, creating a chain.
+ *
+ * <p>
+ * Must be of the same {@link #facetType() type}.
+ */
+ public void setUnderlyingFacet(Facet underlyingFacet);
+
+ /**
+ * Determines the type of this facet to be stored under.
+ *
+ * <p>
+ * The framework looks for {@link Facet}s of certain well-known facet types. Each facet implementation must specify
+ * which type of facet it corresponds to. This therefore allows the (rules of the) programming model to be varied
+ * without impacting the rest of the framework.
+ *
+ * <p>
+ * For example, the <tt>ActionInvocationFacet</tt> specifies the facet to invoke an action. The typical
+ * implementation of this wraps a <tt>public</tt> method. However, a different facet factory could be installed that
+ * creates facet also of type {@link ActionInvocationFacet} but that have some other rule, such as requiring an
+ * <i>action</i> prefix, or that decorate the interaction by logging it, for example.
+ */
+ Class<? extends Facet> facetType();
+
+ /**
+ * Whether this facet implementation is derived (as opposed to explicit); used to determine precedence.
+ *
+ * <p>
+ * For example, we might derive the typical length of a property based on its type; but if the typical length has
+ * been explicitly specified using an annotation then that should take precedence.
+ */
+ public boolean isDerived();
+
+ /**
+ * Whether this facet implementation is a no-op.
+ */
+ public boolean isNoop();
+
+ /**
+ * Whether this facet implementation should replace existing (none-noop) implementations.
+ */
+ public boolean alwaysReplace();
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetAbstract.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetAbstract.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetAbstract.java Tue Apr 26 18:24:05 2011
@@ -17,9 +17,8 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
-
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
@@ -27,144 +26,141 @@ import static org.hamcrest.CoreMatchers.
import org.apache.isis.core.commons.ensure.Ensure;
import org.apache.isis.core.commons.matchers.IsisMatchers;
-
-
-public abstract class FacetAbstract implements Facet {
-
- private Facet underlyingFacet;
-
- private final Class<? extends Facet> facetType;
- private final boolean derived;
- private FacetHolder holder;
-
- /**
- * Populated in {@link #setFacetHolder(FacetHolder)} if the provided holder
- * implements {@link IdentifiedHolder}.
- *
- * <p>
- * Otherwise is <tt>null</tt>.
- */
- private IdentifiedHolder identifiedHolder;
-
- @SuppressWarnings("unchecked")
- public FacetAbstract(
- final Class<? extends Facet> facetType,
- final FacetHolder holder,
- boolean derived) {
- this.facetType = ensureThatArg(facetType, is(not(nullValue(Class.class))));
- setFacetHolder(ensureThatArg(holder, is(not(nullValue(FacetHolder.class)))));
- this.derived = derived;
- }
-
- @Override
- public final Class<? extends Facet> facetType() {
- return facetType;
- }
-
- @Override
- public FacetHolder getFacetHolder() {
- return holder;
- }
-
- @Override
- public boolean isDerived() {
- return derived;
- }
-
- /**
- * Convenience method that returns {@link #getFacetHolder()} downcast to
- * {@link IdentifiedHolder} if the implementation does indeed inherit from
- * {@link IdentifiedHolder}, otherwise <tt>null</tt>.
- */
- public IdentifiedHolder getIdentified() {
- return identifiedHolder;
- }
-
- @Override
- public Facet getUnderlyingFacet() {
- return underlyingFacet;
- }
- @Override
- public void setUnderlyingFacet(Facet underlyingFacet) {
- Ensure.ensureThatArg(underlyingFacet.facetType(), IsisMatchers.classEqualTo(facetType));
- this.underlyingFacet = underlyingFacet;
- }
-
- /**
- * Assume implementation is <i>not</i> a no-op.
- *
- * <p>
- * No-op implementations should override and return <tt>true</tt>.
- */
- @Override
- public boolean isNoop() {
- return false;
- }
-
- /**
- * Default implementation of this method that returns <tt>true</tt>, ie should replace (none
- * {@link #isNoop() no-op} implementations.
- *
- * <p>
- * Implementations that don't wish to replace none no-op implementations should override and return
- * <tt>false</tt>.
- */
- @Override
- public boolean alwaysReplace() {
- return true;
- }
-
- @Override
- public void setFacetHolder(final FacetHolder facetHolder) {
- this.holder = facetHolder;
- this.identifiedHolder = holder instanceof IdentifiedHolder? (IdentifiedHolder)holder: null;
- }
+
+public abstract class FacetAbstract implements Facet {
+
+ private Facet underlyingFacet;
+
+ private final Class<? extends Facet> facetType;
+ private final boolean derived;
+ private FacetHolder holder;
+
+ /**
+ * Populated in {@link #setFacetHolder(FacetHolder)} if the provided holder implements {@link IdentifiedHolder}.
+ *
+ * <p>
+ * Otherwise is <tt>null</tt>.
+ */
+ private IdentifiedHolder identifiedHolder;
+
+ @SuppressWarnings("unchecked")
+ public FacetAbstract(final Class<? extends Facet> facetType, final FacetHolder holder, final boolean derived) {
+ this.facetType = ensureThatArg(facetType, is(not(nullValue(Class.class))));
+ setFacetHolder(ensureThatArg(holder, is(not(nullValue(FacetHolder.class)))));
+ this.derived = derived;
+ }
+
+ @Override
+ public final Class<? extends Facet> facetType() {
+ return facetType;
+ }
+
+ @Override
+ public FacetHolder getFacetHolder() {
+ return holder;
+ }
+
+ @Override
+ public boolean isDerived() {
+ return derived;
+ }
+
+ /**
+ * Convenience method that returns {@link #getFacetHolder()} downcast to {@link IdentifiedHolder} if the
+ * implementation does indeed inherit from {@link IdentifiedHolder}, otherwise <tt>null</tt>.
+ */
+ public IdentifiedHolder getIdentified() {
+ return identifiedHolder;
+ }
+
+ @Override
+ public Facet getUnderlyingFacet() {
+ return underlyingFacet;
+ }
+
+ @Override
+ public void setUnderlyingFacet(final Facet underlyingFacet) {
+ Ensure.ensureThatArg(underlyingFacet.facetType(), IsisMatchers.classEqualTo(facetType));
+ this.underlyingFacet = underlyingFacet;
+ }
+
+ /**
+ * Assume implementation is <i>not</i> a no-op.
+ *
+ * <p>
+ * No-op implementations should override and return <tt>true</tt>.
+ */
+ @Override
+ public boolean isNoop() {
+ return false;
+ }
+
+ /**
+ * Default implementation of this method that returns <tt>true</tt>, ie should replace (none {@link #isNoop() no-op}
+ * implementations.
+ *
+ * <p>
+ * Implementations that don't wish to replace none no-op implementations should override and return <tt>false</tt>.
+ */
+ @Override
+ public boolean alwaysReplace() {
+ return true;
+ }
+
+ @Override
+ public void setFacetHolder(final FacetHolder facetHolder) {
+ this.holder = facetHolder;
+ this.identifiedHolder = holder instanceof IdentifiedHolder ? (IdentifiedHolder) holder : null;
+ }
protected String toStringValues() {
return "";
}
-
- @Override
- public String toString() {
- String details = "";
- if (Validating.class.isAssignableFrom(getClass())) {
- details += "Validating";
- }
- if (Disabling.class.isAssignableFrom(getClass())) {
- details += (details.length() > 0 ? ";" : "") + "Disabling";
- }
- if (Hiding.class.isAssignableFrom(getClass())) {
- details += (details.length() > 0 ? ";" : "") + "Hiding";
- }
- if (!"".equals(details)) {
- details = "interaction=" + details + ",";
- }
-
- final String className = getClass().getName();
- final String stringValues = toStringValues();
- if (getClass() != facetType()) {
- final String facetType = facetType().getName();
- details += "type=" + facetType.substring(facetType.lastIndexOf('.') + 1);
- }
- if (!"".equals(stringValues)) {
- details += ",";
- }
- return className.substring(className.lastIndexOf('.') + 1) + "[" + details + stringValues + "]";
+
+ @Override
+ public String toString() {
+ String details = "";
+ if (Validating.class.isAssignableFrom(getClass())) {
+ details += "Validating";
+ }
+ if (Disabling.class.isAssignableFrom(getClass())) {
+ details += (details.length() > 0 ? ";" : "") + "Disabling";
+ }
+ if (Hiding.class.isAssignableFrom(getClass())) {
+ details += (details.length() > 0 ? ";" : "") + "Hiding";
+ }
+ if (!"".equals(details)) {
+ details = "interaction=" + details + ",";
+ }
+
+ final String className = getClass().getName();
+ final String stringValues = toStringValues();
+ if (getClass() != facetType()) {
+ final String facetType = facetType().getName();
+ details += "type=" + facetType.substring(facetType.lastIndexOf('.') + 1);
+ }
+ if (!"".equals(stringValues)) {
+ details += ",";
+ }
+ return className.substring(className.lastIndexOf('.') + 1) + "[" + details + stringValues + "]";
}
/**
* Marker interface used within {@link #toString()}.
*/
- public static interface Hiding {}
+ public static interface Hiding {
+ }
/**
* Marker interface used within {@link #toString()}.
*/
- public static interface Disabling {}
+ public static interface Disabling {
+ }
/**
* Marker interface used within {@link #toString()}.
*/
- public static interface Validating {}
+ public static interface Validating {
+ }
-}
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetFilters.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetFilters.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetFilters.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetFilters.java Tue Apr 26 18:24:05 2011
@@ -17,41 +17,40 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
-
import org.apache.isis.applib.filter.Filter;
import org.apache.isis.applib.filter.Filters;
-
-
-public final class FacetFilters {
-
- private FacetFilters() {}
-
- /**
- * {@link Filter<Facet>#accept(Facet) Accepts} everything.
- */
- public static final Filter<Facet> ANY = Filters.anyOfType(Facet.class);
- /**
- * {@link Filter<Facet>#accept(Facet) Accepts} nothing.
- */
- public static final Filter<Facet> NONE = new Filter<Facet>() {
- @Override
- public boolean accept(final Facet facet) {
- return false;
- }
- };
-
- public static Filter<Facet> isA(final Class<?> superClass) {
- return new Filter<Facet>() {
- @Override
- public boolean accept(final Facet facet) {
- if (facet instanceof DecoratingFacet) {
- final DecoratingFacet<?> decoratingFacet = (DecoratingFacet<?>) facet;
- return accept(decoratingFacet.getDecoratedFacet());
- }
- return superClass.isAssignableFrom(facet.getClass());
- }
- };
- }
-}
+
+public final class FacetFilters {
+
+ private FacetFilters() {
+ }
+
+ /**
+ * {@link Filter<Facet>#accept(Facet) Accepts} everything.
+ */
+ public static final Filter<Facet> ANY = Filters.anyOfType(Facet.class);
+ /**
+ * {@link Filter<Facet>#accept(Facet) Accepts} nothing.
+ */
+ public static final Filter<Facet> NONE = new Filter<Facet>() {
+ @Override
+ public boolean accept(final Facet facet) {
+ return false;
+ }
+ };
+
+ public static Filter<Facet> isA(final Class<?> superClass) {
+ return new Filter<Facet>() {
+ @Override
+ public boolean accept(final Facet facet) {
+ if (facet instanceof DecoratingFacet) {
+ final DecoratingFacet<?> decoratingFacet = (DecoratingFacet<?>) facet;
+ return accept(decoratingFacet.getDecoratedFacet());
+ }
+ return superClass.isAssignableFrom(facet.getClass());
+ }
+ };
+ }
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolder.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolder.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolder.java Tue Apr 26 18:24:05 2011
@@ -17,32 +17,30 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
-
import java.util.List;
import org.apache.isis.applib.filter.Filter;
-
-
-/**
- * Anything in the metamodel (which also includes peers in the reflector) that can be extended.
- */
-public interface FacetHolder {
-
- /**
- * Get the list of all facet <i>types</i> that are supported by objects of this specification.
- */
- Class<? extends Facet>[] getFacetTypes();
-
- /**
- * Whether there is a facet registered of the specified type.
- *
- * <p>
- * Convenience; saves having to {@link #getFacet(Class)} and then check if <tt>null</tt>.
- */
- boolean containsFacet(Class<? extends Facet> facetType);
-
+
+/**
+ * Anything in the metamodel (which also includes peers in the reflector) that can be extended.
+ */
+public interface FacetHolder {
+
+ /**
+ * Get the list of all facet <i>types</i> that are supported by objects of this specification.
+ */
+ Class<? extends Facet>[] getFacetTypes();
+
+ /**
+ * Whether there is a facet registered of the specified type.
+ *
+ * <p>
+ * Convenience; saves having to {@link #getFacet(Class)} and then check if <tt>null</tt>.
+ */
+ boolean containsFacet(Class<? extends Facet> facetType);
+
/**
* Whether there is a facet registered of the specified type that is not a {@link Facet#isNoop() no-op}.
*
@@ -51,48 +49,48 @@ public interface FacetHolder {
*/
boolean containsDoOpFacet(Class<? extends Facet> facetType);
- /**
- * Get the facet of the specified type (as per the type it reports from {@link Facet#facetType()}).
- */
- <T extends Facet> T getFacet(Class<T> cls);
-
- /**
- * Returns all {@link Facet}s matching the specified {@link FacetFilter}.
- *
- * @param filter
- * @return
- */
- List<Facet> getFacets(Filter<Facet> filter);
-
- /**
- * Adds the facet, extracting its {@link Facet#facetType() type} as the key.
- *
- * <p>
- * If there are any facet of the same type, they will be overwritten <i>provided</i> that either the
- * {@link Facet} specifies to {@link Facet#alwaysReplace() always replace} or if the existing
- * {@link Facet} is a {@link Facet#isNoop() no-op}.
- */
- void addFacet(Facet facet);
-
- /**
- * Adds the {@link MultiTypedFacet multi-typed facet}, extracting each of its
- * {@link MultiTypedFacet#facetTypes() types} as keys.
- *
- * <p>
- * If there are any facet of the same type, they will be overwritten <i>provided</i> that either the
- * {@link Facet} specifies to {@link Facet#alwaysReplace() always replace} or if the existing
- * {@link Facet} is a {@link Facet#isNoop() no-op}.
- */
- void addFacet(MultiTypedFacet facet);
-
- /**
- * Remove the facet whose type is that reported by {@link Facet#facetType()}.
- */
- void removeFacet(Facet facet);
-
- /**
- * Remove the facet of the specified type.
- */
- void removeFacet(Class<? extends Facet> facetType);
-
-}
+ /**
+ * Get the facet of the specified type (as per the type it reports from {@link Facet#facetType()}).
+ */
+ <T extends Facet> T getFacet(Class<T> cls);
+
+ /**
+ * Returns all {@link Facet}s matching the specified {@link FacetFilter}.
+ *
+ * @param filter
+ * @return
+ */
+ List<Facet> getFacets(Filter<Facet> filter);
+
+ /**
+ * Adds the facet, extracting its {@link Facet#facetType() type} as the key.
+ *
+ * <p>
+ * If there are any facet of the same type, they will be overwritten <i>provided</i> that either the {@link Facet}
+ * specifies to {@link Facet#alwaysReplace() always replace} or if the existing {@link Facet} is a
+ * {@link Facet#isNoop() no-op}.
+ */
+ void addFacet(Facet facet);
+
+ /**
+ * Adds the {@link MultiTypedFacet multi-typed facet}, extracting each of its {@link MultiTypedFacet#facetTypes()
+ * types} as keys.
+ *
+ * <p>
+ * If there are any facet of the same type, they will be overwritten <i>provided</i> that either the {@link Facet}
+ * specifies to {@link Facet#alwaysReplace() always replace} or if the existing {@link Facet} is a
+ * {@link Facet#isNoop() no-op}.
+ */
+ void addFacet(MultiTypedFacet facet);
+
+ /**
+ * Remove the facet whose type is that reported by {@link Facet#facetType()}.
+ */
+ void removeFacet(Facet facet);
+
+ /**
+ * Remove the facet of the specified type.
+ */
+ void removeFacet(Class<? extends Facet> facetType);
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolderImpl.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolderImpl.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetHolderImpl.java Tue Apr 26 18:24:05 2011
@@ -17,28 +17,26 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.isis.applib.filter.Filter;
-
-
-/**
- * For base subclasses or, more likely, to help write tests.
- */
-public class FacetHolderImpl implements FacetHolder {
-
- private final Map<Class<? extends Facet>, Facet> facetsByClass = new HashMap<Class<? extends Facet>, Facet>();
-
- @Override
- public boolean containsFacet(final Class<? extends Facet> facetType) {
- return getFacet(facetType) != null;
- }
-
+
+/**
+ * For base subclasses or, more likely, to help write tests.
+ */
+public class FacetHolderImpl implements FacetHolder {
+
+ private final Map<Class<? extends Facet>, Facet> facetsByClass = new HashMap<Class<? extends Facet>, Facet>();
+
+ @Override
+ public boolean containsFacet(final Class<? extends Facet> facetType) {
+ return getFacet(facetType) != null;
+ }
+
@Override
public boolean containsDoOpFacet(final Class<? extends Facet> facetType) {
final Facet facet = getFacet(facetType);
@@ -46,59 +44,58 @@ public class FacetHolderImpl implements
}
@Override
- public void addFacet(final Facet facet) {
- addFacet(facet.facetType(), facet);
- }
-
- @Override
- public void addFacet(final MultiTypedFacet facet) {
- final Class<? extends Facet>[] facetTypes = facet.facetTypes();
- for (int i = 0; i < facetTypes.length; i++) {
- addFacet(facetTypes[i], facet.getFacet(facetTypes[i]));
- }
- }
-
- private void addFacet(final Class<? extends Facet> facetType, final Facet facet) {
- final Facet existingFacet = getFacet(facetType);
- if (existingFacet == null || existingFacet.isNoop()) {
- facetsByClass.put(facetType, facet);
- return;
- }
- if (!facet.alwaysReplace()) {
- return;
- }
- if (facet.isDerived() && !existingFacet.isDerived()) {
- return;
- }
- facet.setUnderlyingFacet(existingFacet);
- facetsByClass.put(facetType, facet);
- }
-
- @Override
- public void removeFacet(final Facet facet) {
- FacetUtil.removeFacet(facetsByClass, facet);
- }
-
- @Override
- public void removeFacet(final Class<? extends Facet> facetType) {
- FacetUtil.removeFacet(facetsByClass, facetType);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T extends Facet> T getFacet(final Class<T> facetType) {
- return (T) facetsByClass.get(facetType);
- }
-
- @Override
- public Class<? extends Facet>[] getFacetTypes() {
- return FacetUtil.getFacetTypes(facetsByClass);
- }
-
- @Override
- public List<Facet> getFacets(final Filter<Facet> filter) {
- return FacetUtil.getFacets(facetsByClass, filter);
- }
-
-
-}
+ public void addFacet(final Facet facet) {
+ addFacet(facet.facetType(), facet);
+ }
+
+ @Override
+ public void addFacet(final MultiTypedFacet facet) {
+ final Class<? extends Facet>[] facetTypes = facet.facetTypes();
+ for (final Class<? extends Facet> facetType : facetTypes) {
+ addFacet(facetType, facet.getFacet(facetType));
+ }
+ }
+
+ private void addFacet(final Class<? extends Facet> facetType, final Facet facet) {
+ final Facet existingFacet = getFacet(facetType);
+ if (existingFacet == null || existingFacet.isNoop()) {
+ facetsByClass.put(facetType, facet);
+ return;
+ }
+ if (!facet.alwaysReplace()) {
+ return;
+ }
+ if (facet.isDerived() && !existingFacet.isDerived()) {
+ return;
+ }
+ facet.setUnderlyingFacet(existingFacet);
+ facetsByClass.put(facetType, facet);
+ }
+
+ @Override
+ public void removeFacet(final Facet facet) {
+ FacetUtil.removeFacet(facetsByClass, facet);
+ }
+
+ @Override
+ public void removeFacet(final Class<? extends Facet> facetType) {
+ FacetUtil.removeFacet(facetsByClass, facetType);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T extends Facet> T getFacet(final Class<T> facetType) {
+ return (T) facetsByClass.get(facetType);
+ }
+
+ @Override
+ public Class<? extends Facet>[] getFacetTypes() {
+ return FacetUtil.getFacetTypes(facetsByClass);
+ }
+
+ @Override
+ public List<Facet> getFacets(final Filter<Facet> filter) {
+ return FacetUtil.getFacets(facetsByClass, filter);
+ }
+
+}
Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetUtil.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetUtil.java?rev=1096837&r1=1096836&r2=1096837&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetUtil.java (original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/FacetUtil.java Tue Apr 26 18:24:05 2011
@@ -17,9 +17,8 @@
* under the License.
*/
+package org.apache.isis.core.metamodel.facetapi;
-package org.apache.isis.core.metamodel.facetapi;
-
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
@@ -28,122 +27,123 @@ import java.util.Map;
import org.apache.isis.applib.filter.Filter;
import com.google.common.collect.Lists;
-
-
-public final class FacetUtil {
-
- private FacetUtil() {}
-
- /**
- * Attaches the {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
- *
- * @return <tt>true</tt> if a non-<tt>null</tt> facet was added, <tt>false</tt> otherwise.
- */
- public static boolean addFacet(final Facet facet) {
- if (facet == null) {
- return false;
- }
- facet.getFacetHolder().addFacet(facet);
- return true;
- }
-
- public static boolean addFacet(final MultiTypedFacet facet) {
- if (facet == null) {
- return false;
- }
- facet.getFacetHolder().addFacet(facet);
- return true;
- }
-
- /**
- * Attaches each {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
- *
- * @return <tt>true</tt> if any facets were added, <tt>false</tt> otherwise.
- */
- public static boolean addFacets(final Facet[] facets) {
- boolean addedFacets = false;
- for (int i = 0; i < facets.length; i++) {
- addedFacets = addFacet(facets[i]) | addedFacets;
- }
- return addedFacets;
- }
-
- /**
- * Attaches each {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
- *
- * @return <tt>true</tt> if any facets were added, <tt>false</tt> otherwise.
- */
- public static boolean addFacets(final List<Facet> facetList) {
- boolean addedFacets = false;
- for (final Facet facet : facetList) {
- addedFacets = addFacet(facet) | addedFacets;
- }
- return addedFacets;
- }
-
- /**
- * Bit nasty, for use only by {@link FacetHolder}s that index their {@link Facet}s in a Map.
- *
- * @param facetsByClass
- * @return
- */
- @SuppressWarnings("unchecked")
- public static Class<? extends Facet>[] getFacetTypes(final Map<Class<? extends Facet>, Facet> facetsByClass) {
- return facetsByClass.keySet().toArray(new Class[0]);
- }
-
- /**
- * Bit nasty, for use only by {@link FacetHolder}s that index their {@link Facet}s in a Map.
- *
- * @param facetsByClass
- * @return
- */
- public static List<Facet> getFacets(final Map<Class<? extends Facet>, Facet> facetsByClass, final Filter<Facet> filter) {
- final List<Facet> filteredFacets = Lists.newArrayList();
- final List<Facet> allFacets = new ArrayList<Facet>(facetsByClass.values());
- for (int i = 0; i < allFacets.size(); i++) {
- final Facet facet = allFacets.get(i);
- if (filter.accept(facet)) {
- filteredFacets.add(facet);
- }
- }
- return filteredFacets;
- }
-
- public static void removeFacet(final Map<Class<? extends Facet>, Facet> facetsByClass, final Facet facet) {
- removeFacet(facetsByClass, facet.facetType());
- }
-
- public static void removeFacet(final Map<Class<? extends Facet>, Facet> facetsByClass, final Class<? extends Facet> facetType) {
- final Facet facet = facetsByClass.get(facetType);
- if (facet == null) {
- return;
- }
- facetsByClass.remove(facetType);
- facet.setFacetHolder(null);
- }
-
- public static void addFacet(final Map<Class<? extends Facet>, Facet> facetsByClass, final Facet facet) {
- facetsByClass.put(facet.facetType(), facet);
- }
-
- public static Facet[] toArray(final List<Facet> facetList) {
- if (facetList == null) {
- return new Facet[0];
- } else {
- return facetList.toArray(new Facet[] {});
- }
- }
-
- public static Hashtable<Class<? extends Facet>, Facet> getFacetsByType(final FacetHolder facetHolder) {
- final Hashtable<Class<? extends Facet>, Facet> facetByType = new Hashtable<Class<? extends Facet>, Facet>();
- final Class<? extends Facet>[] facetsFor = facetHolder.getFacetTypes();
- for (int i = 0; i < facetsFor.length; i++) {
- final Class<? extends Facet> facetType = facetsFor[i];
- final Facet facet = facetHolder.getFacet(facetType);
- facetByType.put(facetType, facet);
- }
- return facetByType;
- }
-
-}
+
+public final class FacetUtil {
+
+ private FacetUtil() {
+ }
+
+ /**
+ * Attaches the {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
+ *
+ * @return <tt>true</tt> if a non-<tt>null</tt> facet was added, <tt>false</tt> otherwise.
+ */
+ public static boolean addFacet(final Facet facet) {
+ if (facet == null) {
+ return false;
+ }
+ facet.getFacetHolder().addFacet(facet);
+ return true;
+ }
+
+ public static boolean addFacet(final MultiTypedFacet facet) {
+ if (facet == null) {
+ return false;
+ }
+ facet.getFacetHolder().addFacet(facet);
+ return true;
+ }
+
+ /**
+ * Attaches each {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
+ *
+ * @return <tt>true</tt> if any facets were added, <tt>false</tt> otherwise.
+ */
+ public static boolean addFacets(final Facet[] facets) {
+ boolean addedFacets = false;
+ for (final Facet facet : facets) {
+ addedFacets = addFacet(facet) | addedFacets;
+ }
+ return addedFacets;
+ }
+
+ /**
+ * Attaches each {@link Facet} to its {@link Facet#getFacetHolder() facet holder}.
+ *
+ * @return <tt>true</tt> if any facets were added, <tt>false</tt> otherwise.
+ */
+ public static boolean addFacets(final List<Facet> facetList) {
+ boolean addedFacets = false;
+ for (final Facet facet : facetList) {
+ addedFacets = addFacet(facet) | addedFacets;
+ }
+ return addedFacets;
+ }
+
+ /**
+ * Bit nasty, for use only by {@link FacetHolder}s that index their {@link Facet}s in a Map.
+ *
+ * @param facetsByClass
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static Class<? extends Facet>[] getFacetTypes(final Map<Class<? extends Facet>, Facet> facetsByClass) {
+ return facetsByClass.keySet().toArray(new Class[0]);
+ }
+
+ /**
+ * Bit nasty, for use only by {@link FacetHolder}s that index their {@link Facet}s in a Map.
+ *
+ * @param facetsByClass
+ * @return
+ */
+ public static List<Facet> getFacets(final Map<Class<? extends Facet>, Facet> facetsByClass,
+ final Filter<Facet> filter) {
+ final List<Facet> filteredFacets = Lists.newArrayList();
+ final List<Facet> allFacets = new ArrayList<Facet>(facetsByClass.values());
+ for (int i = 0; i < allFacets.size(); i++) {
+ final Facet facet = allFacets.get(i);
+ if (filter.accept(facet)) {
+ filteredFacets.add(facet);
+ }
+ }
+ return filteredFacets;
+ }
+
+ public static void removeFacet(final Map<Class<? extends Facet>, Facet> facetsByClass, final Facet facet) {
+ removeFacet(facetsByClass, facet.facetType());
+ }
+
+ public static void removeFacet(final Map<Class<? extends Facet>, Facet> facetsByClass,
+ final Class<? extends Facet> facetType) {
+ final Facet facet = facetsByClass.get(facetType);
+ if (facet == null) {
+ return;
+ }
+ facetsByClass.remove(facetType);
+ facet.setFacetHolder(null);
+ }
+
+ public static void addFacet(final Map<Class<? extends Facet>, Facet> facetsByClass, final Facet facet) {
+ facetsByClass.put(facet.facetType(), facet);
+ }
+
+ public static Facet[] toArray(final List<Facet> facetList) {
+ if (facetList == null) {
+ return new Facet[0];
+ } else {
+ return facetList.toArray(new Facet[] {});
+ }
+ }
+
+ public static Hashtable<Class<? extends Facet>, Facet> getFacetsByType(final FacetHolder facetHolder) {
+ final Hashtable<Class<? extends Facet>, Facet> facetByType = new Hashtable<Class<? extends Facet>, Facet>();
+ final Class<? extends Facet>[] facetsFor = facetHolder.getFacetTypes();
+ for (final Class<? extends Facet> facetType : facetsFor) {
+ final Facet facet = facetHolder.getFacet(facetType);
+ facetByType.put(facetType, facet);
+ }
+ return facetByType;
+ }
+
+}