Find Intersections custom Java geoprocessing tool
arcgissamples\geoprocessing\customtool\FIFunctionFactory.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 FIFunctionFactory implements IGPFunctionFactory {

  private static final long serialVersionUID = 1L;
  private String functionFactoryAlias = "fifunctionfactory";
  private String factoryName = "FIFunctionFactory";
  private String category = "FindIntersectionsJavaToolset";

  private String findIntersectionsToolName = "FindIntersections";
  private String findIntersectionsToolDisplayName = "Java Find Intersections";
  private String findIntersectionsToolDescription = "This tool finds intersections in a Network Dataset and saves these as a point feature class";

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

    return null;
  }

  /**
   * Returns a GPFunctionName objects based on specified tool name
   */
  public IGPName getFunctionName(String name) throws IOException, AutomationException {
    if (name.equalsIgnoreCase(findIntersectionsToolName)) {
      GPFunctionName functionName = new GPFunctionName();
      functionName.setCategory(category);
      functionName.setDescription(findIntersectionsToolDescription);
      functionName.setDisplayName(findIntersectionsToolDisplayName);
      functionName.setName(findIntersectionsToolName);
      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(findIntersectionsToolName));

    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;
  }
}