/** * Provides an instance from the application. * * @param clazz the type's class. * @param <T> the type to return, using `app.injector.instanceOf` * @return an instance of type T. */ protected <T> T instanceOf(Class<T> clazz) { return app.injector().instanceOf(clazz); }
/** * Provides an instance from the application. * * @param clazz the type's class. * @param <T> the type to return, using `app.injector.instanceOf` * @return an instance of type T. */ protected <T> T instanceOf(Class<T> clazz) { return app.injector().instanceOf(clazz); }
@SuppressWarnings(value = "unchecked") private static Result invokeHandler(play.api.mvc.Handler handler, Request requestBuilder, long timeout) { if (handler instanceof play.api.mvc.Action) { play.api.mvc.Action action = (play.api.mvc.Action) handler; return wrapScalaResult(action.apply(requestBuilder._underlyingRequest()), timeout); } else if (handler instanceof JavaHandler) { return invokeHandler( ((JavaHandler) handler).withComponents(Play.application().injector().instanceOf(JavaHandlerComponents.class)), requestBuilder, timeout ); } else { throw new RuntimeException("This is not a JavaAction and can't be invoked this way."); } }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
private static MessagesApi getMessagesApi() { return play.Play.application().injector().instanceOf(MessagesApi.class); }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * @return the messages for the current lang */ public Messages messages() { return Play.application().injector().instanceOf(MessagesApi.class).preferred(request()); }
IoCApplication(final Map<ApplicationLoader, Application> values, final Map<String, String> routing) { this.delegates = new ArrayList<>(values.values()); this.injector = new IoCInjector( values.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().injector(), (a, b) -> { throw new IllegalStateException("Conflicting keys for " + a + "/" + b); }, LinkedHashMap::new)), routing); this.scalaRef = delegates.iterator().next().asScala(); this.java = new DefaultApplication(this, injector.asJava()); playxIntegration(); }
/** * Get the JPA api for the current play application. */ public static JPAApi jpaApi() { Application app = Play.application(); if (app == null) { throw new RuntimeException("No application running"); } return app.injector().instanceOf(JPAApi.class); }