01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import java.util.Properties;
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 {
32:
33: private final PropertiesEditor propertiesEditor = new PropertiesEditor();
34:
35: public void setAsText(String text) throws IllegalArgumentException {
36: if (text == null) {
37: throw new IllegalArgumentException(
38: "JndiTemplate cannot be created from null string");
39: }
40: if ("".equals(text)) {
41: // empty environment
42: setValue(new JndiTemplate());
43: } else {
44: // we have a non-empty properties string
45: this .propertiesEditor.setAsText(text);
46: Properties props = (Properties) this .propertiesEditor
47: .getValue();
48: setValue(new JndiTemplate(props));
49: }
50: }
51:
52: }
|