KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > convert > support > ConverterPropertyEditorAdapter


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.binding.convert.support;
17
18 import java.beans.PropertyEditorSupport JavaDoc;
19
20 import org.springframework.binding.convert.ConversionExecutor;
21 import org.springframework.util.Assert;
22
23 /**
24  * Adapts a Converter to the PropertyEditor interface.
25  * <p>
26  * Note: with a converter, only forward conversion from-string-to-value is
27  * supported. Value-to-string conversion is not supported. If you need this
28  * capability, use a Formatter with a FormatterPropertyEditor adapter.
29  * @author Keith Donald
30  */

31 public class ConverterPropertyEditorAdapter extends PropertyEditorSupport JavaDoc {
32
33     private ConversionExecutor conversionExecutor;
34
35     public ConverterPropertyEditorAdapter(ConversionExecutor conversionExecutor) {
36         Assert.notNull(conversionExecutor, "A conversion executor is required");
37         Assert.isTrue(conversionExecutor.getSourceClass().equals(String JavaDoc.class),
38                 "A string conversion executor is required");
39         this.conversionExecutor = conversionExecutor;
40     }
41
42     public Class JavaDoc getTargetClass() {
43         return conversionExecutor.getTargetClass();
44     }
45
46     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
47         setValue(conversionExecutor.execute(text));
48     }
49
50     public String JavaDoc getAsText() {
51         throw new UnsupportedOperationException JavaDoc();
52     }
53 }
Popular Tags