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.graph.sequencer; 025 026 import java.util.Collections; 027 import java.util.HashMap; 028 import java.util.HashSet; 029 import java.util.Map; 030 import java.util.Set; 031 import org.jboss.dna.common.collection.Problems; 032 import org.jboss.dna.common.collection.SimpleProblems; 033 import org.jboss.dna.graph.ExecutionContext; 034 import org.jboss.dna.graph.property.Name; 035 import org.jboss.dna.graph.property.Path; 036 import org.jboss.dna.graph.property.Property; 037 038 /** 039 * @author John Verhaeg 040 */ 041 public class SequencerContext extends ExecutionContext { 042 043 private final Path inputPath; 044 private final Map<Name, Property> inputPropertiesByName; 045 private final Set<Property> inputProperties; 046 private final Problems problems; 047 private final String mimeType; 048 049 public SequencerContext( ExecutionContext context, 050 Path inputPath, 051 Set<Property> inputProperties, 052 String mimeType, 053 Problems problems ) { 054 super(context); 055 this.inputPath = inputPath; 056 this.inputProperties = inputProperties != null ? new HashSet<Property>(inputProperties) : new HashSet<Property>(); 057 this.mimeType = mimeType; 058 this.problems = problems != null ? problems : new SimpleProblems(); 059 Map<Name, Property> inputPropertiesByName = new HashMap<Name, Property>(); 060 for (Property property : this.inputProperties) { 061 inputPropertiesByName.put(property.getName(), property); 062 } 063 this.inputPropertiesByName = Collections.unmodifiableMap(inputPropertiesByName); 064 } 065 066 /** 067 * Return the path of the input node containing the content being sequenced. 068 * 069 * @return input node's path. 070 */ 071 public Path getInputPath() { 072 return inputPath; 073 } 074 075 /** 076 * Return the set of properties from the input node containing the content being sequenced. 077 * 078 * @return the input node's properties; never <code>null</code>. 079 */ 080 public Set<Property> getInputProperties() { 081 return inputProperties; 082 } 083 084 /** 085 * Return the property with the supplied name from the input node containing the content being sequenced. 086 * 087 * @param name 088 * @return the input node property, or <code>null</code> if none exists. 089 */ 090 public Property getInputProperty( Name name ) { 091 return inputPropertiesByName.get(name); 092 } 093 094 /** 095 * Return the MIME-type of the content being sequenced. 096 * 097 * @return the MIME-type 098 */ 099 public String getMimeType() { 100 return this.mimeType; 101 } 102 103 /** 104 * Get an interface that can be used to record various problems, warnings, and errors that are not extreme enough to warrant 105 * throwing exceptions. 106 * 107 * @return the interface for recording problems; never null 108 */ 109 public Problems getProblems() { 110 return this.problems; 111 } 112 }