summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/myfaces/src
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-01 23:48:21 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-01 23:48:21 +0000
commit1ee24d7df3cebec4b0ce916e4d445635ade5b4e3 (patch)
treec7090d6f828386f260b6362c5aa59299634df68e /java/sca/modules/myfaces/src
parentc18149566d30f01ce29434bc3f289bd36e396640 (diff)
Start to get JSF webapps going using Apache MyFaces
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@749147 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/myfaces/src')
-rw-r--r--java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationLifecycleProvider.java78
-rw-r--r--java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationProcessor.java55
2 files changed, 133 insertions, 0 deletions
diff --git a/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationLifecycleProvider.java b/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationLifecycleProvider.java
new file mode 100644
index 0000000000..2c470ffda2
--- /dev/null
+++ b/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationLifecycleProvider.java
@@ -0,0 +1,78 @@
+/*
+ * 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.tuscany.myfaces;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.faces.context.ExternalContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletContext;
+
+import org.apache.AnnotationProcessor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.config.annotation.DiscoverableLifecycleProvider;
+import org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+public class TuscanyAnnotationLifecycleProvider extends TomcatAnnotationLifecycleProvider implements DiscoverableLifecycleProvider {
+ private static Log log = LogFactory.getLog(TomcatAnnotationLifecycleProvider.class);
+
+ private TuscanyAnnotationProcessor annotationProcessor;
+ private ExternalContext externalContext;
+ private ServletContext sc;
+
+ public TuscanyAnnotationLifecycleProvider(ExternalContext externalContext) {
+ super(externalContext);
+ this.externalContext = externalContext;
+ this.sc = (ServletContext)externalContext.getContext();
+ AnnotationProcessor ap = (org.apache.AnnotationProcessor)sc.getAttribute(org.apache.AnnotationProcessor.class.getName());
+ annotationProcessor = new TuscanyAnnotationProcessor(ap);
+ }
+
+ public Object newInstance(String className) throws InstantiationException, IllegalAccessException, InvocationTargetException, NamingException, ClassNotFoundException {
+
+ System.out.println("foo newInstance: " + className);
+
+ Class clazz = ClassUtils.classForName(className);
+ log.info("Creating instance of " + className);
+ Object object = clazz.newInstance();
+ annotationProcessor.processAnnotations(object, sc);
+ annotationProcessor.postConstruct(object);
+
+ return object;
+ }
+
+// public boolean isAvailable() {
+// try {
+// ServletContext sc = (ServletContext)externalContext.getContext();
+// AnnotationProcessor ap = (org.apache.AnnotationProcessor)sc.getAttribute(org.apache.AnnotationProcessor.class.getName());
+//
+// annotationProcessor = new TuscanyAnnotationProcessor(ap);
+// sc.setAttribute(org.apache.AnnotationProcessor.class.getName(), annotationProcessor);
+//
+// return super.isAvailable();
+// } catch (Exception e) {
+// // ignore
+// }
+// return false;
+// }
+
+}
diff --git a/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationProcessor.java b/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationProcessor.java
new file mode 100644
index 0000000000..09aaac713a
--- /dev/null
+++ b/java/sca/modules/myfaces/src/main/java/org/apache/tuscany/myfaces/TuscanyAnnotationProcessor.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.tuscany.myfaces;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+import javax.servlet.ServletContext;
+
+import org.apache.AnnotationProcessor;
+import org.apache.tuscany.sca.implementation.web.runtime.utils.ContextHelper;
+
+public class TuscanyAnnotationProcessor implements org.apache.AnnotationProcessor {
+
+ org.apache.AnnotationProcessor annotationProcessor;
+
+ public TuscanyAnnotationProcessor(AnnotationProcessor annotationProcessor) {
+ this.annotationProcessor = annotationProcessor;
+ }
+
+ public void postConstruct(Object arg0) throws IllegalAccessException, InvocationTargetException {
+ annotationProcessor.postConstruct(arg0);
+ }
+
+ public void preDestroy(Object arg0) throws IllegalAccessException, InvocationTargetException {
+ annotationProcessor.preDestroy(arg0);
+ }
+
+ public void processAnnotations(Object arg0, ServletContext servletContext) throws IllegalAccessException, InvocationTargetException, NamingException {
+ System.out.println("foo2 processAnnotations: " + arg0);
+ ContextHelper.inject(arg0, servletContext);
+ annotationProcessor.processAnnotations(arg0);
+ }
+
+ public void processAnnotations(Object arg0) throws IllegalAccessException, InvocationTargetException, NamingException {
+ annotationProcessor.processAnnotations(arg0);
+ }
+}