arcgissamples\geodatabase\simplepointdatasource\SimplePointWorkspaceHelper.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Point plug-in data source
arcgissamples\geodatabase\simplepointdatasource\SimplePointWorkspaceHelper.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.geodatabase.simplepointdatasource;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import com.esri.arcgis.geodatabase.INativeType;
import com.esri.arcgis.geodatabase.IPlugInDatasetHelper;
import com.esri.arcgis.geodatabase.IPlugInMetadataPath;
import com.esri.arcgis.geodatabase.IPlugInWorkspaceHelper;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.interop.extn.ArcGISExtension;
import com.esri.arcgis.system.Array;
import com.esri.arcgis.system.IArray;

@ArcGISExtension
public class SimplePointWorkspaceHelper implements IPlugInWorkspaceHelper, IPlugInMetadataPath {
  /**
   * The location of the workspace on the file system.
   */

  String workspacePath;

  public SimplePointWorkspaceHelper(){
  }

  /**
   * Creates a new workspace helper for the workspace at the specified location.
   */

  public SimplePointWorkspaceHelper(String workspace){
    this.workspacePath = workspace;
  }

  public IArray getDatasetNames(int arg0) throws IOException,
      AutomationException {
    if (arg0 != esriDatasetType.esriDTFeatureClass && arg0 != esriDatasetType.esriDTAny && arg0 != esriDatasetType.esriDTTable)
      return null;

    IArray array = new Array();
    File file = new File(workspacePath);
    if (!file.exists())
      return null;
    String[] sptFileNames = file.list(new SPTFileFilter());

    for (int i = 0; i < sptFileNames.length; i++) {
      String fileName = sptFileNames[i];
      if (fileName.lastIndexOf(SimplePointWorkspaceFactoryHelper.fileExtension) > 0)
        fileName = fileName.substring(0, fileName.length()-SimplePointWorkspaceFactoryHelper.fileExtension.length());
      SimplePointDatasetHelper sptdh = new SimplePointDatasetHelper(workspacePath, fileName);
      array.add(sptdh);
    }
    return array;
  }

  /**
   * The native type object for the specified dataset.
   */
  public INativeType getNativeType(int arg0, String arg1) throws IOException,AutomationException {
    return null;
  }

  /**
   * Indicates whether the OID is the number of the record, i.e. whether IDs are continuous.
   */
  public boolean isOIDIsRecordNumber() throws IOException,AutomationException {
    return true;
  }

  /**
   * Indicates if a dataset has to count each row to get the number of rows in the dataset.
   */
  public boolean isRowCountIsCalculated() throws IOException,AutomationException {
    return true;
  }

  /**
   * Opens a dataset help for the dataset identified by the parameter.
   */
  public IPlugInDatasetHelper openDataset(String arg0) throws IOException,AutomationException {
    // Append the path and the dataset name to get the dataset's full path, then make sure the dataset exists.
    String fileName = this.workspacePath + File.separator + arg0 + SimplePointWorkspaceFactoryHelper.fileExtension;
    File file = new File(fileName);
    if (!file.exists())
      return null;
    // Create and return a new dataset helper.
    SimplePointDatasetHelper sptdh = new SimplePointDatasetHelper(workspacePath, arg0);
    return sptdh;
  }

  /**
   * The path to the metadata file for the dataset specified by the parameter.
   */
  public String getMetadataPath(String localName)
  {
    String metadataPath = this.workspacePath + File.separator + localName + SimplePointWorkspaceFactoryHelper.metaFileExtension;
    return metadataPath;
  }


  class SPTFileFilter implements FilenameFilter {
      public boolean accept(File dir, String name) {
          return (name.endsWith(SimplePointWorkspaceFactoryHelper.fileExtension));
      }
  }
}