You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/02/28 08:19:52 UTC
[isis] branch master updated: ISIS-1841 Internal API: introduce
_Plugin for plugin loading
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 4bb8ca1 ISIS-1841 Internal API: introduce _Plugin for plugin loading
4bb8ca1 is described below
commit 4bb8ca1ca4148a8cb50dfdad765c4813ae51cd94
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Feb 28 09:19:47 2018 +0100
ISIS-1841 Internal API: introduce _Plugin for plugin loading
Utilizes the Java 7+ service-provider loading facility
---
.../isis/applib/internal/collections/_Sets.java | 12 ++++
.../isis/applib/internal/context/_Plugin.java | 67 ++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/collections/_Sets.java b/core/applib/src/main/java/org/apache/isis/applib/internal/collections/_Sets.java
index 194ea33..c8067fc 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/internal/collections/_Sets.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/collections/_Sets.java
@@ -27,10 +27,13 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap.KeySetView;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+import org.apache.isis.applib.internal.base._NullSafe;
+
/**
* <h1>- internal use only -</h1>
* <p>
@@ -64,6 +67,15 @@ public final class _Sets {
return Collections.unmodifiableSet(setPreservingOrder);
}
+ public static <T> Set<T> unmodifiable(Iterable<T> iterable) {
+ if(iterable==null) {
+ return Collections.emptySet();
+ }
+ return Collections.unmodifiableSet(
+ _NullSafe.stream(iterable)
+ .collect(Collectors.toSet()));
+ }
+
// -- HASH SET
public static <T> HashSet<T> newHashSet() {
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/context/_Plugin.java b/core/applib/src/main/java/org/apache/isis/applib/internal/context/_Plugin.java
new file mode 100644
index 0000000..5f9a043
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/context/_Plugin.java
@@ -0,0 +1,67 @@
+/*
+ * 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.isis.applib.internal.context;
+
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.Set;
+
+import org.apache.isis.applib.internal.collections._Sets;
+
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * Utilizes the Java 7+ service-provider loading facility.<br/>
+ * see {@link java.util.ServiceLoader}
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * These may be changed or removed without notice!
+ * </p>
+ * @since 2.0.0
+ */
+public final class _Plugin {
+
+ private _Plugin(){}
+
+ /**
+ * Returns all services implementing the interface or abstract class representing the {@code service}.
+ * <p>
+ * If com.example.impl.StandardCodecs is an implementation of the CodecSet service then its jar file also contains a file named
+ * <pre>
+ * META-INF/services/com.example.CodecSet
+ * </pre>
+ * This file contains the single line:
+ * <pre>
+ * com.example.impl.StandardCodecs # Standard codecs
+ * </pre>
+ * </p>
+ * @param service
+ * @return non null
+ */
+ public static <S> Set<S> load(Class<S> service){
+ Objects.requireNonNull(service);
+
+ ServiceLoader<S> loader = ServiceLoader.load(service, _Context.getDefaultClassLoader());
+
+ return _Sets.unmodifiable(loader);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.