Logo Search packages:      
Sourcecode: uimaj version File versions  Download package

CollectionReader_ImplBase.java

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.uima.collection;

import java.io.IOException;
import java.util.Map;

import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.TypeSystem;
import org.apache.uima.resource.ConfigurableResource_ImplBase;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceCreationSpecifier;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
import org.apache.uima.util.Level;

/**
 * Base class for Collection Readers, which developers should extend with their own Collection
 * Reader implementation classes.
 * 
 * 
 */

00042 public abstract class CollectionReader_ImplBase extends ConfigurableResource_ImplBase implements
        CollectionReader {
  /**
   * @deprecated
   */
  @Deprecated
00048 private CasInitializer mCasInitializer;

  /**
   * current class
   */
00053   private static final Class<CollectionReader_ImplBase> CLASS_NAME = CollectionReader_ImplBase.class;

  /**
   * Called by the framework to initialize this Collection Reader. Subclasses should generally NOT
   * override this method; instead they should override the zero-argument {@link #initialize()}
   * method and access metadata via the {@link #getProcessingResourceMetaData()} method. This method
   * is non-final only for legacy reasons.
   * <p>
   * 
   * @see org.apache.uima.resource.Resource#initialize(org.apache.uima.resource.ResourceSpecifier,
   *      java.util.Map)
   */
00065   public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
          throws ResourceInitializationException {
    if (aSpecifier instanceof ResourceCreationSpecifier) {
      // do framework intitialiation
      if (super.initialize(aSpecifier, aAdditionalParams)) {
        // do user initialization
        initialize();
        return true;
      }
    }
    return false;
  }

  /**
   * This method is called during initialization, and does nothing by default. Subclasses should
   * override it to perform one-time startup logic.
   * 
   * @throws ResourceInitializationException
   *           if a failure occurs during initialization.
   */
00085   public void initialize() throws ResourceInitializationException {
    // no default behavior
  }

  /**
   * Default implementation of destroy, which calls {@link #close()}. If close throws an
   * IOException, it will be logged.
   * 
   * @see org.apache.uima.resource.Resource#destroy()
   */
00095   public void destroy() {
    try {
      close();
    } catch (IOException e) {
      UIMAFramework.getLogger(CLASS_NAME).log(Level.SEVERE, "", e);
    }
  }

  /**
   * Default implementation of typeSystemInit, which calls the CAS Initializer's typeSystemInit
   * method if a CAS Initializer is present.
   * 
   * @see org.apache.uima.collection.CollectionReader#typeSystemInit(org.apache.uima.cas.TypeSystem)
   */
00109   public void typeSystemInit(TypeSystem aTypeSystem) throws ResourceInitializationException {
    if (getCasInitializer() != null) {
      getCasInitializer().typeSystemInit(aTypeSystem);
    }
  }

  /**
   * Gets the metadata for this CollectionReader, which was extracted from the descriptor during
   * initialization.
   * 
   * @see org.apache.uima.collection.CollectionReader#getProcessingResourceMetaData()
   */
00121   public ProcessingResourceMetaData getProcessingResourceMetaData() {
    return (ProcessingResourceMetaData) getMetaData();
  }

  /**
   * Returns false.
   * 
   * @see org.apache.uima.collection.CollectionReader#isConsuming()
   */
00130   public boolean isConsuming() {
    return false;
  }

  /**
   * Gets the CAS initializer associated with this CollectionReader, if one was supplied via
   * {@link #setCasInitializer(CasInitializer)}.
   * 
   * @see org.apache.uima.collection.CollectionReader#getCasInitializer()
   * 
   * @deprecated As of v2.0 CAS Initializers are deprecated.
   */
  @Deprecated
00143   public CasInitializer getCasInitializer() {
    return mCasInitializer;
  }

  /**
   * Stores the CAS initializer in a private field and provides access to it via
   * {@link #getCasInitializer()}.
   * 
   * @see org.apache.uima.collection.CollectionReader#setCasInitializer(org.apache.uima.collection.CasInitializer)
   * 
   * @deprecated As of v2.0 CAS Initializers are deprecated.
   */
  @Deprecated
00156   public void setCasInitializer(CasInitializer aCasInitializer) {
    mCasInitializer = aCasInitializer;
  }

  /**
   * Notifies this Collection Reader that its configuration parameter settings have been changed. By
   * default this method just calls {@link #destroy()} followed by {@link #initialize()}.
   * Collection Readers that have expensive initialization that does not need to be redone whenever
   * configuration parameters change may wish to override this method to provide a more efficient
   * implementation.
   * 
   * @see org.apache.uima.resource.ConfigurableResource_ImplBase#reconfigure()
   */
00169   public void reconfigure() throws ResourceConfigurationException {
    super.reconfigure();
    destroy();
    try {
      initialize();
    } catch (ResourceInitializationException e) {
      throw new ResourceConfigurationException(e);
    }
  }
}

Generated by  Doxygen 1.6.0   Back to index