Create Buffer custom Java geoprocessing tool
arcgissamples\geoprocessing\customtool\CBFunctionFactory.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package arcgissamples.geoprocessing.customtool;

import java.io.IOException;
import java.util.UUID;

import com.esri.arcgis.geodatabase.IEnumGPName;
import com.esri.arcgis.geodatabase.IGPName;
import com.esri.arcgis.geoprocessing.EnumGPName;
import com.esri.arcgis.geoprocessing.GPFunctionName;
import com.esri.arcgis.geoprocessing.IEnumGPEnvironment;
import com.esri.arcgis.geoprocessing.IGPFunction;
import com.esri.arcgis.geoprocessing.IGPFunctionFactory;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.interop.extn.ArcGISCategories;
import com.esri.arcgis.interop.extn.ArcGISExtension;
import com.esri.arcgis.system.IUID;
import com.esri.arcgis.system.UID;
import com.esri.arcgis.system.esriProductCode;

@ArcGISExtension(categories = { ArcGISCategories.GPFunctionFactories })
public class CBFunctionFactory implements IGPFunctionFactory {
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private String functionFactoryAlias = "cbfunctionfactory";
  private String factoryName = "CBFunctionFactory";
  private String category = "CreateBufferJavaToolset";

  private String createBufferToolName = "CreateBuffer";
  private String createBufferToolDisplayName = "Java Create Buffer Tool";

  /**
   * Returns the appropriate GPFunction object based on specified tool name
   */
  public IGPFunction getFunction(String name) throws IOException, AutomationException {
    if (name.equalsIgnoreCase(createBufferToolName)) {
      return new CreateBuffer();
    }

    return null;
  }

  /**
   * Returns a GPFunctionName objects based on specified tool name
   */
  public IGPName getFunctionName(String name) throws IOException, AutomationException {
    if (name.equalsIgnoreCase(createBufferToolName)) {
      GPFunctionName functionName = new GPFunctionName();
      functionName.setCategory(category);
      functionName.setDescription("Creates a Buffer - implemented in Java");
      functionName.setDisplayName(createBufferToolDisplayName);
      functionName.setName(createBufferToolName);
      functionName.setMinimumProduct(esriProductCode.esriProductCodeProfessional);
      functionName.setFactoryByRef(this);
      return functionName;
    }

    return null;
  }

  /**
   * Returns names of all gp tools created by this function factory
   */
  public IEnumGPName getFunctionNames() throws IOException, AutomationException {
    EnumGPName nameArray = new EnumGPName();
    nameArray.add(getFunctionName(createBufferToolName));
    return nameArray;
  }

  /**
   * Returns Alias of the function factory
   */
  public String getAlias() throws IOException, AutomationException {
    return functionFactoryAlias;
  }

  /**
   * Returns Class ID
   */
  public IUID getCLSID() throws IOException, AutomationException {
    UID uid = new UID();
    uid.setValue("{" + UUID.nameUUIDFromBytes(this.getClass().getName().getBytes()) + "}");

    return uid;
  }

  /**
   * Returns Function Environments
   */
  public IEnumGPEnvironment getFunctionEnvironments() throws IOException, AutomationException {
    return null;
  }

  /**
   * Returns name of the FunctionFactory
   */
  public String getName() throws IOException, AutomationException {
    return factoryName;
  }
}