1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.context;
20
21 import java.io.IOException;
22
23 import java.util.Map;
24
25 import javax.faces.context.ExternalContext;
26
27 import javax.faces.context.FacesContext;
28
29 import org.apache.myfaces.trinidad.event.WindowLifecycleListener;
30
31 /**
32 * <p>
33 * Manages the set of Windows currently in the Session and allows listeners on the Windows'
34 * lifecycles to be registered.
35 * </p>
36 * @see org.apache.myfaces.trinidad.context.RequestContext#getWindowManager
37 */
38 abstract public class WindowManager
39 {
40 /**
41 * @param extContext ExternalContext so that the WindowManager may be called before the
42 * FacesContext is available
43 * @return The Window that contains the document making the current request
44 */
45 public abstract Window getCurrentWindow(ExternalContext extContext);
46
47 /**
48 * @param extContext ExternalContext so that the WindowManager may be called before the
49 * FacesContext is available
50 * @return The Unmodifiable Map of WindowIds to Windows
51 */
52 public abstract Map<String, ? extends Window> getWindows(ExternalContext extContext);
53
54 /**
55 * <p>
56 * Registers a listener that will be informed of changes to the Lifecylce state of any of
57 * the known Windows.
58 * </p>
59 * <p>
60 * WindowLifecycleListener may be registered automatically by adding a file
61 * containing the names of the classes implementing the WindowListener in a file named
62 * <code>org.apache.myfaces.trinidad.event.WindowListener</code> inside of
63 * the <code>META_INF/services</code> directory.
64 * </p>
65 * @param extContext ExternalContext so that the WindowManager may be called before the
66 * FacesContext is available
67 * @param windowListener
68 */
69 public abstract void addWindowLifecycleListener(
70 ExternalContext extContext, WindowLifecycleListener windowListener);
71
72 /**
73 * Removes a listener that will be informed of changes to the Lifecylce state of any of
74 * the known Windows
75 * @param extContext ExternalContext so that the WindowManager may be called before the
76 * FacesContext is available
77 * @param windowListener
78 */
79 public abstract void removeWindowLifecycleListener(
80 ExternalContext extContext, WindowLifecycleListener windowListener);
81
82 /**
83 * Performs any necessary action to embed the current window identifier into the output
84 * @param context FacesContext to use to write the output
85 * @throws IOException if an output exception occurs
86 */
87 public abstract void writeState(FacesContext context) throws IOException;
88 }