01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Evgeniya G. Maenkova
19: * @version $Revision$
20: */package org.apache.harmony.awt.text;
21:
22: import java.lang.reflect.Constructor;
23: import java.lang.reflect.InvocationTargetException;
24: import java.security.AccessController;
25: import java.security.PrivilegedAction;
26:
27: import javax.swing.text.Element;
28: import javax.swing.text.View;
29:
30: public abstract class TextFactory {
31: private static final String FACTORY_IMPL_CLS_NAME = "javax.swing.text.TextFactoryImpl"; //$NON-NLS-1$
32:
33: private static final TextFactory viewFactory = createTextFactory();
34:
35: public static TextFactory getTextFactory() {
36: return viewFactory;
37: }
38:
39: private static TextFactory createTextFactory() {
40: PrivilegedAction<TextFactory> createAction = new PrivilegedAction<TextFactory>() {
41: public TextFactory run() {
42: try {
43: Class<?> factoryImplClass = Class
44: .forName(FACTORY_IMPL_CLS_NAME);
45: Constructor<?> defConstr = factoryImplClass
46: .getDeclaredConstructor(new Class[0]);
47: defConstr.setAccessible(true);
48: return (TextFactory) defConstr
49: .newInstance(new Object[0]);
50: } catch (ClassNotFoundException e) {
51: e.printStackTrace();
52:
53: } catch (InvocationTargetException e) {
54: e.printStackTrace();
55: } catch (InstantiationException e) {
56: e.printStackTrace();
57: } catch (NoSuchMethodException e) {
58: e.printStackTrace();
59: } catch (IllegalArgumentException e) {
60: e.printStackTrace();
61: } catch (IllegalAccessException e) {
62: e.printStackTrace();
63: }
64: return null;
65: }
66: };
67:
68: return AccessController.doPrivileged(createAction);
69: }
70:
71: public abstract RootViewContext createRootView(final Element element);
72:
73: public abstract View createPlainView(final Element e);
74:
75: public abstract View createWrappedPlainView(final Element e);
76:
77: public abstract View createFieldView(final Element e);
78:
79: public abstract View createPasswordView(Element e);
80:
81: public abstract TextCaret createCaret();
82: }
|