deboer | 65ea507 | 2005-02-17 19:14:45 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2003, 2005 IBM Corporation and others. |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
deboer | df10c15 | 2005-02-17 18:24:46 +0000 | [diff] [blame] | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 5 | * which accompanies this distribution, and is available at |
deboer | df10c15 | 2005-02-17 18:24:46 +0000 | [diff] [blame] | 6 | * http://www.eclipse.org/legal/epl-v10.html |
deboer | 65ea507 | 2005-02-17 19:14:45 +0000 | [diff] [blame] | 7 | * |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 8 | * Contributors: |
deboer | f942357 | 2005-02-17 19:34:29 +0000 | [diff] [blame] | 9 | * IBM Corporation - Initial API and implementation |
deboer | 65ea507 | 2005-02-17 19:14:45 +0000 | [diff] [blame] | 10 | *******************************************************************************/ |
deboer | 03d3897 | 2004-12-06 22:29:45 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.internet.monitor.core.internal; |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 12 | |
| 13 | import java.io.IOException; |
| 14 | import java.net.Socket; |
| 15 | import org.eclipse.core.runtime.IConfigurationElement; |
deboer | ed82993 | 2005-05-11 16:06:22 +0000 | [diff] [blame] | 16 | import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor; |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 17 | /** |
| 18 | * |
| 19 | */ |
| 20 | public class ProtocolAdapter implements IProtocolAdapter { |
| 21 | protected IConfigurationElement element; |
| 22 | protected ProtocolAdapterDelegate delegate; |
deboer | 9606717 | 2005-10-10 21:51:37 +0000 | [diff] [blame] | 23 | |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 24 | protected ProtocolAdapter(IConfigurationElement element) { |
| 25 | this.element = element; |
| 26 | } |
| 27 | |
deboer | 0e31213 | 2005-04-11 20:30:11 +0000 | [diff] [blame] | 28 | /** |
| 29 | * @see IProtocolAdapter#getId() |
| 30 | */ |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 31 | public String getId() { |
| 32 | return element.getAttribute("id"); |
| 33 | } |
deboer | 9606717 | 2005-10-10 21:51:37 +0000 | [diff] [blame] | 34 | |
deboer | 0e31213 | 2005-04-11 20:30:11 +0000 | [diff] [blame] | 35 | /** |
| 36 | * @see IProtocolAdapter#getName() |
| 37 | */ |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 38 | public String getName() { |
| 39 | return element.getAttribute("name"); |
| 40 | } |
deboer | 9606717 | 2005-10-10 21:51:37 +0000 | [diff] [blame] | 41 | |
deboer | b10b8b1 | 2005-02-09 19:11:39 +0000 | [diff] [blame] | 42 | protected ProtocolAdapterDelegate getDelegate() { |
| 43 | if (delegate != null) |
| 44 | return delegate; |
| 45 | |
| 46 | try { |
| 47 | delegate = (ProtocolAdapterDelegate) element.createExecutableExtension("class"); |
| 48 | } catch (Exception e) { |
| 49 | Trace.trace(Trace.SEVERE, "Could not create protocol adapter delegate: " + getId(), e); |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 50 | } |
deboer | b10b8b1 | 2005-02-09 19:11:39 +0000 | [diff] [blame] | 51 | return delegate; |
| 52 | } |
deboer | 9606717 | 2005-10-10 21:51:37 +0000 | [diff] [blame] | 53 | |
deboer | 0e31213 | 2005-04-11 20:30:11 +0000 | [diff] [blame] | 54 | /** |
| 55 | * Connect with the protocol. |
| 56 | * |
| 57 | * @param monitor a monitor |
| 58 | * @param in an inbound socket |
| 59 | * @param out an outbound socket |
| 60 | * @throws IOException |
| 61 | */ |
deboer | b10b8b1 | 2005-02-09 19:11:39 +0000 | [diff] [blame] | 62 | public void connect(IMonitor monitor, Socket in, Socket out) throws IOException { |
| 63 | getDelegate().connect(monitor, in, out); |
| 64 | } |
deboer | 9606717 | 2005-10-10 21:51:37 +0000 | [diff] [blame] | 65 | |
deboer | 0e31213 | 2005-04-11 20:30:11 +0000 | [diff] [blame] | 66 | /** |
| 67 | * Disconnect from the sockets. |
| 68 | * |
| 69 | * @param monitor a monitor |
| 70 | * @throws IOException |
| 71 | */ |
deboer | b10b8b1 | 2005-02-09 19:11:39 +0000 | [diff] [blame] | 72 | public void disconnect(IMonitor monitor) throws IOException { |
| 73 | getDelegate().disconnect(monitor); |
deboer | fbd35ee | 2004-12-06 22:18:24 +0000 | [diff] [blame] | 74 | } |
| 75 | } |