Example usage for java.lang.reflect Method isAccessible

List of usage examples for java.lang.reflect Method isAccessible

Introduction

In this page you can find the example usage for java.lang.reflect Method isAccessible.

Prototype

@Deprecated(since = "9")
public boolean isAccessible() 

Source Link

Document

Get the value of the accessible flag for this reflected object.

Usage

From source file:org.apache.nifi.web.security.spring.LoginIdentityProviderFactoryBean.java

private void performMethodInjection(final LoginIdentityProvider instance,
        final Class loginIdentityProviderClass)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    for (final Method method : loginIdentityProviderClass.getMethods()) {
        if (method.isAnnotationPresent(LoginIdentityProviderContext.class)) {
            // make the method accessible
            final boolean isAccessible = method.isAccessible();
            method.setAccessible(true);//w  w  w. j a v  a  2s. c o m

            try {
                final Class<?>[] argumentTypes = method.getParameterTypes();

                // look for setters (single argument)
                if (argumentTypes.length == 1) {
                    final Class<?> argumentType = argumentTypes[0];

                    // look for well known types
                    if (NiFiProperties.class.isAssignableFrom(argumentType)) {
                        // nifi properties injection
                        method.invoke(instance, properties);
                    }
                }
            } finally {
                method.setAccessible(isAccessible);
            }
        }
    }

    final Class parentClass = loginIdentityProviderClass.getSuperclass();
    if (parentClass != null && LoginIdentityProvider.class.isAssignableFrom(parentClass)) {
        performMethodInjection(instance, parentClass);
    }
}

From source file:com.marmalade.studio.android.gcm.s3eGCMClientBroadcastReceiver.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doNotificationCallback() {

    try {// www.  ja  v  a 2s . c  om

        // Get extension class
        final Class extension_class = Class.forName("s3eGCMClient");

        // Get notification method
        final Method notification_method = extension_class.getMethod("s3eGCMClientNotificationReceived",
                new Class[] {});

        // Access method
        AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws Exception {

                // Set accessible
                if (!notification_method.isAccessible()) {
                    notification_method.setAccessible(true);
                }

                // Invoke
                notification_method.invoke(extension_class.newInstance());

                return null;
            }
        });

    } catch (Exception e) {

        // Do nothing
        // e.printStackTrace();
    }
}

From source file:org.springframework.security.extensions.portlet.PortletSessionContextIntegrationInterceptor.java

private boolean preHandle(PortletRequest request, PortletResponse response, Object handler) throws Exception {

    PortletSession portletSession = null;
    boolean portletSessionExistedAtStartOfRequest = false;

    // see if the portlet session already exists (or should be eagerly created)
    try {//w ww  .  j  a  v a2  s .c om
        portletSession = request.getPortletSession(forceEagerSessionCreation);
    } catch (IllegalStateException ignored) {
    }

    // if there is a session, then see if there is a contextClass to bring in
    if (portletSession != null) {

        // remember that the session already existed
        portletSessionExistedAtStartOfRequest = true;

        // attempt to retrieve the contextClass from the session
        Object contextFromSessionObject = portletSession.getAttribute(SPRING_SECURITY_CONTEXT_KEY,
                portletSessionScope());

        // if we got a contextClass then place it into the holder
        if (contextFromSessionObject != null) {

            // if we are supposed to clone it, then do so
            if (cloneFromPortletSession) {
                Assert.isInstanceOf(Cloneable.class, contextFromSessionObject,
                        "Context must implement Clonable and provide a Object.clone() method");
                try {
                    Method m = contextFromSessionObject.getClass().getMethod("clone", new Class[] {});
                    if (!m.isAccessible()) {
                        m.setAccessible(true);
                    }
                    contextFromSessionObject = m.invoke(contextFromSessionObject, new Object[] {});
                } catch (Exception ex) {
                    ReflectionUtils.handleReflectionException(ex);
                }
            }

            // if what we got is a valid contextClass then place it into the holder, otherwise create a new one
            if (contextFromSessionObject instanceof SecurityContext) {
                if (logger.isDebugEnabled())
                    logger.debug("Obtained from SPRING_SECURITY_CONTEXT a valid SecurityContext and "
                            + "set to SecurityContextHolder: '" + contextFromSessionObject + "'");
                SecurityContextHolder.setContext((SecurityContext) contextFromSessionObject);
            } else {
                if (logger.isWarnEnabled())
                    logger.warn("SPRING_SECURITY_CONTEXT did not contain a SecurityContext but contained: '"
                            + contextFromSessionObject
                            + "'; are you improperly modifying the PortletSession directly "
                            + "(you should always use SecurityContextHolder) or using the PortletSession attribute "
                            + "reserved for this class? - new SecurityContext instance associated with "
                            + "SecurityContextHolder");
                SecurityContextHolder.setContext(generateNewContext());
            }

        } else {

            // there was no contextClass in the session, so create a new contextClass and put it in the holder
            if (logger.isDebugEnabled())
                logger.debug("PortletSession returned null object for SPRING_SECURITY_CONTEXT - new "
                        + "SecurityContext instance associated with SecurityContextHolder");
            SecurityContextHolder.setContext(generateNewContext());
        }

    } else {

        // there was no session, so create a new contextClass and place it in the holder
        if (logger.isDebugEnabled())
            logger.debug("No PortletSession currently exists - new SecurityContext instance "
                    + "associated with SecurityContextHolder");
        SecurityContextHolder.setContext(generateNewContext());

    }

    // place attributes onto the request to remember if the session existed and the hashcode of the contextClass
    request.setAttribute(SESSION_EXISTED, new Boolean(portletSessionExistedAtStartOfRequest));
    request.setAttribute(CONTEXT_HASHCODE, new Integer(SecurityContextHolder.getContext().hashCode()));

    return true;
}

