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 | */\r |
19 | package de.lohndirekt.print;\r |
20 | \r |
21 | import java.lang.reflect.Constructor;\r |
22 | import java.net.URI;\r |
23 | \r |
24 | import javax.print.attribute.AttributeSet;\r |
25 | import javax.print.attribute.HashAttributeSet;\r |
26 | import javax.print.attribute.standard.RequestingUserName;\r |
27 | \r |
28 | import de.lohndirekt.print.attribute.auth.RequestingUserPassword;\r |
29 | import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r |
30 | \r |
31 | /**\r |
32 | * @author bpusch\r |
33 | * \r |
34 | */\r |
35 | public final class IppRequestFactory {\r |
36 | \r |
37 | final static String IPP_REQUEST_IMPL_KEY = "de.lohndirekt.print.IppRequest.Impl";\r |
38 | \r |
39 | final static IppRequest createIppRequest(URI uri,\r |
40 | OperationsSupported operation, RequestingUserName user,\r |
41 | RequestingUserPassword passwd) {\r |
42 | String requestClassName = System.getProperty(IPP_REQUEST_IMPL_KEY);\r |
43 | IppRequest request = null;\r |
44 | if (requestClassName == null) {\r |
45 | request = new IppRequestCupsImpl(uri, operation);\r |
46 | } else {\r |
47 | Class clazz = null;\r |
48 | try {\r |
49 | clazz = Class.forName(requestClassName);\r |
50 | } catch (ClassNotFoundException e) {\r |
51 | throw new IllegalArgumentException("Class " + requestClassName\r |
52 | + " does not exist.");\r |
53 | }\r |
54 | \r |
55 | try {\r |
56 | Constructor constructor = clazz\r |
57 | .getDeclaredConstructor(new Class[] { URI.class,\r |
58 | OperationsSupported.class });\r |
59 | request = (IppRequest) constructor.newInstance(new Object[] {\r |
60 | uri, operation });\r |
61 | } catch (Exception e) {\r |
62 | throw new RuntimeException(e);\r |
63 | }\r |
64 | }\r |
65 | if (user != null && passwd != null) {\r |
66 | AttributeSet set = new HashAttributeSet();\r |
67 | set.add(user);\r |
68 | set.add(passwd);\r |
69 | request.addOperationAttributes(set);\r |
70 | }\r |
71 | return request;\r |
72 | }\r |
73 | } |