inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.core / src / net / sourceforge / phpdt / monitor / core / internal / ProtocolAdapter.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.core.internal;
12
13 import java.io.IOException;
14 import java.net.Socket;
15
16 import net.sourceforge.phpdt.monitor.core.IMonitor;
17 import net.sourceforge.phpdt.monitor.core.IProtocolAdapter;
18 import net.sourceforge.phpdt.monitor.core.IProtocolAdapterDelegate;
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21 /**
22  * 
23  */
24 public class ProtocolAdapter implements IProtocolAdapter {
25         protected IConfigurationElement element;
26         protected IProtocolAdapterDelegate delegate;
27         
28         protected ProtocolAdapter(IConfigurationElement element) {
29                 this.element = element;
30         }
31
32         public String getId() {
33                 return element.getAttribute("id");
34         }
35         
36         public String getName() {
37                 return element.getAttribute("name");
38         }
39         
40         public void parse(IMonitor monitor, Socket in, Socket out) throws IOException {
41                 if (delegate == null) {
42                         try {
43                                 delegate = (IProtocolAdapterDelegate) element.createExecutableExtension("class");
44                         } catch (Exception e) {
45                                 Trace.trace(Trace.SEVERE, "Could not create protocol adapter delegate: " + getId(), e);
46                                 return;
47                         }
48                 }
49                 delegate.parse(monitor, in, out);
50         }
51 }