src/share/classes/javax/print/SimpleDoc.java

Print this page




  72      * Constructs a <code>SimpleDoc</code> with the specified
  73      * print data, doc flavor and doc attribute set.
  74      * @param printData the print data object
  75      * @param flavor the <code>DocFlavor</code> object
  76      * @param attributes a <code>DocAttributeSet</code>, which can
  77      *                   be <code>null</code>
  78      * @throws IllegalArgumentException if <code>flavor</code> or
  79      *         <code>printData</code> is <code>null</code>, or the
  80      *         <code>printData</code> does not correspond
  81      *         to the specified doc flavor--for example, the data is
  82      *         not of the type specified as the representation in the
  83      *         <code>DocFlavor</code>.
  84      */
  85     public SimpleDoc(Object printData,
  86                      DocFlavor flavor, DocAttributeSet attributes) {
  87 
  88        if (flavor == null || printData == null) {
  89            throw new IllegalArgumentException("null argument(s)");
  90        }
  91 
  92        Class repClass = null;
  93        try {
  94             String className = flavor.getRepresentationClassName();
  95             sun.reflect.misc.ReflectUtil.checkPackageAccess(className);
  96             repClass = Class.forName(className, false,
  97                               Thread.currentThread().getContextClassLoader());
  98        } catch (Throwable e) {
  99            throw new IllegalArgumentException("unknown representation class");
 100        }
 101 
 102        if (!repClass.isInstance(printData)) {
 103            throw new IllegalArgumentException("data is not of declared type");
 104        }
 105 
 106        this.flavor = flavor;
 107        if (attributes != null) {
 108            this.attributes = AttributeSetUtilities.unmodifiableView(attributes);
 109        }
 110        this.printData = printData;
 111     }
 112 




  72      * Constructs a <code>SimpleDoc</code> with the specified
  73      * print data, doc flavor and doc attribute set.
  74      * @param printData the print data object
  75      * @param flavor the <code>DocFlavor</code> object
  76      * @param attributes a <code>DocAttributeSet</code>, which can
  77      *                   be <code>null</code>
  78      * @throws IllegalArgumentException if <code>flavor</code> or
  79      *         <code>printData</code> is <code>null</code>, or the
  80      *         <code>printData</code> does not correspond
  81      *         to the specified doc flavor--for example, the data is
  82      *         not of the type specified as the representation in the
  83      *         <code>DocFlavor</code>.
  84      */
  85     public SimpleDoc(Object printData,
  86                      DocFlavor flavor, DocAttributeSet attributes) {
  87 
  88        if (flavor == null || printData == null) {
  89            throw new IllegalArgumentException("null argument(s)");
  90        }
  91 
  92        Class<?> repClass = null;
  93        try {
  94             String className = flavor.getRepresentationClassName();
  95             sun.reflect.misc.ReflectUtil.checkPackageAccess(className);
  96             repClass = Class.forName(className, false,
  97                               Thread.currentThread().getContextClassLoader());
  98        } catch (Throwable e) {
  99            throw new IllegalArgumentException("unknown representation class");
 100        }
 101 
 102        if (!repClass.isInstance(printData)) {
 103            throw new IllegalArgumentException("data is not of declared type");
 104        }
 105 
 106        this.flavor = flavor;
 107        if (attributes != null) {
 108            this.attributes = AttributeSetUtilities.unmodifiableView(attributes);
 109        }
 110        this.printData = printData;
 111     }
 112