Example usage for java.lang Class getConstructors

List of usage examples for java.lang Class getConstructors

Introduction

In this page you can find the example usage for java.lang Class getConstructors.

Prototype

@CallerSensitive
public Constructor<?>[] getConstructors() throws SecurityException 

Source Link

Document

Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object.

Usage

From source file:azkaban.webapp.AzkabanWebServer.java

private UserManager loadUserManager(Props props) {
    Class<?> userManagerClass = props.getClass(USER_MANAGER_CLASS_PARAM, null);
    logger.info("Loading user manager class " + userManagerClass.getName());
    UserManager manager = null;//w  w w .  j  av a  2s. co m
    if (userManagerClass != null && userManagerClass.getConstructors().length > 0) {
        try {
            Constructor<?> userManagerConstructor = userManagerClass.getConstructor(Props.class);
            manager = (UserManager) userManagerConstructor.newInstance(props);
        } catch (Exception e) {
            logger.error("Could not instantiate UserManager " + userManagerClass.getName());
            throw new RuntimeException(e);
        }
    } else {
        manager = new XmlUserManager(props);
    }
    return manager;
}

From source file:com.opensymphony.xwork2.util.finder.ClassFinder.java

public ClassFinder(List<Class> classes) {
    this.classLoaderInterface = null;
    List<Info> infos = new ArrayList<Info>();
    List<Package> packages = new ArrayList<Package>();
    for (Class clazz : classes) {

        Package aPackage = clazz.getPackage();
        if (aPackage != null && !packages.contains(aPackage)) {
            infos.add(new PackageInfo(aPackage));
            packages.add(aPackage);//from ww w.j av a  2s  .  c  o  m
        }

        ClassInfo classInfo = new ClassInfo(clazz);
        infos.add(classInfo);
        classInfos.put(classInfo.getName(), classInfo);
        for (Method method : clazz.getDeclaredMethods()) {
            infos.add(new MethodInfo(classInfo, method));
        }

        for (Constructor constructor : clazz.getConstructors()) {
            infos.add(new MethodInfo(classInfo, constructor));
        }

        for (Field field : clazz.getDeclaredFields()) {
            infos.add(new FieldInfo(classInfo, field));
        }
    }

    for (Info info : infos) {
        for (AnnotationInfo annotation : info.getAnnotations()) {
            List<Info> annotationInfos = getAnnotationInfos(annotation.getName());
            annotationInfos.add(info);
        }
    }
}

From source file:alice.tuprolog.lib.OOLibrary.java

