Repository: wicket Updated Branches: refs/heads/master a94217728 -> 752b7a87c
WICKET-6550 : Unify all metadata capable objects. Introduce a IMetadataContext that contains the current metadata implementation. This should allow more generic code to be written for all of the objects currently capable of storing and handling metadata. Ideally, this could be expanded with useful default methods. This closes #276 Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/752b7a87 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/752b7a87 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/752b7a87 Branch: refs/heads/master Commit: 752b7a87c98be3c774c43fc1fbf8f60ce82f14ef Parents: a942177 Author: Jezza <[email protected]> Authored: Thu Apr 19 22:16:47 2018 +0200 Committer: Sven Meier <[email protected]> Committed: Wed Sep 26 10:37:19 2018 +0200 ---------------------------------------------------------------------- .../java/org/apache/wicket/Application.java | 6 ++- .../main/java/org/apache/wicket/Component.java | 5 ++- .../org/apache/wicket/IMetadataContext.java | 43 ++++++++++++++++++++ .../main/java/org/apache/wicket/Session.java | 4 +- .../wicket/request/cycle/RequestCycle.java | 5 ++- 5 files changed, 58 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/752b7a87/wicket-core/src/main/java/org/apache/wicket/Application.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Application.java b/wicket-core/src/main/java/org/apache/wicket/Application.java index 9415afa..4ba6e05 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Application.java +++ b/wicket-core/src/main/java/org/apache/wicket/Application.java @@ -138,7 +138,7 @@ import org.slf4j.LoggerFactory; * @see org.apache.wicket.protocol.http.WebApplication * @author Jonathan Locke */ -public abstract class Application implements UnboundListener, IEventSink +public abstract class Application implements UnboundListener, IEventSink, IMetadataContext<Object, Application> { /** Configuration constant for the 2 types */ public static final String CONFIGURATION = "configuration"; @@ -405,6 +405,7 @@ public abstract class Application implements UnboundListener, IEventSink * @return The metadata * @see MetaDataKey */ + @Override public final synchronized <T> T getMetaData(final MetaDataKey<T> key) { return key.get(metaData); @@ -518,7 +519,8 @@ public abstract class Application implements UnboundListener, IEventSink * @throws IllegalArgumentException * @see MetaDataKey */ - public final synchronized <T> Application setMetaData(final MetaDataKey<T> key, final Object object) + @Override + public synchronized final <T> Application setMetaData(final MetaDataKey<T> key, final T object) { metaData = key.set(metaData, object); return this; http://git-wip-us.apache.org/repos/asf/wicket/blob/752b7a87/wicket-core/src/main/java/org/apache/wicket/Component.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java index d408dae..0f5fc7d 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Component.java +++ b/wicket-core/src/main/java/org/apache/wicket/Component.java @@ -221,7 +221,8 @@ public abstract class Component IHeaderContributor, IHierarchical<Component>, IEventSink, - IEventSource + IEventSource, + IMetadataContext<Serializable, Component> { /** Log. */ private static final Logger log = LoggerFactory.getLogger(Component.class); @@ -1503,6 +1504,7 @@ public abstract class Component * @return The metadata or null of no metadata was found for the given key * @see MetaDataKey */ + @Override public final <M extends Serializable> M getMetaData(final MetaDataKey<M> key) { return key.get(getMetaData()); @@ -2855,6 +2857,7 @@ public abstract class Component * @throws IllegalArgumentException * @see MetaDataKey */ + @Override public final <M extends Serializable> Component setMetaData(final MetaDataKey<M> key, final M object) { MetaDataEntry<?>[] old = getMetaData(); http://git-wip-us.apache.org/repos/asf/wicket/blob/752b7a87/wicket-core/src/main/java/org/apache/wicket/IMetadataContext.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/IMetadataContext.java b/wicket-core/src/main/java/org/apache/wicket/IMetadataContext.java new file mode 100644 index 0000000..82475fc --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/IMetadataContext.java @@ -0,0 +1,43 @@ +/* + * 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.wicket; + +/** + * Used to unify all metadata methods across the various objects. + * <p> + * This allows for metadata to be mutated at arms length without dealing with the intricacies of + * each type that implements it. + * <p> + * Due to the inability to refer to implementing types (e.g. Self in Rust) we use the {@code R} parameter + * to return the type of the implementing object. + * + * @param <B> + * The base type the metadata object must extend. (e.g. {@link java.io.Serializable}) + * @param <R> + * The type of the implementing object. + * @author Jezza + * @see Application + * @see Component + * @see Session + * @see org.apache.wicket.request.cycle.RequestCycle + */ +public interface IMetadataContext<B, R extends IMetadataContext<B, R>> +{ + <T extends B> T getMetaData(MetaDataKey<T> key); + + <T extends B> R setMetaData(MetaDataKey<T> key, T data); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/752b7a87/wicket-core/src/main/java/org/apache/wicket/Session.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/Session.java b/wicket-core/src/main/java/org/apache/wicket/Session.java index cb8f4a2..a7aee21 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Session.java +++ b/wicket-core/src/main/java/org/apache/wicket/Session.java @@ -106,7 +106,7 @@ import org.slf4j.LoggerFactory; * @author Eelco Hillenius * @author Igor Vaynberg (ivaynberg) */ -public abstract class Session implements IClusterable, IEventSink +public abstract class Session implements IClusterable, IEventSink, IMetadataContext<Serializable, Session> { private static final long serialVersionUID = 1L; @@ -422,6 +422,7 @@ public abstract class Session implements IClusterable, IEventSink * @return The metadata * @see MetaDataKey */ + @Override public synchronized final <M extends Serializable> M getMetaData(final MetaDataKey<M> key) { return key.get(metaData); @@ -606,6 +607,7 @@ public abstract class Session implements IClusterable, IEventSink * @throws IllegalArgumentException * @see MetaDataKey */ + @Override public final synchronized <M extends Serializable> Session setMetaData(final MetaDataKey<M> key, final M object) { metaData = key.set(metaData, object); http://git-wip-us.apache.org/repos/asf/wicket/blob/752b7a87/wicket-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java b/wicket-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java index 272fcde..327bede 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java @@ -19,6 +19,7 @@ package org.apache.wicket.request.cycle; import java.util.Optional; import org.apache.wicket.Application; +import org.apache.wicket.IMetadataContext; import org.apache.wicket.MetaDataEntry; import org.apache.wicket.MetaDataKey; import org.apache.wicket.Page; @@ -70,7 +71,7 @@ import org.slf4j.LoggerFactory; * @author Matej Knopp * @author igor.vaynberg */ -public class RequestCycle implements IRequestCycle, IEventSink +public class RequestCycle implements IRequestCycle, IEventSink, IMetadataContext<Object, RequestCycle> { private static final Logger log = LoggerFactory.getLogger(RequestCycle.class); @@ -409,6 +410,7 @@ public class RequestCycle implements IRequestCycle, IEventSink * @throws IllegalArgumentException * @see MetaDataKey */ + @Override public final <T> RequestCycle setMetaData(final MetaDataKey<T> key, final T object) { metaData = key.set(metaData, object); @@ -426,6 +428,7 @@ public class RequestCycle implements IRequestCycle, IEventSink * @return The metadata or null if no metadata was found for the given key * @see MetaDataKey */ + @Override public final <T> T getMetaData(final MetaDataKey<T> key) { return key.get(metaData);
