/
IEncodingFactory.java
238 lines (220 loc) · 10.3 KB
/
IEncodingFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.encodings;
import java.nio.charset.Charset;
import java.sql.SQLException;
/**
* Interface for the EncodingFactory.
* <p>
* Note on naming convention: normally the prefix {@code I} for interfaces is avoided in Java, in this particular
* case I decided to use it as the concrete class {@link EncodingFactory} is the actual factory and the main access for
* encoding related information. This interface is used for connection specific factories (eg so the defaultEncoding is
* the connection character set).
* </p>
*
* @author <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
* @since 3.0
*/
public interface IEncodingFactory {
/**
* @return The {@link Encoding} for {@link java.nio.charset.Charset#defaultCharset()}.
*/
Encoding getDefaultEncoding();
/**
* Returns the {@link EncodingDefinition} for the default platform character set.
* <p>
* If the default character set is not supported by Jaybird, an instance of EncodingDefinition should be returned
* with Firebird encoding name {@code "NONE"}.
* </p>
*
* @return The {@link EncodingDefinition} for {@link java.nio.charset.Charset#defaultCharset()}.
*/
EncodingDefinition getDefaultEncodingDefinition();
/**
* Looks up the {@link org.firebirdsql.encodings.EncodingDefinition} for the specified Firebird encoding name.
*
* @param firebirdEncodingName
* The Firebird encoding name (case insensitive)
* @return EncodingDefinition instance or {@code null} if the encoding name is unknown
*/
EncodingDefinition getEncodingDefinitionByFirebirdName(String firebirdEncodingName);
/**
* Gets an {@link org.firebirdsql.encodings.Encoding} for the specified Firebird encoding. If there is no known
* encoding for this name,
* or the loaded EncodingDefinition is information-only, then the defaultEncoding is used.
*
* @param firebirdEncodingName
* The Firebird encoding name (case insensitive)
* @return Encoding instance (never null)
*/
Encoding getEncodingForFirebirdName(final String firebirdEncodingName);
/**
* Looks up the {@link org.firebirdsql.encodings.EncodingDefinition} for the specified Firebird character set id.
* <p>
* Implementations that do not know the connection character set should return {@code null} for the
* value {@link org.firebirdsql.gds.ISCConstants#CS_dynamic} (= 127), as that is the indicator to use
* the connection character set.
* </p>
*
* @param firebirdCharacterSetId
* Firebird character set id
* @return EncodingDefinition instance or {@code null} if the character set id is unknown or {@code 127} and this
* implementation doesn't know the connection character set.
*/
EncodingDefinition getEncodingDefinitionByCharacterSetId(int firebirdCharacterSetId);
/**
* Gets an {@link org.firebirdsql.encodings.Encoding} for the specified Firebird character set id. If there is no
* known encoding for this character set id (or if it is 127,
* see {@link #getEncodingDefinitionByCharacterSetId(int)}), or the loaded EncodingDefinition is information-only,
* then the defaultEncoding will be used.
*
* @param firebirdCharacterSetId
* The Firebird character set id
* @return Encoding instance (never null)
*/
Encoding getEncodingForCharacterSetId(int firebirdCharacterSetId);
/**
* Looks up an {@link org.firebirdsql.encodings.EncodingDefinition} for the Java {@link java.nio.charset.Charset}.
*
* @param charset
* The Java character set
* @return EncodingDefinition instance or {@code null} if the character set is not mapped
*/
EncodingDefinition getEncodingDefinitionByCharset(Charset charset);
/**
* Gets an {@link org.firebirdsql.encodings.Encoding} for the specified Java character set. If there is no known
* encoding for this {@link java.nio.charset.Charset}, or the loaded EncodingDefinition is information-only, then
* the fallbackEncoding will be used.
*
* @param charset
* The Java character set
* @param fallbackEncoding
* The Encoding to use as fallback if no encoding is found (usually the connection encoding). If
* {@code null}, the defaultEncoding for the JVM is used.
* @return Encoding instance (never null)
* @see #getOrCreateEncodingForCharset(java.nio.charset.Charset)
*/
Encoding getEncodingForCharset(final Charset charset, final Encoding fallbackEncoding);
/**
* Gets an {@link org.firebirdsql.encodings.Encoding} for the specified Java character set. If there is no known
* encoding for this {@link java.nio.charset.Charset}, or the loaded EncodingDefinition is information-only, then
* the defaultEncoding will be used.
*
* @param charset
* The Java character set
* @return Encoding instance (never null)
*/
Encoding getEncodingForCharset(Charset charset);
/**
* Creates an {@link Encoding} for the specified Java character set. If there is no known encoding for this
* charset, then an Encoding instance based on the charset is returned.
* <p>
* In general the method {@link #getEncodingForCharset(java.nio.charset.Charset, Encoding)} should be used.
* </p>
* <p>
* Don't confuse this method with {@link #getEncodingForCharset(Charset)}, which falls back to the default
* encoding.
* </p>
*
* @param charset
* The Java character set
* @return Encoding instance (never null)
* @see #getEncodingForCharset(java.nio.charset.Charset, Encoding)
*/
Encoding getOrCreateEncodingForCharset(final Charset charset);
/**
* Looks up the {@link org.firebirdsql.encodings.EncodingDefinition} by the specified Java character set name or
* alias.
*
* @param charsetAlias
* Name (or alias) of the Java character set (case insensitive)
* @return EncodingDefinition instance or {@code null} if the character set name is not mapped
*/
EncodingDefinition getEncodingDefinitionByCharsetAlias(String charsetAlias);
/**
* Gets an {@link org.firebirdsql.encodings.Encoding} for the specified Java character set name or alias. If there
* is no known encoding for
* this name, or the loaded EncodingDefinition is information-only, then the defaultEncoding will be used.
*
* @param charsetAlias
* The Java character set name or alias
* @return Encoding instance (never null)
*/
Encoding getEncodingForCharsetAlias(String charsetAlias);
/**
* Gets an instance of {@link org.firebirdsql.encodings.CharacterTranslator} for the specified mappingPath.
*
* @param mappingPath
* Path of the file with mapping definition
* @return Instance of CharacterTranslator
* @throws java.sql.SQLException
* @deprecated To be removed in Jaybird 3.1
*/
@Deprecated
CharacterTranslator getCharacterTranslator(String mappingPath) throws SQLException;
/**
* Gets or creates an {@link EncodingDefinition} for the supplied Firebird encoding and Java charset.
* <p>
* When {@code firebirdEncodingName} is not null and {@code javaCharsetAlias} is null, then the
* encoding definition as returned by {@link #getEncodingDefinitionByFirebirdName(String)} is returned. For the
* reverse ({@code firebirdEncodingName} is null and {@code javaCharsetAlias} isn't), the encoding
* definition
* as returned by {@link #getEncodingDefinitionByCharsetAlias(String)} is returned.
* </p>
* <p>
* When both parameters are set, the result of {@link #getEncodingDefinitionByFirebirdName(String)} is returned if
* the
* character set matches, otherwise a new {@link DefaultEncodingDefinition} is created based on its information,
* but
* with the specified character set. This can be useful for attempting to fix encoding issues in Firebird.
* </p>
* <p>
* If either of the parameters cannot be resolved, to an EncodingDefinition or {@link Charset}, or the
* EncodingDefinition
* is information-only - with the exception of Firebird encoding NONE - and no Java Charset is specified, then null
* is returned.
* </p>
*
* @param firebirdEncodingName
* Name of the Firebird encoding, or null to defer decision to the java Charset alias
* @param javaCharsetAlias
* Alias of the Java character set, or null to defer decision to the Firebird encoding
* @return An EncodingDefinition or null if both parameters are null, no encoding was found or if an exception
* occurred.
*/
EncodingDefinition getEncodingDefinition(String firebirdEncodingName, String javaCharsetAlias);
/**
* Returns an {@link org.firebirdsql.encodings.IEncodingFactory} that uses {@code encodingDefinition} as the
* default.
*
* @param encodingDefinition
* The default encoding to use (or {@code null} for the value of {@link #getDefaultEncoding()}
* @return IEncodingFactory instance with the specified default.
*/
IEncodingFactory withDefaultEncodingDefinition(EncodingDefinition encodingDefinition);
/**
* Returns an {@link org.firebirdsql.encodings.IEncodingFactory} that uses an {@link EncodingDefinition} identified
* by {@code charSet} as the default.
*
* @param charset
* The default charset to use.
* @return IEncodingFactory instance with the specified default.
*/
IEncodingFactory withDefaultEncodingDefinition(Charset charset);
}