/** * Registers a new codec and associates the name of the template constructor * in the codec with the codec object. Automatically creates an alias if the * codename and the classname are not equal. */ public static mxObjectCodec register(mxObjectCodec codec) { if (codec != null) { String name = codec.getName(); codecs.put(name, codec); String classname = getName(codec.getTemplate()); if (!classname.equals(name)) { addAlias(classname, name); } } return codec; }
/** * 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; }
Object instance = getInstanceForName(name); register(codec);
/** * Returns the name used for the nodenames and lookup of the codec when * classes are encoded and nodes are decoded. For classes to work with * this the codec registry automatically adds an alias for the classname * if that is different than what this returns. The default implementation * returns the classname of the template class. * * Here is an example on how to use this for renaming mxCell nodes: * <code> * mxCodecRegistry.register(new mxCellCodec() * { * public String getName() * { * return "anotherName"; * } * }); * </code> */ public String getName() { return mxCodecRegistry.getName(getTemplate()); }
/** * Returns the name used for the nodenames and lookup of the codec when * classes are encoded and nodes are decoded. For classes to work with * this the codec registry automatically adds an alias for the classname * if that is different than what this returns. The default implementation * returns the classname of the template class. * * Here is an example on how to use this for renaming mxCell nodes: * <code> * mxCodecRegistry.register(new mxCellCodec() * { * public String getName() * { * return "anotherName"; * } * }); * </code> */ public String getName() { return mxCodecRegistry.getName(getTemplate()); }
/** * Registers a new codec and associates the name of the template constructor * in the codec with the codec object. Automatically creates an alias if the * codename and the classname are not equal. */ public static mxObjectCodec register(mxObjectCodec codec) { if (codec != null) { String name = codec.getName(); codecs.put(name, codec); String classname = getName(codec.getTemplate()); if (!classname.equals(name)) { addAlias(classname, name); } } return codec; }
Object instance = getInstanceForName(name); register(codec);
mxObjectCodec codec = mxCodecRegistry.getCodec(node.getNodeName());
/** * 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; }
mxObjectCodec codec = mxCodecRegistry.getCodec(node.getNodeName());
/** * 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; }
.getCodec(element.getNodeName());
Class<?> clazz = getClassForName(name);
.getCodec(element.getNodeName());