0N/A/*
2362N/A * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.loops;
0N/A
0N/A/**
0N/A * GraphicsPrimitiveProxy
0N/A *
0N/A * Acts as a proxy for instances of GraphicsPrimitive, enabling lazy
0N/A * classloading of these primitives. This leads to a substantial
0N/A * savings in start-up time and footprint. In the typical case,
0N/A * it has been found that a small number of GraphicsPrimitive instance
0N/A * actually end up getting instantiated.
0N/A * <p>
0N/A * Note that the makePrimitive method should never be invoked on
0N/A * a GraphicsPrimitiveProxy object since they are instantiated as
0N/A * soon as they are found in the primitive list and never returned
0N/A * to the caller.
0N/A */
0N/Apublic class GraphicsPrimitiveProxy extends GraphicsPrimitive {
0N/A
0N/A private Class owner;
0N/A private String relativeClassName;
0N/A
0N/A /**
0N/A * Create a GraphicsPrimitiveProxy for a primitive with a no-argument
0N/A * constructor.
0N/A *
0N/A * @param owner The owner class for this primitive. The primitive
0N/A * must be in the same package as this owner.
0N/A * @param relativeClassName The name of the class this is a proxy for.
0N/A * This should not include the package.
0N/A */
0N/A public GraphicsPrimitiveProxy(Class owner, String relativeClassName,
0N/A String methodSignature,
0N/A int primID,
0N/A SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A super(methodSignature, primID, srctype, comptype, dsttype);
0N/A this.owner = owner;
0N/A this.relativeClassName = relativeClassName;
0N/A }
0N/A
0N/A public GraphicsPrimitive makePrimitive(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype) {
0N/A // This should never happen.
0N/A throw new InternalError("makePrimitive called on a Proxy!");
0N/A }
0N/A
0N/A //
0N/A // Come up with the real instance. Called from
0N/A // GraphicsPrimitiveMgr.locate()
0N/A //
0N/A GraphicsPrimitive instantiate() {
0N/A String name = getPackageName(owner.getName()) + "."
0N/A + relativeClassName;
0N/A try {
0N/A Class clazz = Class.forName(name);
0N/A GraphicsPrimitive p = (GraphicsPrimitive) clazz.newInstance();
0N/A if (!satisfiesSameAs(p)) {
0N/A throw new RuntimeException("Primitive " + p
0N/A + " incompatible with proxy for "
0N/A + name);
0N/A }
0N/A return p;
0N/A } catch (ClassNotFoundException ex) {
0N/A throw new RuntimeException(ex.toString());
0N/A } catch (InstantiationException ex) {
0N/A throw new RuntimeException(ex.toString());
0N/A } catch (IllegalAccessException ex) {
0N/A throw new RuntimeException(ex.toString());
0N/A }
0N/A // A RuntimeException should never happen in a deployed JDK, because
0N/A // the regression test GraphicsPrimitiveProxyTest will catch any
0N/A // of these errors.
0N/A }
0N/A
0N/A private static String getPackageName(String className) {
0N/A int lastDotIdx = className.lastIndexOf('.');
0N/A if (lastDotIdx < 0) {
0N/A return className;
0N/A }
0N/A return className.substring(0, lastDotIdx);
0N/A }
0N/A
0N/A public GraphicsPrimitive traceWrap() {
0N/A return instantiate().traceWrap();
0N/A }
0N/A}