summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-web-runtime/src/main
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 07:24:10 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 07:24:10 +0000
commite27636b1c565137aa605466614c6fbb7590da257 (patch)
tree4391b153988738c0654aeaa1c22b86a59f448688 /java/sca/modules/implementation-web-runtime/src/main
parent3e2bf547eb6ef513e6ab9a8279b52b9760f79942 (diff)
Add start of a helper class to simplify using the implementation.web ComponentContext
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@748046 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-web-runtime/src/main')
-rw-r--r--java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java
new file mode 100644
index 0000000000..9d904a0986
--- /dev/null
+++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java
@@ -0,0 +1,45 @@
+/*
+ * 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.sca.implementation.web.runtime.utils;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.oasisopen.sca.ComponentContext;
+import org.oasisopen.sca.ServiceReference;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+public class ContextHelper {
+
+ public static final String COMPONENT_ATTR = "org.apache.tuscany.sca.implementation.web.RuntimeComponent";
+
+ public static ComponentContext getComponentContext(ServletContext sc) {
+ RuntimeComponent rc = (RuntimeComponent)sc.getAttribute(COMPONENT_ATTR);
+ return rc.getComponentContext();
+ }
+
+ public static <T> T getReference(String name, Class<T> type, ServletContext sc) {
+ ServiceReference<T> sr = getComponentContext(sc).getServiceReference(type, name);
+ if (sr == null) {
+ throw new ServiceRuntimeException("Reference '" + name + "' undefined");
+ }
+ return sr.getService();
+ }
+}