You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2009/09/05 15:46:04 UTC
svn commit: r811648 -
/james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java
Author: rdonkin
Date: Sat Sep 5 13:46:03 2009
New Revision: 811648
URL: http://svn.apache.org/viewvc?rev=811648&view=rev
Log:
Apologies for missing this one
Added:
james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java (with props)
Added: james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java?rev=811648&view=auto
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java (added)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java Sat Sep 5 13:46:03 2009
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.james;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.kernel.LoaderService;
+
+public class FakeLoader implements LoaderService {
+ private final Map<String, Object> servicesByName;
+
+ public FakeLoader() {
+ servicesByName = new HashMap<String, Object>();
+ servicesByName.put("org.apache.james.LoaderService", this);
+ }
+
+
+ public Object get(String name) {
+ Object service = servicesByName.get(name);
+ return service;
+ }
+
+ private void injectResources(Object resource) {
+ final Method[] methods = resource.getClass().getMethods();
+ for (Method method : methods) {
+ final Resource resourceAnnotation = method.getAnnotation(Resource.class);
+ if (resourceAnnotation != null) {
+ final String name = resourceAnnotation.name();
+ if (name == null) {
+ // Unsupported
+ } else {
+ // Name indicates a service
+ final Object service = get(name);
+ if (service == null) {
+ } else {
+ try {
+ Object[] args = {service};
+ method.invoke(resource, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Injection failed", e);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Injection failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Injection failed", e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public <T> T load(Class<T> type) {
+ try {
+ final T newInstance = type.newInstance();
+ injectResources(newInstance);
+ return newInstance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Propchange: james/server/trunk/phoenix-deployment/src/test/org/apache/james/FakeLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org