You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2023/12/05 10:26:54 UTC
(sling-org-apache-sling-scripting-sightly) branch master updated: Make sling models really optional. (#25)
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git
The following commit(s) were added to refs/heads/master by this push:
new 015b6e7 Make sling models really optional. (#25)
015b6e7 is described below
commit 015b6e735c92b0daea3b4c851a8ee62d1b26ee74
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Tue Dec 5 11:26:48 2023 +0100
Make sling models really optional. (#25)
---
bnd.bnd | 1 -
.../impl/engine/extension/use/JavaUseProvider.java | 18 +++++++++---------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/bnd.bnd b/bnd.bnd
index c4c672d..4ab1356 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -12,6 +12,5 @@ Import-Package: org.apache.sling.scripting.sightly.compiler.*;resolution:=op
org.apache.sling.commons.compiler.*;resolution:=optional, \\
org.apache.sling.commons.classloader.*;resolution:=optional, \\
org.apache.sling.models.*;resolution:=optional, \\
- org.apache.sling.models.*;resolution:=optional, \\
com.ibm.icu.*;resolution:=optional, \\
*
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
index c1f70cd..5ac8979 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
@@ -80,8 +80,8 @@ public class JavaUseProvider implements UseProvider {
@Reference
private BundledUnitManagerImpl bundledUnitManager;
- @Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY)
- private ModelFactory modelFactory;
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY, service = ModelFactory.class)
+ private Object modelFactory;
@Override
public ProviderOutcome provide(String identifier, RenderContext renderContext, Bindings arguments) {
@@ -169,23 +169,23 @@ public class JavaUseProvider implements UseProvider {
SlingHttpServletRequest request = BindingsUtils.getRequest(globalBindings);
Resource resource = BindingsUtils.getResource(globalBindings);
// Sling Model
- if (modelFactory != null && modelFactory.isModelClass(cls)) {
+ if (modelFactory != null && ((ModelFactory) modelFactory).isModelClass(cls)) {
try {
// Attempt to instantiate via sling models
// first, try to use the provided adaptable
- if (adaptable != null && modelFactory.canCreateFromAdaptable(adaptable, cls)) {
+ if (adaptable != null && ((ModelFactory) modelFactory).canCreateFromAdaptable(adaptable, cls)) {
LOG.debug("Trying to instantiate class {} as Sling Model from provided adaptable.", cls);
- return ProviderOutcome.notNullOrFailure(modelFactory.createModel(adaptable, cls));
+ return ProviderOutcome.notNullOrFailure(((ModelFactory) modelFactory).createModel(adaptable, cls));
}
// then, try to use the request
- if (request != null && modelFactory.canCreateFromAdaptable(request, cls)) {
+ if (request != null && ((ModelFactory) modelFactory).canCreateFromAdaptable(request, cls)) {
LOG.debug("Trying to instantiate class {} as Sling Model from request.", cls);
- return ProviderOutcome.notNullOrFailure(modelFactory.createModel(request, cls));
+ return ProviderOutcome.notNullOrFailure(((ModelFactory) modelFactory).createModel(request, cls));
}
// finally, try to use the resource
- if (resource != null && modelFactory.canCreateFromAdaptable(resource, cls)) {
+ if (resource != null && ((ModelFactory) modelFactory).canCreateFromAdaptable(resource, cls)) {
LOG.debug("Trying to instantiate class {} as Sling Model from resource.", cls);
- return ProviderOutcome.notNullOrFailure(modelFactory.createModel(resource, cls));
+ return ProviderOutcome.notNullOrFailure(((ModelFactory) modelFactory).createModel(resource, cls));
}
return ProviderOutcome.failure(
new IllegalStateException("Could not adapt the given Sling Model from neither request nor resource: " + cls));