I am now using Twig 2.0 in a way that is more compatible to Twig 1.0.4:
I subclassed AnnotationConfiguration to create a Configuration that supports auto-registering and using the long class names as kind names.
Then I created my own factory where I can set the Configuration to use for new datastores.
Additionally, the datastores are created as Singleton per thread with the help of ThreadLocal.
This avoids the multi-thread issues with the 2.0 ObjectDatastore but it also avoids another incompatibility where I load a parent early in the thread and store children later, without explicitly keeping the same datastore.
I attached both the configuration and the factory; feel free to incorporate anything you find useful in twig.
Actually, I am quite puzzled with the original ObjectDatastoreFactory:
- It contains a register method which does something similar, but not quite the same as AnnotationConfiguration.register
- It contains a getConfiguration method, but no way of supplying my own configuration
- It contains some create methods while it is recommended to use
new AnnotationObjectDatastore() directly