From source file:com.marmalade.studio.android.gcm.s3eGCMClientBroadcastReceiver.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doRegistrationCallback(String reg_id) {

    try {// w w  w  . ja v  a2  s  .  c  o  m

        // Get context
        final Context context = m_Context;

        // Get registration identifier
        final String registration_id = reg_id;

        // Get extension class
        final Class extension_class = Class.forName("s3eGCMClient");

        // Get registration method
        final Method registration_method = extension_class.getMethod("s3eGCMClientRegistrationReceived",
                new Class[] { Context.class, String.class });

        // Access method
        AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws Exception {

                // Set accessible
                if (!registration_method.isAccessible()) {
                    registration_method.setAccessible(true);
                }

                // Invoke
                registration_method.invoke(extension_class.newInstance(), context, registration_id);

                return null;
            }
        });

    } catch (Exception e) {

        // Do nothing
        // e.printStackTrace();

    }
}

From source file:org.acegisecurity.context.HttpSessionContextIntegrationFilter.java

/**
 * Gets the security context from the session (if available) and returns it.
 * <p/>/* ww  w .j  a va  2s.  co m*/
 * If the session is null, the context object is null or the context object stored in the session
 * is not an instance of SecurityContext it will return null.
 * <p/>
 * If <tt>cloneFromHttpSession</tt> is set to true, it will attempt to clone the context object
 * and return the cloned instance.
 *
 * @param httpSession the session obtained from the request.
 */
private SecurityContext readSecurityContextFromSession(HttpSession httpSession) {
    if (httpSession == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("No HttpSession currently exists");
        }

        return null;
    }

    // Session exists, so try to obtain a context from it.

    Object contextFromSessionObject = httpSession.getAttribute(ACEGI_SECURITY_CONTEXT_KEY);

    if (contextFromSessionObject == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("HttpSession returned null object for ACEGI_SECURITY_CONTEXT");
        }

        return null;
    }

    // We now have the security context object from the session.

    // Clone if required (see SEC-356)
    if (cloneFromHttpSession) {
        Assert.isInstanceOf(Cloneable.class, contextFromSessionObject,
                "Context must implement Clonable and provide a Object.clone() method");
        try {
            Method m = contextFromSessionObject.getClass().getMethod("clone", new Class[] {});
            if (!m.isAccessible()) {
                m.setAccessible(true);
            }
            contextFromSessionObject = m.invoke(contextFromSessionObject, new Object[] {});
        } catch (Exception ex) {
            ReflectionUtils.handleReflectionException(ex);
        }
    }

    if (!(contextFromSessionObject instanceof SecurityContext)) {
        if (logger.isWarnEnabled()) {
            logger.warn("ACEGI_SECURITY_CONTEXT did not contain a SecurityContext but contained: '"
                    + contextFromSessionObject + "'; are you improperly modifying the HttpSession directly "
                    + "(you should always use SecurityContextHolder) or using the HttpSession attribute "
                    + "reserved for this class?");
        }

        return null;
    }

    // Everything OK. The only non-null return from this method.

    return (SecurityContext) contextFromSessionObject;
}

