@@ -74,34 +74,44 @@ public static <T> T getFromCurrentPath(final PageContext pageContext, final Clas
7474 }
7575
7676 /**
77- * A helper method that returns the {@link Class} object, resolving it via it's Canonical Name.
77+ * A helper method that returns the model of {@code type}
7878 *
7979 * @param pageContext allows to access request context
80- * @param type canonical name of the modal object , whose {@link Class} object needs to be returned
81- * @return {@link Class} object pertaining to {@code type} as it's canonical name
80+ * @param type canonical name of the class , whose model object needs to be returned
81+ * @return Model object pertaining to {@code type} as it's canonical name
8282 * @throws ClassNotFoundException if the class was not found
8383 */
84- public static Class <?> getClassFromType (final PageContext pageContext , final String type ) throws ClassNotFoundException {
85- final SlingHttpServletRequest request = SliceTagUtils .slingRequestFrom (pageContext );
86- final InjectorsRepository injectorsRepository = SliceTagUtils .injectorsRepositoryFrom (pageContext );
84+ public static Object getFromCurrentPath (final PageContext pageContext , final String type ,
85+ final String appName ) throws ClassNotFoundException {
86+ final SlingHttpServletRequest request = slingRequestFrom (pageContext );
87+ final InjectorWithContext injector = getInjectorWithContext (pageContext , request , appName );
8788
88- final String injectorName = getInjectorName (request , null , injectorsRepository );
89-
90- final InjectorWithContext injector = injectorsRepository .getInjector (injectorName );
91- if (injector == null ) {
92- throw new IllegalStateException ("Guice injector not found: " + injectorName );
93- }
9489 injector .pushContextProvider (contextProviderFrom (pageContext ));
9590
9691 final ModelProvider modelProvider = injector .getInstance (ModelProvider .class );
9792
9893 try {
99- return modelProvider .get (type , request .getResource ()). getClass () ;
94+ return modelProvider .get (type , request .getResource ());
10095 } finally {
10196 injector .popContextProvider ();
10297 }
10398 }
10499
100+ private static InjectorWithContext getInjectorWithContext (final PageContext pageContext ,
101+ final SlingHttpServletRequest request , final String appName ){
102+ final InjectorsRepository injectorsRepository = injectorsRepositoryFrom (pageContext );
103+
104+ final String injectorName = getInjectorName (request , appName , injectorsRepository );
105+
106+ InjectorWithContext injector = injectorsRepository .getInjector (injectorName );
107+
108+ if (injector == null ) {
109+ throw new IllegalStateException ("Guice injector not found for app: " + appName );
110+ } else {
111+ return injector ;
112+ }
113+ }
114+
105115 /**
106116 * A helper method that returns a model of the Sling resource related to given request
107117 *
0 commit comments