KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.framework.configuration.ConfigurationException;
19 import org.apache.cocoon.forms.util.DomHelper;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * Builds {@link RepeaterDefinition}s.
24  *
25  * @version $Id: RepeaterDefinitionBuilder.java 307119 2005-10-07 13:28:45Z sylvain $
26  */

27 public final class RepeaterDefinitionBuilder extends AbstractContainerDefinitionBuilder {
28
29     public WidgetDefinition buildWidgetDefinition(Element JavaDoc repeaterElement) throws Exception JavaDoc {
30         
31         int initialSize = DomHelper.getAttributeAsInteger(repeaterElement, "initial-size", 0);
32         int minSize = DomHelper.getAttributeAsInteger(repeaterElement, "min-size", 0);
33         int maxSize = DomHelper.getAttributeAsInteger(repeaterElement, "max-size", Integer.MAX_VALUE);
34
35         // should throw error on negative values ? Just correct them for now.
36
if (minSize < 0) {
37             throw new ConfigurationException("min-size should be positive, at " + DomHelper.getLocationObject(repeaterElement));
38         }
39         
40         if (maxSize < 0) {
41             throw new ConfigurationException("max-size should be positive, at " + DomHelper.getLocationObject(repeaterElement));
42         }
43         
44         if (maxSize < minSize) {
45             throw new ConfigurationException("max-size should be greater that or equal to min-size, at " + DomHelper.getLocationObject(repeaterElement));
46         }
47
48         // initial size is at least the min size
49
initialSize = minSize > initialSize ? minSize : initialSize;
50                 
51         RepeaterDefinition repeaterDefinition = new RepeaterDefinition(initialSize, minSize, maxSize);
52         super.setupDefinition(repeaterElement, repeaterDefinition);
53         setDisplayData(repeaterElement, repeaterDefinition);
54
55         setupContainer(repeaterElement,"widgets",repeaterDefinition);
56
57         repeaterDefinition.makeImmutable();
58         return repeaterDefinition;
59     }
60 }
61
Popular Tags