From source file:org.jaffa.soa.dataaccess.TransformerUtils.java

static void updateBeanData(String path, GraphDataObject source, UOW uow, ITransformationHandler handler,
        GraphMapping mapping, IPersistent domainObject, DataTransformer.Mode mode, GraphDataObject newGraph)
        throws InstantiationException, IllegalAccessException, InvocationTargetException, ApplicationExceptions,
        FrameworkException {/*from   www. j a v a 2s .co m*/

    try {
        // Call custom validation code in the GraphObject
        // The validate() method may have mandatory-rules bound to it via AOP. Hence do not invoke it during prevalidation
        // No need to invoke it during CLONING/MASS_UPDATE as well, since the source object should be unmodified
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && mode != DataTransformer.Mode.CLONE
                && mode != DataTransformer.Mode.MASS_UPDATE)
            source.validate();

        List<ITransformationHandler> handlers = null;
        if (handler != null) {
            handlers = handler.getTransformationHandlers();
        }

        // Ensure the domain object has not been modified
        domainObjectChangedTest(path, source, mapping, domainObject);

        // Stamp the UOW on the domain object to avoid creation of separate UOWs during foreign-key validations
        if (domainObject.getUOW() == null)
            domainObject.setUOW(uow);

        // Reflect ProcessEventGraphs from newGraph to source - This will handle Pending/Warning Events during a clone/mass update
        if (newGraph != null && newGraph.getProcessEventGraphs() != null)
            source.setProcessEventGraphs(newGraph.getProcessEventGraphs());
        //----------------------------------------------------------------
        // Fire 'startBean' handler
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && handlers != null) {
            for (ITransformationHandler transformationHandler : handlers) {
                transformationHandler.startBean(path, source, domainObject);
            }
        }

        //----------------------------------------------------------------
        // Reflect all normal fields
        for (Iterator it = mapping.getFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            // ignore read-only fields
            if (mapping.isReadOnly(field))
                continue;

            // values from the newGraph take precedence in CLONE/MASS_UPDATE mode
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore dirty-read fields, and no-cloning fields unless a value is passed in the newGraph
                if (field.equals(mapping.getDirtyReadDataFieldName())
                        || (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field))))
                    continue;
                Object value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
                updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field)) {
                    Object value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
                    updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
                }
            } else {
                Object value = getProperty(mapping.getDataFieldDescriptor(field), source);
                if ((!domainObject.isDatabaseOccurence() && value != null) || source.hasChanged(field))
                    updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
            }
        }

        //----------------------------------------------------------------
        // Update flex fields
        if (source instanceof IFlexFields && domainObject instanceof IFlexFields) {
            if (log.isDebugEnabled())
                log.debug("Updating flex fields for " + path);
            FlexBean sFlexBean = ((IFlexFields) source).getFlexBean();
            FlexBean tFlexBean = ((IFlexFields) domainObject).getFlexBean();
            if (sFlexBean != null && tFlexBean != null) {
                for (DynaProperty flexProperty : tFlexBean.getDynaClass().getDynaProperties()) {
                    String name = flexProperty.getName();
                    // values from the newGraph take precedence in CLONE/MASS_UPDATE mode
                    if (mode == DataTransformer.Mode.CLONE) {
                        FlexBean nFlexBean = newGraph != null && newGraph instanceof IFlexFields
                                ? ((IFlexFields) newGraph).getFlexBean()
                                : null;
                        Object value = nFlexBean != null && nFlexBean.hasChanged(name) ? nFlexBean.get(name)
                                : sFlexBean.get(name);
                        if (value != null)
                            tFlexBean.set(name, value);
                    } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                        FlexBean nFlexBean = newGraph != null && newGraph instanceof IFlexFields
                                ? ((IFlexFields) newGraph).getFlexBean()
                                : null;
                        if (nFlexBean != null && nFlexBean.hasChanged(name)) {
                            Object value = nFlexBean.get(name);
                            tFlexBean.set(name, value);
                        }
                    } else {
                        if (sFlexBean.hasChanged(name)) {
                            Object value = sFlexBean.get(name);
                            if (log.isDebugEnabled())
                                log.debug("Update flex field '" + name + '=' + value + "' on object '"
                                        + domainObject.getClass().getName() + '\'');
                            tFlexBean.set(name, value);
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("Flex field '" + name + " has not changed on object "
                                        + source.getClass().getName());
                        }
                    }
                }
            }
        }

        //----------------------------------------------------------------
        // Reflect any foreign keys
        for (Iterator it = mapping.getForeignFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            // ignore read-only fields
            if (mapping.isReadOnly(field))
                continue;

            // It is possible that the foreign object may get resused, and only its fields may have been changed.
            // Hence also invoke the hasChanged() method on the foreign object itself
            Object value = null;
            boolean hasChanged = false;
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore dirty-read fields, and no-cloning fields unless a value is passed in the newGraph
                if (field.equals(mapping.getDirtyReadDataFieldName())
                        || (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field))))
                    continue;
                value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
                hasChanged = value != null;
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field)) {
                    value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
                    hasChanged = true;
                }
            } else {
                value = getProperty(mapping.getDataFieldDescriptor(field), source);
                hasChanged = (!domainObject.isDatabaseOccurence() && value != null) || source.hasChanged(field);
            }
            if (!hasChanged && value != null && value instanceof GraphDataObject)
                hasChanged = ((GraphDataObject) value).hasChanged();
            if (hasChanged) {
                // need to map foreign keys back
                List targetKeys = mapping.getForeignKeys(field);
                GraphMapping fMapping = MappingFactory
                        .getInstance(mapping.getDataFieldDescriptor(field).getPropertyType());
                Set sourceKeys = fMapping.getKeyFields();
                int i = 0;
                for (Iterator i2 = sourceKeys.iterator(); i2.hasNext(); i++) {
                    String sourceFld = (String) i2.next();
                    String targetFld = (String) targetKeys.get(i);
                    if (log.isDebugEnabled())
                        log.debug("Copy Foreign Key Field from " + sourceFld + " to " + targetFld);
                    if (value == null) {
                        // ForeignGraph is null. Null out the foreign-key
                        updateProperty(mapping.getRealDomainFieldDescriptor(targetFld), null, domainObject);
                    } else {
                        // Obtain the key-field from the ForeignGraph
                        Object value2 = getProperty(fMapping.getDataFieldDescriptor(sourceFld), value);

                        // Set the foreign-key, only if the key-field has been flagged as changed in the ForeignGraph.
                        // This will allow the UI to pass in just the modified portion of a composite foreign-key, and thus
                        // ensuring that the un-modified portion doesn't get nulled out
                        // The check is not required while cloning
                        if (mode == DataTransformer.Mode.CLONE || !(value instanceof GraphDataObject)
                                || ((GraphDataObject) value).hasChanged(sourceFld))
                            updateProperty(mapping.getRealDomainFieldDescriptor(targetFld), value2,
                                    domainObject);
                    }
                }

                // Invoke the getter on the domain. An exception will be raised if the foreign-key is invalid
                if (log.isDebugEnabled())
                    log.debug("Performing validation on the domain object for the foreign object "
                            + mapping.getDomainFieldName(field));
                PropertyDescriptor pd = mapping.getDomainFieldDescriptor(field);
                if (pd != null && pd.getReadMethod() != null) {
                    Method m = pd.getReadMethod();
                    if (!m.isAccessible())
                        m.setAccessible(true);
                    m.invoke(domainObject, (Object[]) null);
                }
            }
        }

        //----------------------------------------------------------------
        // Store Record
        if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
            if (log.isDebugEnabled())
                log.debug(
                        "Domain object will not be persisted during prevalidation. Invoking the prevalidateBean handler");
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.prevalidateBean(path, source, domainObject);
                }
            }
        } else if (domainObject.isDatabaseOccurence()) {
            if (log.isDebugEnabled())
                log.debug("UOW.Update Domain Object");
            //----------------------------------------------------------------
            // Fire 'startBeanUpdate' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanUpdate(path, source, domainObject);
                }
            }
            if (domainObject.isModified()) {
                uow.update(domainObject);
                if (handlers != null) {
                    for (ITransformationHandler transformationHandler : handlers) {
                        transformationHandler.setChangeDone(true);
                    }
                }
            }
            //----------------------------------------------------------------
            // Fire 'endBeanUpdate' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanUpdate(path, source, domainObject);
                }
            }
        } else {
            if (handlers != null && mode == DataTransformer.Mode.CLONE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke startBeanClone");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanClone(path, source, domainObject, newGraph);
                }
            } else if (handlers != null && mode == DataTransformer.Mode.MASS_UPDATE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke startBeanMassUpdate");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanMassUpdate(path, source, domainObject, newGraph);
                }
            }
            if (log.isDebugEnabled())
                log.debug("UOW.Add Domain Object");
            //----------------------------------------------------------------
            // Fire 'startBeanAdd' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanAdd(path, source, domainObject);
                }
            }
            uow.add(domainObject);
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.setChangeDone(true);
                }
            }
            //----------------------------------------------------------------
            // Fire 'endBeanAdd' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanAdd(path, source, domainObject);
                }
            }
            if (handlers != null && mode == DataTransformer.Mode.CLONE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke endBeanClone");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanClone(path, source, domainObject, newGraph);
                }
            } else if (handlers != null && mode == DataTransformer.Mode.MASS_UPDATE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke endBeanMassUpdate");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanMassUpdate(path, source, domainObject, newGraph);
                }
            }
        }

        //----------------------------------------------------------------
        // Reflect any related objects
        for (Iterator it = mapping.getRelatedFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            if (mapping.isReadOnly(field))
                continue;
            Object value = null;
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore no-cloning fields unless a value is passed in the newGraph
                if (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field)))
                    continue;
                value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field))
                    value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
            } else
                value = getProperty(mapping.getDataFieldDescriptor(field), source);
            if (value != null) {
                if (value.getClass().isArray()) {
                    // The related field is an array of objects (one-to-many)
                    Object[] values = (Object[]) value;
                    for (int i = 0; i < values.length; i++) {
                        GraphDataObject dao = (GraphDataObject) values[i]; // Assumes its a DAO....what else could it be?
                        if (dao != null) {
                            if (dao.getDeleteObject() != null && dao.getDeleteObject()) {
                                if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
                                    if (log.isDebugEnabled())
                                        log.debug(
                                                "The 'deleteObject' property is true. No prevalidations will be performed for the childBean.");
                                } else {
                                    if (log.isDebugEnabled())
                                        log.debug(
                                                "The 'deleteObject' property is true. Invoking deleteChildBean()");
                                    deleteChildBean(path + '.' + field + '[' + i + ']', dao, uow, handler,
                                            domainObject, mapping, field);
                                }
                            } else {
                                Object newValue = newGraph != null
                                        ? getProperty(mapping.getDataFieldDescriptor(field), newGraph)
                                        : null;
                                GraphDataObject newDao = newValue != null
                                        && ((GraphDataObject[]) newValue).length > i
                                                ? ((GraphDataObject[]) newValue)[i]
                                                : null;
                                updateChildBean(path + '.' + field + '[' + i + ']', dao, uow, handler,
                                        domainObject, mapping, field, mode, newDao);
                            }
                        }
                    }
                } else {
                    // Or a single Object (one-to-one)
                    GraphDataObject dao = (GraphDataObject) value; // Assumes its a DAO....what else could it be?
                    if (dao.getDeleteObject() != null && dao.getDeleteObject()) {
                        if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
                            if (log.isDebugEnabled())
                                log.debug(
                                        "The 'deleteObject' property is true. No prevalidations will be performed for the childBean.");
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("The 'deleteObject' property is true. Invoking deleteChildBean()");
                            deleteChildBean(path + '.' + field, dao, uow, handler, domainObject, mapping,
                                    field);
                        }
                    } else {
                        GraphDataObject newDao = newGraph != null
                                ? (GraphDataObject) getProperty(mapping.getDataFieldDescriptor(field), newGraph)
                                : null;
                        updateChildBean(path + '.' + field, dao, uow, handler, domainObject, mapping, field,
                                mode, newDao);
                    }
                }
            }
        }

        //----------------------------------------------------------------
        // Fire 'endBean' handler
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && handlers != null) {
            for (ITransformationHandler transformationHandler : handlers) {
                transformationHandler.endBean(path, source, domainObject);
            }
        }

    } catch (SkipTransformException e) {
        if (log.isDebugEnabled()) {
            log.debug("Processing of " + path + " will be skipped", e);
        }
    } catch (ApplicationException e) {
        throw new ApplicationExceptions(e);
    }
}

