KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > AggregateFieldDefinition


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.woody.formmodel;
17
18 import org.apache.excalibur.xml.sax.XMLizable;
19 import org.apache.oro.text.regex.Pattern;
20
21 import org.outerj.expression.Expression;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * The {@link WidgetDefinition} part of a AggregateField widget, see {@link AggregateField} for more information.
29  *
30  * @version $Id: AggregateFieldDefinition.java 53987 2004-10-07 15:33:25Z vgritsenko $
31  */

32 public class AggregateFieldDefinition extends FieldDefinition {
33
34     /**
35      * Defines expression which combines values of nested fields into this value
36      */

37     private Expression combineExpr;
38
39     /**
40      * Regular expression which splits this value on the values of the nested fields.
41      * It is compiled into the {@link #splitPattern}.
42      */

43     private String JavaDoc splitRegexp;
44
45     /**
46      * Compiled pattern out of the {@link #splitRegexp} regular expression.
47      */

48     private Pattern splitPattern;
49
50     /**
51      * Message to be displayed when the {@link #setSplitPattern(Pattern, String) splitPattern}
52      * does not match what the user entered. Optional.
53      */

54     protected XMLizable splitFailMessage;
55
56     /**
57      * List containing instances of {@link SplitMapping}, i.e. the mapping between
58      * a group (paren) from the regular expression and corresponding field id.
59      */

60     private List JavaDoc splitMappings = new ArrayList JavaDoc();
61
62     /**
63      *
64      */

65     private ContainerDefinitionDelegate container = new ContainerDefinitionDelegate(this);
66
67
68     public void addWidgetDefinition(WidgetDefinition widgetDefinition) throws DuplicateIdException {
69         container.addWidgetDefinition(widgetDefinition);
70     }
71
72     public boolean hasWidget(String JavaDoc id) {
73         return container.hasWidget(id);
74     }
75
76     protected void setCombineExpression(Expression expression) {
77         combineExpr = expression;
78     }
79
80     public Expression getCombineExpression() {
81         return combineExpr;
82     }
83
84     protected void setSplitPattern(Pattern pattern, String JavaDoc regexp) {
85         this.splitPattern = pattern;
86         this.splitRegexp = regexp;
87     }
88
89     public Pattern getSplitPattern() {
90         return splitPattern;
91     }
92
93     public String JavaDoc getSplitRegexp() {
94         return splitRegexp;
95     }
96
97     public XMLizable getSplitFailMessage() {
98         return splitFailMessage;
99     }
100
101     protected void setSplitFailMessage(XMLizable splitFailMessage) {
102         this.splitFailMessage = splitFailMessage;
103     }
104
105     protected void addSplitMapping(int group, String JavaDoc fieldId) {
106         splitMappings.add(new SplitMapping(group, fieldId));
107     }
108
109     public Iterator JavaDoc getSplitMappingsIterator() {
110         return splitMappings.iterator();
111     }
112
113     public Widget createInstance() {
114         AggregateField aggregateField = new AggregateField(this);
115
116         Iterator JavaDoc fieldDefinitionIt = container.getWidgetDefinitions().iterator();
117         while (fieldDefinitionIt.hasNext()) {
118             FieldDefinition fieldDefinition = (FieldDefinition)fieldDefinitionIt.next();
119             aggregateField.addField((Field)fieldDefinition.createInstance());
120         }
121
122         return aggregateField;
123     }
124
125     public static class SplitMapping {
126         private int group;
127         private String JavaDoc fieldId;
128
129         public SplitMapping(int group, String JavaDoc fieldId) {
130             this.group = group;
131             this.fieldId = fieldId;
132         }
133
134         public int getGroup() {
135             return group;
136         }
137
138         public String JavaDoc getFieldId() {
139             return fieldId;
140         }
141     }
142 }
143
Popular Tags