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.common.component.ClassLoaderFactory;
35  import org.modeshape.graph.ExecutionContext;
36  import org.modeshape.graph.SecurityContext;
37  import org.modeshape.graph.mimetype.MimeTypeDetector;
38  import org.modeshape.graph.property.Name;
39  import org.modeshape.graph.property.NamespaceRegistry;
40  import org.modeshape.graph.property.Path;
41  import org.modeshape.graph.property.Property;
42  
43  /**
44   * A special {@link ExecutionContext} that is used for sequencing streams.
45   */
46  @ThreadSafe
47  public class StreamSequencerContext extends ExecutionContext {
48  
49      private final Path inputPath;
50      private final Map<Name, Property> inputPropertiesByName;
51      private final Set<Property> inputProperties;
52      private final Problems problems;
53      private final String mimeType;
54  
55      public StreamSequencerContext( ExecutionContext context,
56                                     Path inputPath,
57                                     Set<Property> inputProperties,
58                                     String mimeType,
59                                     Problems problems ) {
60          super(context);
61          this.inputPath = inputPath;
62          this.inputProperties = inputProperties != null ? new HashSet<Property>(inputProperties) : new HashSet<Property>();
63          this.mimeType = mimeType;
64          this.problems = problems != null ? problems : new SimpleProblems();
65          Map<Name, Property> inputPropertiesByName = new HashMap<Name, Property>();
66          for (Property property : this.inputProperties) {
67              inputPropertiesByName.put(property.getName(), property);
68          }
69          this.inputPropertiesByName = Collections.unmodifiableMap(inputPropertiesByName);
70      }
71  
72      /**
73       * Return the path of the input node containing the content being sequenced.
74       * 
75       * @return input node's path.
76       */
77      public Path getInputPath() {
78          return inputPath;
79      }
80  
81      /**
82       * Return the set of properties from the input node containing the content being sequenced.
83       * 
84       * @return the input node's properties; never <code>null</code>.
85       */
86      public Set<Property> getInputProperties() {
87          return inputProperties;
88      }
89  
90      /**
91       * Return the property with the supplied name from the input node containing the content being sequenced.
92       * 
93       * @param name
94       * @return the input node property, or <code>null</code> if none exists.
95       */
96      public Property getInputProperty( Name name ) {
97          return inputPropertiesByName.get(name);
98      }
99  
100     /**
101      * Return the MIME-type of the content being sequenced.
102      * 
103      * @return the MIME-type
104      */
105     public String getMimeType() {
106         return this.mimeType;
107     }
108 
109     /**
110      * Get an interface that can be used to record various problems, warnings, and errors that are not extreme enough to warrant
111      * throwing exceptions.
112      * 
113      * @return the interface for recording problems; never null
114      */
115     public Problems getProblems() {
116         return this.problems;
117     }
118 
119     /**
120      * {@inheritDoc}
121      * 
122      * @see org.modeshape.graph.ExecutionContext#with(org.modeshape.common.component.ClassLoaderFactory)
123      */
124     @Override
125     public StreamSequencerContext with( ClassLoaderFactory classLoaderFactory ) {
126         return new StreamSequencerContext(super.with(classLoaderFactory), inputPath, inputProperties, mimeType, problems);
127     }
128 
129     /**
130      * {@inheritDoc}
131      * 
132      * @see org.modeshape.graph.ExecutionContext#with(java.util.Map)
133      */
134     @Override
135     public StreamSequencerContext with( Map<String, String> data ) {
136         return new StreamSequencerContext(super.with(data), inputPath, inputProperties, mimeType, problems);
137     }
138 
139     /**
140      * {@inheritDoc}
141      * 
142      * @see org.modeshape.graph.ExecutionContext#with(org.modeshape.graph.mimetype.MimeTypeDetector)
143      */
144     @Override
145     public StreamSequencerContext with( MimeTypeDetector mimeTypeDetector ) {
146         return new StreamSequencerContext(super.with(mimeTypeDetector), inputPath, inputProperties, mimeType, problems);
147     }
148 
149     /**
150      * {@inheritDoc}
151      * 
152      * @see org.modeshape.graph.ExecutionContext#with(org.modeshape.graph.property.NamespaceRegistry)
153      */
154     @Override
155     public StreamSequencerContext with( NamespaceRegistry namespaceRegistry ) {
156         return new StreamSequencerContext(super.with(namespaceRegistry), inputPath, inputProperties, mimeType, problems);
157     }
158 
159     /**
160      * {@inheritDoc}
161      * 
162      * @see org.modeshape.graph.ExecutionContext#with(org.modeshape.graph.SecurityContext)
163      */
164     @Override
165     public StreamSequencerContext with( SecurityContext securityContext ) {
166         return new StreamSequencerContext(super.with(securityContext), inputPath, inputProperties, mimeType, problems);
167     }
168 
169     /**
170      * {@inheritDoc}
171      * 
172      * @see org.modeshape.graph.ExecutionContext#with(java.lang.String, java.lang.String)
173      */
174     @Override
175     public StreamSequencerContext with( String key,
176                                         String value ) {
177         return new StreamSequencerContext(super.with(key, value), inputPath, inputProperties, mimeType, problems);
178     }
179 
180     /**
181      * {@inheritDoc}
182      * 
183      * @see org.modeshape.graph.ExecutionContext#with(java.lang.String)
184      */
185     @Override
186     public StreamSequencerContext with( String processId ) {
187         return new StreamSequencerContext(super.with(processId), inputPath, inputProperties, mimeType, problems);
188     }
189 }