| package org.eclipse.epp.installer.internal.core; |
| |
| import java.lang.reflect.Constructor; |
| import java.lang.reflect.InvocationTargetException; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.epp.installer.internal.core.operations.ProxyOperation; |
| import org.eclipse.epp.installer.internal.core.operations.StubOperation; |
| |
| |
| public class OperationProxyManager { |
| private Map proxyStubMap = new HashMap(); |
| |
| protected void registerOperationStub( Class proxyClass, Class operationStub ) { |
| proxyStubMap.put( proxyClass, operationStub ); |
| } |
| protected StubOperation resolveProxy( ProxyOperation operation ) { |
| Class proxyClass = operation.getClass(); |
| if( proxyStubMap.containsKey(proxyClass)) { |
| Class stubClass = (Class)proxyStubMap.get(proxyClass); |
| try { |
| Constructor ctr = stubClass.getConstructor( new Class[] {ProxyOperation.class}); |
| return (StubOperation)ctr.newInstance(new Object[] {operation}); |
| //return (StubOperation)stubClass.newInstance(); |
| } |
| catch( InvocationTargetException ex ) { |
| ex.printStackTrace(); |
| } |
| catch( NoSuchMethodException ex ) { |
| ex.printStackTrace(); |
| } |
| catch( InstantiationException ex ) { |
| ex.printStackTrace(); |
| } |
| catch( IllegalAccessException ex ) { |
| ex.printStackTrace(); |
| } |
| } |
| return null; |
| } |
| } |