View Javadoc

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.change;
20  
21  import java.util.Map;
22  
23  import javax.faces.component.UIComponent;
24  
25  import org.w3c.dom.Element;
26  import org.w3c.dom.Node;
27  import org.apache.myfaces.trinidad.logging.TrinidadLogger;
28  
29  /**
30   * Change specialization for removal of a facet.
31   * While applying this Change, if there were to be a facet with the specified
32   *  name, it will be removed.
33   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/change/RemoveFacetComponentChange.java#0 $) $Date: 10-nov-2005.19:10:01 $
34   */
35  public class RemoveFacetComponentChange extends ComponentChange
36                                          implements DocumentChange
37  {
38    /**
39     * Constructs a RemoveFacetChange with the specified name of the facet.
40     * @param facetName The name of facet that needs to be removed.
41     * @throws IllegalArgumentException if specified facetName is 
42     *          <code>null</code>.
43     */
44    public RemoveFacetComponentChange(String facetName)
45    {
46      if ((facetName == null) || (facetName.length() == 0))
47        throw new IllegalArgumentException(_LOG.getMessage(
48          "CANNOT_CONSTRUCT_REMOVEFACETCHANGE_WITH_NULL_FACETNAME"));
49      _facetName = facetName;
50    }
51    
52    /**
53     * Returns the name of facet that needs to be removed.
54     */
55    public String getFacetName()
56    {
57      return _facetName;
58    }
59    
60    /**
61     * {@inheritDoc}
62     */
63    @SuppressWarnings("unchecked")
64    @Override
65    public void changeComponent(UIComponent uiComponent)
66    {
67      Map<String, UIComponent> facets = uiComponent.getFacets();
68      facets.remove(_facetName);
69    }
70  
71    /**
72     * {@inheritDoc}
73     */
74    public void changeDocument(Node componentNode)
75    {
76      Element facetElement = ChangeUtils.__getFacetElement(componentNode, _facetName);
77      
78      if (facetElement != null)
79      {
80        componentNode.removeChild(facetElement);
81      }
82    }
83  
84    /** 
85     * Returns true if adding the DocumentChange should force the JSP Document
86     * to reload
87     */
88    public boolean getForcesDocumentReload()
89    {
90      return false;
91    }
92  
93    private final String _facetName;
94    private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
95      RemoveFacetComponentChange.class);
96    private static final long serialVersionUID = 1L;
97  }