KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > strategy > SimpleTypeMapper


1 /*
2  * Copyright 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
17
18 package org.apache.commons.betwixt.strategy;
19
20 import org.apache.commons.betwixt.IntrospectionConfiguration;
21
22 /**
23  * Strategy for binding simple types.
24  * Simple types (in xml) have no attributes or child elements.
25  * For Betwixt, these are converted to and from strings
26  * and these strings used to populate either attributes or element body's.
27  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
28  * @version $Revision: 1.2 $
29  */

30 public abstract class SimpleTypeMapper {
31
32     /**
33      * Enumerates binding options for simple types.
34      * Simple types (in xml) have no attributes or child elements.
35      * For Betwixt, these are converted to and from strings
36      * and these strings used to populate either attributes or element body's.
37      * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
38      * @version $Revision: 1.2 $
39      */

40     public static class Binding {
41         public static final Binding ELEMENT = new Binding(1);
42         public static final Binding ATTRIBUTE = new Binding(2);
43         
44         private static final int ELEMENT_CODE = 1;
45         private static final int ATTRIBUTE_CODE = 2;
46         
47         private int code;
48         private Binding(int code) {
49             this.code = code;
50         }
51         
52         
53         /**
54          * Equals compatible with the enumeration.
55          */

56         public boolean equals( Object JavaDoc obj ) {
57             boolean result = false;
58             if ( obj == this ) {
59                 result = true;
60             }
61             return result;
62         }
63
64         /**
65          * Implementation compatible with equals
66          */

67         public int hashCode() {
68             return code;
69         }
70
71         /**
72          * Generate something appropriate for logging.
73          */

74         public String JavaDoc toString() {
75             String JavaDoc result = "[Binding]";
76             switch (code) {
77                 case ELEMENT_CODE:
78                     result = "[Binding: ELEMENT]";
79                     break;
80                     
81                 case ATTRIBUTE_CODE:
82                     result = "[Binding: ATTRIBUTE]";
83                     break;
84             }
85             return result;
86         }
87     }
88     
89     /**
90      * <p>Specifies the binding of a simple type.
91      * </p><p>
92      * <strong>Note:</strong> the xml name to which this property will be bound
93      * cannot be known at this stage (since it depends
94      * </p>
95      * @param propertyName the name of the property (to be bound)
96      * @param propertyType the type of the property (to be bound)
97      * @param configuration the current IntrospectionConfiguration
98      */

99     public abstract SimpleTypeMapper.Binding bind(
100                                                 String JavaDoc propertyName,
101                                                 Class JavaDoc propertyType,
102                                                 IntrospectionConfiguration configuration);
103 }
104
Popular Tags