Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / CancelableJob.java
CommitLineData
3ea135bb 1/**\r
2 * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>\r
3 *\r
4 * This library is free software; you can redistribute it and/or\r
5 * modify it under the terms of the GNU Lesser General Public\r
6 * License as published by the Free Software Foundation; either\r
7 * version 2.1 of the License, or (at your option) any later version.\r
8 * \r
9 * This library is distributed in the hope that it will be useful,\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
12 * Lesser General Public License for more details.\r
13 * \r
14 * You should have received a copy of the GNU Lesser General Public\r
15 * License along with this library; if not, write to the Free Software\r
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
17 * \r
18 */package de.lohndirekt.print;\r
19\r
20import java.io.IOException;\r
21import java.util.logging.Level;\r
22\r
23import javax.print.CancelablePrintJob;\r
24import javax.print.PrintException;\r
25import javax.print.attribute.AttributeSet;\r
26import javax.print.attribute.HashAttributeSet;\r
27import javax.print.event.PrintJobEvent;\r
28\r
29import de.lohndirekt.print.attribute.IppStatus;\r
30import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r
31\r
32/**\r
33 * @author bpusch\r
34 *\r
35 */\r
36class CancelableJob extends Job implements CancelablePrintJob{\r
37 \r
38 \r
39 /**\r
40 * @param service\r
41 */\r
42 public CancelableJob(IppPrintService service) {\r
43 super(service);\r
44 }\r
45 \r
46 public void cancel() throws PrintException {\r
47 if (!ok) {\r
48 throw new PrintException("Job has not been sent. Cannot be canceled");\r
49 }\r
50 AttributeSet operationAttributes = new HashAttributeSet();\r
51 operationAttributes.add(this.jobUri);\r
52 try {\r
53 IppResponse response =\r
54 sendRequest(\r
55 OperationsSupported.CANCEL_JOB,\r
56 operationAttributes);\r
57 if (response.getStatus().equals(IppStatus.SUCCESSFUL_OK)\r
58 || response.getStatus().equals(\r
59 IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)\r
60 || response.getStatus().equals(\r
61 IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)) {\r
62 notifyJobListeners(PrintJobEvent.JOB_CANCELED);\r
63 }\r
64 } catch (IOException e) {\r
65 log.log(Level.SEVERE, e.getMessage(), e);\r
66 throw new PrintException("Cannot be canceled: IOException", e);\r
67 }\r
68 }\r
69 \r
70 \r
71 \r
72\r
73}\r