private static Constructor<?> lookupConstructor(Class<?> target, Class<?>[] argClasses, Object[] argValues)
        throws NoSuchMethodException {
    // first try for exact match
    try {// w w  w .j a v a 2 s  . c om
        return target.getConstructor(argClasses);
    } catch (NoSuchMethodException e) {
        if (argClasses.length == 0) { // if no args & no exact match, out of
            // luck
            return null;
        }
    }

    // go the more complicated route
    Constructor<?>[] constructors = target.getConstructors();
    Vector<Constructor<?>> goodConstructors = new Vector<>();
    for (int i = 0; i != constructors.length; i++) {
        if (matchClasses(constructors[i].getParameterTypes(), argClasses))
            goodConstructors.addElement(constructors[i]);
    }
    switch (goodConstructors.size()) {
    case 0:
        // no constructors have been found checking for assignability
        // and (int -> long) conversion. One last chance:
        // looking for compatible methods considering also
        // type conversions:
        // double --> float
        // (the first found is used - no most specific
        // method algorithm is applied )

        for (int i = 0; i != constructors.length; i++) {
            Class<?>[] types = constructors[i].getParameterTypes();
            Object[] val = matchClasses(types, argClasses, argValues);
            if (val != null) {
                // found a method compatible
                // after type conversions
                for (int j = 0; j < types.length; j++) {
                    argClasses[j] = types[j];
                    argValues[j] = val[j];
                }
                return constructors[i];
            }
        }

        return null;
    case 1:
        return goodConstructors.firstElement();
    default:
        return mostSpecificConstructor(goodConstructors);
    }
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;//from  w  ww  .  j a  v  a 2 s  . c om
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java

/** Loads strategy class and creates instance by calling constructor.
    @param strategyText contains full class name followed by
    parameter list for constructor.  Constructor parameters may be
    int, double, boolean, String.  Constructor parameters are parsed by
    splitting on commas and trimming whitespace.
    <pre>//from   ww  w  . ja  v  a  2  s . co  m
    mypkg.MyStrategy(12, -345.67, true, false, Alpha Strategy)
    </pre>
**/
protected TradingStrategy loadStrategy(String strategyText)
        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
        ExceptionInInitializerError, InstantiationException, InvocationTargetException {
    Pattern strategyPattern = // matches full.class.Name(args...)
            Pattern.compile("^([A-Za-z](?:[A-Za-z0-9_.]*))\\s*[(](.*)[)]$");
    Matcher matcher = strategyPattern.matcher(strategyText);
    if (!matcher.matches())
        throw new IllegalArgumentException(
                "Bad Strategy: " + strategyText + "\n" + "Expected: full.class.name(-123.45, 67, true, false)");

    final String strategyClassName = matcher.group(1).trim();
    String parameters[] = matcher.group(2).split(",");

    // clean parameters
    for (int i = 0; i < parameters.length; i++)
        parameters[i] = parameters[i].trim();
    if (parameters.length == 1 && parameters[0].length() == 0)
        parameters = new String[] {}; // 0 parameters

    // build classpath
    String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator);
    ArrayList<URL> classPathURLs = new ArrayList<URL>();
    for (int i = 0; i < classPath.length; i++) {
        String path = classPath[i];
        if (".".equals(path))
            path = System.getProperty("user.dir");
        path = path.replace(File.separatorChar, '/');
        if (!path.endsWith("/") && !path.endsWith(".jar"))
            path += "/";
        try {
            classPathURLs.add(new File(path).toURL());
        } catch (MalformedURLException e) {
            // bad directory in class path, skip
        }
    }
    final String strategyPackagePrefix = strategyClassName.substring(0,
            Math.max(0, strategyClassName.lastIndexOf('.') + 1));
    ClassLoader loader = new URLClassLoader(classPathURLs.toArray(new URL[] {}),
            this.getClass().getClassLoader()) {
        /** Don't search parent for classes with strategyPackagePrefix.
            Exception: interface TradingStrategy **/
        protected Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException {
            Class<?> loadedClass = findLoadedClass(className);
            if (loadedClass != null)
                return loadedClass;
            if (!className.startsWith(strategyPackagePrefix)
                    || className.equals(TradingStrategy.class.getName())) {
                loadedClass = this.getParent().loadClass(className);
                if (loadedClass != null)
                    return loadedClass;
            }
            loadedClass = findClass(className);
            if (loadedClass != null) {
                if (resolve)
                    resolveClass(loadedClass);
                return loadedClass;
            } else
                throw new ClassNotFoundException(className);
        }
    };
    // load class.  Throws ClassNotFoundException if not found.
    Class<?> strategyClass = loader.loadClass(strategyClassName);

    // Make sure it is a TradingStrategy.
    if (!TradingStrategy.class.isAssignableFrom(strategyClass))
        throw new ClassCastException(strategyClass.getName() + " does not implement TradingStrategy");

    // Find constructor compatible with parameters
    Constructor[] constructors = strategyClass.getConstructors();
    findConstructor: for (Constructor constructor : constructors) {
        Class<?>[] parameterTypes = constructor.getParameterTypes();
        if (parameterTypes.length != parameters.length)
            continue;
        Object[] values = new Object[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            if (boolean.class.equals(parameterTypes[i])) {
                String parameter = parameters[i].toLowerCase();
                if ("false".equals(parameter))
                    values[i] = Boolean.FALSE;
                else if ("true".equals(parameter))
                    values[i] = Boolean.TRUE;
                else
                    continue findConstructor;
            } else if (int.class.equals(parameterTypes[i])) {
                try {
                    values[i] = new Integer(parameters[i]);
                } catch (NumberFormatException e) {
                    continue findConstructor;
                }
            } else if (double.class.equals(parameterTypes[i])) {
                try {
                    values[i] = new Double(parameters[i]);
                } catch (NumberFormatException e) {
                    continue findConstructor;
                }
            } else if (String.class.equals(parameterTypes[i])) {
                values[i] = parameters[i];
            } else
                continue findConstructor; // unsupported parameter type, skip
        }
        // all values matched types, so create instance
        return (TradingStrategy) constructor.newInstance(values);
    }
    throw new NoSuchMethodException(strategyText);
}

