KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jndi > JndiTemplateEditor


1 /*
2  * Copyright 2002-2005 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
17 package org.springframework.jndi;
18
19 import java.beans.PropertyEditorSupport JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import org.springframework.beans.propertyeditors.PropertiesEditor;
23
24 /**
25  * Properties editor for JndiTemplate objects. Allows properties of type
26  * JndiTemplate to be populated with a properties-format string.
27  *
28  * @author Rod Johnson
29  * @since 09.05.2003
30  */

31 public class JndiTemplateEditor extends PropertyEditorSupport JavaDoc {
32
33     private final PropertiesEditor propertiesEditor = new PropertiesEditor();
34
35     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
36         if (text == null) {
37             throw new IllegalArgumentException JavaDoc("JndiTemplate cannot be created from null string");
38         }
39         if ("".equals(text)) {
40             // empty environment
41
setValue(new JndiTemplate());
42         }
43         else {
44             // we have a non-empty properties string
45
this.propertiesEditor.setAsText(text);
46             Properties JavaDoc props = (Properties JavaDoc) this.propertiesEditor.getValue();
47             setValue(new JndiTemplate(props));
48         }
49     }
50
51 }
52
Popular Tags