KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > ActionDefinitionBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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 org.apache.cocoon.forms.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.forms.event.ActionListener;
21 import org.apache.cocoon.forms.util.DomHelper;
22 import org.apache.cocoon.util.Deprecation;
23 import org.w3c.dom.Element JavaDoc;
24
25 /**
26  * Builds {@link ActionDefinition}s.
27  *
28  * @version $Id: ActionDefinitionBuilder.java 219043 2005-07-14 14:44:06Z cziegeler $
29  */

30 public class ActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
31
32     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
33         ActionDefinition definition = new ActionDefinition();
34         setupDefinition(widgetElement, definition);
35         definition.makeImmutable();
36         return definition;
37     }
38     
39     protected void setupDefinition(Element JavaDoc widgetElement, ActionDefinition definition) throws Exception JavaDoc {
40         super.setupDefinition(widgetElement, definition);
41
42         setDisplayData(widgetElement, definition);
43
44         // Get the "command" optional attribute
45
String JavaDoc actionCommand = DomHelper.getAttribute(widgetElement, "command", null);
46         
47         // If unspecified, check the deprecated "action-command" deprecated attribute
48
if (actionCommand == null) {
49             actionCommand = DomHelper.getAttribute(widgetElement, "action-command", null);
50             if (actionCommand != null) {
51                 Deprecation.logger.info("The 'action-command' attribute is deprecated and replaced by 'command', at " +
52                     DomHelper.getLocation(widgetElement));
53             }
54         }
55         
56         definition.setActionCommand(actionCommand);
57
58         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-action", ActionListener.class).iterator();
59         while (iter.hasNext()) {
60             definition.addActionListener((ActionListener)iter.next());
61         }
62     }
63 }
64
Popular Tags