01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel;
18:
19: import java.util.Iterator;
20:
21: import org.apache.avalon.framework.service.ServiceException;
22: import org.apache.avalon.framework.service.ServiceManager;
23: import org.apache.cocoon.forms.event.ProcessingPhaseListener;
24: import org.apache.cocoon.forms.formmodel.library.LibraryManager;
25: import org.apache.cocoon.util.location.LocationAttributes;
26: import org.w3c.dom.Element;
27:
28: /**
29: * Builds {@link FormDefinition}s.
30: *
31: * @version $Id: FormDefinitionBuilder.java 449149 2006-09-23 03:58:05Z crossley $
32: */
33: public final class FormDefinitionBuilder extends
34: AbstractContainerDefinitionBuilder {
35:
36: protected LibraryManager libraryManager;
37:
38: public void service(ServiceManager manager) throws ServiceException {
39: super .service(manager);
40: libraryManager = (LibraryManager) serviceManager
41: .lookup(LibraryManager.ROLE);
42: }
43:
44: public WidgetDefinition buildWidgetDefinition(
45: Element widgetElement,
46: WidgetDefinitionBuilderContext context) throws Exception {
47: throw new UnsupportedOperationException(
48: "Please use the other signature without WidgetDefinitionBuilderContext!");
49: }
50:
51: public WidgetDefinition buildWidgetDefinition(Element formElement)
52: throws Exception {
53: FormDefinition formDefinition = new FormDefinition(
54: libraryManager);
55: this .context = new WidgetDefinitionBuilderContext();
56: this .context.setLocalLibrary(formDefinition.getLocalLibrary());
57:
58: // set local URI
59: formDefinition.getLocalLibrary().setSourceURI(
60: LocationAttributes.getURI(formElement));
61:
62: Iterator i = buildEventListeners(formElement,
63: "on-processing-phase", ProcessingPhaseListener.class)
64: .iterator();
65: while (i.hasNext()) {
66: formDefinition
67: .addProcessingPhaseListener((ProcessingPhaseListener) i
68: .next());
69: }
70:
71: super .setupDefinition(formElement, formDefinition);
72: setDisplayData(formElement, formDefinition);
73:
74: setupContainer(formElement, "widgets", formDefinition);
75:
76: formDefinition.resolve();
77:
78: formDefinition.makeImmutable();
79:
80: this.context = null;
81: return formDefinition;
82: }
83: }
|