@NotNull
 private static <S> PackagingElement<S> copyElement(
     @NotNull PackagingElement<S> element, @NotNull Project project) {
   //noinspection unchecked
   final PackagingElement<S> copy = (PackagingElement<S>) element.getType().createEmpty(project);
   copy.loadState(element.getState());
   return copy;
 }
Beispiel #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;
  }