arcgissamples\geoprocessing\customtool\CBFunctionFactory.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Custom Java geoprocessing tool - Create Buffer
arcgissamples\geoprocessing\customtool\CBFunctionFactory.java
/* Copyright 2015 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 at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
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;

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

  private String createBufferToolName = "JavaCreateBuffer";
  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.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;
  }
}