Java Code Examples for org.apache.commons.beanutils.MethodUtils#invokeExactMethod()

The following examples show how to use org.apache.commons.beanutils.MethodUtils#invokeExactMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleConfiguration.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * This method is deprecated and won't do anything if the database repository file paths are null or empty.
 *
 * We use reflection here to avoid having to reference PersistenceService directly since it may or may not be on
 * our classpath depending on whether or not KSB is in use.
 */
@Deprecated
protected void loadOjbRepositoryFiles() {
    String persistenceServiceOjbName = "persistenceServiceOjb";
    if (getDatabaseRepositoryFilePaths() != null) {
        for (String repositoryLocation : getDatabaseRepositoryFilePaths()) {
            // Need the OJB persistence service because it is the only one ever using the database repository files
            if (getPersistenceService() == null) {
                setPersistenceService(GlobalResourceLoader.getService(persistenceServiceOjbName));
            }
            if (persistenceService == null) {
                setPersistenceService(applicationContext.getBean(persistenceServiceOjbName));
            }
            LOG.warn("Loading OJB Configuration in "
                    + getNamespaceCode()
                    + " module.  OJB is deprecated as of Rice 2.4: "
                    + repositoryLocation);
            try {
                MethodUtils.invokeExactMethod(persistenceService, "loadRepositoryDescriptor", repositoryLocation);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

}
 
Example 2
Source File: TopicRule.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void end(final String namespace, final String name) throws Exception {
    Element subsection = getDigester().pop();
    String description = extractNodeContent(subsection);

    MethodUtils.invokeExactMethod(getDigester().peek(), "setValue", description);
}
 
Example 3
Source File: SetRootRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = child.getClass();
    }
    
    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
    
    }
}
 
Example 4
Source File: SetNextRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = child.getClass();
    }
    
    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(parent, methodName,
            new Object[]{ child }, paramTypes);
    
    }
}
 
Example 5
Source File: AnnotationUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes an annotation method.
 *
 * @param annotationn the annotation has to be introspected.
 * @param method the method name to execute.
 * @return the annotation method value, null if any error occurs.
 */
private static Object invokeAnnotationMethod(Annotation annotation, String method) {
    try {
        return MethodUtils.invokeExactMethod(annotation, method, null);
    } catch (Throwable t) {
        return null;
    }
}
 
Example 6
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Calls the objects destroy method is it exists.
 */
private static void destroy(Object o) throws IllegalAccessException, InvocationTargetException {
    if (o == null) return;
    log.info("Destroying " + o + "...");
    try {
        log.info("Check if there is a destroy method...");
        MethodUtils.invokeExactMethod(o, "destroy", (Object[])null);
        log.info("destroy method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No destroy method...");
    }
}
 
Example 7
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Creates the FileSystemHandler and set all its properties.
 * Will also call the init method if it exists.
 */
private static FileSystemHandler getFileSystemHandler(Properties p, String fileSystemHandlerName) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
    String clazz = p.getProperty(fileSystemHandlerName);
    log.info("Building FileSystemHandler: " + clazz);
    Class<? extends FileSystemHandler> fshClass = Class.forName(clazz).asSubclass(FileSystemHandler.class);
    FileSystemHandler fsh = fshClass.newInstance();

    Enumeration<String> propertyNames = (Enumeration<String>) p.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String fullProperty = propertyNames.nextElement();
        if (fullProperty.startsWith(fileSystemHandlerName + ".")) {
            String property = fullProperty.substring(fullProperty.indexOf(".")+1);
            log.info("Setting property: " + property);
            BeanUtils.setProperty(fsh, property, p.getProperty(fullProperty));
        }
    }

    try {
        log.info("Check if there is a init method...");
        MethodUtils.invokeExactMethod(fsh, "init", (Object[])null);
        log.info("init method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No init method...");
    }
    log.info("Done with FileSystemHandler: " + clazz);
    return fsh;
}
 
Example 8
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Calls the objects destroy method is it exists.
 */
private static void destroy(Object o) throws IllegalAccessException, InvocationTargetException {
    if (o == null) return;
    log.info("Destroying " + o + "...");
    try {
        log.info("Check if there is a destroy method...");
        MethodUtils.invokeExactMethod(o, "destroy", (Object[])null);
        log.info("destroy method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No destroy method...");
    }
}
 
Example 9
Source File: StorageConverter.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Creates the FileSystemHandler and set all its properties.
 * Will also call the init method if it exists.
 */
private static FileSystemHandler getFileSystemHandler(Properties p, String fileSystemHandlerName) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
    String clazz = p.getProperty(fileSystemHandlerName);
    log.info("Building FileSystemHandler: " + clazz);
    Class<? extends FileSystemHandler> fshClass = Class.forName(clazz).asSubclass(FileSystemHandler.class);
    FileSystemHandler fsh = fshClass.newInstance();

    Enumeration<String> propertyNames = (Enumeration<String>) p.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String fullProperty = propertyNames.nextElement();
        if (fullProperty.startsWith(fileSystemHandlerName + ".")) {
            String property = fullProperty.substring(fullProperty.indexOf(".")+1);
            log.info("Setting property: " + property);
            BeanUtils.setProperty(fsh, property, p.getProperty(fullProperty));
        }
    }

    try {
        log.info("Check if there is a init method...");
        MethodUtils.invokeExactMethod(fsh, "init", (Object[])null);
        log.info("init method invoked...");
    } catch (NoSuchMethodException e) {
        log.info("No init method...");
    }
    log.info("Done with FileSystemHandler: " + clazz);
    return fsh;
}
 
Example 10
Source File: SetTopRule.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Process the end of this element.
 */
@Override
public void end() throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    Class<?> paramTypes[] = new Class<?>[1];
    if (paramType != null) {
        paramTypes[0] =
                digester.getClassLoader().loadClass(paramType);
    } else {
        paramTypes[0] = parent.getClass();
    }

    if (useExactMatch) {
    
        MethodUtils.invokeExactMethod(child, methodName,
            new Object[]{ parent }, paramTypes);
            
    } else {
    
        MethodUtils.invokeMethod(child, methodName,
            new Object[]{ parent }, paramTypes);
    
    }
}