raducotescu commented on a change in pull request #13:
URL:
https://github.com/apache/sling-org-apache-sling-scripting-core/pull/13#discussion_r802461016
##########
File path:
src/main/java/org/apache/sling/scripting/core/impl/bundled/AbstractBundledRenderUnit.java
##########
@@ -101,83 +95,37 @@ public BundleContext getBundleContext() {
return scriptExtension;
}
+ @Override
+ public @NotNull ServiceCache getServiceCache() {
+ return serviceCache;
+ }
+
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T getService(@NotNull String className) {
- LOG.debug("Attempting to load class {} as an OSGi service.",
className);
- T result = (this.services == null ? null : (T)
this.services.get(className));
- if (result == null) {
- final ServiceReference<?> ref =
this.bundleContext.getServiceReference(className);
- if (ref != null) {
- result = (T) this.bundleContext.getService(ref);
- if (result != null) {
- if (this.services == null) {
- this.services = new HashMap<>();
- }
- if (this.references == null) {
- this.references = new ArrayList<>();
- }
- this.references.add(ref);
- this.services.put(className, result);
- return result;
- }
- }
+ try {
+ ClassLoader bundleClassloader =
getBundle().adapt(BundleWiring.class).getClassLoader();
+ return (T)
serviceCache.getService(bundleClassloader.loadClass(className));
+ } catch (ClassNotFoundException e) {
Review comment:
In HTL we always made sure that the object to load was accessible to the
classloader with which the script was loaded. This was not necessarily the case
for JSPs, but for bundled scripts they worked like that from the beginning -
see
https://github.com/apache/sling-org-apache-sling-scripting-spi/blob/47949fedc62380822961d8ef649130dee68a28e8/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnit.java#L83.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]