From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java

private Object getValueFromMethods(String path, Class<?> type, Object inst) throws Exception {
    Method[] methods = type.getDeclaredMethods();
    for (Method method : methods) {
        JsonProperty ann = method.getAnnotation(JsonProperty.class);
        if (ann != null) {
            String annName = ann.value();
            if (StringUtils.isBlank(annName)) {
                annName = ann.defaultValue();
            }//from   w  w  w. j a  va2 s. c om
            if (StringUtils.isBlank(annName)) {
                annName = getNameFromMethod(method);
            }
            if (StringUtils.equals(path, annName)) {
                boolean accessible = method.isAccessible();
                if (!accessible) {
                    method.setAccessible(true);
                }
                Object value = method.invoke(inst);
                if (!accessible) {
                    method.setAccessible(false);
                }
                return value;
            }
        }
    }
    return null;
}

From source file:org.apache.nifi.authorization.AuthorizerFactoryBean.java

private void performMethodInjection(final Authorizer instance, final Class authorizerClass)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (final Method method : authorizerClass.getMethods()) {
        if (method.isAnnotationPresent(AuthorizerContext.class)) {
            // make the method accessible
            final boolean isAccessible = method.isAccessible();
            method.setAccessible(true);/*from www  . j a  v a  2  s  .  com*/

            try {
                final Class<?>[] argumentTypes = method.getParameterTypes();

                // look for setters (single argument)
                if (argumentTypes.length == 1) {
                    final Class<?> argumentType = argumentTypes[0];

                    // look for well known types
                    if (NiFiProperties.class.isAssignableFrom(argumentType)) {
                        // nifi properties injection
                        method.invoke(instance, properties);
                    }
                }
            } finally {
                method.setAccessible(isAccessible);
            }
        }
    }

    final Class parentClass = authorizerClass.getSuperclass();
    if (parentClass != null && Authorizer.class.isAssignableFrom(parentClass)) {
        performMethodInjection(instance, parentClass);
    }
}

