You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/12/29 21:58:24 UTC
[tapestry-5] branch 5.6.x updated: TAP5-2655: annotation to disable
validation in event handler methods # Conflicts:
# tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
# tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/5.6.x by this push:
new e3b92e5 TAP5-2655: annotation to disable validation in event handler methods # Conflicts: # tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java # tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
e3b92e5 is described below
commit e3b92e5229601a17bea7f52e8b8477c3fdc61484
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Tue Dec 29 18:43:01 2020 -0300
TAP5-2655: annotation to disable validation in event handler methods
# Conflicts:
# tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
# tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
---
.../internal/transform/OnEventWorker.java | 5 +++
.../tapestry5/services/AssetNotFoundException.java | 49 ++++++++++++++++++++++
.../integration/app1/pages/ActionViaLinkDemo.java | 17 +++++++-
.../tapestry5/annotations/DisableStrictChecks.java | 30 +++++++++++++
4 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
index fdb2dc9..9ddb7d9 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OnEventWorker.java
@@ -20,6 +20,7 @@ import java.util.Map;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.annotations.DisableStrictChecks;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.PublishEvent;
import org.apache.tapestry5.annotations.RequestParameter;
@@ -406,6 +407,10 @@ public class OnEventWorker implements ComponentClassTransformWorker2
{
return null;
}
+ if (element.method.getAnnotation(DisableStrictChecks.class) != null)
+ {
+ return null;
+ }
return new ComponentIdValidator(element.componentId, element.method.getMethodIdentifier());
}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetNotFoundException.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetNotFoundException.java
new file mode 100644
index 0000000..12604de
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/AssetNotFoundException.java
@@ -0,0 +1,49 @@
+// Licensed 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.tapestry5.services;
+
+import org.apache.tapestry5.commons.Resource;
+
+/**
+ * Class that represents the exception of an asset not being found.
+ * @author thiago
+ *
+ */
+public class AssetNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ final private Resource resource;
+
+ /**
+ * {@inheritDoc}
+ */
+ public AssetNotFoundException(String message) {
+ super(message);
+ resource = null;
+ }
+
+ /**
+ * Constructs an exception with message and a {@link Resource}.
+ * @param message a <code>String</code>.
+ * @param resource a {@link Resource}.
+ */
+ public AssetNotFoundException(String message, Resource resource) {
+ super(message);
+ this.resource = resource;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+}
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
index 5289cac..1c4b955 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ActionViaLinkDemo.java
@@ -13,8 +13,9 @@
package org.apache.tapestry5.integration.app1.pages;
import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.Link;
import org.apache.tapestry5.PersistenceConstants;
+import org.apache.tapestry5.annotations.DisableStrictChecks;
+import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.ioc.annotations.Inject;
@@ -48,4 +49,18 @@ public class ActionViaLinkDemo
return link.toURI();
}
+
+ @DisableStrictChecks
+ void onActionFromNonExistent()
+ {
+
+ }
+
+ @DisableStrictChecks
+ @OnEvent(value = "test", component = "nonExistent")
+ void someEventHandlerMethod()
+ {
+
+ }
+
}
diff --git a/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java b/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java
new file mode 100644
index 0000000..6ce849e
--- /dev/null
+++ b/tapestry5-annotations/src/main/java/org/apache/tapestry5/annotations/DisableStrictChecks.java
@@ -0,0 +1,30 @@
+// Licensed 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.tapestry5.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Disables strict checks Tapestry-IoC or Tapestry may perform on methods. So far, this annotation
+ * can be used in Tapestry event handler methods to disable the check on whether they match
+ * a component id which actually exists.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(METHOD)
+public @interface DisableStrictChecks
+{
+
+}