2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.loops;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* GraphicsPrimitiveProxy
|
|
30 |
*
|
|
31 |
* Acts as a proxy for instances of GraphicsPrimitive, enabling lazy
|
|
32 |
* classloading of these primitives. This leads to a substantial
|
|
33 |
* savings in start-up time and footprint. In the typical case,
|
|
34 |
* it has been found that a small number of GraphicsPrimitive instance
|
|
35 |
* actually end up getting instantiated.
|
|
36 |
* <p>
|
|
37 |
* Note that the makePrimitive method should never be invoked on
|
|
38 |
* a GraphicsPrimitiveProxy object since they are instantiated as
|
|
39 |
* soon as they are found in the primitive list and never returned
|
|
40 |
* to the caller.
|
|
41 |
*/
|
|
42 |
public class GraphicsPrimitiveProxy extends GraphicsPrimitive {
|
|
43 |
|
|
44 |
private Class owner;
|
|
45 |
private String relativeClassName;
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Create a GraphicsPrimitiveProxy for a primitive with a no-argument
|
|
49 |
* constructor.
|
|
50 |
*
|
|
51 |
* @param owner The owner class for this primitive. The primitive
|
|
52 |
* must be in the same package as this owner.
|
|
53 |
* @param relativeClassName The name of the class this is a proxy for.
|
|
54 |
* This should not include the package.
|
|
55 |
*/
|
|
56 |
public GraphicsPrimitiveProxy(Class owner, String relativeClassName,
|
|
57 |
String methodSignature,
|
|
58 |
int primID,
|
|
59 |
SurfaceType srctype,
|
|
60 |
CompositeType comptype,
|
|
61 |
SurfaceType dsttype)
|
|
62 |
{
|
|
63 |
super(methodSignature, primID, srctype, comptype, dsttype);
|
|
64 |
this.owner = owner;
|
|
65 |
this.relativeClassName = relativeClassName;
|
|
66 |
}
|
|
67 |
|
|
68 |
public GraphicsPrimitive makePrimitive(SurfaceType srctype,
|
|
69 |
CompositeType comptype,
|
|
70 |
SurfaceType dsttype) {
|
|
71 |
// This should never happen.
|
|
72 |
throw new InternalError("makePrimitive called on a Proxy!");
|
|
73 |
}
|
|
74 |
|
|
75 |
//
|
|
76 |
// Come up with the real instance. Called from
|
|
77 |
// GraphicsPrimitiveMgr.locate()
|
|
78 |
//
|
|
79 |
GraphicsPrimitive instantiate() {
|
|
80 |
String name = getPackageName(owner.getName()) + "."
|
|
81 |
+ relativeClassName;
|
|
82 |
try {
|
|
83 |
Class clazz = Class.forName(name);
|
|
84 |
GraphicsPrimitive p = (GraphicsPrimitive) clazz.newInstance();
|
|
85 |
if (!satisfiesSameAs(p)) {
|
|
86 |
throw new RuntimeException("Primitive " + p
|
|
87 |
+ " incompatible with proxy for "
|
|
88 |
+ name);
|
|
89 |
}
|
|
90 |
return p;
|
|
91 |
} catch (ClassNotFoundException ex) {
|
|
92 |
throw new RuntimeException(ex.toString());
|
|
93 |
} catch (InstantiationException ex) {
|
|
94 |
throw new RuntimeException(ex.toString());
|
|
95 |
} catch (IllegalAccessException ex) {
|
|
96 |
throw new RuntimeException(ex.toString());
|
|
97 |
}
|
|
98 |
// A RuntimeException should never happen in a deployed JDK, because
|
|
99 |
// the regression test GraphicsPrimitiveProxyTest will catch any
|
|
100 |
// of these errors.
|
|
101 |
}
|
|
102 |
|
|
103 |
private static String getPackageName(String className) {
|
|
104 |
int lastDotIdx = className.lastIndexOf('.');
|
|
105 |
if (lastDotIdx < 0) {
|
|
106 |
return className;
|
|
107 |
}
|
|
108 |
return className.substring(0, lastDotIdx);
|
|
109 |
}
|
|
110 |
|
|
111 |
public GraphicsPrimitive traceWrap() {
|
|
112 |
return instantiate().traceWrap();
|
|
113 |
}
|
|
114 |
}
|