Making the model persistent

Making a symbol model persistent means providing a way to embed SDM model information inside a map file.
This can be done through the IlvPersistentSDMNodeFactory interface and the IlvPersistentSDMModelProperty manager property.
You should not use this feature if you intend to use JViews Diagrammer Designer with your map, as it stores and sets up symbol model differently, in separated xml files. You should use an IlvMapStyleSheetRenderer if you want to take advantage of this feature. If you do not, the manager layers that will be used to place your symbols may not be instances of the IlvMapStyleSheetRenderer.IlvMapSymbolManagerLayer class, which means that the graphical representation of the symbols will be saved separately in the ivl file, causing its duplication when you read the map back.
The persistent SDM model property
This class is a named property that will be attached to a manager, and trigger the saving and reading of an engine model inside an IVL file.
Example of use:
IlvPersistentSDMModelProperty property = 
IlvPersistentSDMModelProperty.GetPersistentSDMModel(engine,factory,listenToChanges);
This call will register the property on the engine’s manager. It will be saved (like every named property) when the manager gets saved, and will invoke an internal IlvXMLConnector that will save the XML content of the engine model as a string.
At read time, this property requires the use a node factory to create SDM nodes in the engine model, detailed below.
If you use this call with listenToChanges set to true, you can register this property for an engine before reading the map IVL file. The listener attached will ensure that the factory and engine used when reading the property get replaced by the ones you specify before the data is read.
If you do not do this, internal XML data will be read, and you will have to attach the engine manually later.
The persistent SDM Node factory
The principal purpose of the IlvPersistentSDMNodeFactory interface is to provide a way for model nodes to be created when you read the model data back in. Usually creating a symbol is dependent on some application so this interface also includes methods to manage that persistent context.
The following provides a simple code example which can help you to write your own factory.
public class SampleFactory implements IlvPersistentSDMNodeFactory {
  static public class SampleContext extends IlvPersistentObject {
	// some implementation of a persistent object ...
  }
  IlvPersistentObject _factoryPersistentContext;

  public IlvPersistentObject getPersistentContext() {
    // the persistent context should be created or updated at this point.
    _factoryPersistentContext=new SampleContext();
    _factoryPersistentContext.setSomeData(this.getSomeData());
    return _factoryPersistentContext;
  }

  public boolean isPropertyIgnored(IlvSDMModel model, Object node, String name) {
   // ignore the “data” property
   if(“data”.equals(name)) return true;
   return false;
  }

  public Object newSymbol(String tag) {
   // we will create default SDM nodes
   IlvDefaultSDMNode node=new IlvDefaultSDMNode(tag);
   // configure the node, for example
   node.setProperty("data", this.getSomeData());
   return node;
  }

  public void setPersistentContext(IlvPersistentObject context) {
   // the local information should be updated with what was stored in the context
   this.setSomeData(context.getSomeData());
  }