You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/03/09 20:25:33 UTC
svn commit: r921067 - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator:
core/ core/proxy/ util/
Author: gpetracek
Date: Tue Mar 9 19:25:32 2010
New Revision: 921067
URL: http://svn.apache.org/viewvc?rev=921067&view=rev
Log:
EXTVAL-87 initial implementation
Added:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/DefaultProxyHelper.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/ProxyHelper.java
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ProxyUtils.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java?rev=921067&r1=921066&r2=921067&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java Tue Mar 9 19:25:32 2010
@@ -109,6 +109,9 @@ public interface WebXmlParameter
static final String CUSTOM_FACES_MESSAGE_FACTORY = WebXmlUtils
.getInitParameter("CUSTOM_FACES_MESSAGE_FACTORY");
+ static final String CUSTOM_PROXY_HELPER = WebXmlUtils
+ .getInitParameter("CUSTOM_PROXY_HELPER");
+
/*
* activate
*/
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/DefaultProxyHelper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/DefaultProxyHelper.java?rev=921067&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/DefaultProxyHelper.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/DefaultProxyHelper.java Tue Mar 9 19:25:32 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.proxy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class DefaultProxyHelper implements ProxyHelper
+{
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ public DefaultProxyHelper()
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(getClass().getName() + " instantiated");
+ }
+ }
+
+ public <T> Class<T> getUnproxiedClass(Class currentClass, Class<T> targetType)
+ {
+ return (Class<T>)getUnproxiedClass(currentClass);
+ }
+
+ public Class getUnproxiedClass(Class currentClass)
+ {
+ if(isProxiedClass(currentClass))
+ {
+ return ClassUtils.tryToLoadClassForName(getNameOfClass(currentClass));
+ }
+ return currentClass;
+ }
+
+ public String getNameOfClass(Class proxiedClass)
+ {
+ if (isProxiedClass(proxiedClass))
+ {
+ return proxiedClass.getName().substring(0, proxiedClass.getName().indexOf("$"));
+ }
+ return proxiedClass.getName();
+ }
+
+ public String getClassNameOfObject(Object proxiedObject)
+ {
+ if(proxiedObject != null)
+ {
+ return getNameOfClass(proxiedObject.getClass());
+ }
+ return null;
+ }
+
+ public boolean isProxiedClass(Class currentClass)
+ {
+ return currentClass.getName().contains("$$EnhancerByCGLIB$$")
+ || currentClass.getName().contains("$$FastClassByCGLIB$$");
+ }
+
+ public boolean isProxiedObject(Object proxiedObject)
+ {
+ return proxiedObject != null && isProxiedClass(proxiedObject.getClass());
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/ProxyHelper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/ProxyHelper.java?rev=921067&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/ProxyHelper.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/proxy/ProxyHelper.java Tue Mar 9 19:25:32 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.proxy;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface ProxyHelper
+{
+ Class getUnproxiedClass(Class currentClass);
+
+ <T> Class<T> getUnproxiedClass(Class currentClass, Class<T> targetType);
+
+ String getNameOfClass(Class proxiedClass);
+
+ String getClassNameOfObject(Object proxiedObject);
+
+ boolean isProxiedClass(Class currentClass);
+
+ boolean isProxiedObject(Object proxiedObject);
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ProxyUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ProxyUtils.java?rev=921067&r1=921066&r2=921067&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ProxyUtils.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ProxyUtils.java Tue Mar 9 19:25:32 2010
@@ -18,8 +18,11 @@
*/
package org.apache.myfaces.extensions.validator.util;
-import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.core.proxy.ProxyHelper;
+import org.apache.myfaces.extensions.validator.core.proxy.DefaultProxyHelper;
+import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
/**
* @author Gerhard Petracek
@@ -28,33 +31,62 @@ import org.apache.myfaces.extensions.val
@UsageInformation(UsageCategory.INTERNAL)
public class ProxyUtils
{
+ private static ProxyHelper proxyHelper;
+
public static <T> Class<T> getUnproxiedClass(Class currentClass, Class<T> targetType)
{
- return (Class<T>)getUnproxiedClass(currentClass);
+ return getProxyHelper().getUnproxiedClass(currentClass, targetType);
}
public static Class getUnproxiedClass(Class currentClass)
{
- if(isProxiedClass(currentClass))
- {
- return ClassUtils.tryToLoadClassForName(getClassName(currentClass));
- }
- return currentClass;
+ return getProxyHelper().getUnproxiedClass(currentClass);
}
public static String getClassName(Class proxiedClass)
{
- if (isProxiedClass(proxiedClass))
- {
- return proxiedClass.getName().substring(0, proxiedClass.getName().indexOf("$"));
- }
- return proxiedClass.getName();
+ return getProxyHelper().getNameOfClass(proxiedClass);
+ }
+
+ public static String getClassNameOfObject(Object proxiedObject)
+ {
+ return getProxyHelper().getClassNameOfObject(proxiedObject);
}
public static boolean isProxiedClass(Class currentClass)
{
- return currentClass.getName().contains("$$EnhancerByCGLIB$$")
- || currentClass.getName().contains("$$FastClassByCGLIB$$");
+ return getProxyHelper().isProxiedClass(currentClass);
+ }
+
+ public static boolean isProxiedObject(Object proxiedObject)
+ {
+ return getProxyHelper().isProxiedObject(proxiedObject);
}
+ private static ProxyHelper getProxyHelper()
+ {
+ if (proxyHelper == null)
+ {
+ proxyHelper = createProxyHelper();
+ }
+ return proxyHelper;
+ }
+
+ //don't use the default approach (factory finder) - ProxyHelper is called too often...
+ private static ProxyHelper createProxyHelper()
+ {
+ String customProxyHelperClassName = WebXmlParameter.CUSTOM_PROXY_HELPER;
+
+ ProxyHelper result = null;
+ if(customProxyHelperClassName != null && !"".equals(customProxyHelperClassName))
+ {
+ result = (ProxyHelper)ClassUtils.tryToInstantiateClassForName(customProxyHelperClassName);
+ }
+ if(result == null)
+ {
+ result = new DefaultProxyHelper();
+ }
+
+ return result;
+ }
}