src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java

Print this page
rev 9629 : 8038644: Fix raw and unchecked warnings in sun.java2d.*
Reviewed-by:


  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) {


  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) {