incubator-deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-41 example usage of BeanProvider#getContextualReferences
Date Sat, 31 Dec 2011 12:13:27 GMT
Updated Branches:
  refs/heads/master 592060d08 -> 6e32b883d


DELTASPIKE-41 example usage of BeanProvider#getContextualReferences


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/6e32b883
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/6e32b883
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/6e32b883

Branch: refs/heads/master
Commit: 6e32b883df7911aa566994c13e8f86714e89b30a
Parents: 592060d
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Dec 30 13:09:38 2011 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Dec 30 13:09:38 2011 +0100

----------------------------------------------------------------------
 deltaspike/examples/jse-owb-examples/pom.xml       |   82 +++++++++++++++
 .../apache/deltaspike/example/CdiContainer.java    |   47 ++++++++
 .../beanmanagement/SimpleBeanLookupExample.java    |   61 +++++++++++
 .../example/echo/DefaultEchoService.java           |   37 +++++++
 .../deltaspike/example/echo/EchoService.java       |   32 ++++++
 .../example/echo/ToLowerCaseEchoService.java       |   37 +++++++
 .../example/echo/ToUpperCaseEchoService.java       |   37 +++++++
 .../src/main/resources/META-INF/beans.xml          |   23 ++++
 deltaspike/examples/pom.xml                        |   42 ++++++++
 deltaspike/pom.xml                                 |    1 +
 10 files changed, 399 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/pom.xml b/deltaspike/examples/jse-owb-examples/pom.xml
new file mode 100644
index 0000000..54f69e4
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!--
+    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.
+-->
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.deltaspike.examples</groupId>
+        <artifactId>jse-examples-project</artifactId>
+        <version>0.1-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.deltaspike.examples</groupId>
+    <artifactId>deltaspike-jse-owb-example</artifactId>
+
+    <name>DeltaSpike Java-SE/OpenWebBeans Examples</name>
+
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-spi</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.core</groupId>
+            <artifactId>core-api</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.deltaspike.core</groupId>
+            <artifactId>core-impl</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+    </dependencies>
+</project>
+

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/CdiContainer.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/CdiContainer.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/CdiContainer.java
new file mode 100644
index 0000000..7815a27
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/CdiContainer.java
@@ -0,0 +1,47 @@
+/*
+ * 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.example;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContainerLifecycle;
+
+/**
+ * Helper class to start and stop the OpenWebBeansContainer
+ */
+public class CdiContainer
+{
+    private static ContainerLifecycle lifecycle = null;
+
+    /**
+     * Bootstraps the CDI container
+     */
+    public static void start()
+    {
+        lifecycle = WebBeansContext.currentInstance().getService(ContainerLifecycle.class);
+        lifecycle.startApplication(null);
+    }
+
+    /**
+     * Shutdown of the CDI container
+     */
+    public static void stop()
+    {
+        lifecycle.stopApplication(null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/beanmanagement/SimpleBeanLookupExample.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/beanmanagement/SimpleBeanLookupExample.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/beanmanagement/SimpleBeanLookupExample.java
new file mode 100644
index 0000000..76df4b1
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/beanmanagement/SimpleBeanLookupExample.java
@@ -0,0 +1,61 @@
+/*
+ * 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.example.beanmanagement;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.example.CdiContainer;
+import org.apache.deltaspike.example.echo.EchoService;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Example which illustrates the usage of {@inheritDoc BeanProvider}
+ */
+public class SimpleBeanLookupExample
+{
+    private static final Logger LOG = Logger.getLogger(SimpleBeanLookupExample.class.getName());
+
+    /**
+     * Entry point
+     * @param args currently not used
+     */
+    public static void main(String[] args)
+    {
+        CdiContainer.start();
+
+        List<EchoService> echoServiceList = BeanProvider.getContextualReferences(EchoService.class,
false, true);
+
+        for(EchoService echoService : echoServiceList)
+        {
+            LOG.info(echoService.echo("Hello CDI beans!"));
+        }
+
+        LOG.info("---");
+
+        echoServiceList = BeanProvider.getContextualReferences(EchoService.class, false,
false);
+
+        for(EchoService echoService : echoServiceList)
+        {
+            LOG.info(echoService.echo("Hello non dependent CDI scoped beans!"));
+        }
+
+        CdiContainer.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/DefaultEchoService.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/DefaultEchoService.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/DefaultEchoService.java
new file mode 100644
index 0000000..d722a1d
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/DefaultEchoService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.example.echo;
+
+import javax.enterprise.context.Dependent;
+
+/**
+ * Default implementation
+ */
+@Dependent
+public class DefaultEchoService implements EchoService
+{
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String echo(String message)
+    {
+        return message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/EchoService.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/EchoService.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/EchoService.java
new file mode 100644
index 0000000..0a86ab9
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/EchoService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.example.echo;
+
+/**
+ * Interface for the different kinds of echo-services
+ */
+public interface EchoService
+{
+    /**
+     * Returns the given text again - the format might change
+     * @param message given message
+     * @return message text
+     */
+    String echo(String message);
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToLowerCaseEchoService.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToLowerCaseEchoService.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToLowerCaseEchoService.java
new file mode 100644
index 0000000..2d123ad
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToLowerCaseEchoService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.example.echo;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Implementation of {@link EchoService} which returns the given text in lower-case format
+ */
+@ApplicationScoped
+public class ToLowerCaseEchoService implements EchoService
+{
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String echo(String message)
+    {
+        return message.toLowerCase();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToUpperCaseEchoService.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToUpperCaseEchoService.java
b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToUpperCaseEchoService.java
new file mode 100644
index 0000000..b9a20b7
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/echo/ToUpperCaseEchoService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.example.echo;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Implementation of {@link EchoService} which returns the given text in upper-case format
+ */
+@ApplicationScoped
+public class ToUpperCaseEchoService implements EchoService
+{
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String echo(String message)
+    {
+        return message.toUpperCase();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/beans.xml b/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..4070730
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/examples/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/pom.xml b/deltaspike/examples/pom.xml
new file mode 100644
index 0000000..d794be0
--- /dev/null
+++ b/deltaspike/examples/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!--
+    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.
+-->
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.deltaspike</groupId>
+        <artifactId>parent</artifactId>
+        <version>0.1-SNAPSHOT</version>
+        <relativePath>../parent/pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.deltaspike.examples</groupId>
+    <artifactId>jse-examples-project</artifactId>
+    <packaging>pom</packaging>
+
+    <name>DeltaSpike Examples</name>
+
+    <modules>
+        <!-- TODO include again - just excluded to discuss further details-->
+        <!--module>jse-owb-examples</module-->
+    </modules>
+
+</project>
+

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/6e32b883/deltaspike/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/pom.xml b/deltaspike/pom.xml
index 4547e42..eb5748f 100644
--- a/deltaspike/pom.xml
+++ b/deltaspike/pom.xml
@@ -57,6 +57,7 @@
         <module>checkstyle-rules</module>
         <module>parent</module>
         <module>core</module>
+        <module>examples</module>
     </modules>
 
 </project>


Mime
View raw message