KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > transform > TypeConversion


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.transform;
20
21 /**
22  * <p>
23  * <code>TypeConversion</code> is used to specify type conversions used in
24  * <code>{@link org.enhydra.zeus.Transformer}</code> and related classes
25  * and processes. It allows character-based data, as found in XML documents,
26  * to be converted to type-specific data in Java.
27  * </p>
28  *
29  * @author Brett McLaughlin
30  */

31 public class TypeConversion {
32     
33     /** The name of this type conversion */
34     private String JavaDoc name;
35     
36     /** The Java type to convert to; generally a fully-qualified Java class */
37     private String JavaDoc type;
38     
39     /** The class/method to use for parsing data into this format */
40     private String JavaDoc parseMethod;
41     
42     /** The class/method to use for printing data in this format */
43     private String JavaDoc printMethod;
44     
45     /**
46      * <p>
47      * This creates a new <code>Conversion</code> with the supplied
48      * name and type. In most cases, the type specified here should
49      * be a fully-qualified Java class name, such as "java.util.Date" or
50      * "java.math.BigDecimal". If the class is in an automatically imported
51      * class, like "java.lang.Integer", then the package does not need to
52      * be supplied.
53      * </p>
54      *
55      * @param name the name for this type conversion.
56      * @param type the Java type for this type conversion.
57      */

58     public TypeConversion(String JavaDoc name, String JavaDoc type) {
59         this(name, type, null, null);
60     }
61     
62     /**
63      * <p>
64      * This creates a new <code>Conversion</code> with the supplied
65      * name and type. In most cases, the type specified here should
66      * be a fully-qualified Java class name, such as "java.util.Date" or
67      * "java.math.BigDecimal". If the class is in an automatically imported
68      * class, like "java.lang.Integer", then the package does not need to
69      * be supplied. It also allows specification of the method to use
70      * for conversion of data from XML to Java, and for printing Java in
71      * the format this <code>TypeConversion</code> represents.
72      * </p>
73      *
74      * @param name the name for this type conversion.
75      * @param type the Java type for this type conversion.
76      * @param parseMethod the method to use for parsing data.
77      * @param printMethof the method to use for printing data.
78      */

79     public TypeConversion(String JavaDoc name, String JavaDoc type,
80                           String JavaDoc parseMethod, String JavaDoc printMethod) {
81              
82         // Error checking
83
if (name == null) {
84             throw new IllegalArgumentException JavaDoc("A TypeConversion cannot " +
85                 "have a null name.");
86         }
87         if (type == null) {
88             throw new IllegalArgumentException JavaDoc("A TypeConversion cannot " +
89                 "have a null type.");
90         }
91         
92         this.name = name;
93         this.type = type;
94         this.parseMethod = parseMethod;
95         this.printMethod = printMethod;
96     }
97     
98     /**
99      * <p>
100      * This will set the name of this <code>TypeConversion</code>.
101      * </p>
102      *
103      * @param name the name for this type conversion
104      */

105     public void setName(String JavaDoc name) {
106         if (name == null) {
107             throw new IllegalArgumentException JavaDoc("A TypeConversion cannot " +
108                 "have a null name.");
109         }
110         this.name = name;
111     }
112     
113     /**
114      * <p>
115      * This will return the current name of this <code>TypeConversion</code>.
116      * </p>
117      *
118      * @return <code>String</code> - the name of this type conversion.
119      */

120     public String JavaDoc getName() {
121         return name;
122     }
123     
124     /**
125      * <p>
126      * This will set the Java type for data using this <code>Conversion</code>.
127      * In most cases, the type specified here should be a fully-qualified
128      * Java class name, such as "java.util.Date" or "java.math.BigDecimal".
129      * If the class is in an automatically imported class, like
130      * "java.lang.Integer", then the package does not need to be supplied.
131      * </p>
132      *
133      * @param type the Java type for this conversion.
134      */

135     public void setType(String JavaDoc type) {
136         if (type == null) {
137             throw new IllegalArgumentException JavaDoc("A TypeConversion cannot " +
138                 "have a null type.");
139         }
140         
141         this.type = type;
142     }
143     
144     /**
145      * <p>
146      * This returns the Java type for this <code>Conversion</code>. This is
147      * generally a fully-qualified Java class, such as "java.util.Date" or
148      * "java.math.BigDecimal".
149      * </p>
150      *
151      * @return <code>String</code> - Java type for this conversion.
152      */

153     public String JavaDoc getType() {
154         return type;
155     }
156     
157     /**
158      * <p>
159      * This sets the name of the method to use for conversion from a
160      * character-based piece of XML data into the Java type for this
161      * <code>TypeConversion</code>.
162      * </p>
163      *
164      * @param parseMethod the name of the method to use for parsing data
165      */

166     public void setParseMethod(String JavaDoc parseMethod) {
167         this.parseMethod = parseMethod;
168     }
169     
170     /**
171      * <p>
172      * This returns the name of the method to use for conversion from
173      * a character-based piece of XML data into the Java type for this
174      * <code>TypeConversion</code>.
175      * </p>
176      *
177      * @return <code>String</code> - the name of the method to use for parsing.
178      */

179     public String JavaDoc getParseMethod() {
180         return parseMethod;
181     }
182     
183     /**
184      * <p>
185      * This sets the name of the method to use for printing data in the
186      * format in this <code>TypeConversion</code>.
187      * </p>
188      *
189      * @param printMethod the name of the method to use for printing data
190      */

191     public void setPrintMethod(String JavaDoc printMethod) {
192         this.printMethod = printMethod;
193     }
194     
195     /**
196      * <p>
197      * This returns the name of the method to use for printing data in the
198      * format in this <code>TypeConversion</code>.
199      * </p>
200      *
201      * @return <code>String</code> - the name of the method to use for printing.
202      */

203     public String JavaDoc getPrintMethod() {
204         return printMethod;
205     }
206 }
207
Popular Tags