View Javadoc

1   /*
2    * Copyright 2004 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.nordija.tapestry.bayeux.stream;
17  
18  import org.apache.hivemind.util.Defense;
19  import org.apache.tapestry.IDynamicInvoker;
20  
21  import java.util.Collection;
22  
23  /**
24   * @author Jacob von Eyben - Nordija A/S
25   */
26  public class StreamServiceParameter {
27  
28      private IStream stream;
29  
30      private String streamResourceSourceExtentionName;
31  
32      private Object[] serviceParameters;
33  
34      private String[] updateParts;
35  
36      private boolean json;
37  
38      private boolean async;
39  
40      public StreamServiceParameter(IStream stream, String streamResourceSourceExtentionName, Object[] serviceParameters) {
41          this(stream, streamResourceSourceExtentionName, serviceParameters, null);
42      }
43  
44      public StreamServiceParameter(IStream stream, String streamResourceSourceExtentionName, Object[] serviceParameters, IDynamicInvoker invoker) {
45          Defense.notNull(stream, "stream");
46          this.stream = stream;
47          this.serviceParameters = serviceParameters;
48          this.streamResourceSourceExtentionName = streamResourceSourceExtentionName;
49  
50          if (invoker == null) {
51  
52              Collection comps = stream.getUpdateComponents();
53              if (comps == null)
54                  updateParts = new String[0];
55              else
56                  updateParts = (String[]) comps.toArray(new String[comps.size()]);
57  
58              json = stream.isJson();
59              async = stream.isAsync();
60          } else {
61  
62              Collection comps = invoker.getUpdateComponents();
63              if (comps == null)
64                  updateParts = new String[0];
65              else
66                  updateParts = (String[]) comps.toArray(new String[comps.size()]);
67  
68              json = invoker.isJson();
69              async = invoker.isAsync();
70          }
71  
72          // if they gave only an updateComponents param make it async by default
73          if (!json && !async && updateParts.length > 0)
74              async = true;
75  
76      }
77  
78      public IStream getStream() {
79          return stream;
80      }
81  
82      public String getStreamResourceSourceExtentionName() {
83          return streamResourceSourceExtentionName;
84      }
85  
86      public Object[] getServiceParameters() {
87          return serviceParameters;
88      }
89  
90      public String[] getUpdateParts() {
91          return updateParts;
92      }
93  
94      public boolean isJson() {
95          return json;
96      }
97  
98      public boolean isAsync() {
99          return async;
100     }
101 }