use of org.glassfish.contextpropagation.ContextViewFactory in project Payara by payara.
the class BootstrapUtils method populateMap.
public static void populateMap() throws InsufficientCredentialException {
ContextMap wcMap = ContextMapHelper.getScopeAwareContextMap();
wcMap.put("true", true, PropagationMode.defaultSet());
wcMap.put("string", "string", PropagationMode.defaultSet());
wcMap.put("one", 1L, PropagationMode.defaultSet());
((ContextMapAdditionalAccessors) wcMap).putAscii("ascii", "ascii", PropagationMode.defaultSet());
((ContextMapAdditionalAccessors) wcMap).putSerializable("serializable", new HashSet<String>(Arrays.asList("foo")), PropagationMode.defaultSet());
wcMap.put("byte", (byte) 'b', PropagationMode.defaultSet());
// View Capable Stuff
// 1 - Create the factory (assumes that you have already created a ViewCapable class
ContextViewFactory viewCapableFactory = new ContextViewFactory() {
@Override
public ViewCapable createInstance(View view) {
return new MyViewCapable(view);
}
@Override
public EnumSet<PropagationMode> getPropagationModes() {
return PropagationMode.defaultSet();
}
};
// 2 - Register the factory
ContextMapHelper.registerContextFactoryForPrefixNamed("view capable", viewCapableFactory);
// 3 - Create the ViewCapable instance
wcMap.createViewCapable("view capable");
assertEquals("a value", ((MyViewCapable) wcMap.get("view capable")).getValue());
wcMap.get("ascii");
}
Aggregations