@Override public LibraryProtos.Book convert( final EClass sourceType, final Book source, final Descriptor targetType) { final LibraryProtos.Book.Builder result = LibraryProtos.Book.newBuilder(); result.setId(pool.getId(source)); if (source.eIsSet(LibraryPackage.Literals.BOOK__NAME)) { result.setName(source.getName()); } if (source.eIsSet(LibraryPackage.Literals.BOOK__AUTHOR)) { final Author curAuthor = source.getAuthor(); if (curAuthor.eClass() == LibraryPackage.Literals.AUTHOR) { result .getAuthorBuilder() .setExtension( LibraryProtos.Author.authorAuthor, LibraryProtos.Author.newBuilder().setId(pool.getId(curAuthor)).build()); } else { // TODO: lookup in converter registry... throw new UnsupportedOperationException(); } } if (source.eIsSet(LibraryPackage.Literals.BOOK__RATING)) { switch (source.getRating()) { case NO_RATING: result.setRating(LibraryProtos.Rating.NO_RATING); break; case GOOD: result.setRating(LibraryProtos.Rating.GOOD); break; case MEDIUM: result.setRating(LibraryProtos.Rating.MEDIUM); break; case BAD: result.setRating(LibraryProtos.Rating.BAD); break; } ; } return result.build(); }
@Override protected Descriptor getTargetType(EClass sourceType) { return LibraryProtos.Book.getDescriptor(); }
@Override public boolean supports(EClass sourceType, Descriptor targetType) { return LibraryProtos.Book.getDescriptor() == targetType && LibraryPackage.Literals.BOOK == sourceType; }