You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/01/18 15:13:16 UTC

git commit: DELTASPIKE-45 example usage of AnnotatedTypeBuilder

Updated Branches:
  refs/heads/master 427a51860 -> 2cf5e35fa


DELTASPIKE-45 example usage of AnnotatedTypeBuilder


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

Branch: refs/heads/master
Commit: 2cf5e35fa1d8b5feaec3adf4f79638965fdef3f4
Parents: 427a518
Author: gpetracek <gp...@apache.org>
Authored: Wed Jan 18 15:05:09 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Wed Jan 18 15:05:09 2012 +0100

----------------------------------------------------------------------
 .../example/echo/DefaultEchoService.java           |    3 +-
 .../NamingConventionAwareMetadataFilter.java       |   55 +++++++++++++++
 .../services/javax.enterprise.inject.spi.Extension |   20 +++++
 3 files changed, 77 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/2cf5e35f/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
index e0f4887..f111723 100644
--- 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
@@ -25,7 +25,8 @@ import javax.inject.Named;
  * Default implementation
  */
 @Dependent
-@Named("defaultEchoService")
+@Named("DefaultEchoService")
+//will be changed to defaultEchoService by org.apache.deltaspike.example.metadata.NamingConventionAwareMetadataFilter
 public class DefaultEchoService implements EchoService
 {
     /**

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/2cf5e35f/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
new file mode 100644
index 0000000..444d830
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/java/org/apache/deltaspike/example/metadata/NamingConventionAwareMetadataFilter.java
@@ -0,0 +1,55 @@
+/*
+ * 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.metadata;
+
+import org.apache.deltaspike.core.api.literal.NamedLiteral;
+import org.apache.deltaspike.core.api.metadata.builder.AnnotatedTypeBuilder;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.inject.Named;
+
+/**
+ * Just a test filter to show the basic functionality provided by {@link AnnotatedTypeBuilder}
+ */
+public class NamingConventionAwareMetadataFilter implements Extension
+{
+    public void ensureNamingConvention(@Observes ProcessAnnotatedType processAnnotatedType)
+    {
+        Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass();
+
+        Named namedAnnotation = beanClass.getAnnotation(Named.class);
+        if(namedAnnotation != null &&
+                namedAnnotation.value().length() > 0 &&
+                Character.isUpperCase(namedAnnotation.value().charAt(0)))
+        {
+            AnnotatedTypeBuilder builder = new AnnotatedTypeBuilder();
+            builder.readFromType(beanClass);
+            
+            String beanName = namedAnnotation.value();
+            String newBeanName = beanName.substring(0, 1).toLowerCase() + beanName.substring(1);
+            
+            builder.removeFromClass(Named.class)
+                   .addToClass(new NamedLiteral(newBeanName));
+
+            processAnnotatedType.setAnnotatedType(builder.create());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/2cf5e35f/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..ea3d1f7
--- /dev/null
+++ b/deltaspike/examples/jse-owb-examples/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1,20 @@
+#####################################################################################
+# 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.
+#####################################################################################
+
+org.apache.deltaspike.example.metadata.NamingConventionAwareMetadataFilter
\ No newline at end of file