@Override public void setAsText(String text) throws IllegalArgumentException { this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new MutablePropertyValues(props)); }
@Override public void setAsText(@Nullable String text) throws IllegalArgumentException { if (text == null) { throw new IllegalArgumentException("JndiTemplate cannot be created from null string"); } if ("".equals(text)) { // empty environment setValue(new JndiTemplate()); } else { // we have a non-empty properties string this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new JndiTemplate(props)); } }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
@Override public void setAsText(@Nullable String text) throws IllegalArgumentException { if (text == null) { throw new IllegalArgumentException("JndiTemplate cannot be created from null string"); } if ("".equals(text)) { // empty environment setValue(new JndiTemplate()); } else { // we have a non-empty properties string this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new JndiTemplate(props)); } }
@Override public void setAsText(String text) throws IllegalArgumentException { this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new MutablePropertyValues(props)); }
@Test public void handlesEmptyPropertyWithoutEquals() { String s = "foo\nme=mi\nx=x"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains three entries", p.entrySet().size() == 3); assertTrue("foo is empty", p.get("foo").equals("")); assertTrue("me=mi", p.get("me").equals("mi")); }
@Test public void handlesEmptyProperty() { String s = "foo=bar\nme=mi\nx="; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains two entries", p.entrySet().size() == 3); assertTrue("foo=bar", p.get("foo").equals("bar")); assertTrue("me=mi", p.get("me").equals("mi")); assertTrue("x='y=z'", p.get("x").equals("")); }
@Test public void oneProperty() { String s = "foo=bar"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains one entry", p.entrySet().size() == 1); assertTrue("foo=bar", p.get("foo").equals("bar")); }
@Test public void twoProperties() { String s = "foo=bar with whitespace\n" + "me=mi"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains two entries", p.entrySet().size() == 2); assertTrue("foo=bar with whitespace", p.get("foo").equals("bar with whitespace")); assertTrue("me=mi", p.get("me").equals("mi")); }
@Test public void handlesEqualsInValue() { String s = "foo=bar\n" + "me=mi\n" + "x=y=z"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains two entries", p.entrySet().size() == 3); assertTrue("foo=bar", p.get("foo").equals("bar")); assertTrue("me=mi", p.get("me").equals("mi")); assertTrue("x='y=z'", p.get("x").equals("y=z")); }
@Test public void nullValue() { PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(null); Properties p = (Properties) pe.getValue(); assertEquals(0, p.size()); }
/** * Comments begin with # */ @Test public void ignoresCommentLinesAndEmptyLines() { String s = "#Ignore this comment\n" + "foo=bar\n" + "#Another=comment more junk /\n" + "me=mi\n" + "x=x\n" + "\n"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains three entries", p.entrySet().size() == 3); assertTrue("foo is bar", p.get("foo").equals("bar")); assertTrue("me=mi", p.get("me").equals("mi")); }
@Test public void emptyString() { PropertiesEditor pe = new PropertiesEditor(); pe.setAsText(""); Properties p = (Properties) pe.getValue(); assertTrue("empty string means empty properties", p.isEmpty()); }
/** * We'll typically align by indenting with tabs or spaces. * These should be ignored if at the beginning of a line. * We must ensure that comment lines beginning with whitespace are * still ignored: The standard syntax doesn't allow this on JDK 1.3. */ @Test public void ignoresLeadingSpacesAndTabs() { String s = " #Ignore this comment\n" + "\t\tfoo=bar\n" + "\t#Another comment more junk \n" + " me=mi\n" + "x=x\n" + "\n"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains 3 entries, not " + p.size(), p.size() == 3); assertTrue("foo is bar", p.get("foo").equals("bar")); assertTrue("me=mi", p.get("me").equals("mi")); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
@Test public void testIntArray() throws Exception { DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar(); BeanWithIntArray result = new BeanWithIntArray(); mapper.setCustomEditors(Collections.singletonMap(int[].class, new IntArrayPropertyEditor())); BeanWrapperImpl wrapper = new BeanWrapperImpl(result); mapper.registerCustomEditors(wrapper); PropertiesEditor editor = new PropertiesEditor(); editor.setAsText("numbers=1,2,3, 4"); Properties props = (Properties) editor.getValue(); wrapper.setPropertyValues(props); assertEquals(4, result.numbers[3]); }
@Test public void testPlainBeanWrapper() throws Exception { TestObject result = new TestObject(); BeanWrapperImpl wrapper = new BeanWrapperImpl(result); PropertiesEditor editor = new PropertiesEditor(); editor.setAsText("varString=This is some dummy string\nvarBoolean=true\nvarChar=C"); Properties props = (Properties) editor.getValue(); wrapper.setPropertyValues(props); assertEquals("This is some dummy string", result.getVarString()); assertEquals(true, result.isVarBoolean()); assertEquals('C', result.getVarChar()); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new MutablePropertyValues(props)); }
@Override public void setAsText(String text) throws IllegalArgumentException { this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new MutablePropertyValues(props)); }
/** * @see java.beans.PropertyEditor#setAsText(java.lang.String) */ public void setAsText(String s) throws IllegalArgumentException { PropertiesEditor pe = new PropertiesEditor(); pe.setAsText(s); Properties props = (Properties) pe.getValue(); setValue(new MutablePropertyValues(props)); }