/** * Creates and returns a new instance for the given class name. * * @param name Name of the class to be instantiated. * @return Returns a new instance of the given class. */ public static Object getInstanceForName(String name) { Class<?> clazz = getClassForName(name); if (clazz != null) { if (clazz.isEnum()) { // For an enum, use the first constant as the default instance return clazz.getEnumConstants()[0]; } else { try { return clazz.newInstance(); } catch (Exception e) { // ignore } } } return null; }
/** * Evaluates a Java expression as a class member using mxCodecRegistry. The * range of supported expressions is limited to static class members such as * mxEdgeStyle.ElbowConnector. */ public static Object eval(String expression) { int dot = expression.lastIndexOf("."); if (dot > 0) { Class<?> clazz = mxCodecRegistry.getClassForName(expression .substring(0, dot)); if (clazz != null) { try { return clazz.getField(expression.substring(dot + 1)).get( null); } catch (Exception e) { // ignore } } } return expression; }
/** * Evaluates a Java expression as a class member using mxCodecRegistry. The * range of supported expressions is limited to static class members such as * mxEdgeStyle.ElbowConnector. */ public static Object eval(String expression) { int dot = expression.lastIndexOf("."); if (dot > 0) { Class<?> clazz = mxCodecRegistry.getClassForName(expression .substring(0, dot)); if (clazz != null) { try { return clazz.getField(expression.substring(dot + 1)).get( null); } catch (Exception e) { log.log(Level.SEVERE, "Failed to eval expression: " + expression, e); } } } return expression; }
Class<?> clazz = getClassForName(name);