KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2005 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.context.Context;
19
20 /**
21  * A {@link FieldDefinition} for {@link CaptchaField}s.
22  *
23  * @see http://www.captcha.net/
24  * @version CVS $Id: CaptchaFieldDefinition.java 289538 2005-09-16 13:46:22Z sylvain $
25  */

26 public class CaptchaFieldDefinition extends FieldDefinition {
27     
28     private Context avalonContext;
29     private int length;
30
31     public CaptchaFieldDefinition(Context avalonContext) {
32         this.avalonContext = avalonContext;
33     }
34     
35     /**
36      * initialize this definition with the other, sort of like a copy constructor
37      */

38     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
39         super.initializeFrom(definition);
40         
41         if(definition instanceof CaptchaFieldDefinition) {
42             CaptchaFieldDefinition other = (CaptchaFieldDefinition)definition;
43             
44             this.length = other.length;
45             
46         } else {
47             throw new Exception JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
48         }
49     }
50
51     public Widget createInstance() {
52         CaptchaField field = new CaptchaField(this, avalonContext);
53         return field;
54     }
55
56     public int getLength() {
57         return length;
58     }
59
60     public void setLength(int length) {
61         checkMutable();
62         this.length = length;
63     }
64
65 }
66
Popular Tags