1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.change;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23
24 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
25
26 import org.w3c.dom.Document;
27
28
29 /**
30 * Base ChangeManager implementation that manages the bookkeeping for
31 * supporting both ComponentChanges and DocumentChanges.
32 * subclasses must implement addComponentChangeImpl() to implement
33 * the ComponentChange support. To support DocumentChanges,
34 * <code>getDocument</code> must be implemented.
35 *
36 * @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/change/BaseChangeManager.java#1 $) $Date: 11-nov-2005.14:59:41 $
37 */
38 abstract class BaseChangeManager extends ChangeManager
39 {
40 /**
41 * {@inheritDoc}
42 */
43 @Override
44 public void addComponentChange(
45 FacesContext facesContext,
46 UIComponent uiComponent,
47 ComponentChange change)
48 {
49 if (facesContext == null || uiComponent == null || change == null)
50 throw new IllegalArgumentException(_LOG.getMessage(
51 "CANNOT_ADD_CHANGE_WITH_FACECONTEXT_OR_UICOMPONENT_OR_NULL"));
52
53
54 addComponentChangeImpl(facesContext, uiComponent, change);
55
56 if (supportsDocumentPersistence(facesContext))
57 {
58 DocumentChange docChange = null;
59
60 if (change instanceof DocumentChange)
61 {
62 docChange = (DocumentChange)change;
63 }
64 else
65 {
66
67 docChange = createDocumentChange(change);
68 }
69
70 if (docChange != null)
71 {
72 addDocumentChange(facesContext, uiComponent, docChange);
73 }
74 }
75 }
76
77 /**
78 * A no-op implementation of adding a ComponentChange. Sub-classers should
79 * override and provide an implementation if they support component changes.
80 * @param facesContext The FacesContext for this request.
81 * @param targetComponent The target component against which this change needs
82 * to be registered and applied later on.
83 * @param componentChange The ComponentChange to add
84 */
85 protected void addComponentChangeImpl(
86 FacesContext facesContext,
87 UIComponent targetComponent,
88 ComponentChange componentChange)
89 {
90
91 }
92
93
94 protected void persistDocumentChanges(
95 FacesContext facesContext)
96 {
97
98 }
99
100 /**
101 * Override to return the Document to modify as part of document-based
102 * persistence.
103 * Subclassers adding Document-based Persistence
104 * must override this method and should override
105 * <code>supportsDocumentPersistence</code>
106 * in order to enable Document-based Persistence
107 */
108 protected abstract Document getDocument(FacesContext context);
109
110 /**
111 * Returns true if we can support Document-based Persistence
112 * in this ChangeManager. Subclassers adding Document-based Persistence
113 * should override this method and must override <code>getDocument</code>
114 * in order to enable Document-based Persistence.
115 * @param context
116 * @return true if we can support Document-based Persistence
117 */
118 protected boolean supportsDocumentPersistence(FacesContext context)
119 {
120
121 return getDocument(context) != null;
122 }
123 private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
124 BaseChangeManager.class);
125 }