From source file:org.apache.nifi.authorization.AuthorityProviderFactoryBean.java

private void performMethodInjection(final AuthorityProvider instance, final Class authorityProviderClass)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (final Method method : authorityProviderClass.getMethods()) {
        if (method.isAnnotationPresent(AuthorityProviderContext.class)) {
            // make the method accessible
            final boolean isAccessible = method.isAccessible();
            method.setAccessible(true);/*w  ww . ja v  a 2 s.co m*/

            try {
                final Class<?>[] argumentTypes = method.getParameterTypes();

                // look for setters (single argument)
                if (argumentTypes.length == 1) {
                    final Class<?> argumentType = argumentTypes[0];

                    // look for well known types
                    if (NiFiProperties.class.isAssignableFrom(argumentType)) {
                        // nifi properties injection
                        method.invoke(instance, properties);
                    } else if (ApplicationContext.class.isAssignableFrom(argumentType)) {
                        // spring application context injection
                        method.invoke(instance, applicationContext);
                    }
                }
            } finally {
                method.setAccessible(isAccessible);
            }
        }
    }

    final Class parentClass = authorityProviderClass.getSuperclass();
    if (parentClass != null && AuthorityProvider.class.isAssignableFrom(parentClass)) {
        performMethodInjection(instance, parentClass);
    }
}

