KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > datatype > typeimpl > EnumType


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.datatype.typeimpl;
17
18 /**
19  * A {@link org.apache.cocoon.woody.datatype.Datatype Datatype} implementation for
20  * types implementing Joshua Bloch's <a HREF="http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">
21  * typesafe enum</a> pattern.
22  * <p>See the following code for an example:</p>
23  * <pre>
24  * package com.example;
25  *
26  * public class Sex {
27  *
28  * public static final Sex MALE = new Sex("M");
29  * public static final Sex FEMALE = new Sex("F");
30  * private String code;
31  *
32  * private Sex(String code) { this.code = code; }
33  * }
34  * </pre>
35  * <p>If your enumerated type does not provide a {@link java.lang.Object#toString()}
36  * method, the enum convertor will use the fully qualified class name,
37  * followed by the name of the public static final field referring to
38  * each instance, i.e. "com.example.Sex.MALE", "com.example.Sex.FEMALE"
39  * and so on.</p>
40  * <p>If you provide a toString() method which returns something
41  * different, you should also provide a fromString(String, Locale)
42  * method to convert those strings back to instances.
43  *
44  * @version CVS $Id: EnumType.java 30932 2004-07-29 17:35:38Z vgritsenko $
45  */

46 public class EnumType extends AbstractDatatype {
47     
48     public EnumType() {
49     }
50     
51     /* (non-Javadoc)
52      * @see org.apache.cocoon.woody.datatype.Datatype#getTypeClass()
53      */

54     public Class JavaDoc getTypeClass() {
55         return this.getConvertor().getTypeClass();
56     }
57
58     /* (non-Javadoc)
59      * @see org.apache.cocoon.woody.datatype.Datatype#getDescriptiveName()
60      */

61     public String JavaDoc getDescriptiveName() {
62         return this.getConvertor().getTypeClass().getName();
63     }
64 }
65
Popular Tags