View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.graph.sequencer;
25  
26  import java.util.Collections;
27  import java.util.HashMap;
28  import java.util.HashSet;
29  import java.util.Map;
30  import java.util.Set;
31  import net.jcip.annotations.ThreadSafe;
32  import org.modeshape.common.collection.Problems;
33  import org.modeshape.common.collection.SimpleProblems;
34  import org.modeshape.graph.ExecutionContext;
35  import org.modeshape.graph.property.Name;
36  import org.modeshape.graph.property.Path;
37  import org.modeshape.graph.property.Property;
38  
39  /**
40   * A special {@link ExecutionContext} that is used for sequencing streams.
41   */
42  @ThreadSafe
43  public class StreamSequencerContext extends ExecutionContext {
44  
45      private final Path inputPath;
46      private final Map<Name, Property> inputPropertiesByName;
47      private final Set<Property> inputProperties;
48      private final Problems problems;
49      private final String mimeType;
50  
51      public StreamSequencerContext( ExecutionContext context,
52                                     Path inputPath,
53                                     Set<Property> inputProperties,
54                                     String mimeType,
55                                     Problems problems ) {
56          super(context);
57          this.inputPath = inputPath;
58          this.inputProperties = inputProperties != null ? new HashSet<Property>(inputProperties) : new HashSet<Property>();
59          this.mimeType = mimeType;
60          this.problems = problems != null ? problems : new SimpleProblems();
61          Map<Name, Property> inputPropertiesByName = new HashMap<Name, Property>();
62          for (Property property : this.inputProperties) {
63              inputPropertiesByName.put(property.getName(), property);
64          }
65          this.inputPropertiesByName = Collections.unmodifiableMap(inputPropertiesByName);
66      }
67  
68      /**
69       * Return the path of the input node containing the content being sequenced.
70       * 
71       * @return input node's path.
72       */
73      public Path getInputPath() {
74          return inputPath;
75      }
76  
77      /**
78       * Return the set of properties from the input node containing the content being sequenced.
79       * 
80       * @return the input node's properties; never <code>null</code>.
81       */
82      public Set<Property> getInputProperties() {
83          return inputProperties;
84      }
85  
86      /**
87       * Return the property with the supplied name from the input node containing the content being sequenced.
88       * 
89       * @param name
90       * @return the input node property, or <code>null</code> if none exists.
91       */
92      public Property getInputProperty( Name name ) {
93          return inputPropertiesByName.get(name);
94      }
95  
96      /**
97       * Return the MIME-type of the content being sequenced.
98       * 
99       * @return the MIME-type
100      */
101     public String getMimeType() {
102         return this.mimeType;
103     }
104 
105     /**
106      * Get an interface that can be used to record various problems, warnings, and errors that are not extreme enough to warrant
107      * throwing exceptions.
108      * 
109      * @return the interface for recording problems; never null
110      */
111     public Problems getProblems() {
112         return this.problems;
113     }
114 }