From source file:de.codesourcery.eve.skills.util.SpringBeanInjector.java

private void doInjectDependencies(Object obj)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {

    Class<?> currentClasz = obj.getClass();
    do {/*  w w  w.j ava2s.  c  om*/
        // inject fields
        for (Field f : currentClasz.getDeclaredFields()) {

            final int m = f.getModifiers();
            if (Modifier.isStatic(m) || Modifier.isFinal(m)) {
                continue;
            }

            final Resource annot = f.getAnnotation(Resource.class);
            if (annot != null) {
                if (!f.isAccessible()) {
                    f.setAccessible(true);
                }

                if (log.isTraceEnabled()) {
                    log.trace("doInjectDependencies(): Setting field " + f.getName() + " with bean '"
                            + annot.name() + "'");
                }
                f.set(obj, getBean(annot.name()));
            }
        }

        // inject methods
        for (Method method : currentClasz.getDeclaredMethods()) {

            final int m = method.getModifiers();
            if (Modifier.isStatic(m) || Modifier.isAbstract(m)) {
                continue;
            }

            if (method.getParameterTypes().length != 1) {
                continue;
            }

            if (!method.getName().startsWith("set")) {
                continue;
            }

            final Resource annot = method.getAnnotation(Resource.class);
            if (annot != null) {
                if (!method.isAccessible()) {
                    method.setAccessible(true);
                }

                if (log.isTraceEnabled()) {
                    log.trace("doInjectDependencies(): Invoking setter method " + method.getName()
                            + " with bean '" + annot.name() + "'");
                }

                method.invoke(obj, getBean(annot.name()));
            }
        }

        currentClasz = currentClasz.getSuperclass();

    } while (currentClasz != null);
}