What should be done if a lookup returns null? I am using Lookup.getDefault().lookup() of org.openide.util.Lookup
which is used for finding instances of objects. The general pattern is to pass a Class object and get back an instance of that class or null.
I am using it in the code below:
StreamingServer server = Lookup.getDefault().lookup(StreamingServer.class);
ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);
StreamingController controller = Lookup.getDefault().lookup(StreamingController.class);
Since no istances are found, null is returned for each of these, 'server
', 'controllerFactory
', 'controller
'. I need to handle this situation so I can use these objects to access methods, as in :
controllerFactory.createServerController(graph)
server.register(serverController, context)
How can I accomplish this?