Author: trustin
Date: Wed Nov 14 17:18:45 2007
New Revision: 595175
URL: http://svn.apache.org/viewvc?rev=595175&view=rev
Log:
* Moved JavaBeans PropertyEditors to org.apache.mina.integration.beans in
mina-core because these editors are shared among all IoC containers -
Springframework, JBoss Microcontainer and PicoContainer
Added:
mina/trunk/core/src/main/java/org/apache/mina/integration/
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
(with props)
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
(with props)
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
(with props)
mina/trunk/core/src/test/java/org/apache/mina/integration/
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
(with props)
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
(with props)
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
(with props)
Removed:
mina/trunk/integration-spring/src/main/java/org/apache/mina/integration/spring/InetAddressEditor.java
mina/trunk/integration-spring/src/main/java/org/apache/mina/integration/spring/InetSocketAddressEditor.java
mina/trunk/integration-spring/src/main/java/org/apache/mina/integration/spring/VmPipeAddressEditor.java
mina/trunk/integration-spring/src/main/java/org/apache/mina/integration/spring/package.html
mina/trunk/integration-spring/src/test/java/org/apache/mina/integration/spring/InetAddressEditorTest.java
mina/trunk/integration-spring/src/test/java/org/apache/mina/integration/spring/InetSocketAddressEditorTest.java
mina/trunk/integration-spring/src/test/java/org/apache/mina/integration/spring/VmPipeAddressEditorTest.java
Modified:
mina/trunk/example/src/main/resources/org/apache/mina/example/chat/serverContext.xml
Added:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
(added)
+++
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.mina.integration.beans;
+
+import java.beans.PropertyEditorSupport;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.mina.filter.firewall.BlacklistFilter;
+
+/**
+ * Java Bean [EMAIL PROTECTED] java.beans.PropertyEditor} which converts
Strings into
+ * [EMAIL PROTECTED] InetAddress} objects. This may be used together with
Spring to be able
+ * to set [EMAIL PROTECTED] InetAddress} bean properties, e.g.
+ * [EMAIL PROTECTED] BlacklistFilter#setBlacklist(InetAddress[])}.
+ * Simply calls [EMAIL PROTECTED] InetAddress#getByName(java.lang.String)} when
+ * converting from a String.
+ * <p>
+ * Use Spring's CustomEditorConfigurer to use this property editor in a Spring
+ * configuration file. See chapter 3.14 of the Spring Reference Documentation
+ * for more info.
+ * </p>
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Revision$, $Date$
+ *
+ * @see java.net.InetAddress
+ */
+public class InetAddressEditor extends PropertyEditorSupport {
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ if (text == null) {
+ throw new IllegalArgumentException("address is null.");
+ }
+ try {
+ setValue(InetAddress.getByName(text));
+ } catch (UnknownHostException uhe) {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(uhe);
+ throw iae;
+ }
+ }
+}
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetAddressEditor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
(added)
+++
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.mina.integration.beans;
+
+import java.beans.PropertyEditorSupport;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+/**
+ * Java Bean [EMAIL PROTECTED] java.beans.PropertyEditor} which converts
Strings into
+ * [EMAIL PROTECTED] InetSocketAddress} objects. Valid values include a
hostname or ip
+ * address and a port number separated by a ':'. If the hostname or ip address
+ * is omitted the wildcard address will be used. E.g.:
+ * <code>google.com:80</code>, <code>:22</code>, <code>192.168.0.1:110</code>.
+ * <p>
+ * Use Spring's CustomEditorConfigurer to use this property editor in a Spring
+ * configuration file. See chapter 3.14 of the Spring Reference Documentation
+ * for more info.
+ * </p>
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Revision$, $Date$
+ *
+ * @see java.net.InetSocketAddress
+ */
+public class InetSocketAddressEditor extends PropertyEditorSupport {
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue(parseSocketAddress(text));
+ }
+
+ private SocketAddress parseSocketAddress(String s) {
+ if (s == null) {
+ throw new IllegalArgumentException("socketAddress is null.");
+ }
+
+ s = s.trim();
+ int colonIndex = s.indexOf(":");
+ if (colonIndex > 0) {
+ String host = s.substring(0, colonIndex);
+ if (!"*".equals(host)) {
+ int port = parsePort(s.substring(colonIndex + 1));
+ return new InetSocketAddress(host, port);
+ }
+ }
+
+ int port = parsePort(s.substring(colonIndex + 1));
+ return new InetSocketAddress(port);
+ }
+
+ private int parsePort(String s) {
+ try {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("Illegal port number: " + s);
+ }
+ }
+}
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/InetSocketAddressEditor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
(added)
+++
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.mina.integration.beans;
+
+import java.beans.PropertyEditorSupport;
+import java.net.SocketAddress;
+
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+
+/**
+ * Java Bean [EMAIL PROTECTED] java.beans.PropertyEditor} which converts
Strings into
+ * [EMAIL PROTECTED] VmPipeAddress} objects. Valid values specify an integer
port number
+ * optionally prefixed with a ':'. E.g.: <code>:80</code>, <code>22</code>.
+ * <p>
+ * Use Spring's CustomEditorConfigurer to use this property editor in a Spring
+ * configuration file. See chapter 3.14 of the Spring Reference Documentation
+ * for more info.
+ * </p>
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Revision$, $Date$
+ *
+ * @see org.apache.mina.transport.vmpipe.VmPipeAddress
+ */
+public class VmPipeAddressEditor extends PropertyEditorSupport {
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue(parseSocketAddress(text));
+ }
+
+ private SocketAddress parseSocketAddress(String s) {
+ if (s == null) {
+ throw new IllegalArgumentException("socketAddress is null.");
+ }
+ s = s.trim();
+ if (s.startsWith(":")) {
+ s = s.substring(1);
+ }
+ try {
+ return new VmPipeAddress(Integer.parseInt(s.trim()));
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("Illegal VmPipeAddress: " + s);
+ }
+ }
+}
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/main/java/org/apache/mina/integration/beans/VmPipeAddressEditor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
(added)
+++
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.mina.integration.beans;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] InetAddressEditor}.
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Rev$, $Date$
+ */
+public class InetAddressEditorTest extends TestCase {
+ InetAddressEditor editor;
+
+ @Override
+ protected void setUp() throws Exception {
+ editor = new InetAddressEditor();
+ }
+
+ public void testSetAsTextWithHostName() throws Exception {
+ try {
+ InetAddress expected = InetAddress.getByName("www.google.com");
+ editor.setAsText("www.google.com");
+ assertEquals(expected, editor.getValue());
+ } catch (UnknownHostException uhe) {
+ // No DNS. Skip the test.
+ }
+
+ editor.setAsText("localhost");
+ assertEquals(InetAddress.getByName("localhost"), editor.getValue());
+ }
+
+ public void testSetAsTextWithIpAddress() throws Exception {
+ editor.setAsText("127.0.0.1");
+ assertEquals(InetAddress.getByName("127.0.0.1"), editor.getValue());
+ }
+}
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetAddressEditorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
(added)
+++
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,82 @@
+/*
+ * 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.mina.integration.beans;
+
+import java.net.InetSocketAddress;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] InetSocketAddressEditor}.
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Rev$, $Date$
+ */
+public class InetSocketAddressEditorTest extends TestCase {
+ InetSocketAddressEditor editor;
+
+ @Override
+ protected void setUp() throws Exception {
+ editor = new InetSocketAddressEditor();
+ }
+
+ public void testSetAsTextWithWildcardAddress() throws Exception {
+ editor.setAsText("1");
+ assertEquals(new InetSocketAddress(1), editor.getValue());
+ editor.setAsText(":10");
+ assertEquals(new InetSocketAddress(10), editor.getValue());
+ }
+
+ public void testSetAsTextWithHostName() throws Exception {
+ editor.setAsText("www.google.com:80");
+ assertEquals(new InetSocketAddress("www.google.com", 80), editor
+ .getValue());
+ }
+
+ public void testSetAsTextWithIpAddress() throws Exception {
+ editor.setAsText("192.168.0.1:1000");
+ assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor
+ .getValue());
+ }
+
+ public void testSetAsTextWithIllegalValues() throws Exception {
+ try {
+ editor.setAsText(null);
+ fail("null string. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ try {
+ editor.setAsText("bar");
+ fail("Illegal port number. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ try {
+ editor.setAsText(":foo");
+ fail("Illegal port number. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ try {
+ editor.setAsText("www.foo.com:yada");
+ fail("Illegal port number. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ }
+
+}
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/InetSocketAddressEditorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java?rev=595175&view=auto
==============================================================================
---
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
(added)
+++
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
Wed Nov 14 17:18:45 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.mina.integration.beans;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+
+/**
+ * Tests [EMAIL PROTECTED] VmPipeAddressEditor}.
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAddressEditorTest extends TestCase {
+ VmPipeAddressEditor editor;
+
+ @Override
+ protected void setUp() throws Exception {
+ editor = new VmPipeAddressEditor();
+ }
+
+ public void testSetAsTextWithLegalValues() throws Exception {
+ editor.setAsText("1");
+ assertEquals(new VmPipeAddress(1), editor.getValue());
+ editor.setAsText(":10");
+ assertEquals(new VmPipeAddress(10), editor.getValue());
+ editor.setAsText(":100");
+ assertEquals(new VmPipeAddress(100), editor.getValue());
+ }
+
+ public void testSetAsTextWithIllegalValues() throws Exception {
+ try {
+ editor.setAsText(null);
+ fail("null string. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ try {
+ editor.setAsText("bar");
+ fail("Illegal port number. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ try {
+ editor.setAsText(":foo");
+ fail("Illegal port number. IllegalArgumentException expected.");
+ } catch (IllegalArgumentException iae) {
+ }
+ }
+
+}
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
mina/trunk/core/src/test/java/org/apache/mina/integration/beans/VmPipeAddressEditorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
mina/trunk/example/src/main/resources/org/apache/mina/example/chat/serverContext.xml
URL:
http://svn.apache.org/viewvc/mina/trunk/example/src/main/resources/org/apache/mina/example/chat/serverContext.xml?rev=595175&r1=595174&r2=595175&view=diff
==============================================================================
---
mina/trunk/example/src/main/resources/org/apache/mina/example/chat/serverContext.xml
(original)
+++
mina/trunk/example/src/main/resources/org/apache/mina/example/chat/serverContext.xml
Wed Nov 14 17:18:45 2007
@@ -9,7 +9,7 @@
<property name="customEditors">
<map>
<entry key="java.net.SocketAddress">
- <bean
class="org.apache.mina.integration.spring.InetSocketAddressEditor" />
+ <bean
class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</entry>
</map>
</property>