diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index 6b16c23ae9..669806bbef 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -39,6 +39,7 @@ import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TimeZone; +import java.util.UUID; import java.util.regex.Pattern; import org.springframework.beans.propertyeditors.ByteArrayPropertyEditor; @@ -61,6 +62,7 @@ import org.springframework.beans.propertyeditors.StringArrayPropertyEditor; import org.springframework.beans.propertyeditors.TimeZoneEditor; import org.springframework.beans.propertyeditors.URIEditor; import org.springframework.beans.propertyeditors.URLEditor; +import org.springframework.beans.propertyeditors.UUIDEditor; import org.springframework.core.convert.ConversionService; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourceArrayPropertyEditor; @@ -174,6 +176,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { this.defaultEditors.put(TimeZone.class, new TimeZoneEditor()); this.defaultEditors.put(URI.class, new URIEditor()); this.defaultEditors.put(URL.class, new URLEditor()); + this.defaultEditors.put(UUID.class, new UUIDEditor()); // Default instances of collection editors. // Can be overridden by registering custom instances of those as custom editors. diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CharsetEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CharsetEditor.java index c4f9d6cdb1..5d742a9253 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CharsetEditor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/CharsetEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -22,7 +22,8 @@ import java.nio.charset.Charset; import org.springframework.util.StringUtils; /** - * Editor for {@link Charset}, to directly populate a Charset property. + * Editor for java.nio.charset.Charset, translating charset + * String representations into Charset objects and back. * *

Expects the same syntax as Charset's {@link java.nio.charset.Charset#name()}, * e.g. UTF-8, ISO-8859-16, etc. diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/UUIDEditor.java b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/UUIDEditor.java new file mode 100644 index 0000000000..885676962b --- /dev/null +++ b/org.springframework.beans/src/main/java/org/springframework/beans/propertyeditors/UUIDEditor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2002-2010 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.beans.propertyeditors; + +import java.beans.PropertyEditorSupport; +import java.util.UUID; + +import org.springframework.util.StringUtils; + +/** + * Editor for java.util.UUID, translating UUID + * String representations into UUID objects and back. + * + * @author Juergen Hoeller + * @since 3.0.1 + * @see java.util.UUID + */ +public class UUIDEditor extends PropertyEditorSupport { + + @Override + public void setAsText(String text) throws IllegalArgumentException { + if (StringUtils.hasText(text)) { + setValue(UUID.fromString(text)); + } + else { + setValue(null); + } + } + + @Override + public String getAsText() { + UUID value = (UUID) getValue(); + return (value != null ? value.toString() : ""); + } + +}