示例#1
0
 /**
  * A helper method that deserializes a object from the given stream.
  *
  * @param stream the stream from which to read the object data.
  * @throws IOException if an IO error occured.
  * @throws ClassNotFoundException if an referenced class cannot be found.
  */
 private void readObject(final ObjectInputStream stream)
     throws IOException, ClassNotFoundException {
   stream.defaultReadObject();
   this.attributes = new ReportAttributeMap<Object>(stream.readLong());
   final String[] nameSpaces = (String[]) stream.readObject();
   for (int i = 0; i < nameSpaces.length; i++) {
     final String nameSpace = nameSpaces[i];
     final String[] names = (String[]) stream.readObject();
     for (int j = 0; j < names.length; j++) {
       final String name = names[j];
       final int nullHandler = stream.readByte();
       if (nullHandler == 0) {
         final Object attribute = SerializerHelper.getInstance().readObject(stream);
         this.attributes.setAttribute(nameSpace, name, attribute);
       }
     }
   }
 }
 private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
   in.defaultReadObject();
   final SerializerHelper helper = SerializerHelper.getInstance();
   outlineStroke = (BasicStroke) helper.readObject(in);
 }
 private void writeObject(final ObjectOutputStream out) throws IOException {
   out.defaultWriteObject();
   final SerializerHelper helper = SerializerHelper.getInstance();
   helper.writeObject(outlineStroke, out);
 }
示例#4
0
  /**
   * A helper method that serializes the element object.
   *
   * @param stream the stream to which the element should be serialized.
   * @throws IOException if an IO error occured or a property was not serializable.
   */
  private void writeObject(final ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    final ReportAttributeMap attributes = this.attributes;
    stream.writeLong(attributes.getChangeTracker());
    final String[] nameSpaces = attributes.getNameSpaces();
    stream.writeObject(nameSpaces);
    for (int i = 0; i < nameSpaces.length; i++) {
      final String nameSpace = nameSpaces[i];
      final String[] names = attributes.getNames(nameSpace);
      stream.writeObject(names);
      for (int j = 0; j < names.length; j++) {
        final String name = names[j];
        final Object attribute = attributes.getAttribute(nameSpace, name);

        final AttributeMetaData data = getMetaData().getAttributeDescription(nameSpace, name);
        if (data != null) {
          if (data.isTransient()) {
            stream.writeByte(1);
            continue;
          }

          if (attribute instanceof ResourceKey) {
            final ResourceKey key = (ResourceKey) attribute;
            final ResourceKey parent = key.getParent();
            if (AttributeNames.Core.NAMESPACE.equals(nameSpace)
                && (AttributeNames.Core.CONTENT_BASE.equals(name)
                    || AttributeNames.Core.SOURCE.equals(name))) {
              if (parent != null) {
                // unwrap the content base attribute. After deserialization, the report assumes the
                // bundle-location
                // as content base, as the bundle will be gone.
                if (isKeySerializable(parent)) {
                  stream.writeByte(0);
                  SerializerHelper.getInstance().writeObject(parent, stream);
                } else {
                  stream.writeByte(1);
                }
              } else {
                // great, the report was never part of a bundle. That makes life easier and the key
                // should be
                // safely serializable too.

                if (isKeySerializable(key)) {
                  stream.writeByte(0);
                  SerializerHelper.getInstance().writeObject(key, stream);
                } else {
                  stream.writeByte(1);
                }
              }
            } else {
              if ("Resource".equals(data.getValueRole()) || parent != null) {
                stream.writeByte(0);
                try {
                  final ResourceKey resourceKey =
                      ResourceKeyUtils.embedResourceInKey(
                          locateResourceManager(), key, key.getFactoryParameters());
                  SerializerHelper.getInstance().writeObject(resourceKey, stream);
                } catch (ResourceException e) {
                  throw new IOException("Failed to convert resource-key into byte-array key: " + e);
                }
              } else {
                stream.writeByte(0);
                SerializerHelper.getInstance().writeObject(attribute, stream);
              }
            }
          } else if (SerializerHelper.getInstance().isSerializable(attribute)) {
            stream.writeByte(0);
            SerializerHelper.getInstance().writeObject(attribute, stream);
          } else {
            stream.writeByte(1);
          }
        } else if (attribute instanceof String) {
          stream.writeByte(0);
          SerializerHelper.getInstance().writeObject(attribute, stream);
        } else {
          stream.writeByte(1);
        }
      }
    }
  }