src/windows/classes/sun/print/Win32PrintJob.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 291                 listenedAttributeSets.remove(index);
 292                 if (attrListeners.isEmpty()) {
 293                     attrListeners = null;
 294                     listenedAttributeSets = null;
 295                 }
 296             }
 297         }
 298     }
 299 
 300     public void print(Doc doc, PrintRequestAttributeSet attributes)
 301         throws PrintException {
 302 
 303         synchronized (this) {
 304             if (printing) {
 305                 throw new PrintException("already printing");
 306             } else {
 307                 printing = true;
 308             }
 309         }
 310 
 311         PrinterState prnState = (PrinterState)service.getAttribute(
 312                                                   PrinterState.class);
 313         if (prnState == PrinterState.STOPPED) {
 314             PrinterStateReasons prnStateReasons =
 315                     (PrinterStateReasons)service.getAttribute(
 316                                                  PrinterStateReasons.class);
 317                 if ((prnStateReasons != null) &&
 318                     (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
 319                 {
 320                     throw new PrintException("PrintService is no longer available.");
 321                 }
 322         }
 323 
 324         if ((PrinterIsAcceptingJobs)(service.getAttribute(
 325                          PrinterIsAcceptingJobs.class)) ==
 326                          PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
 327             throw new PrintException("Printer is not accepting job.");
 328         }
 329 
 330 
 331         this.doc = doc;
 332         /* check if the parameters are valid before doing much processing */
 333         DocFlavor flavor = doc.getDocFlavor();
 334         Object data;
 335 
 336         try {
 337             data = doc.getPrintData();
 338         } catch (IOException e) {
 339             notifyEvent(PrintJobEvent.JOB_FAILED);
 340             throw new PrintException("can't get print data: " + e.toString());
 341         }
 342 
 343         if (data == null) {
 344             throw new PrintException("Null print data.");
 345         }


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 291                 listenedAttributeSets.remove(index);
 292                 if (attrListeners.isEmpty()) {
 293                     attrListeners = null;
 294                     listenedAttributeSets = null;
 295                 }
 296             }
 297         }
 298     }
 299 
 300     public void print(Doc doc, PrintRequestAttributeSet attributes)
 301         throws PrintException {
 302 
 303         synchronized (this) {
 304             if (printing) {
 305                 throw new PrintException("already printing");
 306             } else {
 307                 printing = true;
 308             }
 309         }
 310 
 311         PrinterState prnState = service.getAttribute(PrinterState.class);

 312         if (prnState == PrinterState.STOPPED) {
 313             PrinterStateReasons prnStateReasons =
 314                 service.getAttribute(PrinterStateReasons.class);

 315                 if ((prnStateReasons != null) &&
 316                     (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
 317                 {
 318                     throw new PrintException("PrintService is no longer available.");
 319                 }
 320         }
 321 
 322         if (service.getAttribute(PrinterIsAcceptingJobs.class) ==

 323             PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
 324             throw new PrintException("Printer is not accepting job.");
 325         }
 326 
 327 
 328         this.doc = doc;
 329         /* check if the parameters are valid before doing much processing */
 330         DocFlavor flavor = doc.getDocFlavor();
 331         Object data;
 332 
 333         try {
 334             data = doc.getPrintData();
 335         } catch (IOException e) {
 336             notifyEvent(PrintJobEvent.JOB_FAILED);
 337             throw new PrintException("can't get print data: " + e.toString());
 338         }
 339 
 340         if (data == null) {
 341             throw new PrintException("Null print data.");
 342         }