You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2019/08/24 01:08:04 UTC

[GitHub] [sling-org-apache-sling-models-impl] paul-bjorkstrand commented on a change in pull request #14: SLING-8655 - Updated dependency on API, provided Externalized Path In…

paul-bjorkstrand commented on a change in pull request #14: SLING-8655 - Updated dependency on API, provided Externalized Path In…
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/14#discussion_r317337946
 
 

 ##########
 File path: src/main/java/org/apache/sling/models/impl/injectors/ExternalizedPathInjector.java
 ##########
 @@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.models.impl.injectors;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.models.annotations.ExternalizePath;
+import org.apache.sling.models.annotations.injectorspecific.ExternalizedPathProvider;
+import org.apache.sling.models.spi.DisposalCallbackRegistry;
+import org.apache.sling.models.spi.Injector;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+@Component(
+    property=Constants.SERVICE_RANKING+":Integer=1000",
+    service={
+        Injector.class
+    }
+)
+public class ExternalizedPathInjector
+    extends AbstractInjector
+    implements Injector
+{
+    List<ExternalizedPathProvider> providerList = new ArrayList<>();
+
+    @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
+    void bindExternalizedPathProvider(ExternalizedPathProvider provider) {
+        providerList.add(provider);
+        // The providers are sorted so that the one with the highest priority is the first entry
+        Collections.sort(
+            providerList,
+            Comparator.comparingInt(ExternalizedPathProvider::getPriority).reversed()
 
 Review comment:
   Instead of sorting based on a new field called `priority`, you should probably use `service.ranking` of the implementations.  Perhaps you want to look at how ModelAdapterFactory uses [ranked services].
   
   [ranked services]: https://github.com/apache/sling-org-apache-sling-models-impl/blob/398a382724154eb6bd80bd9d4142f100fee2532c/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L217

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services