/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces( final Class<?> target, final Class<T> type) { List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
/** * Builds a {@link Set} of interfaces from the target class. */ public static Set<Class<?>> getAllInterfaces(final Class<?> target) { assert target != null; final Set<Class<?>> ret = new HashSet<Class<?>>(); getAllInteralInterfaces(target, ret); return ret; }
/** * Creates the API operation so it can called multiple times. */ public APIOperationRunner(final OperationalContext context) { this.context = context; // get the APIOperation that this class implements.. List<Class<? extends APIOperation>> apiOps = getInterfaces(this.getClass(), APIOperation.class); // there should be only one.. if (apiOps.size() > 1) { throw new IllegalStateException("Must only implement one operation."); } }
/** * Determines the default set of operations that a {@link Connector} * supports. */ public static Set<Class<? extends APIOperation>> getDefaultSupportedOperations( Class<? extends Connector> connector) { // determine all support operations.. Set<Class<? extends APIOperation>> ret; ret = new HashSet<Class<? extends APIOperation>>(); Set<Class<?>> itrfs = ReflectionUtil.getAllInterfaces(connector); for (Class<? extends SPIOperation> spi : allSPIOperations()) { // determine if the SPI is in the set of interfaces if (itrfs.contains(spi)) { // convert the SPI to API.. ret.addAll(spi2apis(spi)); } } //finally add unconditionally supported ops ret.addAll(getUnconditionallySupportedOperations()); return ret; }
private static String[] getBundleNamePrefixes(final Class<? extends Connector> connector) { // figure out the message catalog.. final ConnectorClass configOpts = connector.getAnnotation(ConnectorClass.class); String[] paths = null; if (configOpts != null) { paths = configOpts.messageCatalogPaths(); } if (paths == null || paths.length == 0) { final String pkage = ReflectionUtil.getPackage(connector); final String messageCatalog = pkage + ".Messages"; paths = new String[] { messageCatalog }; } for (int i = 0; i < paths.length; i++) { paths[i] = paths[i].replace('.', '/'); } return paths; }
/** * Logs based on the parameters given. Uses the format parameter inside * {@link MessageFormat}. * * @param level * the logging level at which to write the message. * @param ex * [optional] exception stack trace to log. * @param format * [optional] create a message of a particular format. * @param args * [optional] parameters to the format string. */ public void log(final Level level, final Throwable ex, final String format, final Object... args) { if (isLoggable(level)) { String message = format; if (format != null && args != null) { // consider using thread local pattern to cache these for // performance the pattern will always may always changed. message = MessageFormat.format(format, args); } else if (format == null && ex != null) { message = ex.getLocalizedMessage(); } String methodName = ReflectionUtil.getMethodName(3); log(_clazz, methodName, level, message, ex); } }
/** * Determines the default set of operations that a {@link Connector} * supports. */ public static Set<Class<? extends APIOperation>> getDefaultSupportedOperations( Class<? extends Connector> connector) { // determine all support operations.. Set<Class<? extends APIOperation>> ret; ret = new HashSet<Class<? extends APIOperation>>(); Set<Class<?>> itrfs = ReflectionUtil.getAllInterfaces(connector); for (Class<? extends SPIOperation> spi : allSPIOperations()) { // determine if the SPI is in the set of interfaces if (itrfs.contains(spi)) { // convert the SPI to API.. ret.addAll(spi2apis(spi)); } } // finally add unconditionally supported ops ret.addAll(getUnconditionallySupportedOperations()); return ret; }
private static String[] getBundleNamePrefixes(final Class<? extends Connector> connector) { // figure out the message catalog.. final ConnectorClass configOpts = connector.getAnnotation(ConnectorClass.class); String[] paths = null; if (configOpts != null) { paths = configOpts.messageCatalogPaths(); } if (paths == null || paths.length == 0) { final String pkage = ReflectionUtil.getPackage(connector); final String messageCatalog = pkage + ".Messages"; paths = new String[]{messageCatalog}; } for (int i = 0; i < paths.length; i++) { paths[i] = paths[i].replace('.', '/'); } return paths; }
@Test public void testGetMethodName() { String actual = ReflectionUtil.getMethodName(1); assertEquals(actual, "testGetMethodName"); } }
/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces(final Class<?> target, final Class<T> type) { final List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); final Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") final Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
for (Class<?> c : ReflectionUtil.getAllInterfaces(config)) { if (c.getName().equals(GROOVY_LANG_GROOVY_OBJECT)) {
private static String[] getBundleNamePrefixes(final Class<? extends Connector> connector) { // figure out the message catalog.. final ConnectorClass configOpts = connector.getAnnotation(ConnectorClass.class); String[] paths = null; if (configOpts != null) { paths = configOpts.messageCatalogPaths(); } if (paths == null || paths.length == 0) { final String pkage = ReflectionUtil.getPackage(connector); final String messageCatalog = pkage + ".Messages"; paths = new String[] { messageCatalog }; } for (int i = 0; i < paths.length; i++) { paths[i] = paths[i].replace('.', '/'); } return paths; }
/** * Builds a {@link Set} of interfaces from the target class. */ public static Set<Class<?>> getAllInterfaces(final Class<?> target) { assert target != null; final Set<Class<?>> ret = new HashSet<Class<?>>(); getAllInteralInterfaces(target, ret); return ret; }
/** * Creates the API operation so it can called multiple times. */ public APIOperationRunner(final OperationalContext context) { this.context = context; // get the APIOperation that this class implements.. List<Class<? extends APIOperation>> apiOps = getInterfaces(this.getClass(), APIOperation.class); // there should be only one.. if (apiOps.size() > 1) { throw new IllegalStateException("Must only implement one operation."); } }
/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces(final Class<?> target, final Class<T> type) { final List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); final Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") final Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
for (Class<?> c : ReflectionUtil.getAllInterfaces(config)) { if (c.getName().equals(GROOVY_LANG_GROOVY_OBJECT)) {
private String[] getBundleNamePrefixes(Class<? extends Connector> connector) { // figure out the message catalog.. ConnectorClass configOpts = connector.getAnnotation(ConnectorClass.class); String[] paths = null; if (configOpts != null) { paths = configOpts.messageCatalogPaths(); } if (paths == null || paths.length == 0) { String pkage = ReflectionUtil.getPackage(connector); String messageCatalog = pkage + ".Messages"; paths = new String[] { messageCatalog }; } for (int i = 0; i < paths.length; i++) { paths[i] = "/" + paths[i].replace('.', '/'); } return paths; }
/** * Builds a {@link Set} of interfaces from the target class. */ public static Set<Class<?>> getAllInterfaces(final Class<?> target) { assert target != null; Set<Class<?>> ret = new HashSet<Class<?>>(); getAllInteralInterfaces(target, ret); return ret; }
/** * Creates the API operation so it can called multiple times. */ public APIOperationRunner(final OperationalContext context) { _context = context; // get the APIOperation that this class implements.. List<Class<? extends APIOperation>> apiOps = getInterfaces(this .getClass(), APIOperation.class); // there should be only one.. if (apiOps.size() > 1) { final String MSG = "Must only implement one operation."; throw new IllegalStateException(MSG); } }
@Test public void functional() { // getInterfaces Set<Class<?>> set = getAllInterfaces(C1.class); assertTrue(set.contains(I1.class)); assertTrue(set.contains(I2.class)); assertFalse(set.contains(I3.class)); // containsInterface assertTrue(containsInterface(C1.class, I1.class)); assertTrue(containsInterface(C1.class, I2.class)); assertFalse(containsInterface(C1.class, I3.class)); }