tinkerpop/frames — pull request #24 by BrynCooke (2013-03-13 23:41:24+00:00)
Title: Add interface to allow initialization of new framed vertices and edges.

Allows clients to add an initializer that gets to mutate the graph whenever a new framed element is added to the graph.

Some sort of generic annotation defaulting mechanism could be built on this, but for now here is a simple example that default the weight property on a 'knows' edge.

```java

FrameInitializer weightDefaulter = new FrameInitializer() {

@Override
public void initElement(Class kind, FramedGraph framedGraph, Element element) {
assertNotNull(framedGraph);
if (kind == Knows.class) {
element.setProperty("weight", 1.0f);
}
}
};

framedGraph.registerFrameInitializer(weightDefaulter);
```

This would allow someone to write an initializer to add type information https://github.com/tinkerpop/frames/issues/15

I am using this in a similar way in my own project where the an annotation on the class allows specifying of the security class of a vertex.

```java
public class SecurityClassInitializer implements FrameInitializer {

@Override
public void initElement(Class kind, FramedGraph framedGraph, Element element) {
SecurityClass securityClassAnnotation = kind.getAnnotation(SecurityClass.class);
if(securityClassAnnotation != null) {
String securityClass = securityClassAnnotation.value();
if(securityClass == null) { //Default to the class name.
securityClass = kind.getName();
}
element.setProperty(SecureGraph.SECURITY_MODEL, securityClass);
}
}

}
```