com.databasesandlife.util.wicket.UuidConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.wicket;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.Locale;
import java.util.UUID;
/**
* Wicket converter to allow user to enter UUIDs and display errors if they are not valid.
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class UuidConverter implements IConverter {
@Override public @CheckForNull UUID convertToObject(@CheckForNull String value, @Nonnull Locale locale)
throws ConversionException {
if (value == null) return null;
try { return UUID.fromString(value); }
catch (IllegalArgumentException e) {
throw new ConversionException("Cannot understand "+UuidConverter.class+" '" + value + "'")
.setSourceValue(value)
.setResourceKey("UuidConverter.IllegalArgumentException")
.setTargetType(UuidConverter.class)
.setConverter(this)
.setLocale(locale);
}
}
@Override public @CheckForNull String convertToString(@CheckForNull UUID value, @Nonnull Locale locale) {
if (value == null) return null;
return value.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy