diff options
author | rsuen | 2008-03-02 01:43:46 +0000 |
---|---|---|
committer | rsuen | 2008-03-02 01:43:46 +0000 |
commit | 250fd4c465c44359cc5eeb11adf3313f7ad7ce69 (patch) | |
tree | c92fef0cae1f526c186457a8226453ea09f98535 | |
parent | fe0a2ba5b45b3ab0084b1b3b87824dff965a1461 (diff) | |
download | org.eclipse.ecf-250fd4c465c44359cc5eeb11adf3313f7ad7ce69.tar.gz org.eclipse.ecf-250fd4c465c44359cc5eeb11adf3313f7ad7ce69.tar.xz org.eclipse.ecf-250fd4c465c44359cc5eeb11adf3313f7ad7ce69.zip |
Initial commit per bug 218584 - [remoteservices] [ui] add ui for invoking remote methods on interface classes
9 files changed, 668 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/.classpath b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.classpath new file mode 100644 index 000000000..ce7393340 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/.project b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.project new file mode 100644 index 000000000..df988dab4 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.remoteservice.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/.settings/org.eclipse.jdt.core.prefs b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..caf6f109f --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Sat Feb 09 19:19:29 EST 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.remoteservice.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..c610532ea --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ECF Remote Services UI +Bundle-SymbolicName: org.eclipse.ecf.remoteservice.ui;singleton:=true +Bundle-Version: 1.0.0 +Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", + org.eclipse.ui;bundle-version="3.4.0" +Export-Package: org.eclipse.ecf.internal.remoteservices.ui;x-internal:=true, + org.eclipse.ecf.remoteservices.ui diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/build.properties b/framework/bundles/org.eclipse.ecf.remoteservice.ui/build.properties new file mode 100644 index 000000000..34d2e4d2d --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/Messages.java b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/Messages.java new file mode 100644 index 000000000..95791ac19 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/Messages.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 Remy Chi Jian Suen 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: + * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.internal.remoteservices.ui; + +import org.eclipse.osgi.util.NLS; + +public final class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.remoteservices.ui.messages"; //$NON-NLS-1$ + + public static String MethodInvocationDialog_ShellTitle; + public static String MethodInvocationDialog_AvailableMethodsLabel; + public static String MethodInvocationDialog_ArgumentsLabel; + public static String MethodInvocationDialog_ParameterColumn; + public static String MethodInvocationDialog_ValueColumn; + public static String MethodInvocationDialog_TimeoutLabel; + public static String MethodInvocationDialog_InvocationTypeLabel; + public static String MethodInvocationDialog_InvocationTypeAsyncListener; + public static String MethodInvocationDialog_InvocationTypeAsyncFutureResult; + public static String MethodInvocationDialog_InvocationTypeAsyncFireAndGo; + public static String MethodInvocationDialog_InvocationTypeOSGiServiceProxy; + public static String MethodInvocationDialog_InvocationTypeRemoteServiceProxy; + public static String MethodInvocationDialog_InvocationTypeSynchronous; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + +} diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/messages.properties b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/messages.properties new file mode 100644 index 000000000..712a5e311 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/internal/remoteservices/ui/messages.properties @@ -0,0 +1,23 @@ +################################################################################ +# Copyright (c) 2008 Remy Chi Jian Suen 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: +# Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation +################################################################################ +MethodInvocationDialog_ShellTitle = Invoke Remote Method +MethodInvocationDialog_AvailableMethodsLabel = Available Methods: +MethodInvocationDialog_ArgumentsLabel = Arguments: +MethodInvocationDialog_ParameterColumn = Parameter +MethodInvocationDialog_ValueColumn = Value +MethodInvocationDialog_TimeoutLabel = Timeout (in ms): +MethodInvocationDialog_InvocationTypeLabel = Invocation Type: +MethodInvocationDialog_InvocationTypeAsyncListener = Async Listener +MethodInvocationDialog_InvocationTypeAsyncFutureResult = Async Future Result +MethodInvocationDialog_InvocationTypeAsyncFireAndGo = Async Fire-and-Go +MethodInvocationDialog_InvocationTypeOSGiServiceProxy = OSGi Service Proxy +MethodInvocationDialog_InvocationTypeRemoteServiceProxy = Remote Service Proxy +MethodInvocationDialog_InvocationTypeSynchronous = Synchronous diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/MethodInvocationDialog.java b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/MethodInvocationDialog.java new file mode 100644 index 000000000..e82715c2a --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/MethodInvocationDialog.java @@ -0,0 +1,452 @@ +/******************************************************************************* + * Copyright (c) 2008 Remy Chi Jian Suen 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: + * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.remoteservices.ui; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.ecf.internal.remoteservices.ui.Messages; +import org.eclipse.ecf.remoteservices.ui.RemoteMethod.Parameter; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.window.IShellProvider; +import org.eclipse.jface.window.SameShellProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +/** + * The MethodInvocationDialog allows a user to select a method given a + * <code>java.lang.Class</code> to invoke and communicate with a remote + * service. + * + * @since 2.0 + */ +public final class MethodInvocationDialog extends Dialog { + + /** + * An integer constant that corresponds to the "Async Listener" selection. + * + * @see #getInvocationType() + */ + public static final int ASYNC_LISTENER = 0; + + /** + * An integer constant that corresponds to the "Async Future Result" + * selection. + * + * @see #getInvocationType() + */ + public static final int ASYNC_FUTURE_RESULT = ASYNC_LISTENER + 1; + + /** + * An integer constant that corresponds to the "Async Fire-and-Go" + * selection. + * + * @see #getInvocationType() + */ + public static final int ASYNC_FIRE_AND_GO = ASYNC_FUTURE_RESULT + 1; + + /** + * An integer constant that corresponds to the "OSGi Service Proxy" + * selection. + * + * @see #getInvocationType() + */ + public static final int OSGI_SERVICE_PROXY = ASYNC_FIRE_AND_GO + 1; + /** + * An integer constant that corresponds to the "Remote Service Proxy" + * selection. + * + * @see #getInvocationType() + */ + public static final int REMOTE_SERVICE_PROXY = OSGI_SERVICE_PROXY + 1; + /** + * An integer constant that corresponds to the "Synchronous" selection. + * + * @see #getInvocationType() + */ + public static final int SYNCHRONOUS = REMOTE_SERVICE_PROXY + 1; + + private static final String[] COLUMN_PROPERTIES = { "Parameter", "Argument" }; //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * Provide a default timeout value of 30,000 milliseconds. + */ + private static final String DEFAULT_TIMEOUT_VALUE = "30000"; //$NON-NLS-1$ + + private TableViewer methodsViewer; + private TableViewer parametersViewer; + private Text timeoutText; + private Combo invocationCombo; + + private RemoteMethod[] methods; + + private Method method; + private Object[] methodArguments; + private int timeout; + private int invocationType; + + /** + * Creates a new MethodInvocationDialog on top of the specified shell + * provider. + * + * @param parentShell + * the provider to return the parent shell of this dialog + * @param cls + * the class to select the methods from + */ + public MethodInvocationDialog(IShellProvider parentShell, Class cls) { + super(parentShell); + Assert.isNotNull(cls); + + Method[] methods = cls.getMethods(); + List validMethods = new ArrayList(); + for (int i = 0; i < methods.length; i++) { + Class[] parameters = methods[i].getParameterTypes(); + String[] types = new String[parameters.length]; + + if (types.length == 0) { + validMethods.add(methods[i]); + continue; + } + + boolean match = true; + for (int j = 0; j < types.length; j++) { + String name = parameters[j].getName(); + if (!name.equals("char") && !name.equals("boolean") //$NON-NLS-1$ //$NON-NLS-2$ + && !name.equals("int") && !name.equals("double") //$NON-NLS-1$ //$NON-NLS-2$ + && !name.equals("float") && !name.equals("long") //$NON-NLS-1$ //$NON-NLS-2$ + && !name.equals("short") && !name.equals("byte") //$NON-NLS-1$ //$NON-NLS-2$ + && !name.equals("java.lang.String")) { //$NON-NLS-1$ + match = false; + break; + } + } + if (match) { + validMethods.add(methods[i]); + } + } + + methods = (Method[]) validMethods.toArray(new Method[validMethods + .size()]); + this.methods = new RemoteMethod[methods.length]; + for (int i = 0; i < methods.length; i++) { + this.methods[i] = new RemoteMethod(methods[i]); + } + } + + /** + * Creates a new MethodInvocationDialog over the provided shell. + * + * @param parentShell + * the parent shell + * @param cls + * the class to select the methods from + */ + public MethodInvocationDialog(Shell parentShell, Class cls) { + this(new SameShellProvider(parentShell), cls); + } + + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.MethodInvocationDialog_ShellTitle); + } + + protected Control createDialogArea(Composite parent) { + parent = (Composite) super.createDialogArea(parent); + + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setLayout(new GridLayout(2, true)); + + Label label = new Label(composite, SWT.LEAD); + label.setText(Messages.MethodInvocationDialog_AvailableMethodsLabel); + + label = new Label(composite, SWT.LEAD); + label.setText(Messages.MethodInvocationDialog_ArgumentsLabel); + + methodsViewer = new TableViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL + | SWT.BORDER); + methodsViewer.getControl().setLayoutData( + new GridData(SWT.FILL, SWT.FILL, true, true)); + methodsViewer.setContentProvider(new ArrayContentProvider()); + methodsViewer + .addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent e) { + IStructuredSelection iss = (IStructuredSelection) e + .getSelection(); + Object element = iss.getFirstElement(); + if (element != null) { + getButton(IDialogConstants.OK_ID).setEnabled( + !timeoutText.getText().equals("")); //$NON-NLS-1$ + RemoteMethod method = (RemoteMethod) element; + parametersViewer.setInput(method.getParameters()); + } + } + }); + methodsViewer.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + RemoteMethod method = (RemoteMethod) element; + return method.getReturnType() + ' ' + method.getSignature(); + } + }); + + parametersViewer = new TableViewer(composite, SWT.V_SCROLL + | SWT.H_SCROLL | SWT.BORDER); + parametersViewer.getControl().setLayoutData( + new GridData(SWT.FILL, SWT.FILL, true, true)); + parametersViewer.setContentProvider(new ArrayContentProvider()); + parametersViewer.setLabelProvider(new ITableLabelProvider() { + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + Parameter p = (Parameter) element; + if (columnIndex == 0) { + String name = p.getParameter().getName(); + if (name.charAt(0) == 'j') { + // this is java.lang.String + return "String"; //$NON-NLS-1$ + } else { + return name; + } + } else { + return p.getArgument(); + } + } + + public void addListener(ILabelProviderListener listener) { + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return true; + } + + public void removeListener(ILabelProviderListener listener) { + } + }); + parametersViewer.setCellEditors(new CellEditor[] { null, + new TextCellEditor(parametersViewer.getTable()) }); + parametersViewer.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return property.equals(COLUMN_PROPERTIES[1]); + } + + public Object getValue(Object element, String property) { + return ((Parameter) element).getArgument(); + } + + public void modify(Object element, String property, Object value) { + if (property.equals(COLUMN_PROPERTIES[1])) { + if (element instanceof TableItem) { + TableItem item = ((TableItem) element); + Parameter p = (Parameter) item.getData(); + String argument = (String) value; + p.setArgument(argument); + item.setText(1, argument); + } + } + } + }); + parametersViewer.setColumnProperties(COLUMN_PROPERTIES); + + Table table = parametersViewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + TableColumn column = new TableColumn(table, SWT.LEAD); + column.setWidth(150); + column.setText(Messages.MethodInvocationDialog_ParameterColumn); + column = new TableColumn(table, SWT.LEAD); + column.setWidth(150); + column.setText(Messages.MethodInvocationDialog_ValueColumn); + + methodsViewer.setInput(methods); + + Composite bottomComposite = new Composite(composite, SWT.NONE); + bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + false, 2, 1)); + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + bottomComposite.setLayout(layout); + + label = new Label(bottomComposite, SWT.LEAD); + label.setText(Messages.MethodInvocationDialog_TimeoutLabel); + label + .setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, + true)); + + timeoutText = new Text(bottomComposite, SWT.BORDER); + timeoutText.setText(DEFAULT_TIMEOUT_VALUE); + timeoutText.addVerifyListener(new VerifyListener() { + public void verifyText(VerifyEvent e) { + switch (e.text.length()) { + case 0: + e.doit = true; + break; + case 1: + e.doit = Character.isDigit(e.text.charAt(0)); + break; + default: + e.doit = false; + break; + } + } + }); + timeoutText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + getButton(IDialogConstants.OK_ID).setEnabled( + !timeoutText.getText().equals("") //$NON-NLS-1$ + && !methodsViewer.getSelection().isEmpty()); + } + }); + timeoutText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, + false)); + + label = new Label(bottomComposite, SWT.LEAD); + label.setText(Messages.MethodInvocationDialog_InvocationTypeLabel); + label + .setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, + true)); + + invocationCombo = new Combo(bottomComposite, SWT.READ_ONLY); + invocationCombo + .setItems(new String[] { + Messages.MethodInvocationDialog_InvocationTypeAsyncListener, + Messages.MethodInvocationDialog_InvocationTypeAsyncFutureResult, + Messages.MethodInvocationDialog_InvocationTypeAsyncFireAndGo, + Messages.MethodInvocationDialog_InvocationTypeOSGiServiceProxy, + Messages.MethodInvocationDialog_InvocationTypeRemoteServiceProxy, + Messages.MethodInvocationDialog_InvocationTypeSynchronous }); + invocationCombo.select(0); + bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, + false)); + + return parent; + } + + public void create() { + super.create(); + getButton(IDialogConstants.OK_ID).setEnabled(false); + } + + protected void okPressed() { + IStructuredSelection selection = (IStructuredSelection) methodsViewer + .getSelection(); + RemoteMethod remoteMethod = (RemoteMethod) selection.getFirstElement(); + method = remoteMethod.getMethod(); + Parameter[] p = remoteMethod.getParameters(); + methodArguments = new Object[p.length]; + for (int i = 0; i < p.length; i++) { + String name = p[i].getParameter().getName(); + String arg = p[i].getArgument(); + if (name.equals("char")) { //$NON-NLS-1$ + methodArguments[i] = new Character(arg.charAt(0)); + } else if (name.equals("boolean")) { //$NON-NLS-1$ + methodArguments[i] = Boolean.valueOf(arg); + } else if (name.equals("int")) { //$NON-NLS-1$ + methodArguments[i] = Integer.valueOf(arg); + } else if (name.equals("double")) { //$NON-NLS-1$ + methodArguments[i] = Double.valueOf(arg); + } else if (name.equals("float")) { //$NON-NLS-1$ + methodArguments[i] = Float.valueOf(arg); + } else if (name.equals("long")) { //$NON-NLS-1$ + methodArguments[i] = Long.valueOf(arg); + } else if (name.equals("short")) { //$NON-NLS-1$ + methodArguments[i] = Short.valueOf(arg); + } else if (name.equals("byte")) { //$NON-NLS-1$ + methodArguments[i] = Byte.valueOf(arg); + } else { + methodArguments[i] = arg; + } + } + timeout = Integer.parseInt(timeoutText.getText()); + invocationType = invocationCombo.getSelectionIndex(); + super.okPressed(); + } + + /** + * Returns the method that has been selected by the user. + * + * @return the selected method + */ + public Method getMethod() { + return method; + } + + /** + * Returns the arguments that has been specified by the user to pass to the + * method. + * + * @return the list of arguments to pass into the method + */ + public Object[] getMethodArguments() { + return methodArguments; + } + + /** + * Retrieves the timeout value that has been specified by the user. This + * value is in milliseconds. + * + * @return the timeout valued specified by the user in milliseconds + */ + public int getTimeout() { + return timeout; + } + + /** + * Returns the type of invocation that should be used to call the selected + * method to communicate with a remote service. + * + * @return the invocation type selected by the user + * @see #ASYNC_LISTENER + * @see #ASYNC_FUTURE_RESULT + * @see #ASYNC_FIRE_AND_GO + * @see #OSGI_SERVICE_PROXY + * @see #REMOTE_SERVICE_PROXY + * @see #SYNCHRONOUS + */ + public int getInvocationType() { + return invocationType; + } +} diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/RemoteMethod.java b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/RemoteMethod.java new file mode 100644 index 000000000..e8a73a0a1 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.remoteservice.ui/src/org/eclipse/ecf/remoteservices/ui/RemoteMethod.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2008 Remy Chi Jian Suen 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: + * Remy Chi Jian Suen <remy.suen@gmail.com> - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.remoteservices.ui; + +import java.lang.reflect.Method; + +class RemoteMethod { + + private Method method; + private Parameter[] parameters; + private Class[] parameterTypes; + + RemoteMethod(Method method) { + this.method = method; + parameterTypes = method.getParameterTypes(); + parameters = new Parameter[parameterTypes.length]; + for (int i = 0; i < parameters.length; i++) { + parameters[i] = new Parameter(parameterTypes[i]); + } + } + + public String[] getParameterTypes() { + String[] types = new String[parameterTypes.length]; + for (int i = 0; i < types.length; i++) { + String name = parameterTypes[i].getName(); + if (name.charAt(0) == 'j') { + types[i] = "String"; //$NON-NLS-1$ + } else { + types[i] = name; + } + } + return types; + } + + Method getMethod() { + return method; + } + + Parameter[] getParameters() { + return parameters; + } + + public String getReturnType() { + String name = method.getReturnType().getName(); + int index = name.lastIndexOf('.'); + if (index != -1) { + name = name.substring(index + 1); + } + name = name.replace('$', '.'); + return name; + } + + public String getSignature() { + StringBuffer buffer = new StringBuffer(method.getName()); + synchronized (buffer) { + buffer.append('('); + String[] types = getParameterTypes(); + if (types.length != 0) { + for (int i = 0; i < types.length; i++) { + buffer.append(types[i]).append(", "); //$NON-NLS-1$ + } + buffer.delete(buffer.length() - 2, buffer.length()); + } + buffer.append(')'); + return buffer.toString(); + } + } + + class Parameter { + + private Class parameter; + private String argument = ""; //$NON-NLS-1$ + + Parameter(Class parameter) { + this.parameter = parameter; + } + + void setArgument(String argument) { + this.argument = argument; + } + + String getArgument() { + return argument; + } + + Class getParameter() { + return parameter; + } + + } + +} |