@@ -74,34 +74,44 @@ public static <T> T getFromCurrentPath(final PageContext pageContext, final Clas
74
74
}
75
75
76
76
/**
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}
78
78
*
79
79
* @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
82
82
* @throws ClassNotFoundException if the class was not found
83
83
*/
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 );
87
88
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
- }
94
89
injector .pushContextProvider (contextProviderFrom (pageContext ));
95
90
96
91
final ModelProvider modelProvider = injector .getInstance (ModelProvider .class );
97
92
98
93
try {
99
- return modelProvider .get (type , request .getResource ()). getClass () ;
94
+ return modelProvider .get (type , request .getResource ());
100
95
} finally {
101
96
injector .popContextProvider ();
102
97
}
103
98
}
104
99
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
+
105
115
/**
106
116
* A helper method that returns a model of the Sling resource related to given request
107
117
*
0 commit comments