Пример #1
0
  private static void testEncodable(Encodable encodable) throws Exception {
    ByteQueue queue = new ByteQueue();
    encodable.write(queue);

    ServicesSupported servicesSupported = new ServicesSupported();
    servicesSupported.setAll(true);

    Encodable deserialized;
    if (BaseError.class.isAssignableFrom(encodable.getClass()))
      deserialized = BaseError.createBaseError(queue);
    else if (NotificationParameters.class.isAssignableFrom(encodable.getClass()))
      deserialized = NotificationParameters.createNotificationParameters(queue);
    else if (EventParameter.class.isAssignableFrom(encodable.getClass()))
      deserialized = EventParameter.createEventParameter(queue);
    else if (AcknowledgementService.class.isAssignableFrom(encodable.getClass()))
      deserialized =
          AcknowledgementService.createAcknowledgementService(
              ((Service) encodable).getChoiceId(), queue);
    else if (UnconfirmedRequestService.class.isAssignableFrom(encodable.getClass()))
      deserialized =
          UnconfirmedRequestService.createUnconfirmedRequestService(
              ((Service) encodable).getChoiceId(), queue);
    else {
      Constructor<? extends Encodable> c = encodable.getClass().getConstructor(ByteQueue.class);
      deserialized = c.newInstance(queue);
    }

    if (!deserialized.equals(encodable))
      throw new Exception("Unequal deserialization in class " + encodable.getClass());
  }
 public void handleUnconfirmedRequest(
     Address from, Network network, UnconfirmedRequestService serviceRequest) {
   System.out.println("Received unconfirmed service request " + serviceRequest.getClass());
 }