Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / IppRequestFactory.java
diff --git a/jspi/src/main/java/de/lohndirekt/print/IppRequestFactory.java b/jspi/src/main/java/de/lohndirekt/print/IppRequestFactory.java
new file mode 100644 (file)
index 0000000..c9c8e8d
--- /dev/null
@@ -0,0 +1,73 @@
+/**\r
+ * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ * \r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *  \r
+ */\r
+package de.lohndirekt.print;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.net.URI;\r
+\r
+import javax.print.attribute.AttributeSet;\r
+import javax.print.attribute.HashAttributeSet;\r
+import javax.print.attribute.standard.RequestingUserName;\r
+\r
+import de.lohndirekt.print.attribute.auth.RequestingUserPassword;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r
+\r
+/**\r
+ * @author bpusch\r
+ *  \r
+ */\r
+public final class IppRequestFactory {\r
+\r
+    final static String IPP_REQUEST_IMPL_KEY = "de.lohndirekt.print.IppRequest.Impl";\r
+\r
+    final static IppRequest createIppRequest(URI uri,\r
+            OperationsSupported operation, RequestingUserName user,\r
+            RequestingUserPassword passwd) {\r
+        String requestClassName = System.getProperty(IPP_REQUEST_IMPL_KEY);\r
+        IppRequest request = null;\r
+        if (requestClassName == null) {\r
+            request = new IppRequestCupsImpl(uri, operation);\r
+        } else {\r
+            Class clazz = null;\r
+            try {\r
+                clazz = Class.forName(requestClassName);\r
+            } catch (ClassNotFoundException e) {\r
+                throw new IllegalArgumentException("Class " + requestClassName\r
+                        + " does not exist.");\r
+            }\r
+\r
+            try {\r
+                Constructor constructor = clazz\r
+                        .getDeclaredConstructor(new Class[] { URI.class,\r
+                                OperationsSupported.class });\r
+                request = (IppRequest) constructor.newInstance(new Object[] {\r
+                        uri, operation });\r
+            } catch (Exception e) {\r
+                throw new RuntimeException(e);\r
+            }\r
+        }\r
+        if (user != null && passwd != null) {\r
+            AttributeSet set = new HashAttributeSet();\r
+            set.add(user);\r
+            set.add(passwd);\r
+            request.addOperationAttributes(set);\r
+        }\r
+        return request;\r
+    }\r
+}
\ No newline at end of file