You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/14 07:01:32 UTC
[14/15] git commit: Add required annotation.
Add required annotation.
- Part of LOG4J2-825.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0cf76d6a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0cf76d6a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0cf76d6a
Branch: refs/heads/master
Commit: 0cf76d6a5087f118e3ac38bd35e20793cf6b7448
Parents: 59b7833
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 14 00:00:02 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 14 00:00:02 2014 -0500
----------------------------------------------------------------------
.../validation/constraints/RequiresNonNull.java | 39 ++++++++++++++++++++
.../validators/RequiresNonNullValidator.java | 36 ++++++++++++++++++
2 files changed, 75 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cf76d6a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
new file mode 100644
index 0000000..b3ef11d
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.config.plugins.validation.constraints;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.logging.log4j.core.config.plugins.validation.Constraint;
+import org.apache.logging.log4j.core.config.plugins.validation.validators.RequiresNonNullValidator;
+
+/**
+ * Marks a plugin builder field or plugin factory parameter as required.
+ *
+ * @since 2.1
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.PARAMETER})
+@Constraint(RequiresNonNullValidator.class)
+public @interface RequiresNonNull {
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cf76d6a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
new file mode 100644
index 0000000..49c5806
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
@@ -0,0 +1,36 @@
+/*
+ * 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.logging.log4j.core.config.plugins.validation.validators;
+
+import org.apache.logging.log4j.core.config.plugins.validation.ConstraintValidator;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.RequiresNonNull;
+
+/**
+ * Validator implementation for {@link RequiresNonNull}.
+ *
+ * @since 2.1
+ */
+public class RequiresNonNullValidator implements ConstraintValidator<RequiresNonNull, Object> {
+ @Override
+ public void initialize(final RequiresNonNull annotation) {
+ }
+
+ @Override
+ public boolean isValid(final Object value) {
+ return value != null;
+ }
+}