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 javax.faces.component.UIComponent;
22
23 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
24
25
26 /**
27 * Change specialization for adding a facet.
28 * While applying this Change, the specified component is re-created and added as a facet. If there
29 * were to be a facet by the specified name already, the new facet will not be added.
30 * @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/change/SetFacetChildComponentChange.java#0 $) $Date: 10-nov-2005.19:10:02 $
31 */
32 public class SetFacetChildComponentChange extends AddComponentChange
33 {
34 /**
35 * Constructs an AddFacetChange with the specified facet name and the
36 * corresponding component.
37 * @param facetName The name by which the component is to be added as a facet.
38 * @param facetComponent The component that is to be added as a facet.
39 * @throws IllegalArgumentException if specified facetName or the
40 * facetComponent were to be null.
41 */
42 public SetFacetChildComponentChange(
43 String facetName,
44 UIComponent facetComponent)
45 {
46 super(facetComponent);
47
48 if ((facetName == null) || (facetName.length() == 0))
49 throw new IllegalArgumentException(_LOG.getMessage(
50 "CANNOT_CONSTRUCT_ADDFACETCHANGE_WITH_NULL_FACETNAME_FACETCOMPONENT"));
51
52 _facetName = facetName;
53 }
54
55 /**
56 * Returns the name by which the facet is to be added while applying this
57 * Change.
58 */
59 public String getFacetName()
60 {
61 return _facetName;
62 }
63
64
65 /**
66 * {@inheritDoc}
67 */
68 @SuppressWarnings("unchecked")
69 @Override
70 public void changeComponent(UIComponent uiComponent)
71 {
72 UIComponent facetComponent = getComponent();
73
74 if (facetComponent == null)
75 return;
76
77 // Do not replace a facet if it already exists.
78 if (uiComponent.getFacets().get(_facetName) != null)
79 {
80 _LOG.info("FACET_ALREADY_PRESENT", _facetName);
81 return;
82 }
83
84 uiComponent.getFacets().put(_facetName, facetComponent);
85
86 }
87
88 private final String _facetName;
89 private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
90 SetFacetChildComponentChange.class);
91
92 private static final long serialVersionUID = 1L;
93 }