Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-06 18:05:10 +0000
committerEike Stepper2012-06-06 18:05:10 +0000
commit4a711b5a64c086bd1aec35465e96807cd7572dc0 (patch)
tree1f094a2acda82566abd8de555f21044dfdf16a40 /plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j
parentbc6860460ea734dc2dfa4cc82238486f53c81d41 (diff)
downloadcdo-4a711b5a64c086bd1aec35465e96807cd7572dc0.tar.gz
cdo-4a711b5a64c086bd1aec35465e96807cd7572dc0.tar.xz
cdo-4a711b5a64c086bd1aec35465e96807cd7572dc0.zip
[381472] Design a repository administration API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381472
Diffstat (limited to 'plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j')
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java202
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java200
2 files changed, 219 insertions, 183 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
index 5597190a3d..4d67e9f778 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
@@ -1,82 +1,120 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Caspar De Groot - maintenance
- */
-package org.eclipse.net4j.internal.tcp;
-
-import org.eclipse.net4j.tcp.ITCPAcceptor;
-import org.eclipse.net4j.util.StringUtil;
-
-import org.eclipse.spi.net4j.AcceptorFactory;
-
-/**
- * @author Eike Stepper
- */
-public class TCPAcceptorFactory extends AcceptorFactory
-{
- public static final String TYPE = "tcp"; //$NON-NLS-1$
-
- private static final String SEPARATOR = ":"; //$NON-NLS-1$
-
- public TCPAcceptorFactory()
- {
- super(TYPE);
- }
-
- /**
- * Allows derived classes to override the TYPE identifier
- */
- protected TCPAcceptorFactory(String type)
- {
- super(type);
- }
-
- public TCPAcceptor create(String description)
- {
- String address = ITCPAcceptor.DEFAULT_ADDRESS;
- int port = ITCPAcceptor.DEFAULT_PORT;
-
- if (!StringUtil.isEmpty(description))
- {
- String[] tokens = description.split(SEPARATOR);
- if (!StringUtil.isEmpty(tokens[0]))
- {
- address = tokens[0];
- }
-
- if (tokens.length > 1 && !StringUtil.isEmpty(tokens[1]))
- {
- port = Integer.parseInt(tokens[1]);
- }
- }
-
- TCPAcceptor acceptor = createAcceptor();
- acceptor.setAddress(address);
- acceptor.setPort(port);
- return acceptor;
- }
-
- protected TCPAcceptor createAcceptor()
- {
- return new TCPAcceptor();
- }
-
- @Override
- public String getDescriptionFor(Object object)
- {
- if (object instanceof TCPAcceptor)
- {
- TCPAcceptor acceptor = (TCPAcceptor)object;
- return acceptor.getAddress() + SEPARATOR + acceptor.getPort();
- }
-
- return null;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
+ */
+package org.eclipse.net4j.internal.tcp;
+
+import org.eclipse.net4j.tcp.ITCPAcceptor;
+import org.eclipse.net4j.util.StringUtil;
+
+import org.eclipse.spi.net4j.AcceptorFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class TCPAcceptorFactory extends AcceptorFactory
+{
+ public static final String TYPE = "tcp"; //$NON-NLS-1$
+
+ private static final String SEPARATOR = ":"; //$NON-NLS-1$
+
+ public TCPAcceptorFactory()
+ {
+ super(TYPE);
+ }
+
+ /**
+ * Allows derived classes to override the TYPE identifier
+ */
+ protected TCPAcceptorFactory(String type)
+ {
+ super(type);
+ }
+
+ public TCPAcceptor create(String description)
+ {
+ Data data = new Data(description);
+
+ TCPAcceptor acceptor = createAcceptor();
+ acceptor.setAddress(data.getAddress());
+ acceptor.setPort(data.getPort());
+ return acceptor;
+ }
+
+ protected TCPAcceptor createAcceptor()
+ {
+ return new TCPAcceptor();
+ }
+
+ @Override
+ public String getDescriptionFor(Object object)
+ {
+ if (object instanceof TCPAcceptor)
+ {
+ TCPAcceptor acceptor = (TCPAcceptor)object;
+ return acceptor.getAddress() + SEPARATOR + acceptor.getPort();
+ }
+
+ return null;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Data
+ {
+ private String address = ITCPAcceptor.DEFAULT_ADDRESS;
+
+ private int port = ITCPAcceptor.DEFAULT_PORT;
+
+ public Data()
+ {
+ }
+
+ public Data(String address, int port)
+ {
+ this.address = address;
+ this.port = port;
+ }
+
+ public Data(String description)
+ {
+ if (!StringUtil.isEmpty(description))
+ {
+ String[] tokens = description.split(SEPARATOR);
+ if (!StringUtil.isEmpty(tokens[0]))
+ {
+ address = tokens[0];
+ }
+
+ if (tokens.length > 1 && !StringUtil.isEmpty(tokens[1]))
+ {
+ port = Integer.parseInt(tokens[1]);
+ }
+ }
+ }
+
+ public String getAddress()
+ {
+ return address == null ? "" : address;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+
+ @Override
+ public String toString()
+ {
+ return address + SEPARATOR + port;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
index f7281a5dae..3982bedbdd 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
@@ -1,101 +1,99 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Caspar De Groot - maintenance
- */
-package org.eclipse.net4j.internal.tcp;
-
-import org.eclipse.net4j.tcp.ITCPConnector;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import org.eclipse.spi.net4j.ConnectorFactory;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-/**
- * @author Eike Stepper
- */
-public class TCPConnectorFactory extends ConnectorFactory
-{
- public static final String TYPE = "tcp"; //$NON-NLS-1$
-
- private static final String URL_SCHEME = "http://"; //$NON-NLS-1$
-
- public TCPConnectorFactory()
- {
- super(TYPE);
- }
-
- /**
- * Allows derived classes to override the TYPE identifier
- */
- protected TCPConnectorFactory(String type)
- {
- super(type);
- }
-
- public TCPConnector create(String description)
- {
- try
- {
- // TODO Don't use URL
- // Scheme "tcp://" would be rejected!
- URL url = new URL(URL_SCHEME + description);
- String userID = url.getUserInfo();
- String host = url.getHost();
- int port = url.getPort();
- if (port == -1)
- {
- port = ITCPConnector.DEFAULT_PORT;
- }
-
- TCPConnector connector = createConnector();
- connector.setUserID(userID);
- connector.setHost(host);
- connector.setPort(port);
- return connector;
- }
- catch (MalformedURLException ex)
- {
- throw new ProductCreationException(ex);
- }
- }
-
- protected TCPConnector createConnector()
- {
- return new TCPClientConnector();
- }
-
- @Override
- public String getDescriptionFor(Object object)
- {
- if (object instanceof TCPConnector)
- {
- TCPConnector connector = (TCPConnector)object;
- String description = connector.getHost();
- String userID = connector.getUserID();
- if (!StringUtil.isEmpty(userID))
- {
- description = userID + "@" + description; //$NON-NLS-1$
- }
-
- int port = connector.getPort();
- if (port != ITCPConnector.DEFAULT_PORT)
- {
- description = description + ":" + port; //$NON-NLS-1$
- }
-
- return description;
- }
-
- return null;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
+ */
+package org.eclipse.net4j.internal.tcp;
+
+import org.eclipse.net4j.tcp.ITCPConnector;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import org.eclipse.spi.net4j.ConnectorFactory;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @author Eike Stepper
+ */
+public class TCPConnectorFactory extends ConnectorFactory
+{
+ public static final String TYPE = "tcp"; //$NON-NLS-1$
+
+ public TCPConnectorFactory()
+ {
+ super(TYPE);
+ }
+
+ /**
+ * Allows derived classes to override the TYPE identifier
+ */
+ protected TCPConnectorFactory(String type)
+ {
+ super(type);
+ }
+
+ public TCPConnector create(String description)
+ {
+ try
+ {
+ // TODO Don't use URL
+ // Scheme "tcp://" would be rejected!
+ URL url = new URL("http://" + description);
+ String userID = url.getUserInfo();
+ String host = url.getHost();
+ int port = url.getPort();
+ if (port == -1)
+ {
+ port = ITCPConnector.DEFAULT_PORT;
+ }
+
+ TCPConnector connector = createConnector();
+ connector.setUserID(userID);
+ connector.setHost(host);
+ connector.setPort(port);
+ return connector;
+ }
+ catch (MalformedURLException ex)
+ {
+ throw new ProductCreationException(ex);
+ }
+ }
+
+ protected TCPConnector createConnector()
+ {
+ return new TCPClientConnector();
+ }
+
+ @Override
+ public String getDescriptionFor(Object object)
+ {
+ if (object instanceof TCPConnector)
+ {
+ TCPConnector connector = (TCPConnector)object;
+ String description = connector.getHost();
+ String userID = connector.getUserID();
+ if (!StringUtil.isEmpty(userID))
+ {
+ description = userID + "@" + description; //$NON-NLS-1$
+ }
+
+ int port = connector.getPort();
+ if (port != ITCPConnector.DEFAULT_PORT)
+ {
+ description = description + ":" + port; //$NON-NLS-1$
+ }
+
+ return description;
+ }
+
+ return null;
+ }
+}

Back to the top