ECF Service Access Handler

Identifier:
org.eclipse.ecf.discovery.ui.serviceAccessHandler

Since:
2.0.0M5

Description:
This extension point allows plugins to add menu items to the discovery view's context menu for accessing/invoking a remote service.

Configuration Markup:

<!ELEMENT extension (serviceAccessHandler)+>

<!ATTLIST extension

point CDATA #REQUIRED

id    CDATA #IMPLIED

name  CDATA #IMPLIED>


<!ELEMENT serviceAccessHandler EMPTY>

<!ATTLIST serviceAccessHandler

class CDATA #REQUIRED>


Examples:
Here is example usage of the serviceAccessHandler extension point. In this example, a http/http service handler is declared:

   <extension
         point="org.eclipse.ecf.discovery.ui.serviceAccessHandler">
      <serviceAccessHandler
            class="org.eclipse.ecf.discovery.ui.HttpServiceAccessHandler">
      </serviceAccessHandler>
   </extension>
Here's is implementation of the HttpServiceAccessHandler:

public class HttpServiceAccessHandler implements IServiceAccessHandler {

 private static final String RFC2782_PATH = "path"; //$NON-NLS-1$
 //private static final String RFC2782_USERNAME = "u"; //$NON-NLS-1$
 //private static final String RFC2782_PASSWORD = "p"; //$NON-NLS-1$
 static final IContributionItem[] EMPTY_CONTRIBUTION = {};

 public HttpServiceAccessHandler() {
  // nothing to do
 }

 public IContributionItem[] getContributionsForService(IServiceInfo serviceInfo) {
  IServiceID serviceID = serviceInfo.getServiceID();
  List serviceTypes = Arrays.asList(serviceID.getServiceTypeID().getProtocols());
  String protocol = null;
  if (serviceTypes.contains("http")) //$NON-NLS-1$
   protocol = "http"; //$NON-NLS-1$
  else if (serviceTypes.contains("https")) //$NON-NLS-1$
   protocol = "https"; //$NON-NLS-1$
  if (protocol == null)
   return EMPTY_CONTRIBUTION;
  URI location = serviceInfo.getLocation();
  StringBuffer buf = new StringBuffer(protocol);
  buf.append("://").append(location.getHost()); //$NON-NLS-1$
  if (location.getPort() != -1)
   buf.append(":").append(location.getPort()).append("/"); //$NON-NLS-1$ //$NON-NLS-2$
  IServiceProperties svcProps = serviceInfo.getServiceProperties();
  final String path = svcProps.getPropertyString(RFC2782_PATH);
  if (path != null)
   buf.append(path);
  final String urlString = buf.toString();
  //final String username = svcProps.getPropertyString(RFC2782_USERNAME);
  //final String password = svcProps.getPropertyString(RFC2782_PASSWORD);
  Action action = new Action() {
   public void run() {
    openBrowser(urlString);
   }
  };
  action.setText(Messages.HttpServiceAccessHandler_MENU_TEXT + urlString);
  return new IContributionItem[] {new ActionContributionItem(action)};
 }

 protected void openBrowser(String urlString) {
  final IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
  try {
   support.createBrowser(null).openURL(new URL(urlString));
  } catch (final Exception e) {
   logError(Messages.HttpServiceAccessHandler_EXCEPTION_CREATEBROWSER, e);
  }

 }

 protected void logError(String exceptionString, Throwable e) {
  Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, exceptionString, e));

 }

}

Supplied Implementation:
None.


/**************************************************************************** * Copyright (c) 2008 Composent, Inc. 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: * Composent, Inc. - initial API and implementation *****************************************************************************/