Author: hardy.ferentschik
Date: 2010-05-20 07:58:01 -0400 (Thu, 20 May 2010)
New Revision: 19566
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/FutureDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetClassLoader.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetConstructor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredFields.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/LoadClass.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Tournament.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetClassLoader.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetConstructor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredField.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredFields.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/LoadClass.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/NewInstance.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/SetAccessibility.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
Log:
HV-274 Moved privileged actions into own package
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefinition.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -24,7 +24,7 @@
import java.util.Map;
import javax.validation.ValidationException;
-import org.hibernate.validator.util.NewInstance;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
import org.hibernate.validator.util.ReflectionHelper;
/**
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintsForType.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
@@ -21,7 +21,7 @@
import java.lang.annotation.ElementType;
import java.security.AccessController;
-import org.hibernate.validator.util.NewInstance;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
import static java.lang.annotation.ElementType.TYPE;
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/FutureDefinition.java
(from rev 19559,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/NotNullDefinition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/FutureDefinition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/FutureDefinition.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,46 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.hibernate.validator.cfg;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Payload;
+import javax.validation.constraints.Future;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class FutureDefinition extends ConstraintDefinition<Future> {
+ public FutureDefinition(Class<?> beanType, String property, ElementType
elementType, ConstraintMapping mapping) {
+ super( beanType, Future.class, property, elementType, mapping );
+ }
+
+ public FutureDefinition message(String message) {
+ addParameter( "message", message );
+ return this;
+ }
+
+ public FutureDefinition groups(Class<?>... groups) {
+ addParameter( "groups", groups );
+ return this;
+ }
+
+ public FutureDefinition payload(Class<? extends Payload>... payload) {
+ addParameter( "payload", payload );
+ return this;
+ }
+}
\ No newline at end of file
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConstraintValidatorFactoryImpl.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -21,7 +21,7 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
-import org.hibernate.validator.util.NewInstance;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
/**
* Default <code>ConstraintValidatorFactory</code> using a no-arg
constructor.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -20,7 +20,6 @@
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
-import java.security.AccessController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -44,7 +43,6 @@
import org.hibernate.validator.metadata.ConstraintHelper;
import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.metadata.MetaConstraint;
-import org.hibernate.validator.util.GetDeclaredField;
import org.hibernate.validator.util.ReflectionHelper;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
@@ -120,6 +118,11 @@
);
}
+ /**
+ * Reads the configuration from {@code mapping} and creates the appropriate meta-data
structures.
+ *
+ * @param mapping The constraint configuration created via the programmatic API.
+ */
private <A extends Annotation, T> void
initProgrammaticConfiguration(ConstraintMapping mapping) {
Map<Class<?>, List<ConstraintDefinition<?>>> configData =
mapping.getConfigData();
for ( Map.Entry<Class<?>, List<ConstraintDefinition<?>>> entry
: configData.entrySet() ) {
@@ -146,14 +149,10 @@
annotation, constraintHelper, config.getElementType(),
ConstraintOrigin.DEFINED_LOCALLY
);
- final Member member;
- GetDeclaredField action = GetDeclaredField.action( config.getBeanType(),
config.getProperty() );
- if ( System.getSecurityManager() != null ) {
- member = AccessController.doPrivileged( action );
- }
- else {
- member = action.run();
- }
+ final Member member = ReflectionHelper.getMember(
+ config.getBeanType(), config.getProperty(), config.getElementType()
+ );
+
MetaConstraint<T, ?> metaConstraint = new MetaConstraint(
config.getBeanType(), member, constraintDescriptor
);
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/resolver/DefaultTraversableResolver.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -26,8 +26,8 @@
import org.slf4j.Logger;
import org.hibernate.validator.util.LoggerFactory;
-import org.hibernate.validator.util.NewInstance;
-import org.hibernate.validator.util.LoadClass;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
+import org.hibernate.validator.util.privilegedactions.LoadClass;
/**
* A JPA 2 aware <code>TraversableResolver</code>.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/BeanMetaDataImpl.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -42,11 +42,11 @@
import org.slf4j.Logger;
-import org.hibernate.validator.util.GetDeclaredFields;
-import org.hibernate.validator.util.GetDeclaredMethods;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredFields;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.ReflectionHelper;
-import org.hibernate.validator.util.SetAccessibility;
+import org.hibernate.validator.util.privilegedactions.SetAccessibility;
/**
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintDescriptorImpl.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -43,10 +43,10 @@
import org.slf4j.Logger;
-import org.hibernate.validator.util.GetAnnotationParameter;
-import org.hibernate.validator.util.GetDeclaredMethods;
-import org.hibernate.validator.util.GetMethod;
-import org.hibernate.validator.util.GetMethods;
+import org.hibernate.validator.util.privilegedactions.GetAnnotationParameter;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
+import org.hibernate.validator.util.privilegedactions.GetMethod;
+import org.hibernate.validator.util.privilegedactions.GetMethods;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/metadata/ConstraintHelper.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -72,9 +72,9 @@
import org.hibernate.validator.constraints.impl.SizeValidatorForCollection;
import org.hibernate.validator.constraints.impl.SizeValidatorForMap;
import org.hibernate.validator.constraints.impl.SizeValidatorForString;
-import org.hibernate.validator.util.GetMethods;
-import org.hibernate.validator.util.GetMethod;
-import org.hibernate.validator.util.GetAnnotationParameter;
+import org.hibernate.validator.util.privilegedactions.GetMethods;
+import org.hibernate.validator.util.privilegedactions.GetMethod;
+import org.hibernate.validator.util.privilegedactions.GetAnnotationParameter;
/**
* Keeps track of builtin constraints and their validator implementations, as well as
already resolved validator definitions.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/resourceloading/PlatformResourceBundleLocator.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -24,7 +24,7 @@
import org.slf4j.Logger;
-import org.hibernate.validator.util.GetClassLoader;
+import org.hibernate.validator.util.privilegedactions.GetClassLoader;
import org.hibernate.validator.util.LoggerFactory;
/**
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsField.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsField.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsField.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,47 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ContainsField implements PrivilegedAction<Boolean> {
- private final Class<?> clazz;
- private final String property;
-
- public static ContainsField action(Class<?> clazz, String property) {
- return new ContainsField( clazz, property );
- }
-
- private ContainsField(Class<?> clazz, String property) {
- this.clazz = clazz;
- this.property = property;
- }
-
- public Boolean run() {
- try {
- clazz.getDeclaredField( property );
- return true;
- }
- catch ( NoSuchFieldException e ) {
- return false;
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsMethod.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsMethod.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsMethod.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,41 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ContainsMethod implements PrivilegedAction<Boolean> {
- private final Class<?> clazz;
- private final String property;
-
- public static ContainsMethod action(Class<?> clazz, String property) {
- return new ContainsMethod( clazz, property );
- }
-
- private ContainsMethod(Class<?> clazz, String property) {
- this.clazz = clazz;
- this.property = property;
- }
-
- public Boolean run() {
- return ReflectionHelper.getMethod( clazz, property ) != null;
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetAnnotationParameter.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetAnnotationParameter.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetAnnotationParameter.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,45 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.annotation.Annotation;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
- private final Annotation annotation;
- private final String parameterName;
- private final Class<T> type;
-
-
- public static <T> GetAnnotationParameter<T> action(Annotation annotation,
String parameterName, Class<T> type) {
- return new GetAnnotationParameter<T>( annotation, parameterName, type );
- }
-
- private GetAnnotationParameter(Annotation annotation, String parameterName,
Class<T> type) {
- this.annotation = annotation;
- this.parameterName = parameterName;
- this.type = type;
- }
-
- public T run() {
- return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetClassLoader.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetClassLoader.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetClassLoader.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,51 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public final class GetClassLoader implements PrivilegedAction<ClassLoader> {
- private final Class<?> clazz;
-
- public static GetClassLoader fromContext() {
- return new GetClassLoader( null );
- }
-
- public static GetClassLoader fromClass(Class<?> clazz) {
- if ( clazz == null ) {
- throw new IllegalArgumentException( "Class is null" );
- }
- return new GetClassLoader( clazz );
- }
-
- private GetClassLoader(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- public ClassLoader run() {
- if ( clazz != null ) {
- return clazz.getClassLoader();
- }
- else {
- return Thread.currentThread().getContextClassLoader();
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetConstructor.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetConstructor.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetConstructor.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,47 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Constructor;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetConstructor<T> implements
PrivilegedAction<Constructor<T>> {
- private final Class<T> clazz;
- private final Class<?>[] params;
-
- public static <T> GetConstructor<T> action(Class<T> clazz,
Class<?>... params) {
- return new GetConstructor<T>( clazz, params );
- }
-
- private GetConstructor(Class<T> clazz, Class<?>... params) {
- this.clazz = clazz;
- this.params = params;
- }
-
- public Constructor<T> run() {
- try {
- return clazz.getConstructor(params);
- }
- catch ( NoSuchMethodException e ) {
- return null;
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredField.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredField.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredField.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,49 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Field;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetDeclaredField implements PrivilegedAction<Field> {
- private final Class<?> clazz;
- private final String fieldName;
-
- public static GetDeclaredField action(Class<?> clazz, String fieldName) {
- return new GetDeclaredField( clazz, fieldName );
- }
-
- private GetDeclaredField(Class<?> clazz, String fieldName) {
- this.clazz = clazz;
- this.fieldName = fieldName;
- }
-
- public Field run() {
- try {
- final Field field = clazz.getDeclaredField( fieldName );
- ReflectionHelper.setAccessibility( field );
- return field;
- }
- catch ( NoSuchFieldException e ) {
- return null;
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredFields.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredFields.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredFields.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,40 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-import java.lang.reflect.Field;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetDeclaredFields implements PrivilegedAction<Field[]> {
- private final Class<?> clazz;
-
- public static GetDeclaredFields action(Class<?> clazz) {
- return new GetDeclaredFields( clazz );
- }
-
- private GetDeclaredFields(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- public Field[] run() {
- return clazz.getDeclaredFields();
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredMethods.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredMethods.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredMethods.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,40 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-import java.lang.reflect.Method;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetDeclaredMethods implements PrivilegedAction<Method[]> {
- private final Class<?> clazz;
-
- public static GetDeclaredMethods action(Class<?> clazz) {
- return new GetDeclaredMethods( clazz );
- }
-
- private GetDeclaredMethods(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- public Method[] run() {
- return clazz.getDeclaredMethods();
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethod.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethod.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethod.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,47 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethod implements PrivilegedAction<Method> {
- private final Class<?> clazz;
- private final String methodName;
-
- public static GetMethod action(Class<?> clazz, String methodName) {
- return new GetMethod( clazz, methodName );
- }
-
- private GetMethod(Class<?> clazz, String methodName) {
- this.clazz = clazz;
- this.methodName = methodName;
- }
-
- public Method run() {
- try {
- return clazz.getMethod(methodName);
- }
- catch ( NoSuchMethodException e ) {
- return null;
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethodFromPropertyName.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethodFromPropertyName.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethodFromPropertyName.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,42 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
- private final Class<?> clazz;
- private final String property;
-
- public static GetMethodFromPropertyName action(Class<?> clazz, String property) {
- return new GetMethodFromPropertyName( clazz, property );
- }
-
- private GetMethodFromPropertyName(Class<?> clazz, String property) {
- this.clazz = clazz;
- this.property = property;
- }
-
- public Method run() {
- return ReflectionHelper.getMethod( clazz, property );
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethods.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethods.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethods.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,40 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-import java.lang.reflect.Method;
-
-/**
- * @author Emmanuel Bernard
- */
-public class GetMethods implements PrivilegedAction<Method[]> {
- private final Class<?> clazz;
-
- public static GetMethods action(Class<?> clazz) {
- return new GetMethods( clazz );
- }
-
- private GetMethods(Class<?> clazz) {
- this.clazz = clazz;
- }
-
- public Method[] run() {
- return clazz.getMethods();
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/LoadClass.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/LoadClass.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/LoadClass.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,56 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.security.PrivilegedAction;
-import javax.validation.ValidationException;
-
-/**
- * @author Emmanuel Bernard
- */
-public class LoadClass implements PrivilegedAction<Class<?>> {
- private final String className;
- private final Class<?> caller;
-
- public static LoadClass action(String className, Class<?> caller) {
- return new LoadClass( className, caller );
- }
-
- private LoadClass(String className, Class<?> caller) {
- this.className = className;
- this.caller = caller;
- }
-
- public Class<?> run() {
- try {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- if ( contextClassLoader != null ) {
- return contextClassLoader.loadClass( className );
- }
- }
- catch ( Throwable e ) {
- // ignore
- }
- try {
- return Class.forName( className, true, caller.getClassLoader() );
- }
- catch ( ClassNotFoundException e ) {
- throw new ValidationException("Unable to load class: " + className, e);
- }
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/NewInstance.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/NewInstance.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/NewInstance.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,72 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.security.PrivilegedAction;
-import javax.validation.ValidationException;
-
-/**
- * Execute instance creation as privileged action.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public class NewInstance<T> implements PrivilegedAction<T> {
- private final Class<T> clazz;
- private final String message;
- private final Class<?>[] parameterTypes;
- private final Object[] initArgs;
-
- public static <T> NewInstance<T> action(Class<T> clazz, String
message, Object... initArgs) {
- return new NewInstance<T>( clazz, message, initArgs );
- }
-
- private NewInstance(Class<T> clazz, String message, Object... initArgs) {
- this.clazz = clazz;
- this.message = message;
- this.initArgs = initArgs;
- this.parameterTypes = new Class<?>[initArgs.length];
- for ( int i = 0; i < initArgs.length; i++ ) {
- this.parameterTypes[i] = initArgs[i].getClass();
- }
- }
-
- public T run() {
- try {
- Constructor<T> constructor = clazz.getConstructor( parameterTypes );
- return constructor.newInstance( initArgs );
- }
- catch ( InstantiationException e ) {
- throw new ValidationException( "Unable to instantiate " + message + ":
" + clazz, e );
- }
- catch ( IllegalAccessException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
- catch ( NoSuchMethodException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
- catch ( InvocationTargetException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
- catch ( RuntimeException e ) {
- throw new ValidationException( "Unable to instantiate " + clazz, e );
- }
- }
-}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ReflectionHelper.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -30,6 +30,7 @@
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
+import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -39,6 +40,9 @@
import com.googlecode.jtype.TypeUtils;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredField;
+import org.hibernate.validator.util.privilegedactions.GetMethod;
+
/**
* Some reflection utility methods.
*
@@ -120,6 +124,19 @@
* @return {@code true} is the property and can be access via the specified type, {@code
false} otherwise.
*/
public static boolean propertyExists(Class<?> clazz, String property, ElementType
elementType) {
+ return getMember( clazz, property, elementType ) != null;
+ }
+
+ /**
+ * Returns the member with the given name and type.
+ *
+ * @param clazz The class from which to retrieve the member. Cannot be {@code null}.
+ * @param property The property name without 'is', 'get' or
'has'. Cannot be {@code null} or empty.
+ * @param elementType The element type. Either {@code ElementType.FIELD} or {@code
ElementType METHOD}.
+ *
+ * @return the member which matching the name and type or {@code null} if no such member
exists.
+ */
+ public static Member getMember(Class<?> clazz, String property, ElementType
elementType) {
if ( clazz == null ) {
throw new IllegalArgumentException( "The class cannot be null" );
}
@@ -132,31 +149,33 @@
throw new IllegalArgumentException( "Element type has to be FIELD or METHOD"
);
}
- boolean exists = false;
+ Member member = null;
if ( ElementType.FIELD.equals( elementType ) ) {
- try {
- clazz.getDeclaredField( property );
- exists = true;
+ GetDeclaredField action = GetDeclaredField.action( clazz, property );
+ if ( System.getSecurityManager() != null ) {
+ member = AccessController.doPrivileged( action );
}
- catch ( NoSuchFieldException e ) {
- exists = false;
+ else {
+ member = action.run();
}
}
else {
String methodName = property.substring( 0, 1 ).toUpperCase() + property.substring( 1
);
- String[] prefixes = {"is", "get", "has"};
- for(String prefix : prefixes) {
- try {
- clazz.getDeclaredMethod( prefix + methodName );
- exists = true;
+ String[] prefixes = { "is", "get", "has" };
+ for ( String prefix : prefixes ) {
+ GetMethod action = GetMethod.action( clazz, prefix + methodName );
+ if ( System.getSecurityManager() != null ) {
+ member = AccessController.doPrivileged( action );
+ }
+ else {
+ member = action.run();
+ }
+ if ( member != null ) {
break;
- } catch (NoSuchMethodException e) {
-
}
}
-
}
- return exists;
+ return member;
}
@@ -232,7 +251,7 @@
return value;
}
- static void setAccessibility(Member member) {
+ public static void setAccessibility(Member member) {
// HV-257
// Also set accessibility in case of public abstract members. If you proxy an interface
using java.lang.reflect.Proxy
// per default you will get a IllegalAccessException since you are not allowed to
access public abstract methods.
@@ -394,7 +413,7 @@
* @return Returns the method with the specified name or <code>null</code>
if it does not exist.
*/
//run client in privileged block
- static Method getMethod(Class<?> clazz, String methodName) {
+ public static Method getMethod(Class<?> clazz, String methodName) {
try {
char string[] = methodName.toCharArray();
string[0] = Character.toUpperCase( string[0] );
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/SetAccessibility.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/SetAccessibility.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/SetAccessibility.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,41 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.validator.util;
-
-import java.lang.reflect.Member;
-import java.security.PrivilegedAction;
-
-/**
- * @author Emmanuel Bernard
- */
-public class SetAccessibility implements PrivilegedAction<Object> {
- private final Member member;
-
- public static SetAccessibility action(Member member) {
- return new SetAccessibility( member );
- }
-
- private SetAccessibility(Member member) {
- this.member = member;
- }
-
- public Object run() {
- ReflectionHelper.setAccessibility( member );
- return member;
- }
-}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationFactory.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -24,8 +24,8 @@
import java.lang.reflect.Proxy;
import java.security.AccessController;
-import org.hibernate.validator.util.GetConstructor;
-import org.hibernate.validator.util.GetClassLoader;
+import org.hibernate.validator.util.privilegedactions.GetConstructor;
+import org.hibernate.validator.util.privilegedactions.GetClassLoader;
/**
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -27,7 +27,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import org.hibernate.validator.util.GetDeclaredMethods;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredMethods;
/**
* A concrete implementation of <code>Annotation</code> that pretends it is
a
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsField.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ContainsField implements PrivilegedAction<Boolean> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static ContainsField action(Class<?> clazz, String property) {
+ return new ContainsField( clazz, property );
+ }
+
+ private ContainsField(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Boolean run() {
+ try {
+ clazz.getDeclaredField( property );
+ return true;
+ }
+ catch ( NoSuchFieldException e ) {
+ return false;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsField.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/ContainsMethod.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ContainsMethod implements PrivilegedAction<Boolean> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static ContainsMethod action(Class<?> clazz, String property) {
+ return new ContainsMethod( clazz, property );
+ }
+
+ private ContainsMethod(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Boolean run() {
+ return ReflectionHelper.getMethod( clazz, property ) != null;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/ContainsMethod.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetAnnotationParameter.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.annotation.Annotation;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
+ private final Annotation annotation;
+ private final String parameterName;
+ private final Class<T> type;
+
+
+ public static <T> GetAnnotationParameter<T> action(Annotation annotation,
String parameterName, Class<T> type) {
+ return new GetAnnotationParameter<T>( annotation, parameterName, type );
+ }
+
+ private GetAnnotationParameter(Annotation annotation, String parameterName,
Class<T> type) {
+ this.annotation = annotation;
+ this.parameterName = parameterName;
+ this.type = type;
+ }
+
+ public T run() {
+ return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetAnnotationParameter.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetClassLoader.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetClassLoader.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetClassLoader.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetClassLoader.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,51 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public final class GetClassLoader implements PrivilegedAction<ClassLoader> {
+ private final Class<?> clazz;
+
+ public static GetClassLoader fromContext() {
+ return new GetClassLoader( null );
+ }
+
+ public static GetClassLoader fromClass(Class<?> clazz) {
+ if ( clazz == null ) {
+ throw new IllegalArgumentException( "Class is null" );
+ }
+ return new GetClassLoader( clazz );
+ }
+
+ private GetClassLoader(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public ClassLoader run() {
+ if ( clazz != null ) {
+ return clazz.getClassLoader();
+ }
+ else {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetClassLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetConstructor.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetConstructor.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetConstructor.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetConstructor.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Constructor;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetConstructor<T> implements
PrivilegedAction<Constructor<T>> {
+ private final Class<T> clazz;
+ private final Class<?>[] params;
+
+ public static <T> GetConstructor<T> action(Class<T> clazz,
Class<?>... params) {
+ return new GetConstructor<T>( clazz, params );
+ }
+
+ private GetConstructor(Class<T> clazz, Class<?>... params) {
+ this.clazz = clazz;
+ this.params = params;
+ }
+
+ public Constructor<T> run() {
+ try {
+ return clazz.getConstructor(params);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetConstructor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredField.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,51 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Field;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredField implements PrivilegedAction<Field> {
+ private final Class<?> clazz;
+ private final String fieldName;
+
+ public static GetDeclaredField action(Class<?> clazz, String fieldName) {
+ return new GetDeclaredField( clazz, fieldName );
+ }
+
+ private GetDeclaredField(Class<?> clazz, String fieldName) {
+ this.clazz = clazz;
+ this.fieldName = fieldName;
+ }
+
+ public Field run() {
+ try {
+ final Field field = clazz.getDeclaredField( fieldName );
+ ReflectionHelper.setAccessibility( field );
+ return field;
+ }
+ catch ( NoSuchFieldException e ) {
+ return null;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredField.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredFields.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredFields.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredFields.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredFields.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,40 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Field;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredFields implements PrivilegedAction<Field[]> {
+ private final Class<?> clazz;
+
+ public static GetDeclaredFields action(Class<?> clazz) {
+ return new GetDeclaredFields( clazz );
+ }
+
+ private GetDeclaredFields(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Field[] run() {
+ return clazz.getDeclaredFields();
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredFields.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredMethods.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetDeclaredMethods.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredMethods.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredMethods.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,40 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Method;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetDeclaredMethods implements PrivilegedAction<Method[]> {
+ private final Class<?> clazz;
+
+ public static GetDeclaredMethods action(Class<?> clazz) {
+ return new GetDeclaredMethods( clazz );
+ }
+
+ private GetDeclaredMethods(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Method[] run() {
+ return clazz.getDeclaredMethods();
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetDeclaredMethods.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethod.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethod.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethod.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethod.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethod implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String methodName;
+
+ public static GetMethod action(Class<?> clazz, String methodName) {
+ return new GetMethod( clazz, methodName );
+ }
+
+ private GetMethod(Class<?> clazz, String methodName) {
+ this.clazz = clazz;
+ this.methodName = methodName;
+ }
+
+ public Method run() {
+ try {
+ return clazz.getMethod(methodName);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethod.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethodFromPropertyName.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static GetMethodFromPropertyName action(Class<?> clazz, String property) {
+ return new GetMethodFromPropertyName( clazz, property );
+ }
+
+ private GetMethodFromPropertyName(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Method run() {
+ return ReflectionHelper.getMethod( clazz, property );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethodFromPropertyName.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethods.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/GetMethods.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethods.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethods.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,40 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Method;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethods implements PrivilegedAction<Method[]> {
+ private final Class<?> clazz;
+
+ public static GetMethods action(Class<?> clazz) {
+ return new GetMethods( clazz );
+ }
+
+ private GetMethods(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Method[] run() {
+ return clazz.getMethods();
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/GetMethods.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/LoadClass.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/LoadClass.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/LoadClass.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/LoadClass.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,56 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class LoadClass implements PrivilegedAction<Class<?>> {
+ private final String className;
+ private final Class<?> caller;
+
+ public static LoadClass action(String className, Class<?> caller) {
+ return new LoadClass( className, caller );
+ }
+
+ private LoadClass(String className, Class<?> caller) {
+ this.className = className;
+ this.caller = caller;
+ }
+
+ public Class<?> run() {
+ try {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if ( contextClassLoader != null ) {
+ return contextClassLoader.loadClass( className );
+ }
+ }
+ catch ( Throwable e ) {
+ // ignore
+ }
+ try {
+ return Class.forName( className, true, caller.getClassLoader() );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException("Unable to load class: " + className, e);
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/LoadClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/NewInstance.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,72 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * Execute instance creation as privileged action.
+ *
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public class NewInstance<T> implements PrivilegedAction<T> {
+ private final Class<T> clazz;
+ private final String message;
+ private final Class<?>[] parameterTypes;
+ private final Object[] initArgs;
+
+ public static <T> NewInstance<T> action(Class<T> clazz, String
message, Object... initArgs) {
+ return new NewInstance<T>( clazz, message, initArgs );
+ }
+
+ private NewInstance(Class<T> clazz, String message, Object... initArgs) {
+ this.clazz = clazz;
+ this.message = message;
+ this.initArgs = initArgs;
+ this.parameterTypes = new Class<?>[initArgs.length];
+ for ( int i = 0; i < initArgs.length; i++ ) {
+ this.parameterTypes[i] = initArgs[i].getClass();
+ }
+ }
+
+ public T run() {
+ try {
+ Constructor<T> constructor = clazz.getConstructor( parameterTypes );
+ return constructor.newInstance( initArgs );
+ }
+ catch ( InstantiationException e ) {
+ throw new ValidationException( "Unable to instantiate " + message + ":
" + clazz, e );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException( "Unable to instantiate " + clazz, e );
+ }
+ catch ( NoSuchMethodException e ) {
+ throw new ValidationException( "Unable to instantiate " + clazz, e );
+ }
+ catch ( InvocationTargetException e ) {
+ throw new ValidationException( "Unable to instantiate " + clazz, e );
+ }
+ catch ( RuntimeException e ) {
+ throw new ValidationException( "Unable to instantiate " + clazz, e );
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/NewInstance.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
(from rev 19558,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/SetAccessibility.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.util.privilegedactions;
+
+import java.lang.reflect.Member;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class SetAccessibility implements PrivilegedAction<Object> {
+ private final Member member;
+
+ public static SetAccessibility action(Member member) {
+ return new SetAccessibility( member );
+ }
+
+ private SetAccessibility(Member member) {
+ this.member = member;
+ }
+
+ public Object run() {
+ ReflectionHelper.setAccessibility( member );
+ return member;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/privilegedactions/SetAccessibility.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/ValidationXmlParser.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -37,10 +37,10 @@
import org.slf4j.Logger;
import org.xml.sax.SAXException;
-import org.hibernate.validator.util.GetClassLoader;
-import org.hibernate.validator.util.LoadClass;
+import org.hibernate.validator.util.privilegedactions.GetClassLoader;
+import org.hibernate.validator.util.privilegedactions.LoadClass;
import org.hibernate.validator.util.LoggerFactory;
-import org.hibernate.validator.util.NewInstance;
+import org.hibernate.validator.util.privilegedactions.NewInstance;
/**
* Parser for <i>validation.xml</i> using JAXB.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/xml/XmlMappingParser.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -54,13 +54,13 @@
import org.hibernate.validator.metadata.ConstraintHelper;
import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.metadata.MetaConstraint;
-import org.hibernate.validator.util.ContainsField;
-import org.hibernate.validator.util.ContainsMethod;
-import org.hibernate.validator.util.GetClassLoader;
-import org.hibernate.validator.util.GetDeclaredField;
-import org.hibernate.validator.util.GetMethod;
-import org.hibernate.validator.util.GetMethodFromPropertyName;
-import org.hibernate.validator.util.LoadClass;
+import org.hibernate.validator.util.privilegedactions.ContainsField;
+import org.hibernate.validator.util.privilegedactions.ContainsMethod;
+import org.hibernate.validator.util.privilegedactions.GetClassLoader;
+import org.hibernate.validator.util.privilegedactions.GetDeclaredField;
+import org.hibernate.validator.util.privilegedactions.GetMethod;
+import org.hibernate.validator.util.privilegedactions.GetMethodFromPropertyName;
+import org.hibernate.validator.util.privilegedactions.LoadClass;
import org.hibernate.validator.util.LoggerFactory;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -17,6 +17,8 @@
*/
package org.hibernate.validator.test.cfg;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ValidationException;
@@ -29,6 +31,7 @@
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
import org.hibernate.validator.cfg.ConstraintMapping;
+import org.hibernate.validator.cfg.FutureDefinition;
import org.hibernate.validator.cfg.MinDefinition;
import org.hibernate.validator.cfg.NotNullDefinition;
import org.hibernate.validator.test.util.TestUtil;
@@ -89,11 +92,37 @@
assertConstraintViolation( violations.iterator().next(), "may not be null"
);
}
- @Test
- public void testSingleConstraintWrongAccessType() {
+ @Test(enabled = false)
+ public void testInheritedConstraint() {
HibernateValidatorConfiguration config = TestUtil.getConfiguration(
HibernateValidator.class );
ConstraintMapping mapping = new ConstraintMapping();
+ mapping.type( Marathon.class )
+ .property( "name", METHOD )
+ .constraint( NotNullDefinition.class )
+ .type( Tournament.class )
+ .property( "tournamentDate", METHOD )
+ .constraint( FutureDefinition.class );
+
+ config.addMapping( mapping );
+
+ ValidatorFactory factory = config.buildValidatorFactory();
+ Validator validator = factory.getValidator();
+
+ Marathon marathon = new Marathon();
+ marathon.setName( "New York Marathon" );
+ Calendar cal = GregorianCalendar.getInstance();
+ cal.set( Calendar.YEAR, -1 );
+ marathon.setTournamentDate( cal.getTime() );
+
+ Set<ConstraintViolation<Marathon>> violations = validator.validate(
marathon );
+ assertNumberOfViolations( violations, 1 );
+ assertConstraintViolation( violations.iterator().next(), "may not be null"
);
+ }
+
+ @Test
+ public void testSingleConstraintWrongAccessType() {
+ ConstraintMapping mapping = new ConstraintMapping();
try {
mapping.type( Marathon.class )
.property( "numberOfRunners", METHOD )
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
@@ -17,17 +17,18 @@
*/
package org.hibernate.validator.test.cfg;
-import javax.validation.constraints.Min;
-import javax.validation.constraints.NotNull;
+import java.util.Date;
/**
* @author Hardy Ferentschik
*/
-public class Marathon {
+public class Marathon implements Tournament {
private String name;
private long numberOfRunners;
+ private Date tournamentDate;
+
public String getName() {
return name;
}
@@ -35,6 +36,14 @@
public void setName(String name) {
this.name = name;
}
+
+ public Date getTournamentDate() {
+ return tournamentDate;
+ }
+
+ public void setTournamentDate(Date tournamentDate) {
+ this.tournamentDate = tournamentDate;
+ }
}
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Tournament.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Tournament.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Tournament.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -0,0 +1,29 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.hibernate.validator.test.cfg;
+
+import java.util.Date;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Tournament {
+ Date getTournamentDate();
+}
+
+
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -30,7 +30,7 @@
import org.testng.annotations.Test;
import org.hibernate.validator.metadata.ConstraintHelper;
-import org.hibernate.validator.util.SetAccessibility;
+import org.hibernate.validator.util.privilegedactions.SetAccessibility;
/**
* @author Hardy Ferentschik
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java 2010-05-20
10:29:39 UTC (rev 19565)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java 2010-05-20
11:58:01 UTC (rev 19566)
@@ -46,7 +46,7 @@
import static org.testng.Assert.fail;
/**
- * Tests for the <code>ReflectionHelper</code>.
+ * Tests for the {@code ReflectionHelper}.
*
* @author Hardy Ferentschik
*/