/******************************************************************************************************************* * * ******************************************************************************************************************/ public PresentationModelAdapter (final @Nonnull Context context, final @Nonnull PresentationModel presentationModel) { log.debug("PresentationModelAdapter()"); this.context = context; this.presentationModels = new ArrayList<PresentationModel>(); try { // FIXME: why SimpleComposite? final SimpleComposite<PresentationModel> composite = presentationModel.as(SimpleComposite.class); presentationModels.addAll(composite.findChildren().results()); } catch (AsException e) { log.debug(">>>> presentationModel is not a Composite"); // ok, no Composite } // log.debug(">>>> created from {}, {} items", presentationModel, presentationModels.size()); log.debug("PresentationModelAdapter - created from {}@{}, {} items", new Object[] { presentationModel.getClass().getSimpleName(), Integer.toHexString(System.identityHashCode(presentationModel)), presentationModels.size() }); }
@Override public List<? extends PresentationModel> run() { final List<PresentationModel> results = new ArrayList<>(); try { @SuppressWarnings("unchecked") final SimpleComposite<T> composite = scp.datum.as(SimpleComposite.class); for (final T child : composite.findChildren().results()) { final Presentable presentable = child.as(Presentable, new NotFoundBehaviour<Presentable>() { @Override public Presentable run (final Throwable t) { return new SimpleCompositePresentable<>(child); } }); results.add(presentable.createPresentationModel(rolesOrFactories.toArray())); } } catch (AsException e) { // ok, no Composite role log.trace(">>>> no composite role for {}", scp.datum); } return results; } });
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private void assertProperPresentationModel (final @Nonnull String indent, final @Nonnull PresentationModel pm, final @Nonnull MockDatum datum) { log.debug("assertProperPresentationModel() - {} {}, {}", new Object[] { indent, pm, datum }); pm.as(MockRole1.class); // must not throw AsException final MockRole2 role = pm.as(MockRole2.class); // must not throw AsException assertThat(role.getDatum(), is(sameInstance(datum))); final SimpleComposite<PresentationModel> composite = pm.as(SimpleComposite.class); final List<? extends PresentationModel> childrenPm = composite.findChildren().results(); final List<MockDatum> childrenData = datum.getChildren(); assertThat(childrenPm.size(), is(childrenData.size())); for (int i = 0; i < childrenPm.size(); i++) { assertProperPresentationModel(indent + " ", childrenPm.get(i), childrenData.get(i)); } } }