001 /* 002 * JBoss, Home of Professional Open Source. 003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors 004 * as indicated by the @author tags. See the copyright.txt file in the 005 * distribution for a full listing of individual contributors. 006 * 007 * This is free software; you can redistribute it and/or modify it 008 * under the terms of the GNU Lesser General Public License as 009 * published by the Free Software Foundation; either version 2.1 of 010 * the License, or (at your option) any later version. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022 package org.jboss.dna.repository.sequencers; 023 024 import java.util.Set; 025 import javax.jcr.Node; 026 import javax.jcr.RepositoryException; 027 import javax.jcr.Session; 028 import net.jcip.annotations.ThreadSafe; 029 import org.jboss.dna.common.collection.Problems; 030 import org.jboss.dna.common.component.Component; 031 import org.jboss.dna.repository.observation.NodeChange; 032 import org.jboss.dna.repository.observation.NodeChangeListener; 033 import org.jboss.dna.repository.observation.NodeChanges; 034 import org.jboss.dna.repository.observation.ObservationService; 035 import org.jboss.dna.repository.util.JcrExecutionContext; 036 import org.jboss.dna.repository.util.RepositoryNodePath; 037 038 /** 039 * The interface for a DNA sequencer, which sequences nodes and their content to extract additional information from the 040 * information. 041 * <p> 042 * Implementations must provide a no-argument constructor. 043 * </p> 044 * 045 * @author Randall Hauch 046 * @author John Verhaeg 047 */ 048 @ThreadSafe 049 public interface Sequencer extends Component<SequencerConfig> { 050 051 /** 052 * Execute the sequencing operation on the supplied node, which has recently been created or changed. The implementation of 053 * this method is responsible for {@link JcrExecutionContext#getSessionFactory() getting sessions}, modifying the appropriate 054 * nodes, {@link Session#save() saving} any changes made by this sequencer, and {@link Session#logout() closing} all sessions 055 * (and any other acquired resources), even in the case of exceptions. 056 * <p> 057 * The {@link SequencingService} determines the sequencers that should be executed by monitoring the changes to one or more 058 * workspaces (it is a {@link NodeChangeListener} registered with the {@link ObservationService}). Changes in those workspaces 059 * are aggregated for each transaction, and organized into {@link NodeChanges changes for each node}. The SequencingService 060 * then determines for each {@link NodeChange set of changes to a node} the set of full paths to the properties that have 061 * changed and whether those paths {@link SequencerPathExpression#matcher(String) match} the sequencer's 062 * {@link SequencerConfig#getPathExpressions() path expressions}. Each path expression produces the path to the output node, 063 * and these output paths are accumulated and (with the original node that changed, the node change summary, and other 064 * information) supplied to the sequencer via this method. 065 * <p> 066 * It is possible that a sequencer is configured to apply to multiple properties on a node. So, in cases where multiple 067 * properties are changed on a single node (within a single repository transaction), the sequencer will only be executed once. 068 * Also, in such cases the sequencer's configuration may imply multiple output nodes, so it is left to the sequencer to define 069 * the behavior in such cases. 070 * </p> 071 * 072 * @param input the node that has recently been created or changed; never null 073 * @param sequencedPropertyName the name of the property that caused this sequencer to be executed; never null and never empty 074 * @param changes the immutable summary of changes that occurred on the <code>input</code> node within the transaction; never 075 * null 076 * @param outputPaths the paths to the nodes where the sequencing content should be placed; never null and never empty, but 077 * the set may contain paths for non-existant nodes or may reference the <code>input</code> node 078 * @param context the context in which this sequencer is executing; never null 079 * @param problems the interface used for recording problems; never null 080 * @throws RepositoryException if there is a problem while working with the repository 081 * @throws SequencerException if there is an error in this sequencer 082 */ 083 void execute( Node input, 084 String sequencedPropertyName, 085 NodeChange changes, 086 Set<RepositoryNodePath> outputPaths, 087 JcrExecutionContext context, 088 Problems problems ) throws RepositoryException, SequencerException; 089 090 }