Exemple #1
0
 private static Element serializePackagingElement(PackagingElement<?> packagingElement) {
   Element element = new Element(PACKAGING_ELEMENT_NAME);
   element.setAttribute(TYPE_ID_ATTRIBUTE, packagingElement.getType().getId());
   final Object bean = packagingElement.getState();
   if (bean != null) {
     XmlSerializer.serializeInto(bean, element, new SkipDefaultValuesSerializationFilters());
   }
   if (packagingElement instanceof CompositePackagingElement) {
     for (PackagingElement<?> child :
         ((CompositePackagingElement<?>) packagingElement).getChildren()) {
       element.addContent(serializePackagingElement(child));
     }
   }
   return element;
 }
Exemple #2
0
  private <T> PackagingElement<T> deserializeElement(Element element)
      throws UnknownPackagingElementTypeException {
    final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE);
    PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id);
    if (type == null) {
      throw new UnknownPackagingElementTypeException(id);
    }

    PackagingElement<T> packagingElement = (PackagingElement<T>) type.createEmpty(myProject);
    T state = packagingElement.getState();
    if (state != null) {
      XmlSerializer.deserializeInto(state, element);
      packagingElement.loadState(state);
    }
    final List children = element.getChildren(PACKAGING_ELEMENT_NAME);
    //noinspection unchecked
    for (Element child : (List<? extends Element>) children) {
      ((CompositePackagingElement<?>) packagingElement).addOrFindChild(deserializeElement(child));
    }
    return packagingElement;
  }