polishing

This commit is contained in:
Juergen Hoeller 2009-02-16 01:43:49 +00:00
parent d56419dad9
commit 5a09a2d642
5 changed files with 32 additions and 31 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,7 +62,7 @@ class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
// method due to lack of bridge method resolution, in case of the getter using a // method due to lack of bridge method resolution, in case of the getter using a
// covariant return type whereas the setter is defined for the concrete property type. // covariant return type whereas the setter is defined for the concrete property type.
writeMethodToUse = ClassUtils.getMethodIfAvailable(this.beanClass, writeMethodToUse = ClassUtils.getMethodIfAvailable(this.beanClass,
"set" + StringUtils.capitalize(getName()), new Class[] {readMethodToUse.getReturnType()}); "set" + StringUtils.capitalize(getName()), readMethodToUse.getReturnType());
} }
this.readMethod = readMethodToUse; this.readMethod = readMethodToUse;
this.writeMethod = writeMethodToUse; this.writeMethod = writeMethodToUse;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -305,9 +305,10 @@ public class MBeanExporter extends MBeanRegistrationSupport
/** /**
* Indicates whether Spring should ensure that {@link ObjectName ObjectNames} * Indicates whether Spring should ensure that {@link ObjectName ObjectNames}
* generated by the configured {@link ObjectNamingStrategy} for * generated by the configured {@link ObjectNamingStrategy} for
* runtime-registered MBeans should be modified to ensure uniqueness * runtime-registered MBeans ({@link #registerManagedResource}) should get
* for every instance of a managed <code>Class</code>. * modified: to ensure uniqueness for every instance of a managed <code>Class</code>.
* <p>The default value is <code>true</code>. * <p>The default value is <code>true</code>.
* @see #registerManagedResource
* @see JmxUtils#appendIdentityToObjectName(javax.management.ObjectName, Object) * @see JmxUtils#appendIdentityToObjectName(javax.management.ObjectName, Object)
*/ */
public void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames) { public void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames) {

View File

@ -13,8 +13,8 @@
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
Defines the elements used to configure various Java EE (J2EE) related Defines configuration elements for access to traditional Java EE components
technologies such as JNDI lookups and EJBs. such as JNDI resources and EJB session beans.
]]></xsd:documentation> ]]></xsd:documentation>
</xsd:annotation> </xsd:annotation>
@ -178,7 +178,7 @@
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
The JNDI name to look up. This may be a fully-qualified JNDI path The JNDI name to look up. This may be a fully-qualified JNDI path
or a local J2EE environment naming context path in which case the or a local Java EE environment naming context path in which case the
prefix "java:comp/env/" will be prepended if applicable. prefix "java:comp/env/" will be prepended if applicable.
]]></xsd:documentation> ]]></xsd:documentation>
</xsd:annotation> </xsd:annotation>
@ -186,7 +186,7 @@
<xsd:attribute name="resource-ref" type="xsd:boolean" default="true"> <xsd:attribute name="resource-ref" type="xsd:boolean" default="true">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
Controls whether the lookup occurs in a J2EE container, i.e. if the Controls whether the lookup occurs in a Java EE container, i.e. if the
prefix "java:comp/env/" needs to be added if the JNDI name doesn't prefix "java:comp/env/" needs to be added if the JNDI name doesn't
already contain it. Default is "true" (since Spring 2.5). already contain it. Default is "true" (since Spring 2.5).
]]></xsd:documentation> ]]></xsd:documentation>
@ -195,7 +195,13 @@
<xsd:attribute name="expose-access-context" type="xsd:boolean" default="false"> <xsd:attribute name="expose-access-context" type="xsd:boolean" default="false">
<xsd:annotation> <xsd:annotation>
<xsd:documentation><![CDATA[ <xsd:documentation><![CDATA[
TODO Set whether to expose the JNDI environment context for all access to the target
EJB, i.e. for all method invocations on the exposed object reference.
Default is "false", i.e. to only expose the JNDI context for object lookup.
Switch this flag to "true" in order to expose the JNDI environment (including
the authorization context) for each EJB invocation, as needed by WebLogic
for EJBs with authorization requirements.
]]></xsd:documentation> ]]></xsd:documentation>
</xsd:annotation> </xsd:annotation>
</xsd:attribute> </xsd:attribute>

View File

