From 1b26e8f9c6112d3343cf0351e0d91fd7ab39fba8 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 23 Oct 2008 10:35:03 +0000 Subject: [PATCH] Removed commons atts support for JMX, made ModelMap generic --- .../AttributesJmxAttributeSource.java | 203 ------------------ .../java/org/springframework/ui/ModelMap.java | 6 +- 2 files changed, 3 insertions(+), 206 deletions(-) delete mode 100644 org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java b/org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java deleted file mode 100644 index e5a0e00d44..0000000000 --- a/org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2002-2005 the original author or authors. - * - * 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.springframework.jmx.export.metadata; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Iterator; - -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.metadata.Attributes; -import org.springframework.util.Assert; - -/** - * Implementation of the JmxAttributeSource interface that - * reads metadata via Spring's Attributes abstraction. - * - *

Typically used for reading in source-level attributes via - * Commons Attributes. - * - * @author Rob Harrop - * @since 1.2 - * @see org.springframework.metadata.Attributes - * @see org.springframework.metadata.commons.CommonsAttributes - */ -public class AttributesJmxAttributeSource implements JmxAttributeSource, InitializingBean { - - /** - * Underlying Attributes implementation that we're using. - */ - private Attributes attributes; - - - /** - * Create a new AttributesJmxAttributeSource. - * @see #setAttributes - */ - public AttributesJmxAttributeSource() { - } - - /** - * Create a new AttributesJmxAttributeSource. - * @param attributes the Attributes implementation to use - * @see org.springframework.metadata.commons.CommonsAttributes - */ - public AttributesJmxAttributeSource(Attributes attributes) { - if (attributes == null) { - throw new IllegalArgumentException("Attributes is required"); - } - this.attributes = attributes; - } - - /** - * Set the Attributes implementation to use. - * @see org.springframework.metadata.commons.CommonsAttributes - */ - public void setAttributes(Attributes attributes) { - this.attributes = attributes; - } - - public void afterPropertiesSet() { - if (this.attributes == null) { - throw new IllegalArgumentException("'attributes' is required"); - } - } - - - /** - * If the specified class has a ManagedResource attribute, - * then it is returned. Otherwise returns null. - * @param clazz the class to read the attribute data from - * @return the attribute, or null if not found - * @throws InvalidMetadataException if more than one attribute exists - */ - public ManagedResource getManagedResource(Class clazz) { - Assert.notNull(this.attributes, "'attributes' is required"); - Collection attrs = this.attributes.getAttributes(clazz, ManagedResource.class); - if (attrs.isEmpty()) { - return null; - } - else if (attrs.size() == 1) { - return (ManagedResource) attrs.iterator().next(); - } - else { - throw new InvalidMetadataException("A Class can have only one ManagedResource attribute"); - } - } - - /** - * If the specified method has a ManagedAttribute attribute, - * then it is returned. Otherwise returns null. - * @param method the method to read the attribute data from - * @return the attribute, or null if not found - * @throws InvalidMetadataException if more than one attribute exists, - * or if the supplied method does not represent a JavaBean property - */ - public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { - Assert.notNull(this.attributes, "'attributes' is required"); - PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); - if (pd == null) { - throw new InvalidMetadataException( - "The ManagedAttribute attribute is only valid for JavaBean properties: " + - "use ManagedOperation for methods"); - } - Collection attrs = this.attributes.getAttributes(method, ManagedAttribute.class); - if (attrs.isEmpty()) { - return null; - } - else if (attrs.size() == 1) { - return (ManagedAttribute) attrs.iterator().next(); - } - else { - throw new InvalidMetadataException("A Method can have only one ManagedAttribute attribute"); - } - } - - /** - * If the specified method has a ManagedOperation attribute, - * then it is returned. Otherwise return null. - * @param method the method to read the attribute data from - * @return the attribute, or null if not found - * @throws InvalidMetadataException if more than one attribute exists, - * or if the supplied method represents a JavaBean property - */ - public ManagedOperation getManagedOperation(Method method) { - Assert.notNull(this.attributes, "'attributes' is required"); - PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); - if (pd != null) { - throw new InvalidMetadataException( - "The ManagedOperation attribute is not valid for JavaBean properties: " + - "use ManagedAttribute instead"); - } - Collection attrs = this.attributes.getAttributes(method, ManagedOperation.class); - if (attrs.isEmpty()) { - return null; - } - else if (attrs.size() == 1) { - return (ManagedOperation) attrs.iterator().next(); - } - else { - throw new InvalidMetadataException("A Method can have only one ManagedAttribute attribute"); - } - } - - /** - * If the specified method has ManagedOperationParameter attributes, - * then these are returned, otherwise a zero length array is returned. - * @param method the method to get the managed operation parameters for - * @return the array of ManagedOperationParameter objects - * @throws InvalidMetadataException if the number of ManagedOperationParameter - * attributes does not match the number of parameters in the method - */ - public ManagedOperationParameter[] getManagedOperationParameters(Method method) - throws InvalidMetadataException { - - Assert.notNull(this.attributes, "'attributes' is required"); - Collection attrs = this.attributes.getAttributes(method, ManagedOperationParameter.class); - if (attrs.size() == 0) { - return new ManagedOperationParameter[0]; - } - else if (attrs.size() != method.getParameterTypes().length) { - throw new InvalidMetadataException( - "Method [" + method + "] has an incorrect number of ManagedOperationParameters specified"); - } - else { - ManagedOperationParameter[] params = new ManagedOperationParameter[attrs.size()]; - for (Iterator it = attrs.iterator(); it.hasNext();) { - ManagedOperationParameter param = (ManagedOperationParameter) it.next(); - if (param.getIndex() < 0 || param.getIndex() >= params.length) { - throw new InvalidMetadataException( - "ManagedOperationParameter index for [" + param.getName() + "] is out of bounds"); - } - params[param.getIndex()] = param; - } - return params; - } - } - - /** - * If the specified has {@link ManagedNotification} attributes these are returned, otherwise - * a zero-length array is returned. - */ - public ManagedNotification[] getManagedNotifications(Class clazz) { - Assert.notNull(this.attributes, "'attributes' is required"); - Collection attrs = this.attributes.getAttributes(clazz, ManagedNotification.class); - return attrs.isEmpty() ? new ManagedNotification[0] : (ManagedNotification[]) attrs.toArray(new ManagedNotification[attrs.size()]); - } -} diff --git a/org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java b/org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java index d320cc2ea7..d19715faa8 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java @@ -100,7 +100,7 @@ public class ModelMap extends LinkedHashMap { * Map, using attribute name generation for each element. * @see #addAttribute(Object) */ - public ModelMap addAllAttributes(Collection attributeValues) { + public ModelMap addAllAttributes(Collection attributeValues) { if (attributeValues != null) { for (Iterator it = attributeValues.iterator(); it.hasNext();) { addAttribute(it.next()); @@ -113,7 +113,7 @@ public class ModelMap extends LinkedHashMap { * Copy all attributes in the supplied Map into this Map. * @see #addAttribute(String, Object) */ - public ModelMap addAllAttributes(Map attributes) { + public ModelMap addAllAttributes(Map attributes) { if (attributes != null) { putAll(attributes); } @@ -125,7 +125,7 @@ public class ModelMap extends LinkedHashMap { * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ - public ModelMap mergeAttributes(Map attributes) { + public ModelMap mergeAttributes(Map attributes) { if (attributes != null) { for (Iterator it = attributes.keySet().iterator(); it.hasNext();) { Object key = it.next(); -- GitLab