Mercurial > 510Connectbot
comparison src/org/tn5250j/encoding/BuiltInCodePageFactory.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | b29b39f386a4 |
children |
comparison
equal
deleted
inserted
replaced
111:6a0ad4d384ea | 112:77ac18bc1b2f |
---|---|
58 /** | 58 /** |
59 * Methods for built-in code page support. | 59 * Methods for built-in code page support. |
60 */ | 60 */ |
61 class BuiltInCodePageFactory { | 61 class BuiltInCodePageFactory { |
62 private static final String TAG = "BuiltInCodePageFactory"; | 62 private static final String TAG = "BuiltInCodePageFactory"; |
63 private static BuiltInCodePageFactory singleton; | 63 private static BuiltInCodePageFactory singleton; |
64 | 64 |
65 private final List<Class<?>> clazzes = new ArrayList<Class<?>>(); | 65 private final List<Class<?>> clazzes = new ArrayList<Class<?>>(); |
66 | 66 |
67 | 67 |
68 private BuiltInCodePageFactory() { | 68 private BuiltInCodePageFactory() { |
69 register(); | 69 register(); |
70 } | 70 } |
71 | 71 |
72 public static synchronized final BuiltInCodePageFactory getInstance() { | 72 public static synchronized final BuiltInCodePageFactory getInstance() { |
73 if (singleton == null) { | 73 if (singleton == null) { |
74 singleton = new BuiltInCodePageFactory(); | 74 singleton = new BuiltInCodePageFactory(); |
75 } | 75 } |
76 return singleton; | |
77 } | |
78 | 76 |
79 private void register() { | 77 return singleton; |
80 clazzes.add(CCSID37.class); | 78 } |
81 clazzes.add(CCSID273.class); | |
82 clazzes.add(CCSID277.class); | |
83 clazzes.add(CCSID278.class); | |
84 clazzes.add(CCSID280.class); | |
85 clazzes.add(CCSID284.class); | |
86 clazzes.add(CCSID285.class); | |
87 clazzes.add(CCSID297.class); | |
88 clazzes.add(CCSID424.class); | |
89 clazzes.add(CCSID500.class); | |
90 clazzes.add(CCSID870.class); | |
91 clazzes.add(CCSID871.class); | |
92 clazzes.add(CCSID875.class); | |
93 clazzes.add(CCSID1025.class); | |
94 clazzes.add(CCSID1026.class); | |
95 clazzes.add(CCSID1112.class); | |
96 clazzes.add(CCSID1140.class); | |
97 clazzes.add(CCSID1141.class); | |
98 clazzes.add(CCSID1147.class); | |
99 clazzes.add(CCSID1148.class); | |
100 } | |
101 | 79 |
102 /** | 80 private void register() { |
103 * @return unsorted list of available code pages | 81 clazzes.add(CCSID37.class); |
104 */ | 82 clazzes.add(CCSID273.class); |
105 public String[] getAvailableCodePages() { | 83 clazzes.add(CCSID277.class); |
106 HashSet<String> cpset = new HashSet<String>(); | 84 clazzes.add(CCSID278.class); |
107 for (Class<?> clazz : clazzes) { | 85 clazzes.add(CCSID280.class); |
108 final ICodepageConverter converter = getConverterFromClassName(clazz); | 86 clazzes.add(CCSID284.class); |
109 if (converter != null) { | 87 clazzes.add(CCSID285.class); |
110 cpset.add(converter.getName()); | 88 clazzes.add(CCSID297.class); |
111 } | 89 clazzes.add(CCSID424.class); |
112 } | 90 clazzes.add(CCSID500.class); |
113 return cpset.toArray(new String[cpset.size()]); | 91 clazzes.add(CCSID870.class); |
114 } | 92 clazzes.add(CCSID871.class); |
93 clazzes.add(CCSID875.class); | |
94 clazzes.add(CCSID1025.class); | |
95 clazzes.add(CCSID1026.class); | |
96 clazzes.add(CCSID1112.class); | |
97 clazzes.add(CCSID1140.class); | |
98 clazzes.add(CCSID1141.class); | |
99 clazzes.add(CCSID1147.class); | |
100 clazzes.add(CCSID1148.class); | |
101 } | |
115 | 102 |
116 /** | 103 /** |
117 * @param encoding | 104 * @return unsorted list of available code pages |
118 * @return an {@link ICodePage} object OR null, of not found | 105 */ |
119 */ | 106 public String[] getAvailableCodePages() { |
120 public ICodePage getCodePage(String encoding) { | 107 HashSet<String> cpset = new HashSet<String>(); |
121 for (Class<?> clazz : clazzes) { | |
122 final ICodepageConverter converter = getConverterFromClassName(clazz); | |
123 if (converter != null && converter.getName().equals(encoding)) { | |
124 return converter; | |
125 } | |
126 } | |
127 return null; | |
128 } | |
129 | 108 |
130 /** | 109 for (Class<?> clazz : clazzes) { |
131 * Lazy loading converters takes time, | 110 final ICodepageConverter converter = getConverterFromClassName(clazz); |
132 * but doesn't happen so often and saves memory. | 111 |
133 * | 112 if (converter != null) { |
134 * @param clazz {@link ICodepageConverter} | 113 cpset.add(converter.getName()); |
135 * @return | 114 } |
136 */ | 115 } |
137 private ICodepageConverter getConverterFromClassName(Class<?> clazz) { | 116 |
138 try { | 117 return cpset.toArray(new String[cpset.size()]); |
139 final Constructor<?> constructor = clazz.getConstructor(new Class[0]); | 118 } |
140 final ICodepageConverter converter = (ICodepageConverter) constructor.newInstance(); | 119 |
141 converter.init(); | 120 /** |
142 return converter; | 121 * @param encoding |
143 } catch (Exception e) { | 122 * @return an {@link ICodePage} object OR null, of not found |
144 Log.e(TAG,"Couldn't load code page converter class:" + clazz.getCanonicalName(), e); | 123 */ |
145 return null; | 124 public ICodePage getCodePage(String encoding) { |
146 } | 125 for (Class<?> clazz : clazzes) { |
147 } | 126 final ICodepageConverter converter = getConverterFromClassName(clazz); |
127 | |
128 if (converter != null && converter.getName().equals(encoding)) { | |
129 return converter; | |
130 } | |
131 } | |
132 | |
133 return null; | |
134 } | |
135 | |
136 /** | |
137 * Lazy loading converters takes time, | |
138 * but doesn't happen so often and saves memory. | |
139 * | |
140 * @param clazz {@link ICodepageConverter} | |
141 * @return | |
142 */ | |
143 private ICodepageConverter getConverterFromClassName(Class<?> clazz) { | |
144 try { | |
145 final Constructor<?> constructor = clazz.getConstructor(new Class[0]); | |
146 final ICodepageConverter converter = (ICodepageConverter) constructor.newInstance(); | |
147 converter.init(); | |
148 return converter; | |
149 } | |
150 catch (Exception e) { | |
151 Log.e(TAG, "Couldn't load code page converter class:" + clazz.getCanonicalName(), e); | |
152 return null; | |
153 } | |
154 } | |
148 | 155 |
149 } | 156 } |