001
002 /*
003 * Copyright (C) 2012 Archie L. Cobbs. All rights reserved.
004 *
005 * $Id: FilterDelegate.java 255 2012-01-27 23:32:12Z archie.cobbs $
006 */
007
008 package org.dellroad.stuff.pobj;
009
010 import java.io.IOException;
011 import java.util.Set;
012
013 import javax.validation.ConstraintViolation;
014 import javax.xml.transform.Result;
015 import javax.xml.transform.Source;
016
017 /**
018 * Adapter class for {@link PersistentObjectDelegate} implementations that wrap a nested delegate.
019 * All methods in this class forward to the nested delegate.
020 *
021 * @param <T> type of the root persistent object
022 */
023 public class FilterDelegate<T> implements PersistentObjectDelegate<T> {
024
025 protected final PersistentObjectDelegate<T> nested;
026
027 /**
028 * Constructor.
029 *
030 * @param nested nested delegate to wrap
031 * @throws IllegalArgumentException if {@code nested} is null
032 */
033 public FilterDelegate(PersistentObjectDelegate<T> nested) {
034 if (nested == null)
035 throw new IllegalArgumentException("null nested");
036 this.nested = nested;
037 }
038
039 @Override
040 public void serialize(T obj, Result result) throws IOException {
041 this.nested.serialize(obj, result);
042 }
043
044 @Override
045 public T deserialize(Source source) throws IOException {
046 return this.nested.deserialize(source);
047 }
048
049 @Override
050 public T copy(T original) {
051 return this.nested.copy(original);
052 }
053
054 @Override
055 public boolean isSameGraph(T root1, T root2) {
056 return this.nested.isSameGraph(root1, root2);
057 }
058
059 @Override
060 public Set<ConstraintViolation<T>> validate(T obj) {
061 return this.nested.validate(obj);
062 }
063
064 @Override
065 public void handleWritebackException(PersistentObject<T> pobj, Throwable t) {
066 this.nested.handleWritebackException(pobj, t);
067 }
068 }
069