You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2009/06/10 12:27:27 UTC
svn commit: r783281 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/util/BooleanEditor.java
test/java/org/apache/activemq/util/ReflectionSupportTest.java
Author: gtully
Date: Wed Jun 10 10:27:26 2009
New Revision: 783281
URL: http://svn.apache.org/viewvc?rev=783281&view=rev
Log:
resolve https://issues.apache.org/activemq/browse/AMQ-2274 - add simple Boolean PropertyEditor implementation
Added:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java (with props)
Modified:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java
Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java?rev=783281&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java (added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java Wed Jun 10 10:27:26 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.util;
+
+import java.beans.PropertyEditorSupport;
+
+public class BooleanEditor extends PropertyEditorSupport {
+
+ public String getJavaInitializationString() {
+ return String.valueOf(((Boolean)getValue()).booleanValue());
+ }
+
+ public String getAsText() {
+ return getJavaInitializationString();
+ }
+
+ public void setAsText(String text) throws java.lang.IllegalArgumentException {
+ if (text.toLowerCase().equals("true")) {
+ setValue(Boolean.TRUE);
+ } else if (text.toLowerCase().equals("false")) {
+ setValue(Boolean.FALSE);
+ } else {
+ throw new java.lang.IllegalArgumentException(text);
+ }
+ }
+
+ public String[] getTags() {
+ String result[] = { "true", "false" };
+ return result;
+ }
+}
Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java?rev=783281&r1=783280&r2=783281&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/ReflectionSupportTest.java Wed Jun 10 10:27:26 2009
@@ -84,4 +84,27 @@
assertEquals(nonFavoritesString, props.get("nonFavorites"));
assertNull(props.get("others"));
}
+
+ public void testSetBoolean() {
+
+ TestWitBoolean target = new TestWitBoolean();
+ assertTrue(!target.getKeepAlive());
+
+ IntrospectionSupport.setProperty(target, "keepAlive", "TRUE");
+ assertTrue(target.getKeepAlive());
+
+ IntrospectionSupport.setProperty(target, "keepAlive", "false");
+ assertTrue(!target.getKeepAlive());
+ }
+
+ public static class TestWitBoolean {
+ private Boolean keepAlive = new Boolean(false);
+ public Boolean getKeepAlive() {
+ return keepAlive;
+ }
+ public void setKeepAlive(Boolean keepAlive) {
+ this.keepAlive = keepAlive;
+ }
+ }
}
+