/** * Add a utility to the extension point. This default implementation * stores utilities against the interfaces that they implement. * * @param utility The instance of the utility * * @throws IllegalArgumentException if utility is null */ public void addUtility(Object utility) { addUtility(null, utility); }
/** * Returns the set of interfaces implemented by the given class and its * ancestors or a blank set if none */ private static Set<Class<?>> getAllInterfaces(Class<?> clazz) { Set<Class<?>> implemented = new HashSet<Class<?>>(); getAllInterfaces(clazz, implemented); implemented.remove(LifeCycleListener.class); return implemented; }
/** * Get the utility by the interface that it implements * * @param utilityType The lookup key (utility interface) * @return The instance of the utility * * @throws IllegalArgumentException if utilityType is null */ public <T> T getUtility(Class<T> utilityType) { return getUtility(utilityType, null); }
public void addUtility(Object key, Object utility) { if (utility == null) { throw new IllegalArgumentException("Cannot register null as a Service"); } if (utility instanceof LifeCycleListener) { ((LifeCycleListener)utility).start(); } if (key == null) { Class<?> cls = utility.getClass(); Set<Class<?>> interfaces = getAllInterfaces(cls); for (Class<?> i : interfaces) { utilities.put(i, utility); } if (interfaces.isEmpty() || isConcreteClass(cls)) { utilities.put(cls, utility); } } else { utilities.put(key, utility); } }
if (utilityDeclaration != null) { utilityClass = utilityDeclaration.loadClass(); } else if (isConcreteClass(utilityType)) { utilityClass = utilityType; key = utilityType; addUtility(utility); } else { addUtility(key, utility);
public void addUtility(Object key, Object utility) { if (utility == null) { throw new IllegalArgumentException("Cannot register null as a Service"); } if (utility instanceof LifeCycleListener) { ((LifeCycleListener)utility).start(); } if (key == null) { Class<?> cls = utility.getClass(); Set<Class<?>> interfaces = getAllInterfaces(cls); for (Class<?> i : interfaces) { utilities.put(i, utility); } if (interfaces.isEmpty() || isConcreteClass(cls)) { utilities.put(cls, utility); } } else { utilities.put(key, utility); } }
if (utilityDeclaration != null) { utilityClass = utilityDeclaration.loadClass(); } else if (isConcreteClass(utilityType)) { utilityClass = utilityType; key = utilityType; addUtility(utility); } else { addUtility(key, utility);
/** * Returns the set of interfaces implemented by the given class and its * ancestors or a blank set if none */ private static Set<Class<?>> getAllInterfaces(Class<?> clazz) { Set<Class<?>> implemented = new HashSet<Class<?>>(); getAllInterfaces(clazz, implemented); implemented.remove(LifeCycleListener.class); return implemented; }
/** * Add a utility to the extension point. This default implementation * stores utilities against the interfaces that they implement. * * @param utility The instance of the utility * * @throws IllegalArgumentException if utility is null */ public void addUtility(Object utility) { addUtility(null, utility); }
/** * Get the utility by the interface that it implements * * @param utilityType The lookup key (utility interface) * @return The instance of the utility * * @throws IllegalArgumentException if utilityType is null */ public <T> T getUtility(Class<T> utilityType) { return getUtility(utilityType, null); }
private static void getAllInterfaces(Class<?> clazz, Set<Class<?>> implemented) { Class<?>[] interfaces = clazz.getInterfaces(); for (Class<?> interfaze : interfaces) { if (Modifier.isPublic(interfaze.getModifiers())) { implemented.add(interfaze); } } Class<?> superClass = clazz.getSuperclass(); // Object has no superclass so check for null if (superClass != null && !superClass.equals(Object.class)) { getAllInterfaces(superClass, implemented); } }
private static void getAllInterfaces(Class<?> clazz, Set<Class<?>> implemented) { Class<?>[] interfaces = clazz.getInterfaces(); for (Class<?> interfaze : interfaces) { if (Modifier.isPublic(interfaze.getModifiers())) { implemented.add(interfaze); } } Class<?> superClass = clazz.getSuperclass(); // Object has no superclass so check for null if (superClass != null && !superClass.equals(Object.class)) { getAllInterfaces(superClass, implemented); } }