Android Open Source - roboject Service Registry






From Project

Back to project page roboject.

License

The source code is released under:

Apache License

If you think the Android project roboject listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
/* w  ww . ja va  2  s.c om*/
This file is part of Roboject

Copyright (c) 2010-2011 akquinet A.G.

Contact:  http://www.akquinet.de/en

Licensed 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 de.akquinet.android.roboject;

import android.util.Log;

import java.util.HashMap;
import java.util.Map;

public class ServiceRegistry {
    private static final String TAG = ServiceRegistry.class.getSimpleName();
    private static Map<Class, Object> registry = new HashMap<Class, Object>();

    public static <T> void registerService(Class<T> interfaceClass, Object implementation) {
        if (registry.get(interfaceClass) != null)
            Log.w(TAG, "An implementation for service " + interfaceClass.toString() + " is already registered.");
        registry.put(interfaceClass, implementation);
    }

    public static <T> void registerService(Class<T> interfaceClass, Class<? extends T> implementationClass) {
        if (registry.get(interfaceClass) != null)
            Log.w(TAG, "An implementation for service " + interfaceClass.toString() + " is already registered.");
        registry.put(interfaceClass, implementationClass);
    }

    @SuppressWarnings("unchecked")
    public static <T> T getService(Class<T> interfaceClass) {
        Object implementation = registry.get(interfaceClass);
        if (implementation == null)
            return null;
        else if (implementation instanceof Class<?>) {
            Class<T> implementationClass = (Class<T>) implementation;
            try {
                return implementationClass.newInstance();
            } catch (Exception e) {
                throw new RuntimeException("Unable to create instance of " + implementationClass.toString(), e);
            }
        } else
            return (T) implementation;
    }
}




Java Source Code List

de.akquinet.android.roboject.RobojectActivity.java
de.akquinet.android.roboject.RobojectException.java
de.akquinet.android.roboject.RobojectFragmentActivity.java
de.akquinet.android.roboject.RobojectFragment.java
de.akquinet.android.roboject.RobojectSupportFragment.java
de.akquinet.android.roboject.Roboject.java
de.akquinet.android.roboject.ServiceRegistry.java
de.akquinet.android.roboject.ServicesConnector.java
de.akquinet.android.roboject.annotations.InjectExtra.java
de.akquinet.android.roboject.annotations.InjectLayout.java
de.akquinet.android.roboject.annotations.InjectObject.java
de.akquinet.android.roboject.annotations.InjectResource.java
de.akquinet.android.roboject.annotations.InjectService.java
de.akquinet.android.roboject.annotations.InjectView.java
de.akquinet.android.roboject.injectors.ClassInjector.java
de.akquinet.android.roboject.injectors.ExtraInjector.java
de.akquinet.android.roboject.injectors.FieldInjector.java
de.akquinet.android.roboject.injectors.Injector.java
de.akquinet.android.roboject.injectors.LayoutInjector.java
de.akquinet.android.roboject.injectors.ResourceInjector.java
de.akquinet.android.roboject.injectors.ServiceInjector.java
de.akquinet.android.roboject.injectors.ViewInjector.java
de.akquinet.android.roboject.tutorial.activities.AdderActivity.java
de.akquinet.android.roboject.tutorial.activities.RobojectAdderActivity.java
de.akquinet.android.roboject.tutorial.services.TestService.java
de.akquinet.android.roboject.util.AndroidUtil.java
de.akquinet.android.roboject.util.IntentRegistry.java
de.akquinet.android.roboject.util.ReflectionUtil.java
de.akquinet.android.robojecttest.InjectLayoutTest.java
de.akquinet.android.robojecttest.InjectLocalServiceFragmentTest.java
de.akquinet.android.robojecttest.InjectLocalServiceSupportFragmentTest.java
de.akquinet.android.robojecttest.InjectLocalServiceViaClassTest.java
de.akquinet.android.robojecttest.InjectLocalServiceViaObjectTest.java
de.akquinet.android.robojecttest.InjectRemoteServiceFragmentTest.java
de.akquinet.android.robojecttest.InjectRemoteServiceSupportFragmentTest.java
de.akquinet.android.robojecttest.InjectRemoteServiceTest.java
de.akquinet.android.robojecttest.InjectResourceCustomTest.java
de.akquinet.android.robojecttest.InjectResourceFragmentTest.java
de.akquinet.android.robojecttest.InjectResourceSupportFragmentTest.java
de.akquinet.android.robojecttest.InjectResourceTest.java
de.akquinet.android.robojecttest.InjectServiceFragmentTest.java
de.akquinet.android.robojecttest.InjectServiceSupportFragmentTest.java
de.akquinet.android.robojecttest.InjectServiceTest.java
de.akquinet.android.robojecttest.InjectViewCustomTest.java
de.akquinet.android.robojecttest.InjectViewFragmentActivityTest.java
de.akquinet.android.robojecttest.InjectViewFragmentTest.java
de.akquinet.android.robojecttest.InjectViewSupportFragmentTest.java
de.akquinet.android.robojecttest.InjectViewTest.java
de.akquinet.android.robojecttest.activities.DummyFragmentActivity.java
de.akquinet.android.robojecttest.activities.DummySupportFragmentActivity.java
de.akquinet.android.robojecttest.activities.InjectLayoutTestActivity.java
de.akquinet.android.robojecttest.activities.InjectLocalServiceViaClassTestActivity.java
de.akquinet.android.robojecttest.activities.InjectLocalServiceViaObjectTestActivity.java
de.akquinet.android.robojecttest.activities.InjectRemoteServiceTestActivity.java
de.akquinet.android.robojecttest.activities.InjectResourceTestActivity.java
de.akquinet.android.robojecttest.activities.InjectServiceTestActivity.java
de.akquinet.android.robojecttest.activities.InjectViewTestActivity.java
de.akquinet.android.robojecttest.activities.InjectViewTestFragmentActivity.java
de.akquinet.android.robojecttest.fragments.InjectNonAndroidServiceTestFragment.java
de.akquinet.android.robojecttest.fragments.InjectNonAndroidServiceTestSupportFragment.java
de.akquinet.android.robojecttest.fragments.InjectRemoteServiceTestFragment.java
de.akquinet.android.robojecttest.fragments.InjectRemoteServiceTestSupportFragment.java
de.akquinet.android.robojecttest.fragments.InjectResourceTestFragment.java
de.akquinet.android.robojecttest.fragments.InjectResourceTestSupportFragment.java
de.akquinet.android.robojecttest.fragments.InjectServiceTestFragment.java
de.akquinet.android.robojecttest.fragments.InjectServiceTestSupportFragment.java
de.akquinet.android.robojecttest.fragments.InjectViewTestFragment.java
de.akquinet.android.robojecttest.fragments.InjectViewTestSupportFragment.java
de.akquinet.android.robojecttest.services.AdderFragmentImplementation.java
de.akquinet.android.robojecttest.services.AdderImplementation.java
de.akquinet.android.robojecttest.services.AdderInterface.java
de.akquinet.android.robojecttest.services.AdderSupportFragmentImplementation.java
de.akquinet.android.robojecttest.services.RemoteTestService.java
de.akquinet.android.robojecttest.services.TestService.java