Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / IppPrintService.java
1 /**
2 * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19 package de.lohndirekt.print;
20 import java.io.IOException;
21 import java.net.URI;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32
33 import javax.print.DocFlavor;
34 import javax.print.DocPrintJob;
35 import javax.print.PrintException;
36 import javax.print.PrintService;
37 import javax.print.ServiceUIFactory;
38 import javax.print.attribute.*;
39 import javax.print.attribute.standard.PrinterURI;
40 import javax.print.attribute.standard.RequestingUserName;
41 import javax.print.event.PrintServiceAttributeListener;
42
43 import de.lohndirekt.print.attribute.IppAttributeName;
44 import de.lohndirekt.print.attribute.IppStatus;
45 import de.lohndirekt.print.attribute.auth.RequestingUserPassword;
46 import de.lohndirekt.print.attribute.ipp.DocumentFormat;
47 import de.lohndirekt.print.attribute.ipp.jobdesc.JobId;
48 import de.lohndirekt.print.attribute.ipp.printerdesc.supported.DocumentFormatSupported;
49 import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;
50
51 /**
52 * @author bpusch
53 *
54 *
55 */
56 public class IppPrintService implements PrintService {
57
58 private final Logger log = Logger.getLogger(this.getClass().getName());
59 private DocFlavor[] supportedFlavors = null;
60 private URI uri;
61 private RequestingUserName requestingUserName = null;
62 private RequestingUserPassword requestingUserPassword = null;
63 private Map attributes = null;
64
65 /**
66 * @param uri
67 */
68 public IppPrintService(URI uri) {
69 this.uri = uri;
70 }
71
72
73
74 /**
75 * @return
76 */
77 URI getUri() {
78 return this.uri;
79 }
80
81 /* (non-Javadoc)
82 * @see javax.print.PrintService#getName()
83 */
84 public String getName() {
85 return uri.getPath().substring(uri.getPath().lastIndexOf("/") + 1);
86 }
87
88 /**
89 *
90 */
91 public void reset() {
92 supportedFlavors = null;
93 attributes = null;
94 }
95
96 /* (non-Javadoc)
97 * @see javax.print.PrintService#createPrintJob()
98 */
99 public DocPrintJob createPrintJob() {
100 return new CancelableJob(this);
101 }
102
103 /* (non-Javadoc)
104 * @see javax.print.PrintService#getAttributes()
105 */
106 public PrintServiceAttributeSet getAttributes() {
107 PrintServiceAttributeSet set = new HashPrintServiceAttributeSet();
108 for (Iterator mapIter = getAllAttributes().values().iterator(); mapIter.hasNext();) {
109 Set values = (Set) mapIter.next();
110 for (Iterator listIter = values.iterator(); listIter.hasNext();) {
111 Attribute attribute = (Attribute) listIter.next();
112 if (attribute instanceof PrintServiceAttribute) {
113 set.add(attribute);
114 }
115 }
116 }
117 return set;
118 }
119
120 /* (non-Javadoc)
121 * @see javax.print.PrintService#getAttribute(java.lang.Class)
122 */
123 public PrintServiceAttribute getAttribute(Class category) {
124 if (category == null) {
125 throw new NullPointerException("category must not be null");
126 }
127 //TODO As CUPS seems not to support this operation-tag (requested-attributes), we need to get all attributes
128 Set attributes = (Set) getAllAttributes().get(category);
129 if (attributes != null) {
130 try {
131 return (PrintServiceAttribute) attributes.iterator().next();
132 } catch (ClassCastException e) {
133 throw new IllegalArgumentException("category must be a Class that implements interface PrintServiceAttribute");
134 }
135 }
136 return null;
137 }
138
139 /* (non-Javadoc)
140 * @see javax.print.PrintService#getSupportedDocFlavors()
141 */
142 public DocFlavor[] getSupportedDocFlavors() {
143 if (supportedFlavors == null) {
144 List flavors = new ArrayList();
145 Set flavorAttributes =
146 (Set) getAllAttributes().get(IppAttributeName.DOCUMENT_FORMAT_SUPORTED.getCategory());
147 if (flavorAttributes != null) {
148 for (Iterator iter = flavorAttributes.iterator(); iter.hasNext();) {
149 Attribute attribute = (Attribute) iter.next();
150 String mimeType = ((DocumentFormatSupported) attribute).getValue();
151 if (mimeType.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE.getMimeType())) {
152 flavors.add(DocFlavor.INPUT_STREAM.AUTOSENSE);
153 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.GIF.getMimeType())) {
154 flavors.add(DocFlavor.INPUT_STREAM.GIF);
155 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.JPEG.getMimeType())) {
156 flavors.add(DocFlavor.INPUT_STREAM.JPEG);
157 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PCL.getMimeType())) {
158 flavors.add(DocFlavor.INPUT_STREAM.PCL);
159 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PDF.getMimeType())) {
160 flavors.add(DocFlavor.INPUT_STREAM.PDF);
161 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType())) {
162 flavors.add(DocFlavor.INPUT_STREAM.POSTSCRIPT);
163 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PNG.getMimeType())) {
164 flavors.add(DocFlavor.INPUT_STREAM.PNG);
165 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.TEXT_HTML_HOST.getMimeType().substring(0, 9))) {
166 flavors.add(DocFlavor.INPUT_STREAM.TEXT_HTML_HOST);
167 } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST.getMimeType().substring(0, 10))) {
168 flavors.add(DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST);
169 }
170 }
171 }
172 DocFlavor[] flavorArray = new DocFlavor[flavors.size()];
173 flavorArray = (DocFlavor[]) flavors.toArray(flavorArray);
174 supportedFlavors = flavorArray;
175 }
176 return supportedFlavors;
177 }
178
179 /* (non-Javadoc)
180 * @see javax.print.PrintService#isDocFlavorSupported(javax.print.DocFlavor)
181 */
182 public boolean isDocFlavorSupported(DocFlavor flavor) {
183 List supportedFlavors = Arrays.asList(getSupportedDocFlavors());
184 return supportedFlavors.contains(flavor);
185 }
186
187 /* (non-Javadoc)
188 * @see javax.print.PrintService#getSupportedAttributeCategories()
189 */
190 public Class[] getSupportedAttributeCategories() {
191 Set supportedCategories = new HashSet();
192 //Attributes named in 4.2 of rfc2911 are optional
193 if (getAllAttributes().containsKey(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory())) {
194 supportedCategories.add(IppAttributeName.JOB_PRIORIY.getCategory());
195 }
196 if (getAllAttributes().containsKey(IppAttributeName.JOB_HOLD_UNTIL_SUPPORTED.getCategory())) {
197 supportedCategories.add(IppAttributeName.JOB_HOLD_UNTIL.getCategory());
198 }
199 if (getAllAttributes().containsKey(IppAttributeName.JOB_SHEETS_SUPORTED.getCategory())) {
200 supportedCategories.add(IppAttributeName.JOB_SHEETS.getCategory());
201 }
202 if (getAllAttributes().containsKey(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory())) {
203 supportedCategories.add(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory());
204 }
205 if (getAllAttributes().containsKey(IppAttributeName.COPIES_SUPPORTED.getCategory())) {
206 supportedCategories.add(IppAttributeName.COPIES.getCategory());
207 }
208 if (getAllAttributes().containsKey(IppAttributeName.FINISHINGS_SUPPORTED.getCategory())) {
209 supportedCategories.add(IppAttributeName.FINISHINGS.getCategory());
210 }
211 if (getAllAttributes().containsKey(IppAttributeName.PAGE_RANGES_SUPPORTED.getCategory())) {
212 supportedCategories.add(IppAttributeName.PAGE_RANGES.getCategory());
213 }
214 if (getAllAttributes().containsKey(IppAttributeName.SIDES_SUPPORTED.getCategory())) {
215 supportedCategories.add(IppAttributeName.SIDES.getCategory());
216 }
217 if (getAllAttributes().containsKey(IppAttributeName.NUMBER_UP_SUPPORTED.getCategory())) {
218 supportedCategories.add(IppAttributeName.NUMBER_UP.getCategory());
219 }
220 if (getAllAttributes().containsKey(IppAttributeName.ORIENTATION_REQUESTED_SUPPORTED.getCategory())) {
221 supportedCategories.add(IppAttributeName.ORIENTATION_REQUESTED.getCategory());
222 }
223 if (getAllAttributes().containsKey(IppAttributeName.MEDIA_SUPPORTED.getCategory())) {
224 supportedCategories.add(IppAttributeName.MEDIA.getCategory());
225 }
226 if (getAllAttributes().containsKey(IppAttributeName.PRINTER_RESOLUTION.getCategory())) {
227 //printer-resolution-supported attribute currently not implemented
228 }
229 if (getAllAttributes().containsKey(IppAttributeName.PRINT_QUALITY.getCategory())) {
230 //print-quality-supported attribute currently not implemented
231 }
232 if (getAllAttributes().containsKey(IppAttributeName.JOB_K_OCTETS_SUPPORTED.getCategory())) {
233 supportedCategories.add(IppAttributeName.JOB_K_OCTETS.getCategory());
234 }
235 if (getAllAttributes().containsKey(IppAttributeName.JOB_IMPRESSIONS_SUPPORTED.getCategory())) {
236 supportedCategories.add(IppAttributeName.JOB_IMPRESSIONS.getCategory());
237 }
238 if (getAllAttributes().containsKey(IppAttributeName.JOB_MEDIA_SHEETS_SUPPORTED.getCategory())) {
239 supportedCategories.add(IppAttributeName.JOB_MEDIA_SHEETS.getCategory());
240 }
241 //Printer object MUST support compression attribute
242 supportedCategories.add(IppAttributeName.COMPRESSION.getCategory());
243 Class[] categories = new Class[supportedCategories.size()];
244 categories = (Class[]) supportedCategories.toArray(categories);
245 return categories;
246 }
247
248 /* (non-Javadoc)
249 * @see javax.print.PrintService#isAttributeCategorySupported(java.lang.Class)
250 */
251 public boolean isAttributeCategorySupported(Class category) {
252 return Arrays.asList(this.getSupportedAttributeCategories()).contains(category);
253 }
254
255 /* (non-Javadoc)
256 * @see javax.print.PrintService#getDefaultAttributeValue(java.lang.Class)
257 */
258 public Object getDefaultAttributeValue(Class category) {
259 //Only the attributes listed in rfc2911 4.2(Job Template Attributes) make sense here
260 Object value = null;
261 if (category.equals(IppAttributeName.JOB_PRIORIY.getCategory())) {
262 Attribute attr = getAttribute(IppAttributeName.JOB_PRIORITY_DEFAULT.getCategory());
263 if (attr != null) {
264 value = new Integer(((IntegerSyntax) attr).getValue());
265 }
266 } else if (category.equals(IppAttributeName.JOB_HOLD_UNTIL.getCategory())) {
267 Attribute attr = getAttribute(IppAttributeName.JOB_HOLD_UNTIL.getCategory());
268 if (attr != null) {
269 value = new Integer(((TextSyntax) attr).getValue());
270 }
271 } else if (category.equals(IppAttributeName.JOB_SHEETS_DEFAULT.getCategory())) {
272 Attribute attr = getAttribute(IppAttributeName.JOB_SHEETS_DEFAULT.getCategory());
273 if (attr != null) {
274 value = new Integer(((TextSyntax) attr).getValue());
275 }
276 } else if (category.equals(IppAttributeName.COPIES.getCategory())) {
277 Attribute attr = getAttribute(IppAttributeName.COPIES_DEFAULT.getCategory());
278 if (attr != null) {
279 value = new Integer(((IntegerSyntax) attr).getValue());
280 }
281 } else if (category.equals(IppAttributeName.FINISHINGS.getCategory())) {
282 Attribute attr = getAttribute(IppAttributeName.FINISHINGS_DEFAULT.getCategory());
283 if (attr != null) {
284 value = new Integer(((IntegerSyntax) attr).toString());
285 }
286 } else if (category.equals(IppAttributeName.SIDES.getCategory())) {
287 Attribute attr = getAttribute(IppAttributeName.SIDES_DEFAULT.getCategory());
288 if (attr != null) {
289 value = new Integer(((TextSyntax) attr).getValue());
290 }
291 } else if (category.equals(IppAttributeName.NUMBER_UP.getCategory())) {
292 Attribute attr = getAttribute(IppAttributeName.NUMBER_UP_DEFAULT.getCategory());
293 if (attr != null) {
294 value = new Integer(((IntegerSyntax) attr).getValue());
295 }
296 } else if (category.equals(IppAttributeName.ORIENTATION_REQUESTED.getCategory())) {
297 Attribute attr = getAttribute(IppAttributeName.ORIENTATION_REQUESTED_DEFAULT.getCategory());
298 if (attr != null) {
299 value = ((TextSyntax) attr).getValue();
300 }
301 } else if (category.equals(IppAttributeName.MEDIA.getCategory())) {
302 Attribute attr = getAttribute(IppAttributeName.MEDIA_DEFAULT.getCategory());
303 if (attr != null) {
304 value = ((TextSyntax) attr).getValue();
305 }
306 } else if (category.equals(IppAttributeName.PRINTER_RESOLUTION.getCategory())) {
307 //Cups does not support the printer-resolution-default attribute
308 } else if (category.equals(IppAttributeName.PRINT_QUALITY.getCategory())) {
309 //Cups does not support the print-quality-default attribute
310 } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {
311 Attribute attr = getAttribute(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_DEFAULT.getCategory());
312 if (attr != null) {
313 value = ((TextSyntax) attr).getValue();
314 }
315 }
316 return value;
317 }
318
319 /* (non-Javadoc)
320 * @see javax.print.PrintService#getSupportedAttributeValues(java.lang.Class, javax.print.DocFlavor, javax.print.attribute.AttributeSet)
321 */
322 public Object getSupportedAttributeValues(Class category, DocFlavor flavor, AttributeSet attributes) {
323 Set supportedAttributes = new HashSet();
324 // Only the attributes listed in rfc2911 4.2(Job Template Attributes) do make sense here
325 if (category.equals(IppAttributeName.JOB_PRIORIY.getCategory())) {
326 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory());
327 } else if (category.equals(IppAttributeName.JOB_HOLD_UNTIL.getCategory())) {
328 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_HOLD_UNTIL_SUPPORTED.getCategory());
329 } else if (category.equals(IppAttributeName.JOB_SHEETS.getCategory())) {
330 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_SHEETS_SUPORTED.getCategory());
331 } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {
332 supportedAttributes =
333 (Set) getAllAttributes().get(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory());
334 } else if (category.equals(IppAttributeName.COPIES.getCategory())) {
335 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.COPIES_SUPPORTED.getCategory());
336 } else if (category.equals(IppAttributeName.FINISHINGS.getCategory())) {
337 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.FINISHINGS_SUPPORTED.getCategory());
338 } else if (category.equals(IppAttributeName.SIDES.getCategory())) {
339 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.SIDES_SUPPORTED.getCategory());
340 }
341 //TODO page-ranges
342 else if (category.equals(IppAttributeName.NUMBER_UP.getCategory())) {
343 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.NUMBER_UP_SUPPORTED.getCategory());
344 } else if (category.equals(IppAttributeName.ORIENTATION_REQUESTED.getCategory())) {
345 supportedAttributes =
346 (Set) getAllAttributes().get(IppAttributeName.ORIENTATION_REQUESTED_SUPPORTED.getCategory());
347 } else if (category.equals(IppAttributeName.MEDIA.getCategory())) {
348 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.MEDIA_SUPPORTED.getCategory());
349 } else if (category.equals(IppAttributeName.PRINTER_RESOLUTION)) {
350 //printer-resolution-supported attribute currently not implemented
351 } else if (category.equals(IppAttributeName.PRINT_QUALITY.getCategory())) {
352 //printer-quality-supported attribute currently not implemented
353 } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {
354 supportedAttributes =
355 (Set) getAllAttributes().get(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory());
356 } else if (category.equals(IppAttributeName.JOB_IMPRESSIONS.getCategory())) {
357 supportedAttributes =
358 (Set) getAllAttributes().get(IppAttributeName.JOB_IMPRESSIONS_SUPPORTED.getCategory());
359 } else if (category.equals(IppAttributeName.JOB_K_OCTETS.getCategory())) {
360 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_K_OCTETS_SUPPORTED.getCategory());
361 } else if (category.equals(IppAttributeName.JOB_MEDIA_SHEETS.getCategory())) {
362 supportedAttributes =
363 (Set) getAllAttributes().get(IppAttributeName.JOB_MEDIA_SHEETS_SUPPORTED.getCategory());
364 } else if (category.equals(IppAttributeName.COMPRESSION.getCategory())) {
365 supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.COMPRESSION_SUPORTED.getCategory());
366 }
367 if (supportedAttributes == null) {
368 supportedAttributes = new HashSet();
369 }
370 return supportedAttributes.toArray(new Attribute[supportedAttributes.size()]);
371 }
372
373 /* (non-Javadoc)
374 * @see javax.print.PrintService#isAttributeValueSupported(javax.print.attribute.Attribute, javax.print.DocFlavor, javax.print.attribute.AttributeSet)
375 */
376 public boolean isAttributeValueSupported(Attribute attrVal, DocFlavor flavor, AttributeSet attributes) {
377 AttributeSet operationAttributes = new HashAttributeSet();
378 if (flavor != null) {
379 operationAttributes.add(new DocumentFormat(flavor.getMimeType(), Locale.getDefault()));
380 }
381 IppRequest request = this.request(OperationsSupported.VALIDATE_JOB);
382 if (attributes == null) {
383 attributes = new HashAttributeSet();
384 }
385 attributes.add(attrVal);
386 Object[] attributeArray = attributes.toArray();
387 PrintJobAttributeSet jobAttributes = new HashPrintJobAttributeSet();
388 for (int i = 0; i < attributeArray.length; i++) {
389 Attribute attribute = (Attribute) attributeArray[i];
390 //attributes-charset, attributes-natural-language etc. are not set by the user
391 if (attribute instanceof PrintRequestAttribute && attribute instanceof PrintJobAttribute) {
392 if (attribute.getCategory().equals(IppAttributeName.JOB_NAME.getCategory())
393 || attribute.getCategory().equals(IppAttributeName.FIDELITY.getCategory())
394 || attribute.getCategory().equals(IppAttributeName.JOB_IMPRESSIONS.getCategory())
395 || attribute.getCategory().equals(IppAttributeName.JOB_K_OCTETS.getCategory())
396 || attribute.getCategory().equals(IppAttributeName.JOB_MEDIA_SHEETS.getCategory())) {
397 operationAttributes.add(attribute);
398 } else if (
399 attribute.getCategory().equals(IppAttributeName.JOB_NAME.getCategory())
400 || attribute.getCategory().equals(IppAttributeName.FIDELITY.getCategory())) {
401 //do nothing, Job Template Attributes can not be used in a Validate-Job operation
402 } else {
403 jobAttributes.add(attribute);
404 }
405 }
406 }
407 request.addOperationAttributes(operationAttributes);
408 request.setJobAttributes(jobAttributes);
409 IppResponse response = null;
410 try {
411 response = request.send();
412 } catch (IOException e) {
413 log.log(Level.SEVERE, e.getMessage(), e);
414 }
415 boolean supported = false;
416 if (response != null) {
417 if (response.getStatus().equals(IppStatus.SUCCESSFUL_OK)
418 || response.getStatus().equals(IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)
419 || response.getStatus().equals(IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)) {
420 supported = true;
421 }
422 }
423 return supported;
424 }
425
426 /* (non-Javadoc)
427 * @see javax.print.PrintService#getUnsupportedAttributes(javax.print.DocFlavor, javax.print.attribute.AttributeSet)
428 */
429 public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) {
430 return null;
431 }
432
433 /* (non-Javadoc)
434 * @see javax.print.PrintService#getServiceUIFactory()
435 */
436 public ServiceUIFactory getServiceUIFactory() {
437 return null;
438 }
439
440 /* (non-Javadoc)
441 * @see javax.print.PrintService#addPrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)
442 */
443 public void addPrintServiceAttributeListener(PrintServiceAttributeListener listener) {
444 }
445
446 /* (non-Javadoc)
447 * @see javax.print.PrintService#removePrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)
448 */
449 public void removePrintServiceAttributeListener(PrintServiceAttributeListener listener) {
450 }
451
452 /**
453 * @return
454 */
455 private Map getAllAttributes() {
456 if (this.attributes == null) {
457 IppRequest request = this.request(OperationsSupported.GET_PRINTER_ATTRIBUTES);
458 IppResponse response = null;
459 try {
460 response = request.send();
461 } catch (IOException e) {
462 log.log(Level.SEVERE, e.getMessage(), e);
463 }
464 if (response != null) {
465 this.attributes = response.getAttributes();
466 }
467 }
468 return this.attributes;
469 }
470
471 public String toString() {
472 return this.getName();
473 }
474
475 /**
476 * @param operation
477 * @return
478 */
479 protected IppRequest request(OperationsSupported operation) {
480 IppRequest request = IppRequestFactory.createIppRequest(this.uri, operation, this.getRequestingUserName(), this.getRequestingUserPassword());
481 AttributeSet operationAttributes = new HashAttributeSet();
482 operationAttributes.add(new PrinterURI(this.uri));
483 request.addOperationAttributes(operationAttributes);
484 return request;
485 }
486
487 /**
488 * Returns a job with the given JobId, or null if no such
489 * Job exists.
490 * <br>
491 * Use jobExists to check for a Job with this JobId.
492 * <br>
493 * This method might return a Job which is not hold by this PrintService
494 * but the same CUPS server
495 *
496 * @param jobId
497 * @return the corresponding Job wihth the given JobId, or null if no such Job exists
498 * @throws PrintException
499 */
500 //public Methods which are not part of the JPS API
501 public DocPrintJob getJob(JobId jobId) throws PrintException {
502 Job job = Job.getJob(this, jobId);
503 return job;
504 }
505
506 /**
507 *
508 * Check for a Job with the given JobId.
509 * <br>
510 * This method might return true, even if the printservice does not hold any
511 * job with the given JobId, but another PrintService on the same
512 * Cups server does.
513 *
514 * @param jobId
515 * @return true if a Job with the given JobId exists, false otherwise
516 * @throws PrintException
517 */
518 public boolean jobExists(JobId jobId) throws PrintException {
519 return Job.getJob(this, jobId) != null;
520 }
521
522
523 public RequestingUserName getRequestingUserName() {
524 return requestingUserName;
525 }
526 public void setRequestingUserName(RequestingUserName requestingUserName) {
527 this.requestingUserName = requestingUserName;
528 }
529 public RequestingUserPassword getRequestingUserPassword() {
530 return requestingUserPassword;
531 }
532 public void setRequestingUserPassword(
533 RequestingUserPassword requestingUserPassword) {
534 this.requestingUserPassword = requestingUserPassword;
535 }
536 }