Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*****************************************************************
 WADE - Workflow and Agent Development Environment is a framework to develop 
 multi-agent systems able to execute tasks defined according to the workflow
 metaphor.
 Copyright (C) 2008 Telecom Italia S.p.A. 
    
 GNU Lesser General Public License
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation, 
 version 2.1 of the License. 
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
    
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA  02111-1307, USA.
 *****************************************************************/

public class Main {
    private static final int ACC_ABSTRACT = 0x0400;
    private static final int ACC_INTERFACE = 0x0200;

    static java.util.Collection createConcreteJavaCollection(Class clazz)
            throws InstantiationException, IllegalAccessException {
        int modifiers = clazz.getModifiers();
        java.util.Collection result = null;
        if ((modifiers & ACC_ABSTRACT) == 0 && (modifiers & ACC_INTERFACE) == 0) {
            // class is concrete, we can instantiate it directly
            result = (java.util.Collection) clazz.newInstance();
        } else {
            // class is either abstract or an interface, we have to somehow choose a concrete collection :-(
            if (java.util.List.class.isAssignableFrom(clazz)) {
                result = new java.util.ArrayList();
            } else if (java.util.Set.class.isAssignableFrom(clazz)) {
                result = new java.util.HashSet();
            }
        }
        return result;
    }
}