001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020
021 package org.apache.commons.pipeline.stage;
022
023 import org.apache.commons.pipeline.StageException;
024 import org.apache.commons.pipeline.event.KeyAvailableEvent;
025 import org.apache.commons.pipeline.util.KeyFactory;
026
027 /**
028 *
029 *
030 */
031 public class RaiseKeyAvailableEventStage extends BaseStage {
032
033 /** Creates a new instance of RaiseKeyAvailableEventStage */
034 public RaiseKeyAvailableEventStage() {
035 }
036
037 /**
038 * This implementation of process() simply generates a key for the
039 * processed object and raises a KeyAvailableEvent with the generated
040 * key, then emits the processed object unchanged.
041 */
042 public void process(Object obj) throws StageException {
043 this.context.raise(new KeyAvailableEvent<Object>(this, keyFactory.generateKey(obj)));
044 this.emit(obj);
045 }
046
047 /**
048 * Holds value of property keyFactory.
049 */
050 private KeyFactory<Object,Object> keyFactory;
051
052 /**
053 * Returns the KeyFactory used to create keys for the objects processed
054 * by this stage.
055 */
056 public KeyFactory<Object,Object> getKeyFactory() {
057 return keyFactory;
058 }
059
060 /**
061 * Sets the KeyFactory used to create keys for the objects processed
062 * by this stage.
063 */
064 public void setKeyFactory(KeyFactory<Object,Object> keyFactory) {
065 this.keyFactory = keyFactory;
066 }
067 }