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.woody.datatype.typeimpl;
18:
19: /**
20: * A {@link org.apache.cocoon.woody.datatype.Datatype Datatype} implementation for
21: * types implementing Joshua Bloch's <a href="http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">
22: * typesafe enum</a> pattern.
23: * <p>See the following code for an example:</p>
24: * <pre>
25: * package com.example;
26: *
27: * public class Sex {
28: *
29: * public static final Sex MALE = new Sex("M");
30: * public static final Sex FEMALE = new Sex("F");
31: * private String code;
32: *
33: * private Sex(String code) { this.code = code; }
34: * }
35: * </pre>
36: * <p>If your enumerated type does not provide a {@link java.lang.Object#toString()}
37: * method, the enum convertor will use the fully qualified class name,
38: * followed by the name of the public static final field referring to
39: * each instance, i.e. "com.example.Sex.MALE", "com.example.Sex.FEMALE"
40: * and so on.</p>
41: * <p>If you provide a toString() method which returns something
42: * different, you should also provide a fromString(String, Locale)
43: * method to convert those strings back to instances.
44: *
45: * @version CVS $Id: EnumType.java 433543 2006-08-22 06:22:54Z crossley $
46: */
47: public class EnumType extends AbstractDatatype {
48:
49: public EnumType() {
50: }
51:
52: /* (non-Javadoc)
53: * @see org.apache.cocoon.woody.datatype.Datatype#getTypeClass()
54: */
55: public Class getTypeClass() {
56: return this .getConvertor().getTypeClass();
57: }
58:
59: /* (non-Javadoc)
60: * @see org.apache.cocoon.woody.datatype.Datatype#getDescriptiveName()
61: */
62: public String getDescriptiveName() {
63: return this.getConvertor().getTypeClass().getName();
64: }
65: }
|