public <T> Optional<T> getOneAsComponent(Factory.Query<T> key) { Optional<NamedComponent<T>> namedComponent = getOne(key); if(namedComponent.isPresent()) { return Optional.of(namedComponent.get().getComponent()); } else { return Optional.absent(); } }
@Override protected RestxRouting doNewComponent(SatisfiedBOM satisfiedBOM) { Collection<RestxRoute> r = Lists.newArrayList(); for (RestxRouter router : satisfiedBOM.getAsComponents(routers)) { r.addAll(router.getRoutes()); } Iterables.addAll(r, satisfiedBOM.getAsComponents(routes)); return new RestxRouting( ImmutableList.copyOf(satisfiedBOM.get(filters)), ImmutableList.copyOf(satisfiedBOM.get(routeFilters)), ImmutableList.copyOf(r)); } });
@Override public ComponentBox<SpecRecorderRoute> newComponent(SatisfiedBOM satisfiedBOM) { Optional<NamedComponent<RestxSpecRecorder.Repository>> recorder = satisfiedBOM.getOne(recordedSpecRepo); if (!recorder.isPresent()) { return new EmptyBox<>(RECORDER_ROUTE_NAME); } return BoundlessComponentBox.FACTORY.of(new NamedComponent<>(RECORDER_ROUTE_NAME, new SpecRecorderRoute(recorder.get().getComponent(), satisfiedBOM.getOneAsComponent(storageSettings).get(), satisfiedBOM.getOneAsComponent(securityManager).get(), satisfiedBOM.getOneAsComponent(permissionFactory).get() ))); }
public <T> Iterable<T> getAsComponents(Factory.Query<T> key) { return Iterables.transform(get(key), NamedComponent.<T>toComponent()); }
@Override protected ConfigLoader doNewComponent(SatisfiedBOM satisfiedBOM) { return new ConfigLoader( satisfiedBOM.getOneAsComponent(env) ); } });
private <T> BillOfMaterials findBomFor(Name<T> name) { for (Warehouse provider : providers) { Optional<Warehouse.StoredBox<T>> storedBox = provider.getStoredBox(name); if (storedBox.isPresent()) { return storedBox.get().getSatisfiedBOM().getBom(); } } throw new IllegalArgumentException("name not found " + name); }
@Override public Iterable<Name<?>> listDependencies(Name name) { StoredBox storedBox = boxes.get(name); if (storedBox != null) { Collection<Name<?>> deps = Lists.newArrayList(); for (NamedComponent<? extends Object> namedComponent : storedBox.satisfiedBOM.getAllComponents()) { deps.add(namedComponent.getName()); } return deps; } else { for (Warehouse provider : providers) { Iterable<Name<?>> deps = provider.listDependencies(name); if (!Iterables.isEmpty(deps)) { return deps; } } return Collections.emptySet(); } }
private void satisfyBoms(Deque<BuildingBox<?>> dependencies) { for (BuildingBox<?> buildingBox = dependencies.pollFirst(); buildingBox != null; buildingBox = dependencies.pollFirst()) { if (buildingBox.engine.getBillOfMaterial().getQueries().isEmpty()) { buildingBox.satisfiedBOM = new SatisfiedBOM(buildingBox.engine.getBillOfMaterial(), ImmutableMultimap.<Query<?>, NamedComponent<?>>of()); } else { ImmutableMultimap.Builder<Query<?>, NamedComponent<?>> materials = ImmutableListMultimap.builder(); for (Query<?> key : buildingBox.engine.getBillOfMaterial().getQueries()) { Collection<Name<?>> names = buildingBox.names.get(key); Set<NamedComponent<?>> components = Sets.newTreeSet(NAMED_COMPONENT_COMPARATOR); for (Name<?> name : names) { uncheckedAddIfPresent(components, buildAndStore(getDependencyBuildingBox(buildingBox.deps, name))); } materials.putAll(key, components); } buildingBox.satisfiedBOM = new SatisfiedBOM(buildingBox.engine.getBillOfMaterial(), materials.build()); } } }
public <T> Optional<NamedComponent<T>> getOne(Factory.Query<T> key) { Iterator<NamedComponent<T>> components = get(key).iterator(); if (!components.hasNext()) { return Optional.absent(); } NamedComponent<T> component = components.next(); if (components.hasNext()) { throw new IllegalStateException(String.format( "more than one component is available for %s." + " Please select which one you want with a more specific query." + " Available components are: %s", key, materials.get(key))); } return Optional.of(component); }
@Override protected FactoryMachine doNewComponent(SatisfiedBOM satisfiedBOM) { final RestxConfig config = satisfiedBOM.getOneAsComponent(restxConfigQuery).get(); return new FactoryMachine() { @Override
@Override protected FactoryMachine doNewComponent(SatisfiedBOM satisfiedBOM) { FactoryMachine factoryMachine = alternatives.get(satisfiedBOM.getOne(query).get().getComponent()); if (factoryMachine != null) { return factoryMachine; } else { return NoopFactoryMachine.INSTANCE; } }
@Override public ComponentBox<SpecRecorderRoute> newComponent(SatisfiedBOM satisfiedBOM) { Optional<NamedComponent<RestxSpecRecorder.Repository>> recorder = satisfiedBOM.getOne(recordedSpecRepo); if (!recorder.isPresent()) { return new EmptyBox<>(RECORDER_ROUTE_NAME); } return BoundlessComponentBox.FACTORY.of(new NamedComponent<>(RECORDER_ROUTE_NAME, new SpecRecorderRoute(recorder.get().getComponent(), satisfiedBOM.getOneAsComponent(storageSettings).get(), satisfiedBOM.getOneAsComponent(securityManager).get(), satisfiedBOM.getOneAsComponent(permissionFactory).get() ))); }
@Override protected RestxRouting doNewComponent(SatisfiedBOM satisfiedBOM) { Collection<RestxRoute> r = Lists.newArrayList(); for (RestxRouter router : satisfiedBOM.getAsComponents(routers)) { r.addAll(router.getRoutes()); } Iterables.addAll(r, satisfiedBOM.getAsComponents(routes)); return new RestxRouting( ImmutableList.copyOf(satisfiedBOM.get(filters)), ImmutableList.copyOf(satisfiedBOM.get(routeFilters)), ImmutableList.copyOf(r)); } });
for (NamedComponent<ConfigSupplier> supplier : satisfiedBOM.get(configSupplierQuery)) { addAll(elements, supplier.getComponent().get().elements()); for (NamedComponent<String> s : satisfiedBOM.get(stringsQuery)) { Optional<ConfigElement> element = config.getElement(s.getName().getName()); if (element.isPresent() && element.get().getValue().equals(s.getComponent())) {
@Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; }
@Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; }
@Override @SuppressWarnings("unchecked") protected T doNewComponent(SatisfiedBOM satisfiedBOM) { return (T) new StdJongoCollection(satisfiedBOM.getOne(jongoQuery).get().getComponent(), name.getName()); }
@Override @SuppressWarnings("unchecked") protected T doNewComponent(SatisfiedBOM satisfiedBOM) { return (T) new StdJongoCollection(satisfiedBOM.getOne(jongoQuery).get().getComponent(), name.getName()); }
@Override public ComponentBox<AdminPage> newComponent(SatisfiedBOM satisfiedBOM) { AppSettings settings = satisfiedBOM.getOne(appSettings).get().getComponent(); if (!RestxContext.Modes.RECORDING.equals(settings.mode())) { return new EmptyBox<>(ADMIN_PAGE_NAME); } return BoundlessComponentBox.FACTORY.of(new NamedComponent<>(ADMIN_PAGE_NAME, new AdminPage("/@/ui/recorder/", "Recorder"))); } }
@Override public ComponentBox<AdminPage> newComponent(SatisfiedBOM satisfiedBOM) { AppSettings settings = satisfiedBOM.getOne(appSettings).get().getComponent(); if (!RestxContext.Modes.RECORDING.equals(settings.mode())) { return new EmptyBox<>(ADMIN_PAGE_NAME); } return BoundlessComponentBox.FACTORY.of(new NamedComponent<>(ADMIN_PAGE_NAME, new AdminPage("/@/ui/recorder/", "Recorder"))); } }