From source file:org.apache.myfaces.application.ApplicationImpl.java

private static SystemEvent _createEvent(Class<? extends SystemEvent> systemEventClass, Object source,
        SystemEvent event) {//from   www .ja v a 2 s  .co m
    if (event == null) {
        try {
            Constructor<?>[] constructors = systemEventClass.getConstructors();
            Constructor<? extends SystemEvent> constructor = null;
            for (Constructor<?> c : constructors) {
                if (c.getParameterTypes().length == 1) {
                    // Safe cast, since the constructor belongs
                    // to a class of type SystemEvent
                    constructor = (Constructor<? extends SystemEvent>) c;
                    break;
                }
            }
            if (constructor != null) {
                event = constructor.newInstance(source);
            }

        } catch (Exception e) {
            throw new FacesException("Couldn't instanciate system event of type " + systemEventClass.getName(),
                    e);
        }
    }

    return event;
}

From source file:org.wandora.modules.ModuleManager.java

/**
 * Parses a single param element and returns its value. Handles all the
 * different cases of how a param elements value can be determined.
 * /*from w w w.  j a v  a 2  s  . co  m*/
 * @param e The xml param element.
 * @return The value of the parameter.
 */
public Object parseXMLParamElement(Element e)
        throws ReflectiveOperationException, IllegalArgumentException, ScriptException {
    String instance = e.getAttribute("instance");
    if (instance != null && instance.length() > 0) {
        Class cls = Class.forName(instance);
        HashMap<String, Object> params = parseXMLOptionsElement(e);
        if (!params.isEmpty()) {
            Collection<Object> constructorParams = params.values();
            Constructor[] cs = cls.getConstructors();
            ConstructorLoop: for (int i = 0; i < cs.length; i++) {
                Constructor c = cs[i];
                Class[] paramTypes = c.getParameterTypes();
                if (paramTypes.length != constructorParams.size())
                    continue;

                int j = -1;
                for (Object o : constructorParams) {
                    j++;
                    if (o == null) {
                        if (!paramTypes[j].isPrimitive())
                            continue;
                        else
                            continue ConstructorLoop;
                    }

                    if (paramTypes[j].isPrimitive()) {
                        if (paramTypes[j] == int.class) {
                            if (o.getClass() != Integer.class)
                                continue ConstructorLoop;
                        } else if (paramTypes[j] == long.class) {
                            if (o.getClass() != Long.class)
                                continue ConstructorLoop;
                        } else if (paramTypes[j] == double.class) {
                            if (o.getClass() != Double.class)
                                continue ConstructorLoop;
                        } else if (paramTypes[j] == float.class) {
                            if (o.getClass() != Float.class)
                                continue ConstructorLoop;
                        } else if (paramTypes[j] == byte.class) {
                            if (o.getClass() != Byte.class)
                                continue ConstructorLoop;
                        } else
                            continue ConstructorLoop; //did we forget some primitive type?
                    } else if (!o.getClass().isAssignableFrom(paramTypes[j]))
                        continue ConstructorLoop;
                }

                return c.newInstance(constructorParams.toArray());
            }
            throw new NoSuchMethodException(
                    "Couldn't find a constructor that matches parameters parsed from XML.");
        } else {
            return cls.newInstance();
        }
    }

    String clas = e.getAttribute("class");
    if (clas != null && clas.length() > 0) {
        Class cls = Class.forName(clas);
        return cls;
    }

    if (e.hasAttribute("null"))
        return null;

    if (e.hasAttribute("script")) {
        String engine = e.getAttribute("script");
        if (engine.length() == 0 || engine.equalsIgnoreCase("default"))
            engine = ScriptManager.getDefaultScriptEngine();
        ScriptManager scriptManager = new ScriptManager();
        ScriptEngine scriptEngine = scriptManager.getScriptEngine(engine);
        scriptEngine.put("moduleManager", this);
        scriptEngine.put("element", e);

        try {
            String script = ((String) xpath.evaluate("text()", e, XPathConstants.STRING)).trim();
            return scriptManager.executeScript(script, scriptEngine);
        } catch (XPathExpressionException xpee) {
            throw new RuntimeException(xpee);
        }
    }

    if (e.hasAttribute("module")) {
        String moduleName = e.getAttribute("module").trim();
        return new ModuleDelegate(this, moduleName);
    }

    try {
        String value = ((String) xpath.evaluate("text()", e, XPathConstants.STRING)).trim();
        return replaceVariables(value, variables);
    } catch (XPathExpressionException xpee) {
        throw new RuntimeException(xpee);
    }
}

