KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > metadata > CustomizedEncoder


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.metadata;
24
25 import java.util.Properties JavaDoc;
26
27 import org.xquark.extractor.common.Constants;
28
29 /**
30  * Handle case conversion for database object names used during metadata
31  * contruction from JDBC information providing uniform later use.
32  */

33 public class CustomizedEncoder implements QNameEncoder, Constants {
34
35     private static final String JavaDoc RCSRevision = "$Revision: 1.3 $";
36     private static final String JavaDoc RCSName = "$Name: $";
37
38     private Properties JavaDoc _substitutionMap = new Properties JavaDoc();
39     private int _nameCase = CASE_MIXED;
40
41     public CustomizedEncoder() {}
42
43     public void addSubstitution(char aChar, String JavaDoc subtituteWith) {
44         _substitutionMap.setProperty(String.valueOf(aChar), subtituteWith);
45     }
46
47     public void setSubstitutionMap(Properties JavaDoc map) {
48         _substitutionMap = map;
49     }
50
51     public void setNameCase(int nameCase) {
52         _nameCase = nameCase;
53     }
54
55     public String JavaDoc encode(String JavaDoc dbObjectName) {
56
57         String JavaDoc retVal = null;
58         if (null == _substitutionMap) {
59             retVal = dbObjectName;
60         } else {
61             StringBuffer JavaDoc retBuf = new StringBuffer JavaDoc();
62
63             char[] name = dbObjectName.toCharArray();
64             String JavaDoc aChar = null;
65             String JavaDoc substitution = null;
66             for (int i = 0; i < name.length; i++) {
67                 aChar = String.valueOf(name[i]);
68                 substitution = _substitutionMap.getProperty(aChar);
69                 if (null == substitution) {
70                     retBuf.append(aChar);
71                 } else {
72                     retBuf.append(substitution);
73                 }
74             }
75             retVal = retBuf.toString();
76         }
77
78         if (CASE_MIXED == _nameCase) {
79         } else if (CASE_LOWER == _nameCase) {
80             retVal = retVal.toLowerCase();
81         } else /* (CASE_UPPER == _nameCase) */ {
82             retVal = retVal.toUpperCase();
83         }
84
85         return retVal;
86     }
87 }
88
Popular Tags