protected final <S> S as(Class<? extends S> clazz) throws UnsupportedFeatureException { if(clazz.isInstance(this.delegate)) { return clazz.cast(this.delegate); } throw new UnsupportedFeatureException(resource(),clazz); }
protected final FeatureException featureException(Throwable cause, Class<?> feature) { return new FeatureExecutionException(resource(),feature,cause); }
@Override public void visitResourceSnapshot(ResourceSnapshot resource) { this.adapter=new ResourceAdapter<ResourceSnapshot>(resource,this.resourceId,this.delegate,this.session,this.service); }
@Override public Resource create(DataSet content) throws FeatureException { finalizeSession(); throw new UnsupportedFeatureException(resource(),ContainerHandler.class); }
protected final void checkResponseNotNull(Object response, Class<?> feature, String violation) throws FeaturePostconditionException { if(response==null) { throw new FeaturePostconditionException(resource(),feature,violation); } }
@Override public final void delete() throws FeatureException { try { as(Deletable.class).delete(resource(),writeSession()); } catch (ApplicationException | ApplicationApiRuntimeException e) { throw featureException(e,Deletable.class); } finally { finalizeSession(); } }
@Override public final DataSet get() throws FeatureException { try { DataSet dataSet = this.delegate.get(resource()); checkResponseNotNull(dataSet,ResourceHandler.class,"No data set returned"); return dataSet; } catch (ApplicationException | ApplicationApiRuntimeException e) { throw featureException(e,ResourceHandler.class); } finally { finalizeSession(); } }
@Override public final void update(DataSet content) throws FeatureException { try { as(Modifiable.class).update(resource(), content, writeSession()); } catch (ApplicationException | ApplicationApiRuntimeException e) { throw featureException(e,Modifiable.class); } finally { finalizeSession(); } }
@Override public final DataSet query(Query query) throws FeatureException { try { DataSet dataSet = as(Queryable.class).query(resource(), query, writeSession()); checkResponseNotNull(dataSet,Queryable.class,"No data set returned"); return dataSet; } catch (ApplicationException | ApplicationApiRuntimeException e) { throw featureException(e,Queryable.class); } finally { finalizeSession(); } }