From source file:org.apache.openjpa.util.ProxyManagerImpl.java

/**
 * Create pass-through constructors to base type.
 *///from w  w  w.j ava 2  s.  co m
private void delegateConstructors(BCClass bc, Class type) {
    Constructor[] cons = type.getConstructors();
    Class[] params;
    BCMethod m;
    Code code;
    for (int i = 0; i < cons.length; i++) {
        params = cons[i].getParameterTypes();
        m = bc.declareMethod("<init>", void.class, params);
        m.makePublic();

        code = m.getCode(true);
        code.aload().setThis();
        for (int j = 0; j < params.length; j++)
            code.xload().setParam(j).setType(params[j]);
        code.invokespecial().setMethod(cons[i]);
        code.vreturn();
        code.calculateMaxStack();
        code.calculateMaxLocals();
    }
}

From source file:org.apache.openjpa.util.ProxyManagerImpl.java

/**
 * Find an appropriate copy constructor for the given type, or return null
 * if none.//  www  .j a  va  2 s  .  c  o m
 */
protected Constructor findCopyConstructor(Class cls) {
    Constructor[] cons = cls.getConstructors();
    Constructor match = null;
    Class matchParam = null;
    Class[] params;
    for (int i = 0; i < cons.length; i++) {
        params = cons[i].getParameterTypes();
        if (params.length != 1)
            continue;

        // quit immediately on exact match
        if (params[0] == cls)
            return cons[i];

        if (params[0].isAssignableFrom(cls) && (matchParam == null || matchParam.isAssignableFrom(params[0]))) {
            // track most derived collection constructor
            match = cons[i];
            matchParam = params[0];
        }
    }
    return match;
}

From source file:org.mwc.debrief.editable.test.EditableTests.java

