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