⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ippresponse.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
              else if (name.equals("job-state-reasons")) // setOf                attribute = parseJobStateReasons(value, lastAttribute);              else if (name.equals("printer-state-reasons")) // setOf                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:               // 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                {                  uri = new URI(new String(value));                }              catch (URISyntaxException e)                {                  throw new IppException("Wrong URI syntax encountered.", e);                }              if (name.equals("job-uri"))                attribute = new JobUri(uri);              else if (name.equals("job-printer-uri"))                attribute = new JobPrinterUri(uri);              else if (name.equals("job-more-info"))                attribute = new JobMoreInfo(uri);              else if (name.equals("printer-uri-supported")) // setOf                attribute = new PrinterUriSupported(uri);              else if (name.equals("printer-more-info"))                attribute = new PrinterMoreInfo(uri);              else if (name.equals("printer-driver-installer"))                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);              if (name.equals("attributes-charset"))                attribute = new AttributesCharset(str);              else if (name.equals("charset-configured"))                attribute = new CharsetConfigured(str);              else if (name.equals("charset-supported")) // setOf                attribute = new CharsetSupported(str);                            break;            case IppValueTag.NATURAL_LANGUAGE:              str = new String(value);              if (name.equals("attributes-natural-language"))                attribute = new AttributesNaturalLanguage(str);              else if (name.equals("natural-language-configured"))                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);              if (name.equals("document-format-default"))                attribute = new DocumentFormatDefault(str, null);              else if (name.equals("document-format-supported")) // setOf                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 "                                     + Integer.toHexString(tag) + " found.");            }          if (attribute == null)            attribute =  new UnknownAttribute(tag, name, value);                    addAttribute(attributes, attribute);          lastAttribute = attribute;                    logger.log(Component.IPP, "Attribute: " + name                     + " Value: " + attribute.toString());        }    }    /**     * Adds a new attribute to the given attribute group. If this is the fist     * occurence of this attribute category a new set is created and associated     * with its category as key.     * @param attributeGroup     *          the attribute group     * @param attribute     *          the attribute to add     */    private void addAttribute(Map attributeGroup, Attribute attribute)    {      Class clazz = attribute.getCategory();      Set attributeValues = (Set) attributeGroup.get(clazz);      if (attributeValues == null) // first attribute of this category        {          attributeValues = new HashSet();          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[].     * @param value the byte[]     * @param lastAttr the last attribute     * @return The attribute.     */    private PrinterStateReasons parsePrinterStateReasons(byte[] value, Attribute lastAttr)    {      String str = new String(value);      PrinterStateReasons attribute;             if (lastAttr instanceof PrinterStateReasons)        attribute = (PrinterStateReasons) lastAttr;      else        attribute = new PrinterStateReasons();            // special case indicating no reasons      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         severity = Severity.REPORT;            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[].     * @param value the byte[]     * @param lastAttr the last attribute     * @return The attribute.     */    private JobStateReasons parseJobStateReasons(byte[] value, Attribute lastAttr)    {      String str = new String(value);      JobStateReasons attribute;             if (lastAttr instanceof JobStateReasons)        attribute = (JobStateReasons) lastAttr;      else        attribute = new JobStateReasons();            // special case indicating no reasons      if (str.equals("none"))         return attribute;            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.     * <p>     * The syntax value is defined as 11 octets follwing the DateAndTime format     * of RFC 1903:     * <ul>     * <li>field | octets | contents | range</li>     * <li>1 | 1-2 | year | 0..65536</li>     * <li>2 | 3 | month | 1..12</li>     * <li>3 | 4 | day | 1..31</li>     * <li>4 | 5 | hour | 0..23</li>     * <li>5 | 6 | minutes | 0..59</li>     * <li>6 | 7 | seconds | 0..60 (use 60 for leap-second)</li>     * <li>7 | 8 | deci-seconds | 0..9</li>     * <li>8 | 9 | direction from UTC | '+' / '-'</li>     * <li>9 | 10 | hours from UTC | 0..11</li>     * <li>10 | 11 | minutes from UTC | 0..59</li>     * </ul>     * </p>     *      * @param value the byte[]     * @return The date object.     */    private Date parseDate(byte[] value)    {      short year = IppUtilities.convertToShort(value[0], value[1]);      Calendar cal = Calendar.getInstance();      cal.set(Calendar.YEAR, year);      cal.set(Calendar.MONTH, value[2]);      cal.set(Calendar.DAY_OF_MONTH, value[3]);      cal.set(Calendar.HOUR_OF_DAY, value[4]);      cal.set(Calendar.MINUTE, value[5]);      cal.set(Calendar.SECOND, value[6]);      cal.set(Calendar.MILLISECOND, value[7] * 100); // deci-seconds      // offset from timezone      int offsetMilli = value[9] * 3600000; // hours to millis      offsetMilli = offsetMilli + value[10] * 60000; // minutes to millis      if (((char) value[8]) == '-')        offsetMilli = offsetMilli * (-1);      cal.set(Calendar.ZONE_OFFSET, offsetMilli);      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;  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.   */  public IppResponse(URI uri, short operation_id)  {    this.uri = uri;    this.operation_id = operation_id;    operationAttributes = new ArrayList();    jobAttributes = new ArrayList();    printerAttributes = new ArrayList();    unsupportedAttributes = new ArrayList();  }  /**   * Sets the data received from the request sent.   *    * @param input the input stream received.   * @throws IppException if parsing fails.   */  protected void setResponseData(InputStream input) throws IppException  {    ResponseReader reader = new ResponseReader();    try      {        reader.parseResponse(input);      }    catch (IOException e)      {        throw new IppException(            "Exception during response parsing caused by IOException", e);      }  }  /**   * Returns the uri of the original request.   * @return The URI of the request.   */  public URI getURI()  {    return uri;  }  /**   * Returns the operation id of the original request.   * @return The operation id of the request.   */  public int getOperationID()  {    return operation_id;  }  /**   * 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.   */  public List getJobAttributes()  {    return jobAttributes;  }  /**   * 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.   */  public List getOperationAttributes()  {    return operationAttributes;  }  /**   * 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.   */  public List getPrinterAttributes()  {    return printerAttributes;  }  /**   * Returns the ID of the initial request.   *    * @return The request ID.   */  public int getRequestID()  {    return request_id;  }  /**   * Returns the status code of the response.   * Defined in {@link IppStatusCode}.   *    * @return The status code.   */  public short getStatusCode()  {    return status_code;  }  /**   * 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.   */  public List getUnsupportedAttributes()  {    return unsupportedAttributes;  }  /**   * Returns the data of the response.   *    * @return The data as byte[].   */  public byte[] getData()  {    return data;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -