You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ra...@apache.org on 2015/06/02 00:40:50 UTC
deltaspike git commit: DELTASPIKE-905 OSGi support for Proxy Module
Repository: deltaspike
Updated Branches:
refs/heads/master 087bb799a -> 54d37558c
DELTASPIKE-905 OSGi support for Proxy Module
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/54d37558
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/54d37558
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/54d37558
Branch: refs/heads/master
Commit: 54d37558cab1ad731b68fbee7152436829a9f32c
Parents: 087bb79
Author: Harald Wellmann <ha...@gmx.de>
Authored: Mon Jun 1 23:04:54 2015 +0200
Committer: Harald Wellmann <ha...@gmx.de>
Committed: Mon Jun 1 23:04:54 2015 +0200
----------------------------------------------------------------------
deltaspike/modules/proxy/api/pom.xml | 24 +++++++
.../proxy/api/DeltaSpikeProxyFactory.java | 13 +---
.../proxy/api/ProxyClassGeneratorLookup.java | 68 ++++++++++++++++++++
.../OSGI-INF/ProxyClassGeneratorLookup.xml | 24 +++++++
deltaspike/modules/proxy/impl-asm5/pom.xml | 23 ++++++-
.../OSGI-INF/AsmProxyClassGenerator.xml | 25 +++++++
6 files changed, 165 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/api/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/pom.xml b/deltaspike/modules/proxy/api/pom.xml
index c54224a..e4eac51 100644
--- a/deltaspike/modules/proxy/api/pom.xml
+++ b/deltaspike/modules/proxy/api/pom.xml
@@ -27,9 +27,19 @@
</parent>
<artifactId>deltaspike-proxy-module-api</artifactId>
+ <packaging>bundle</packaging>
<name>Apache DeltaSpike Proxy-Module API</name>
+ <properties>
+ <deltaspike.osgi.export.pkg>
+ org.apache.deltaspike.proxy.*
+ </deltaspike.osgi.export.pkg>
+ <deltaspike.osgi.import>
+ *
+ </deltaspike.osgi.import>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
@@ -37,4 +47,18 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Service-Component>OSGI-INF/*</Service-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
index a0fb274..6232d9b 100644
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
@@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.List;
import javax.interceptor.InterceptorBinding;
import org.apache.deltaspike.core.util.ClassUtils;
-import org.apache.deltaspike.core.util.ServiceUtils;
import org.apache.deltaspike.proxy.spi.ProxyClassGenerator;
public abstract class DeltaSpikeProxyFactory
@@ -76,17 +75,9 @@ public abstract class DeltaSpikeProxyFactory
}
}
- List<ProxyClassGenerator> proxyClassGeneratorList =
- ServiceUtils.loadServiceImplementations(ProxyClassGenerator.class);
+ ProxyClassGenerator proxyClassGenerator = ProxyClassGeneratorLookup.lookupService();
- if (proxyClassGeneratorList.size() != 1)
- {
- throw new IllegalStateException(proxyClassGeneratorList.size()
- + " implementations of " + ProxyClassGenerator.class.getName()
- + " found. It's just allowed to use one implementation.");
- }
-
- proxyClass = proxyClassGeneratorList.iterator().next().generateProxyClass(classLoader,
+ proxyClass = proxyClassGenerator.generateProxyClass(classLoader,
targetClass,
delegateInvocationHandlerClass,
getProxyClassSuffix(),
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/ProxyClassGeneratorLookup.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/ProxyClassGeneratorLookup.java b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/ProxyClassGeneratorLookup.java
new file mode 100644
index 0000000..38d44de
--- /dev/null
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/ProxyClassGeneratorLookup.java
@@ -0,0 +1,68 @@
+/*
+ * 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.deltaspike.proxy.api;
+
+import java.util.List;
+
+import org.apache.deltaspike.core.util.ServiceUtils;
+import org.apache.deltaspike.proxy.spi.ProxyClassGenerator;
+
+/**
+ * Looks up a {@link ProxyClassGenerator} via Java SE ServiceLoader or via Declarative Services
+ * injection when running under OSGi.
+ */
+public class ProxyClassGeneratorLookup
+{
+
+ private static ProxyClassGenerator generator;
+
+ /**
+ * Looks up a unique service implementation.
+ *
+ * @return ProxyClassGenerator service
+ */
+ public static ProxyClassGenerator lookupService()
+ {
+ if (generator == null)
+ {
+ List<ProxyClassGenerator> proxyClassGeneratorList = ServiceUtils
+ .loadServiceImplementations(ProxyClassGenerator.class);
+
+ if (proxyClassGeneratorList.size() != 1)
+ {
+ throw new IllegalStateException(proxyClassGeneratorList.size()
+ + " implementations of " + ProxyClassGenerator.class.getName()
+ + " found. Expected exactly one implementation.");
+ }
+ generator = proxyClassGeneratorList.get(0);
+ }
+ return generator;
+ }
+
+ /**
+ * Setter invoked by OSGi Service Component Runtime
+ *
+ * @param generator
+ * generator service
+ */
+ public void setGenerator(ProxyClassGenerator generator)
+ {
+ ProxyClassGeneratorLookup.generator = generator;
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/api/src/main/resources/OSGI-INF/ProxyClassGeneratorLookup.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/resources/OSGI-INF/ProxyClassGeneratorLookup.xml b/deltaspike/modules/proxy/api/src/main/resources/OSGI-INF/ProxyClassGeneratorLookup.xml
new file mode 100644
index 0000000..8437882
--- /dev/null
+++ b/deltaspike/modules/proxy/api/src/main/resources/OSGI-INF/ProxyClassGeneratorLookup.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="ProxyClassGeneratorLookup">
+ <implementation class="org.apache.deltaspike.proxy.api.ProxyClassGeneratorLookup"/>
+ <reference bind="setGenerator" cardinality="1..1" interface="org.apache.deltaspike.proxy.spi.ProxyClassGenerator"
+ name="ProxyClassGenerator" policy="static" unbind="setGenerator"/>
+</scr:component>
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/impl-asm5/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/impl-asm5/pom.xml b/deltaspike/modules/proxy/impl-asm5/pom.xml
index 2fb7059..5f73700 100644
--- a/deltaspike/modules/proxy/impl-asm5/pom.xml
+++ b/deltaspike/modules/proxy/impl-asm5/pom.xml
@@ -27,10 +27,22 @@
</parent>
<artifactId>deltaspike-proxy-module-impl-asm5</artifactId>
+ <packaging>bundle</packaging>
<name>Apache DeltaSpike Proxy-Module Impl ASM5</name>
- <build>
+ <properties>
+ <deltaspike.osgi.export.pkg>
+ org.apache.deltaspike.proxy.impl.*
+ </deltaspike.osgi.export.pkg>
+ <deltaspike.osgi.import>
+ *
+ </deltaspike.osgi.import>
+ </properties>
+
+
+
+ <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -63,6 +75,15 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Service-Component>OSGI-INF/*</Service-Component>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/54d37558/deltaspike/modules/proxy/impl-asm5/src/main/resources/OSGI-INF/AsmProxyClassGenerator.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/impl-asm5/src/main/resources/OSGI-INF/AsmProxyClassGenerator.xml b/deltaspike/modules/proxy/impl-asm5/src/main/resources/OSGI-INF/AsmProxyClassGenerator.xml
new file mode 100644
index 0000000..5ba78be
--- /dev/null
+++ b/deltaspike/modules/proxy/impl-asm5/src/main/resources/OSGI-INF/AsmProxyClassGenerator.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="AsmProxyClassGenerator">
+ <implementation class="org.apache.deltaspike.proxy.impl.AsmProxyClassGenerator"/>
+ <service>
+ <provide interface="org.apache.deltaspike.proxy.spi.ProxyClassGenerator"/>
+ </service>
+</scr:component>