private Editable getEditable(IType type) {
    Editable editable = null;//  w w w. j  ava 2 s .  c  om
    switch (type.getFullyQualifiedName()) {
    case "Debrief.Wrappers.SensorWrapper":
        SensorWrapper sensor = new SensorWrapper("tester");
        final java.util.Calendar cal = new java.util.GregorianCalendar(2001, 10, 4, 4, 4, 0);

        // and create the list of sensor contact data items
        cal.set(2001, 10, 4, 4, 4, 0);
        sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null,
                null, null, 1, sensor.getName()));

        cal.set(2001, 10, 4, 4, 4, 23);
        sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null,
                null, null, 1, sensor.getName()));
        editable = sensor;
        break;
    case "MWC.GUI.Shapes.ChartFolio":
        editable = new ChartFolio(false, Color.white);
        break;
    case "org.mwc.cmap.naturalearth.wrapper.NELayer":
        editable = new NELayer(Activator.getDefault().getDefaultStyleSet());
        break;
    case "MWC.GUI.VPF.CoverageLayer$ReferenceCoverageLayer":
        final LibrarySelectionTable LST = null;
        final DebriefFeatureWarehouse myWarehouse = new DebriefFeatureWarehouse();
        final FeaturePainter fp = new FeaturePainter("libref", "Coastline");
        fp.setVisible(true);
        editable = new CoverageLayer.ReferenceCoverageLayer(LST, myWarehouse, "libref", "libref", "Coastline",
                fp);
        break;
    case "MWC.GUI.Chart.Painters.ETOPOPainter":
        editable = new ETOPOPainter("etopo", null);
        break;
    case "MWC.GUI.ETOPO.ETOPO_2_Minute":
        editable = new ETOPO_2_Minute("etopo");
        break;
    case "MWC.GUI.ExternallyManagedDataLayer":
        editable = new ExternallyManagedDataLayer("test", "test", "test");
        break;
    case "MWC.GUI.Shapes.CircleShape":
        editable = new CircleShape(new WorldLocation(2d, 2d, 2d), 2d);
        break;
    case "Debrief.Wrappers.Track.SplittableLayer":
        editable = new SplittableLayer(true);
        break;
    case "org.mwc.debrief.satc_interface.data.SATC_Solution":
        final ISolversManager solvMgr = SATC_Activator.getDefault().getService(ISolversManager.class, true);
        final ISolver newSolution = solvMgr.createSolver("test");
        editable = new SATC_Solution(newSolution);
        break;
    case "MWC.GUI.Shapes.PolygonShape":
        editable = new PolygonShape(null);
        break;
    case "ASSET.GUI.Painters.NoiseSourcePainter":
        editable = new ASSET.GUI.Painters.NoiseSourcePainter.PainterTest().getEditable();
        break;
    case "ASSET.GUI.Painters.ScenarioNoiseLevelPainter":
        editable = new ASSET.GUI.Painters.ScenarioNoiseLevelPainter.NoiseLevelTest().getEditable();
        break;
    case "ASSET.GUI.Workbench.Plotters.ScenarioParticipantWrapper":
        editable = new ScenarioParticipantWrapper(new SSN(12), null);
        break;
    case "Debrief.Wrappers.PolygonWrapper":
        // get centre of area
        WorldLocation centre = new WorldLocation(12, 12, 12);
        // create the shape, based on the centre
        final Vector<PolygonNode> path2 = new Vector<PolygonNode>();
        final PolygonShape newShape = new PolygonShape(path2);
        // and now wrap the shape
        final PolygonWrapper theWrapper = new PolygonWrapper("New Polygon", newShape, PlainShape.DEFAULT_COLOR,
                null);
        // store the new point
        newShape.add(new PolygonNode("1", centre, (PolygonShape) theWrapper.getShape()));
        editable = theWrapper;
        break;
    case "Debrief.Wrappers.Track.AbsoluteTMASegment":
        WorldSpeed speed = new WorldSpeed(5, WorldSpeed.Kts);
        double course = 33;
        WorldLocation origin = new WorldLocation(12, 12, 12);
        HiResDate startTime = new HiResDate(11 * 60 * 1000);
        HiResDate endTime = new HiResDate(17 * 60 * 1000);
        editable = new AbsoluteTMASegment(course, speed, origin, startTime, endTime);
        break;
    case "Debrief.Wrappers.Track.RelativeTMASegment":
        speed = new WorldSpeed(5, WorldSpeed.Kts);
        course = 33;
        final WorldVector offset = new WorldVector(12, 12, 0);
        editable = new RelativeTMASegment(course, speed, offset, null);
        break;
    case "Debrief.Wrappers.Track.PlanningSegment":
        speed = new WorldSpeed(5, WorldSpeed.Kts);
        course = 33;
        final WorldDistance worldDistance = new WorldDistance(5, WorldDistance.MINUTES);
        editable = new PlanningSegment("test", course, speed, worldDistance, Color.WHITE);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper":
        BearingMeasurementContribution bmc = new BearingMeasurementContribution();
        bmc.setName("Measured bearing");
        bmc.setAutoDetect(false);
        editable = new BMC_Wrapper(bmc);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper":
        FrequencyMeasurementContribution fmc = new FrequencyMeasurementContribution();
        fmc.setName("Measured frequence");
        editable = new FMC_Wrapper(fmc);
        break;
    case "Debrief.Wrappers.SensorContactWrapper":
        origin = new WorldLocation(0, 0, 0);
        editable = new SensorContactWrapper("blank track", new HiResDate(new java.util.Date().getTime()),
                new WorldDistance(1, WorldDistance.DEGS), 55d, origin, java.awt.Color.red, "my label", 1,
                "theSensorName");
        break;
    case "Debrief.Wrappers.FixWrapper":
        final Fix fx = new Fix(new HiResDate(12, 0), new WorldLocation(2d, 2d, 2d), 2d, 2d);
        final TrackWrapper tw = new TrackWrapper();
        tw.setName("here ew arw");
        FixWrapper ed = new FixWrapper(fx);
        ed.setTrackWrapper(tw);
        editable = ed;
        break;
    case "Debrief.Wrappers.ShapeWrapper":
        centre = new WorldLocation(2d, 2d, 2d);
        editable = new ShapeWrapper("new ellipse", new EllipseShape(centre, 0,
                new WorldDistance(0, WorldDistance.DEGS), new WorldDistance(0, WorldDistance.DEGS)),
                java.awt.Color.red, null);
        break;
    case "Debrief.GUI.Tote.Painters.PainterManager":
        final StepControl stepper = new Debrief.GUI.Tote.Swing.SwingStepControl(null, null, null, null, null,
                null);
        editable = new PainterManager(stepper);
        break;
    case "Debrief.Wrappers.TMAContactWrapper":
        origin = new WorldLocation(2, 2, 0);
        final HiResDate theDTG = new HiResDate(new java.util.Date().getTime());
        final EllipseShape theEllipse = new EllipseShape(origin, 45, new WorldDistance(10, WorldDistance.DEGS),
                new WorldDistance(5, WorldDistance.DEGS));
        theEllipse.setName("test ellipse");
        editable = new TMAContactWrapper("blank sensor", "blank track", theDTG, origin, 5d, 6d, 1d, Color.pink,
                "my label", theEllipse, "some symbol");
        break;
    case "MWC.GUI.JFreeChart.NewFormattedJFreeChart":
        XYPlot plot = new XYPlot();
        DefaultXYItemRenderer renderer = new DefaultXYItemRenderer();
        plot.setRenderer(renderer);
        editable = new NewFormattedJFreeChart("test", new java.awt.Font("Dialog", 0, 18), plot, false);
        break;
    case "org.mwc.cmap.core.ui_support.swt.SWTCanvasAdapter":
        final Editable[] edit = new Editable[1];
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                edit[0] = new SWTCanvasAdapter(null);
            }
        });
        editable = edit[0];
        break;
    case "ASSET.Models.Decision.Conditions.OrCondition":
        System.out.println(type.getFullyQualifiedName() + " hasn't public constructor.");
        return null;
    case "ASSET.Models.Decision.Movement.RectangleWander":
        final WorldLocation topLeft = SupportTesting.createLocation(0, 10000);
        final WorldLocation bottomRight = SupportTesting.createLocation(10000, 0);
        final WorldArea theArea = new WorldArea(topLeft, bottomRight);
        editable = new RectangleWander(theArea, "rect wander");
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper$BearingMeasurementWrapper":
        bmc = new BearingMeasurementContribution();
        bmc.setName("Measured bearing");
        bmc.setAutoDetect(false);
        CoreMeasurement cm = new CoreMeasurement(new Date());
        BMC_Wrapper bmcw = new BMC_Wrapper(bmc);
        editable = bmcw.new BearingMeasurementWrapper(cm);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper$FrequencyMeasurementEditable":
        fmc = new FrequencyMeasurementContribution();
        fmc.setName("Measured frequence");
        FMC_Wrapper fmcw = new FMC_Wrapper(fmc);
        cm = new CoreMeasurement(new Date());
        editable = fmcw.new FrequencyMeasurementEditable(cm);
        break;
    case "ASSET.GUI.SuperSearch.Plotters.SSGuiSupport$ParticipantListener":
        SSGuiSupport ssgs = new SSGuiSupport();
        ssgs.setScenario(new MultiForceScenario());
        editable = new SSGuiSupport.ParticipantListener(new CoreParticipant(12), ssgs);
        break;
    case "ASSET.GUI.Workbench.Plotters.BasePlottable":
        // skip it
        return null;
    case "MWC.TacticalData.GND.GTrack":
        // skip it
        return null;
    default:
        break;
    }

    if (editable != null) {
        return editable;
    }
    Class<?> clazz;
    try {
        clazz = Class.forName(type.getFullyQualifiedName());
    } catch (ClassNotFoundException e1) {
        //e1.printStackTrace();
        System.out.println("CNFE " + e1.getMessage() + " " + type.getFullyQualifiedName());
        return null;
    }
    try {
        @SuppressWarnings("unused")
        Method infoMethod = clazz.getDeclaredMethod("getInfo", new Class[0]);
    } catch (Exception e) {
        return null;
    }
    try {
        editable = (Editable) clazz.newInstance();
    } catch (Exception e) {
        Constructor<?>[] constructors = clazz.getConstructors();
        for (Constructor<?> constructor : constructors) {
            try {
                Class<?>[] paramTypes = constructor.getParameterTypes();
                Object[] params = new Object[paramTypes.length];
                for (int i = 0; i < paramTypes.length; i++) {
                    Class<?> paramType = paramTypes[i];
                    if (HiResDate.class.equals(paramType)) {
                        params[i] = new HiResDate(new Date());
                    } else if (WorldDistance.class.equals(paramType)) {
                        params[i] = new WorldDistance(12d, WorldDistance.DEGS);
                    } else if (WorldSpeed.class.equals(paramType)) {
                        params[i] = new WorldSpeed(12, WorldSpeed.M_sec);
                    } else if (WorldLocation.class.equals(paramType)) {
                        params[i] = new WorldLocation(12, 12, 12);
                    } else if ("java.lang.String".equals(paramType.getName())) {
                        params[i] = "test";
                    } else if (!paramType.isPrimitive()) {
                        params[i] = null;
                    } else {
                        if (paramType.equals(int.class)) {
                            params[i] = new Integer("0");
                        }
                        if (paramType.equals(boolean.class)) {
                            params[i] = Boolean.FALSE;
                        }
                        if (paramType.equals(long.class)) {
                            params[i] = new Long("0");
                        }
                        if (paramType.equals(double.class)) {
                            params[i] = new Double("0");
                        }
                        if (paramType.equals(float.class)) {
                            params[i] = new Float("0");
                        }
                        if (paramType.equals(short.class)) {
                            params[i] = new Short("0");
                        }
                    }
                }
                editable = (Editable) constructor.newInstance(params);
                break;
            } catch (Exception e1) {
                // ignore
                //System.out.println(e1.getMessage());
                //e1.printStackTrace();
            }
        }
    }
    if (editable == null) {
        System.out.println("Can't instantiate type " + type.getFullyQualifiedName());
    }
    return editable;
}