summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/javax/print/ipp/IppResponse.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/javax/print/ipp/IppResponse.java')
-rw-r--r--libjava/classpath/gnu/javax/print/ipp/IppResponse.java200
1 files changed, 103 insertions, 97 deletions
diff --git a/libjava/classpath/gnu/javax/print/ipp/IppResponse.java b/libjava/classpath/gnu/javax/print/ipp/IppResponse.java
index 81a1eb47b03..703bdc1eb90 100644
--- a/libjava/classpath/gnu/javax/print/ipp/IppResponse.java
+++ b/libjava/classpath/gnu/javax/print/ipp/IppResponse.java
@@ -1,4 +1,4 @@
-/* IppResponse.java --
+/* IppResponse.java --
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -99,9 +99,9 @@ import javax.print.attribute.standard.PrinterStateReasons;
import javax.print.attribute.standard.Severity;
/**
- * <code>IppResponse</code> models a response received from an IPP
+ * <code>IppResponse</code> models a response received from an IPP
* compatible server as described in RFC 2910 IPP 1.1 Encoding and Transport.
- *
+ *
* @author Wolfgang Baer (WBaer@gmx.de)
*/
public class IppResponse
@@ -112,7 +112,7 @@ public class IppResponse
* response stream. It provides access to the attribute groups after parsing
* via getter methods.
* <p>
- * The enconding of a response is structured as follows (for an official
+ * The enconding of a response is structured as follows (for an official
* description please have a look at the RFC document mentioned above):
* <ul>
* <li>version-number - 2 bytes - required</li>
@@ -122,19 +122,19 @@ public class IppResponse
* <li>end-of-attributes-tag - 1 byte - required</li>
* <li>data - q bytes - optional</li>
* </ul>
- * </p><p>
+ * </p><p>
* Where each attribute-group (if any) is encoded as follows:
* <ul>
* <li>begin-attribute-group-tag - 1 byte</li>
* <li>attribute - p bytes - 0 or more</li>
* </ul>
- * </p><p>
+ * </p><p>
* Encoding of attributes:
* <ul>
* <li>attribute-with-one-value - q bytes</li>
* <li>additional-value - r bytes - 0 or more</li>
* </ul>
- * </p><p>
+ * </p><p>
* Encoding of attribute-with-one-value:
* <ul>
* <li>value-tag - 1 byte</li>
@@ -143,7 +143,7 @@ public class IppResponse
* <li>value-length (value is v) - 2 bytes</li>
* <li>value - v bytes</li>
* </ul>
- * </p><p>
+ * </p><p>
* Encoding of additional value:
* <ul>
* <li>value-tag - 1 byte</li>
@@ -152,21 +152,21 @@ public class IppResponse
* <li>value - w bytes</li>
* </ul>
* </p>
- *
+ *
* @author Wolfgang Baer (WBaer@gmx.de)
*/
class ResponseReader
{
/** The IPP version defaults to 1.1 */
private static final short VERSION = 0x0101;
-
+
/**
* Parses the inputstream containing the response of the IPP request.
* @param input the inputstream
* @throws IppException if unexpected exceptions occur.
* @throws IOException if IO problems with the underlying inputstream occur.
*/
- public void parseResponse(InputStream input)
+ public void parseResponse(InputStream input)
throws IppException, IOException
{
DataInputStream stream = new DataInputStream(input);
@@ -179,12 +179,12 @@ public class IppResponse
throw new IppException("Version mismatch - "
+ "implementation does not support other versions than IPP 1.1");
- logger.log(Component.IPP, "Statuscode: "
+ logger.log(Component.IPP, "Statuscode: "
+ Integer.toHexString(status_code) + " Request-ID: " + request_id);
byte tag = 0;
boolean proceed = true;
- HashMap tmp;
+ HashMap<Class<? extends Attribute>, Set<Attribute>> tmp;
// iterate over attribute-groups until end-of-attributes-tag is found
while (proceed)
{
@@ -200,23 +200,23 @@ public class IppResponse
proceed = false;
break;
case IppDelimiterTag.OPERATION_ATTRIBUTES_TAG:
- tmp = new HashMap();
+ tmp = new HashMap<Class<? extends Attribute>, Set<Attribute>>();
tag = parseAttributes(tmp, stream);
operationAttributes.add(tmp);
break;
case IppDelimiterTag.JOB_ATTRIBUTES_TAG:
- tmp = new HashMap();
+ tmp = new HashMap<Class<? extends Attribute>, Set<Attribute>>();
tag = parseAttributes(tmp, stream);
jobAttributes.add(tmp);
break;
case IppDelimiterTag.PRINTER_ATTRIBUTES_TAG:
- tmp = new HashMap();
+ tmp = new HashMap<Class<? extends Attribute>, Set<Attribute>>();
tag = parseAttributes(tmp, stream);
printerAttributes.add(tmp);
break;
case IppDelimiterTag.UNSUPPORTED_ATTRIBUTES_TAG:
System.out.println("Called");
- tmp = new HashMap();
+ tmp = new HashMap<Class<? extends Attribute>, Set<Attribute>>();
tag = parseAttributes(tmp, stream);
unsupportedAttributes.add(tmp);
break;
@@ -247,7 +247,8 @@ public class IppResponse
* @throws IppException if unexpected exceptions occur.
* @throws IOException if IO problems with the underlying inputstream occur.
*/
- private byte parseAttributes(Map attributes, DataInputStream stream)
+ private byte parseAttributes(Map<Class<? extends Attribute>, Set<Attribute>> attributes,
+ DataInputStream stream)
throws IppException, IOException
{
Attribute lastAttribute = null;
@@ -294,7 +295,7 @@ public class IppResponse
// (4) The value itself
value = new byte[valueLength];
- stream.read(value);
+ stream.read(value);
// the value itself
switch (tag)
@@ -304,12 +305,12 @@ public class IppResponse
case IppValueTag.UNKNOWN:
// TODO implement out-of-band handling
// We currently throw an exception to see when it occurs - not yet :-)
- throw new IppException(
+ throw new IppException(
"Unexpected name value for out-of-band value tag " + tag);
case IppValueTag.NO_VALUE:
- attribute = null;
+ attribute = null;
- break;
+ break;
case IppValueTag.INTEGER:
int intValue = IppUtilities.convertToInt(value);
attribute = IppUtilities.getIntegerAttribute(name, intValue);
@@ -319,11 +320,11 @@ public class IppResponse
// JPS API models boolean syntax type as enums
// 0x01 = true, 0x00 = false - all are enums
attribute = IppUtilities.getEnumAttribute(name, new Integer(value[0]));
-
+
break;
case IppValueTag.ENUM:
- int intVal = IppUtilities.convertToInt(value);
- attribute = IppUtilities.getEnumAttribute(name, new Integer(intVal));
+ int intVal = IppUtilities.convertToInt(value);
+ attribute = IppUtilities.getEnumAttribute(name, new Integer(intVal));
break;
case IppValueTag.OCTECTSTRING_UNSPECIFIED:
@@ -347,7 +348,7 @@ public class IppResponse
int crossFeed = IppUtilities.convertToInt(value[0], value[1], value[2], value[3]);
int feed = IppUtilities.convertToInt(value[4], value[5], value[6], value[7]);
int units = value[8];
-
+
if (name.equals("printer-resolution-default"))
attribute = new PrinterResolutionDefault(crossFeed, feed, units);
else if (name.equals("printer-resolution-supported")) // may be here also
@@ -362,7 +363,7 @@ public class IppResponse
attribute = new CopiesSupported(lower, upper);
else if (name.equals("number-up-supported"))
attribute = new NumberUpSupported(lower, upper);
- else if (name.equals("job-k-octets-supported"))
+ else if (name.equals("job-k-octets-supported"))
attribute = new JobKOctetsSupported(lower, upper);
else if (name.equals("job-impressions-supported"))
attribute = new JobImpressionsSupported(lower, upper);
@@ -375,19 +376,19 @@ public class IppResponse
case IppValueTag.NAME_WITH_LANGUAGE:
case IppValueTag.NAME_WITHOUT_LANGUAGE:
attribute = IppUtilities.getTextAttribute(name, tag, value);
-
+
break;
case IppValueTag.KEYWORD:
str = new String(value);
if (name.equals("job-hold-until-supported")) // may also be name type
attribute = new JobHoldUntilSupported(str, null);
else if (name.equals("job-hold-until-default"))
- attribute = new JobHoldUntilDefault(str, null);
+ attribute = new JobHoldUntilDefault(str, null);
else if (name.equals("media-supported"))
attribute = new MediaSupported(str, null);
else if (name.equals("media-default"))
- attribute = new MediaDefault(str, null);
- else if (name.equals("job-sheets-default"))
+ attribute = new MediaDefault(str, null);
+ else if (name.equals("job-sheets-default"))
attribute = new JobSheetsDefault(str, null);
else if (name.equals("job-sheets-supported"))
attribute = new JobSheetsSupported(str, null);
@@ -397,13 +398,13 @@ public class IppResponse
attribute = parsePrinterStateReasons(value, lastAttribute);
else
attribute = IppUtilities.getEnumAttribute(name, str);
-
- // all other stuff is either an enum or needs to be mapped to an
- // UnknownAttribute instance. Enums catched here are:
+
+ // all other stuff is either an enum or needs to be mapped to an
+ // UnknownAttribute instance. Enums catched here are:
// ipp-versions-supported, pdl-override-supported, compression-supported
// uri-authentication-supported, uri-security-supported, sides-supported
// sides-default, multiple-document-handling-supported, multiple-document-handling-default
-
+
break;
case IppValueTag.URI:
try
@@ -429,13 +430,13 @@ public class IppResponse
attribute = new PrinterDriverInstaller(uri);
else if (name.equals("printer-more-info-manufacturer"))
attribute = new PrinterMoreInfoManufacturer(uri);
-
+
break;
case IppValueTag.URI_SCHEME:
// only one uri-scheme exists - and its an enum
if (name.equals("reference-uri-schemes-supported"))
attribute = IppUtilities.getEnumAttribute(name, new String(value));
-
+
break;
case IppValueTag.CHARSET:
str = new String(value);
@@ -445,7 +446,7 @@ public class IppResponse
attribute = new CharsetConfigured(str);
else if (name.equals("charset-supported")) // setOf
attribute = new CharsetSupported(str);
-
+
break;
case IppValueTag.NATURAL_LANGUAGE:
str = new String(value);
@@ -455,7 +456,7 @@ public class IppResponse
attribute = new NaturalLanguageConfigured(str);
else if (name.equals("generated-natural-language-supported")) // setOf
attribute = new GeneratedNaturalLanguageSupported(str);
-
+
break;
case IppValueTag.MIME_MEDIA_TYPE:
str = new String(value);
@@ -465,7 +466,7 @@ public class IppResponse
attribute = new DocumentFormatSupported(str, null);
else if (name.equals("document-format")) // setOf
attribute = new DocumentFormat(str, null);
-
+
break;
default:
throw new IppException("Unknown tag with value "
@@ -473,11 +474,11 @@ public class IppResponse
}
if (attribute == null)
- attribute = new UnknownAttribute(tag, name, value);
-
+ attribute = new UnknownAttribute(tag, name, value);
+
addAttribute(attributes, attribute);
lastAttribute = attribute;
-
+
logger.log(Component.IPP, "Attribute: " + name
+ " Value: " + attribute.toString());
}
@@ -492,20 +493,21 @@ public class IppResponse
* @param attribute
* the attribute to add
*/
- private void addAttribute(Map attributeGroup, Attribute attribute)
+ private void addAttribute(Map<Class<? extends Attribute>, Set<Attribute>> attributeGroup,
+ Attribute attribute)
{
- Class clazz = attribute.getCategory();
- Set attributeValues = (Set) attributeGroup.get(clazz);
+ Class<? extends Attribute> clazz = attribute.getCategory();
+ Set<Attribute> attributeValues = attributeGroup.get(clazz);
if (attributeValues == null) // first attribute of this category
{
- attributeValues = new HashSet();
+ attributeValues = new HashSet<Attribute>();
attributeGroup.put(clazz, attributeValues);
}
attributeValues.add(attribute);
}
-
+
/**
* Parses a name with or without language attribute value from the byte[]
* and returns the result as an object[].
@@ -516,39 +518,39 @@ public class IppResponse
private PrinterStateReasons parsePrinterStateReasons(byte[] value, Attribute lastAttr)
{
String str = new String(value);
- PrinterStateReasons attribute;
-
+ PrinterStateReasons attribute;
+
if (lastAttr instanceof PrinterStateReasons)
attribute = (PrinterStateReasons) lastAttr;
else
attribute = new PrinterStateReasons();
-
+
// special case indicating no reasons
- if (str.equals("none"))
+ if (str.equals("none"))
return attribute;
-
+
Severity severity = null;
PrinterStateReason reason = null;
-
+
if (str.endsWith(Severity.WARNING.toString()))
severity = Severity.WARNING;
else if (str.endsWith(Severity.REPORT.toString()))
severity = Severity.REPORT;
else if (str.endsWith(Severity.ERROR.toString()))
severity = Severity.ERROR;
-
+
if (severity != null)
- str = str.substring(0, str.lastIndexOf('-'));
- else // we must associate a severity
+ str = str.substring(0, str.lastIndexOf('-'));
+ else // we must associate a severity
severity = Severity.REPORT;
-
- reason = (PrinterStateReason)
+
+ reason = (PrinterStateReason)
IppUtilities.getEnumAttribute("printer-state-reason", str);
-
+
attribute.put(reason , severity);
return attribute;
}
-
+
/**
* Parses a name with or without language attribute value from the byte[]
* and returns the result as an object[].
@@ -559,24 +561,24 @@ public class IppResponse
private JobStateReasons parseJobStateReasons(byte[] value, Attribute lastAttr)
{
String str = new String(value);
- JobStateReasons attribute;
-
+ JobStateReasons attribute;
+
if (lastAttr instanceof JobStateReasons)
attribute = (JobStateReasons) lastAttr;
else
attribute = new JobStateReasons();
-
+
// special case indicating no reasons
- if (str.equals("none"))
+ if (str.equals("none"))
return attribute;
-
- JobStateReason reason = (JobStateReason)
+
+ JobStateReason reason = (JobStateReason)
IppUtilities.getEnumAttribute("job-state-reason", str);
-
+
attribute.add(reason);
return attribute;
}
-
+
/**
* Parses a DateTime syntax attribute and returns the constructed Date
* object.
@@ -597,7 +599,7 @@ public class IppResponse
* <li>10 | 11 | minutes from UTC | 0..59</li>
* </ul>
* </p>
- *
+ *
* @param value the byte[]
* @return The date object.
*/
@@ -625,28 +627,28 @@ public class IppResponse
return cal.getTime();
}
}
-
+
/**
* Logger for tracing - enable by passing
* -Dgnu.classpath.debug.components=ipp to the vm.
*/
static final Logger logger = SystemLogger.SYSTEM;
-
+
URI uri;
short operation_id;
short status_code;
int request_id;
- List operationAttributes;
- List printerAttributes;
- List jobAttributes;
- List unsupportedAttributes;
+ List<Map<Class<? extends Attribute>, Set<Attribute>>> operationAttributes;
+ List<Map<Class<? extends Attribute>, Set<Attribute>>> printerAttributes;
+ List<Map<Class<? extends Attribute>, Set<Attribute>>> jobAttributes;
+ List<Map<Class<? extends Attribute>, Set<Attribute>>> unsupportedAttributes;
byte[] data;
/**
* Creates an <code>IppResponse</code> instance.
- *
+ *
* @param uri the uri the request was directy to.
* @param operation_id the operation id of the request.
*/
@@ -654,15 +656,19 @@ public class IppResponse
{
this.uri = uri;
this.operation_id = operation_id;
- operationAttributes = new ArrayList();
- jobAttributes = new ArrayList();
- printerAttributes = new ArrayList();
- unsupportedAttributes = new ArrayList();
+ operationAttributes =
+ new ArrayList<Map<Class<? extends Attribute>, Set<Attribute>>>();
+ jobAttributes =
+ new ArrayList<Map<Class<? extends Attribute>, Set<Attribute>>>();
+ printerAttributes =
+ new ArrayList<Map<Class<? extends Attribute>, Set<Attribute>>>();
+ unsupportedAttributes =
+ new ArrayList<Map<Class<? extends Attribute>, Set<Attribute>>>();
}
/**
* Sets the data received from the request sent.
- *
+ *
* @param input the input stream received.
* @throws IppException if parsing fails.
*/
@@ -703,10 +709,10 @@ public class IppResponse
* Returns the set of job attributes group maps.
* There may occur more than one group of type job attribute in a response
* because of e.g. multiple job or print service informations requested.
- *
- * @return The list of job attribute grou maps.
+ *
+ * @return The list of job attribute group maps.
*/
- public List getJobAttributes()
+ public List<Map<Class<? extends Attribute>, Set<Attribute>>> getJobAttributes()
{
return jobAttributes;
}
@@ -715,10 +721,10 @@ public class IppResponse
* Returns the set of operation attributes group maps.
* There may occur more than one group of type job attribute in a response
* because of e.g. multiple job or print service informations requested.
- *
- * @return The list of operation attribute grou maps.
+ *
+ * @return The list of operation attribute group maps.
*/
- public List getOperationAttributes()
+ public List<Map<Class<? extends Attribute>, Set<Attribute>>> getOperationAttributes()
{
return operationAttributes;
}
@@ -727,17 +733,17 @@ public class IppResponse
* Returns the set of printer attributes group maps.
* There may occur more than one group of type job attribute in a response
* because of e.g. multiple job or print service informations requested.
- *
- * @return The list of printer attribute grou maps.
+ *
+ * @return The list of printer attribute group maps.
*/
- public List getPrinterAttributes()
+ public List<Map<Class<? extends Attribute>, Set<Attribute>>> getPrinterAttributes()
{
return printerAttributes;
}
/**
* Returns the ID of the initial request.
- *
+ *
* @return The request ID.
*/
public int getRequestID()
@@ -748,7 +754,7 @@ public class IppResponse
/**
* Returns the status code of the response.
* Defined in {@link IppStatusCode}.
- *
+ *
* @return The status code.
*/
public short getStatusCode()
@@ -760,17 +766,17 @@ public class IppResponse
* Returns the set of unsupported attributes group maps.
* There may occur more than one group of type job attribute in a response
* because of e.g. multiple job or print service informations requested.
- *
- * @return The list of unsupported attribute grou maps.
+ *
+ * @return The list of unsupported attribute group maps.
*/
- public List getUnsupportedAttributes()
+ public List<Map<Class<? extends Attribute>, Set<Attribute>>> getUnsupportedAttributes()
{
return unsupportedAttributes;
}
/**
* Returns the data of the response.
- *
+ *
* @return The data as byte[].
*/
public byte[] getData()