blob: 44f8c0e71959abb6e9367fad30512117d6464100 [file] [log] [blame]
deboer65ea5072005-02-17 19:14:45 +00001/*******************************************************************************
2 * Copyright (c) 2003, 2005 IBM Corporation and others.
deboerfbd35ee2004-12-06 22:18:24 +00003 * All rights reserved. This program and the accompanying materials
deboerdf10c152005-02-17 18:24:46 +00004 * are made available under the terms of the Eclipse Public License v1.0
deboerfbd35ee2004-12-06 22:18:24 +00005 * which accompanies this distribution, and is available at
deboerdf10c152005-02-17 18:24:46 +00006 * http://www.eclipse.org/legal/epl-v10.html
deboer65ea5072005-02-17 19:14:45 +00007 *
deboerfbd35ee2004-12-06 22:18:24 +00008 * Contributors:
deboerf9423572005-02-17 19:34:29 +00009 * IBM Corporation - Initial API and implementation
deboer65ea5072005-02-17 19:14:45 +000010 *******************************************************************************/
deboer03d38972004-12-06 22:29:45 +000011package org.eclipse.wst.internet.monitor.core.internal;
deboerfbd35ee2004-12-06 22:18:24 +000012
13import java.io.IOException;
14import java.net.Socket;
15import org.eclipse.core.runtime.IConfigurationElement;
deboered829932005-05-11 16:06:22 +000016import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
deboerfbd35ee2004-12-06 22:18:24 +000017/**
18 *
19 */
20public class ProtocolAdapter implements IProtocolAdapter {
21 protected IConfigurationElement element;
22 protected ProtocolAdapterDelegate delegate;
deboer96067172005-10-10 21:51:37 +000023
deboerfbd35ee2004-12-06 22:18:24 +000024 protected ProtocolAdapter(IConfigurationElement element) {
25 this.element = element;
26 }
27
deboer0e312132005-04-11 20:30:11 +000028 /**
29 * @see IProtocolAdapter#getId()
30 */
deboerfbd35ee2004-12-06 22:18:24 +000031 public String getId() {
32 return element.getAttribute("id");
33 }
deboer96067172005-10-10 21:51:37 +000034
deboer0e312132005-04-11 20:30:11 +000035 /**
36 * @see IProtocolAdapter#getName()
37 */
deboerfbd35ee2004-12-06 22:18:24 +000038 public String getName() {
39 return element.getAttribute("name");
40 }
deboer96067172005-10-10 21:51:37 +000041
deboerb10b8b12005-02-09 19:11:39 +000042 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);
deboerfbd35ee2004-12-06 22:18:24 +000050 }
deboerb10b8b12005-02-09 19:11:39 +000051 return delegate;
52 }
deboer96067172005-10-10 21:51:37 +000053
deboer0e312132005-04-11 20:30:11 +000054 /**
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 */
deboerb10b8b12005-02-09 19:11:39 +000062 public void connect(IMonitor monitor, Socket in, Socket out) throws IOException {
63 getDelegate().connect(monitor, in, out);
64 }
deboer96067172005-10-10 21:51:37 +000065
deboer0e312132005-04-11 20:30:11 +000066 /**
67 * Disconnect from the sockets.
68 *
69 * @param monitor a monitor
70 * @throws IOException
71 */
deboerb10b8b12005-02-09 19:11:39 +000072 public void disconnect(IMonitor monitor) throws IOException {
73 getDelegate().disconnect(monitor);
deboerfbd35ee2004-12-06 22:18:24 +000074 }
75}