Example usage for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY

List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY.

Prototype

Class EMPTY_CLASS_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_CLASS_ARRAY.

Click Source Link

Document

An empty immutable Class array.

Usage

From source file:net.sf.beanlib.hibernate3.Hibernate3DtoCopier.java

/**
 * Returns a list of DTO's/*from  w  w  w.j a  va2  s  .c om*/
 * by partially cloning the object graphs of the given collection of Hibernate entity beans,
 * excluding all collection and map properties, and including only those properties
 * with package names that match the application package prefix.
 * <p>
 * The replication is typically recursive in that the object graph of the input object is basically replicated 
 * into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.
 * 
 * @param hibernateBeans given collection of Hibernate Beans.
 * 
 * @see #applicationPackagePrefix
 */
public List<?> hibernate2dto(Collection<?> hibernateBeans) {
    if (hibernateBeans == null)
        return null;

    List<Object> list = new ArrayList<Object>(hibernateBeans.size());

    for (Object entityBean : hibernateBeans) {
        Object to = copy(entityBean, ArrayUtils.EMPTY_CLASS_ARRAY);
        list.add(to);
    }
    return list;
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

/**
 * Loads the classes with the given full-qualified names using the provided {@link ClassLoader}.<br/>
 * This method is the inverse of {@link #getNamesFromClasses(Class[])}.
 * <p/>//  w w  w . j a  v  a  2  s.com
 * Note that unknown parameter types i.e., {@code "null"} are handled gracefully. Instead of throwing an exception,
 * they are resolved to {@code null} instead. This allows the caller to predict the type e.g., by comparing them
 * with method or constructor signatures.
 * 
 * @param names the names of the classes to load
 * @param classLoader the class loader to use
 * @return a non-null array of the classes loaded
 * @throws ClassNotFoundException if a class cannot be located by the specified class loader
 */
public static Class<?>[] getClassesFromNames(String[] names, ClassLoader classLoader)
        throws ClassNotFoundException {
    if (ArrayUtils.isEmpty(names)) {
        return ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    Class<?>[] classes = new Class<?>[names.length];
    for (int i = 0; i < names.length; i++) {
        if (names[i] == null) {
            // If there is no name, skip the determination and assume that the caller is able to predict it
            classes[i] = null;
        } else if (isPrimitive(names[i])) {
            classes[i] = getPrimitiveType(names[i]);
        } else {
            classes[i] = Class.forName(names[i], true, classLoader);
        }
    }
    return classes;
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

public static Class<?>[] getClassesFromObjects(Object... args) {
    if (ArrayUtils.isEmpty(args)) {
        return ArrayUtils.EMPTY_CLASS_ARRAY;
    }/*  w w  w  .j  a  va2  s.  co m*/
    // At least one parameter was null
    Class<?>[] paramTypes = new Class<?>[args.length];
    for (int i = 0; i < args.length; i++) {
        paramTypes[i] = args[i] != null ? args[i].getClass() : null;
    }
    return paramTypes;
}

From source file:com.google.gdt.eclipse.designer.model.widgets.support.GwtState.java

/**
 * When we use images, browser requests images in background, so we should wait until all (local)
 * images are loaded before making screen shot. Note: waits no more than 500ms.
 */// www. ja v a 2 s .c  om
private void waitForImages() throws Exception {
    // System.out.println("*** start IMAGE wait");
    long startWait = System.currentTimeMillis();
    while (true) {
        boolean complete = m_hostModeSupport.invokeNativeBoolean("__waitForImages",
                ArrayUtils.EMPTY_CLASS_ARRAY, ArrayUtils.EMPTY_OBJECT_ARRAY);
        if (complete) {
            break;
        }
        // do not wait more than 500ms
        if (System.currentTimeMillis() - startWait > 500) {
            break;
        }
        // wait more
        runMessagesLoop();
    }
    // System.out.println("*** waiting for IMAGE done in " + (System.currentTimeMillis() - startWait) + "ms");
}

From source file:com.google.gdt.eclipse.designer.model.widgets.support.GwtState.java

/**
 * Disposes top level GWT <code>Window</code> class.
 *//*from  w ww  .j a  v a 2s.  c  om*/
private void disposeWindowClass() throws Exception {
    if (!m_initialized) {
        return;
    }
    // outstanding dispatch events spawned just after the browser shell is disposed.
    // the workaround is to call onClosed event handler before disposing and...
    Class<?> classOfWindow = m_uiObjectUtils.getClassOfWindow();
    ReflectionUtils.invokeMethod(classOfWindow, "onClosed()");
    // prevent fire again
    // < 1.6 way
    {
        // used Vector class prior to 1.4 and ArrayList class for 1.4,
        // so use reflection to invoke 'clear()'
        Field closingListenersField = ReflectionUtils.getFieldByName(classOfWindow, "closingListeners");
        if (closingListenersField != null) {
            Object closingListeners = ReflectionUtils.getFieldObject(classOfWindow, "closingListeners");
            // ...clear listeners
            ReflectionUtils.invokeMethod(closingListeners, "clear()");
        }
    }
    // 1.6 way: disable listeners fire
    {
        Field handlersInitedField = ReflectionUtils.getFieldByName(classOfWindow, "closeHandlersInitialized");
        if (handlersInitedField != null) {
            ReflectionUtils.setField(classOfWindow, "closeHandlersInitialized", false);
        }
    }
    // remove window listeners to prevent events firing when the editor closed
    m_hostModeSupport.invokeNativeVoid("__wbp_cleanupEvents", ArrayUtils.EMPTY_CLASS_ARRAY,
            ArrayUtils.EMPTY_OBJECT_ARRAY);
}

From source file:net.sourceforge.seqware.webservice.resources.tables.FileChildWorkflowRunsResource.java

/**
 * Use SQL to directly retrieve relevant workflows runs (defined as any workflow runs that 
 * include one or more files in the set we were given)
 * @param files/*  w  w  w  .  j a  v a  2s. c  om*/
 * @param interestingWorkflows
 * @return
 * @throws SQLException 
 */
protected static WorkflowRunList2 directRetrieveWorkflowRuns(List<Integer> files,
        List<Integer> interestingWorkflows) throws SQLException {
    final Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
    final WorkflowRunList2 runs = new WorkflowRunList2();
    runs.setList(new ArrayList());
    if (files.size() > 0) {

        ResultSet rs = null;
        MetadataDB mdb = null;
        try {
            WorkflowRunService ss = BeanFactory.getWorkflowRunServiceBean();
            StringBuilder query = new StringBuilder();
            query.append("select distinct r.sw_accession from workflow_run r, workflow w, ");
            query.append("workflow_run_input_files rf, file f WHERE r.workflow_run_id = rf.workflow_run_id "
                    + "AND rf.file_id = f.file_id " + "AND w.workflow_id = r.workflow_id " + "AND (");
            // handle file accessions
            for (int i = 0; i < files.size() - 1; i++) {
                Integer fInt = files.get(i);
                query.append(" f.sw_accession = ").append(fInt).append(" OR");
            }
            Integer fInt = files.get(files.size() - 1);
            query.append(" f.sw_accession = ").append(fInt).append(")");
            // handle interesting workflow accessions
            if (interestingWorkflows.size() > 0) {
                query.append(" AND (");
                for (int i = 0; i < interestingWorkflows.size() - 1; i++) {
                    Integer wInt = interestingWorkflows.get(i);
                    query.append(" w.sw_accession = ").append(wInt).append(" OR");
                }
                Integer wInt = interestingWorkflows.get(interestingWorkflows.size() - 1);
                query.append(" w.sw_accession = ").append(wInt).append(")");
            }

            query.append(" ORDER BY sw_accession");

            Log.info("Executing query: " + query);
            mdb = DBAccess.get();

            List<Integer> workflowSWIDs = mdb.executeQuery(query.toString(),
                    new ResultSetHandler<List<Integer>>() {
                        @Override
                        public List<Integer> handle(ResultSet rs) throws SQLException {
                            List<Integer> ids = new ArrayList<>();
                            while (rs.next()) {
                                ids.add(rs.getInt("sw_accession"));
                            }
                            return ids;
                        }
                    });

            for (int workflowSWID : workflowSWIDs) {
                WorkflowRun workflowRun = (WorkflowRun) testIfNull(ss.findBySWAccession(workflowSWID));
                CollectionPropertyName<WorkflowRun>[] createCollectionPropertyNames = CollectionPropertyName
                        .createCollectionPropertyNames(WorkflowRun.class,
                                new String[] { "inputFileAccessions" });
                WorkflowRun dto = copier.hibernate2dto(WorkflowRun.class, workflowRun,
                        ArrayUtils.EMPTY_CLASS_ARRAY, createCollectionPropertyNames);
                runs.add(dto);
            }
        } finally {
            if (mdb != null) {
                DbUtils.closeQuietly(mdb.getDb(), mdb.getSql(), rs);
            }
            DBAccess.close();
        }
    }
    return runs;
}

From source file:net.sourceforge.seqware.webservice.resources.tables.WorkflowRunIDResource.java

/**
 * <p>getXml.</p>//from   ww w .  ja v a 2  s .c o m
 */
@Get
public void getXml() {
    authenticate();
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
    JaxbObject<WorkflowRun> jaxbTool = new JaxbObject<>();
    WorkflowRunService ss = BeanFactory.getWorkflowRunServiceBean();

    WorkflowRun workflowRun = getWorkflowRun(ss);
    // specify that we want the input file set to be copied along, if this works, we should clean up the manual copying below
    CollectionPropertyName<WorkflowRun>[] createCollectionPropertyNames = CollectionPropertyName
            .createCollectionPropertyNames(WorkflowRun.class, new String[] { "inputFileAccessions" });
    WorkflowRun dto = copier.hibernate2dto(WorkflowRun.class, workflowRun, ArrayUtils.EMPTY_CLASS_ARRAY,
            createCollectionPropertyNames);
    //Log.debug("getXML() Workflow run contains " + workflowRun.getInputFileAccessions().size()  + " input files");
    //dto.setInputFileAccessions(workflowRun.getInputFileAccessions());

    if (fields.contains("lanes")) {

        SortedSet<Lane> lanes = workflowRun.getLanes();
        if (lanes != null) {
            SortedSet<Lane> copiedLanes = new TreeSet<>();
            for (Lane lane : lanes) {
                copiedLanes.add(copier.hibernate2dto(Lane.class, lane));
            }
            dto.setLanes(copiedLanes);
        } else {
            Log.info("Could not be found: lanes");
        }
    }

    if (fields.contains("ius")) {
        SortedSet<IUS> iuses = workflowRun.getIus();
        if (iuses != null) {
            SortedSet<IUS> copiedIUS = new TreeSet<>();
            for (IUS i : iuses) {
                copiedIUS.add(copier.hibernate2dto(IUS.class, i));
            }
            dto.setIus(copiedIUS);
        } else {
            Log.info("Could not be found: ius");
        }
    }

    if (fields.contains("processes")) {
        SortedSet<Processing> procs = workflowRun.getProcessings();
        if (procs != null) {
            SortedSet<Processing> copiedPs = new TreeSet<>();
            for (Processing p : procs) {
                copiedPs.add(copier.hibernate2dto(Processing.class, p));
            }
            dto.setProcessings(copiedPs);
        } else {
            Log.info("Could not be found: processings");
        }
        procs = workflowRun.getOffspringProcessings();
        if (procs != null) {
            SortedSet<Processing> copiedPs = new TreeSet<>();
            for (Processing p : procs) {
                copiedPs.add(copier.hibernate2dto(Processing.class, p));
            }
            dto.setOffspringProcessings(copiedPs);
        } else {
            Log.info("Could not be found: offspring processings");
        }
    }
    if (fields.contains("attributes")) {
        Set<WorkflowRunAttribute> wras = workflowRun.getWorkflowRunAttributes();
        if (wras != null && !wras.isEmpty()) {
            Set<WorkflowRunAttribute> newwras = new TreeSet<>();
            for (WorkflowRunAttribute wra : wras) {
                newwras.add(copier.hibernate2dto(WorkflowRunAttribute.class, wra));
            }
            dto.setWorkflowRunAttributes(newwras);
        }
    }

    Document line = XmlTools.marshalToDocument(jaxbTool, dto);
    getResponse().setEntity(XmlTools.getRepresentation(line));

}

From source file:org.apache.velocity.runtime.parser.node.ASTMethod.java

/**
 *  invokes the method.  Returns null if a problem, the
 *  actual return if the method returns something, or
 *  an empty string "" if the method returns void
 * @param o/*from ww w.ja va  2s .  co  m*/
 * @param context
 * @return Result or null.
 * @throws MethodInvocationException
 */
public Object execute(Object o, InternalContextAdapter context) throws MethodInvocationException {
    /*
     *  new strategy (strategery!) for introspection. Since we want
     *  to be thread- as well as context-safe, we *must* do it now,
     *  at execution time.  There can be no in-node caching,
     *  but if we are careful, we can do it in the context.
     */
    Object[] params = new Object[paramCount];

    /*
     * sadly, we do need recalc the values of the args, as this can
     * change from visit to visit
     */
    final Class[] paramClasses = paramCount > 0 ? new Class[paramCount] : ArrayUtils.EMPTY_CLASS_ARRAY;

    for (int j = 0; j < paramCount; j++) {
        params[j] = jjtGetChild(j + 1).value(context);
        if (params[j] != null) {
            paramClasses[j] = params[j].getClass();
        }
    }

    VelMethod method = ClassUtils.getMethod(methodName, params, paramClasses, o, context, this, strictRef);
    if (method == null)
        return null;

    try {
        /*
         *  get the returned object.  It may be null, and that is
         *  valid for something declared with a void return type.
         *  Since the caller is expecting something to be returned,
         *  as long as things are peachy, we can return an empty
         *  String so ASTReference() correctly figures out that
         *  all is well.
         */

        Object obj = method.invoke(o, params);

        if (obj == null) {
            if (method.getReturnType() == Void.TYPE) {
                return "";
            }
        }

        return obj;
    } catch (InvocationTargetException ite) {
        return handleInvocationException(o, context, ite.getTargetException());
    }

    /** Can also be thrown by method invocation **/
    catch (IllegalArgumentException t) {
        return handleInvocationException(o, context, t);
    }

    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "ASTMethod.execute() : exception invoking method '" + methodName + "' in " + o.getClass();
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:org.apache.velocity.test.MethodCacheKeyTestCase.java

public void testMethodKeyCacheEquals() {
    Class[] elements1 = new Class[] { Object.class };
    ASTMethod.MethodCacheKey mck1 = new ASTMethod.MethodCacheKey("test", elements1);

    selfEqualsAssertions(mck1);/*  w  w  w. j av  a  2 s.  c  o m*/

    Class[] elements2 = new Class[] { Object.class };
    ASTMethod.MethodCacheKey mck2 = new ASTMethod.MethodCacheKey("test", elements2);

    assertTrue(mck1.equals(mck2));

    Class[] elements3 = new Class[] { String.class };
    ASTMethod.MethodCacheKey mck3 = new ASTMethod.MethodCacheKey("test", elements3);

    assertFalse(mck1.equals(mck3));

    Class[] elements4 = new Class[] { Object.class };
    ASTMethod.MethodCacheKey mck4 = new ASTMethod.MethodCacheKey("boo", elements4);

    assertFalse(mck1.equals(mck4));

    /** check for potential NPE's **/
    Class[] elements5 = ArrayUtils.EMPTY_CLASS_ARRAY;
    ASTMethod.MethodCacheKey mck5 = new ASTMethod.MethodCacheKey("boo", elements5);
    selfEqualsAssertions(mck5);

    Class[] elements6 = null;
    ASTMethod.MethodCacheKey mck6 = new ASTMethod.MethodCacheKey("boo", elements6);
    selfEqualsAssertions(mck6);

    Class[] elements7 = new Class[] {};
    ASTMethod.MethodCacheKey mck7 = new ASTMethod.MethodCacheKey("boo", elements7);
    selfEqualsAssertions(mck7);

    Class[] elements8 = new Class[] { null };
    ASTMethod.MethodCacheKey mck8 = new ASTMethod.MethodCacheKey("boo", elements8);
    selfEqualsAssertions(mck8);

    Class[] elements9 = new Class[] { Object.class };
    ASTMethod.MethodCacheKey mck9 = new ASTMethod.MethodCacheKey("boo", elements9);
    selfEqualsAssertions(mck9);

}

From source file:org.brushingbits.jnap.struts2.interceptor.RestWorkflowInterceptor.java

/**
 * @param invocation/*from w  w w. j a  v  a  2 s .  c  om*/
 * @param action
 */
protected String findResultName(ActionInvocation invocation, Object action) {
    String resultName = Action.INPUT;
    try {
        Map<String, Object> session = ActionContext.getContext().getSession();
        Method method = action.getClass().getMethod(invocation.getProxy().getMethod(),
                ArrayUtils.EMPTY_CLASS_ARRAY);
        if (action instanceof ValidationWorkflowAware) {
            resultName = ((ValidationWorkflowAware) action).getInputResultName();
        } else if (method.isAnnotationPresent(InputConfig.class)) {
            InputConfig annotation = method.getAnnotation(InputConfig.class);
            if (StringUtils.isNotBlank(annotation.methodName())) {
                Method inputMethod = action.getClass().getMethod(annotation.methodName());
                resultName = (String) inputMethod.invoke(action);
            } else {
                resultName = annotation.resultName();
            }
        } else if (session.containsKey(InputResultInterceptor.INPUT_RESULT_NAME)) {
            resultName = (String) session.get(InputResultInterceptor.INPUT_RESULT_NAME);
        }
    } catch (Exception e) {
        ReflectionUtils.handleReflectionException(e);
    }
    return resultName;
}