Ejemplo n.º 1
0
    @Override
    public JAXBElement<?> map(ArrayItem item, JAXBElement<?> origin) {
      JAXBElement<?> source = origin;
      if (origin == null) {
        if (item instanceof ExtentItem) {
          source = factory.createPhysicalDescriptionTypeExtent(null);
        } else if (item instanceof NoteItem) {
          NoteItem noteItem = (NoteItem) item;
          NoteType noteType = factory.createNoteType();
          noteType.setAtType(noteItem.getType());
          source = factory.createPhysicalDescriptionTypeNote(noteType);
        } else {
          throw new IllegalStateException("unsupported array item: " + item.getClass());
        }
      }

      if (item instanceof ExtentItem) {
        ExtentItem extentItem = (ExtentItem) item;
        JAXBElement<String> extentSource = (JAXBElement<String>) source;
        // delete with empty string to prevent XML nil
        extentSource.setValue(extentItem.getValue() != null ? extentItem.getValue() : "");
      } else if (item instanceof NoteItem && !((NoteItem) item).ignore) {
        NoteItem noteItem = (NoteItem) item;
        NoteType noteType = (NoteType) source.getValue();
        noteType.setValue(noteItem.getValue());
      }
      return source;
    }