@ -28,6 +28,7 @@ import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.PropertyAccessor; import org.springframework.expression.PropertyAccessor;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/** /**
* Simple PropertyResolver that uses reflection to access properties for reading and writing. A property can be accessed * Simple PropertyResolver that uses reflection to access properties for reading and writing. A property can be accessed
@ -225,21 +226,17 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
protected Method findGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) { protected Method findGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) {
Method[] ms = clazz.getMethods(); Method[] ms = clazz.getMethods();
// Try "get*" method... // Try "get*" method...
StringBuilder sb = new StringBuilder(propertyName.length() + 3); String getterName = "get" + StringUtils.capitalize(propertyName);
sb.append("get").append(propertyName.substring(0, 1).toUpperCase()).append(propertyName.substring(1));
String expectedGetterName = sb.toString();
for (Method method : ms) { for (Method method : ms) {
if (method.getName().equals(expectedGetterName) && method.getParameterTypes().length == 0 && if (method.getName().equals(getterName) && method.getParameterTypes().length == 0 &&
(!mustBeStatic || Modifier.isStatic(method.getModifiers()))) { (!mustBeStatic || Modifier.isStatic(method.getModifiers()))) {
return method; return method;
} }
} }
// Try "is*" method... // Try "is*" method...
sb = new StringBuilder(propertyName.length() + 2); getterName = "is" + StringUtils.capitalize(propertyName);
sb.append("is").append(propertyName.substring(0, 1).toUpperCase()).append(propertyName.substring(1));
expectedGetterName = sb.toString();
for (Method method : ms) { for (Method method : ms) {
if (method.getName().equals(expectedGetterName) && method.getParameterTypes().length == 0 && if (method.getName().equals(getterName) && method.getParameterTypes().length == 0 &&
boolean.class.equals(method.getReturnType()) && boolean.class.equals(method.getReturnType()) &&
(!mustBeStatic || Modifier.isStatic(method.getModifiers()))) { (!mustBeStatic || Modifier.isStatic(method.getModifiers()))) {
return method; return method;
@ -252,14 +249,11 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
* Find a setter method for the specified property. * Find a setter method for the specified property.
*/ */
protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) { protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) {
Method[] ms = clazz.getMethods(); Method[] methods = clazz.getMethods();
StringBuilder sb = new StringBuilder(propertyName.length() + 3); String setterName = "set" + StringUtils.capitalize(propertyName);
sb.append("set").append(propertyName.substring(0, 1).toUpperCase()).append(propertyName.substring(1)); for (Method method : methods) {
String setterName = sb.toString(); if (method.getName().equals(setterName) && method.getParameterTypes().length == 1 &&
for (Method method : ms) { (!mustBeStatic || Modifier.isStatic(method.getModifiers()))) {
if (method.getParameterTypes().length == 1 &&
(!mustBeStatic || Modifier.isStatic(method.getModifiers())) &&
method.getName().equals(setterName)) {
return method; return method;
} }
} }
@ -270,7 +264,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
* Find a field of a certain name on a specified class * Find a field of a certain name on a specified class
*/ */
protected Field findField(String name, Class<?> clazz, boolean mustBeStatic) { protected Field findField(String name, Class<?> clazz, boolean mustBeStatic) {
Field[] fields = clazz.getFields(); // TODO use getDeclaredFields() and search up hierarchy? Field[] fields = clazz.getFields();
for (Field field : fields) { for (Field field : fields) {
if (field.getName().equals(name) && (!mustBeStatic || Modifier.isStatic(field.getModifiers()))) { if (field.getName().equals(name) && (!mustBeStatic || Modifier.isStatic(field.getModifiers()))) {
return field; return field;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -99,7 +99,7 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
* @see InternalResourceView#setExposeContextBeansAsAttributes * @see InternalResourceView#setExposeContextBeansAsAttributes
*/ */
public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) { public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) {
this.exposeContextBeansAsAttributes = Boolean.valueOf(exposeContextBeansAsAttributes); this.exposeContextBeansAsAttributes = exposeContextBeansAsAttributes;
} }
/** /**
@ -117,10 +117,10 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
protected AbstractUrlBasedView buildView(String viewName) throws Exception { protected AbstractUrlBasedView buildView(String viewName) throws Exception {
InternalResourceView view = (InternalResourceView) super.buildView(viewName); InternalResourceView view = (InternalResourceView) super.buildView(viewName);
if (this.alwaysInclude != null) { if (this.alwaysInclude != null) {
view.setAlwaysInclude(this.alwaysInclude.booleanValue()); view.setAlwaysInclude(this.alwaysInclude);
} }
if (this.exposeContextBeansAsAttributes != null) { if (this.exposeContextBeansAsAttributes != null) {
view.setExposeContextBeansAsAttributes(this.exposeContextBeansAsAttributes.booleanValue()); view.setExposeContextBeansAsAttributes(this.exposeContextBeansAsAttributes);
} }
if (this.exposedContextBeanNames != null) { if (this.exposedContextBeanNames != null) {
view.setExposedContextBeanNames(this.exposedContextBeanNames); view.setExposedContextBeanNames(this.exposedContextBeanNames);