This project has moved and is read-only. For the latest updates, please go here.

Java import statement

May 7, 2014 at 4:33 PM
I have developed a large system that uses Bloomberg.
Was wanting to use the emulator so others without Bloomberg can also work on the code.

However from the example:

import com.bemu.BEmu.*; //un-comment this line to use the Bloomberg API Emulator
//import com.bloomberglp.blpapi.*; //un-comment this line to use the actual Bloomberg API

Does this mean every single class that uses the Bloomberg API I would need to change to not import the API and use the emulator line
And then when i want to use Bloomberg I'd have to edit all the classes again to comment out the emulator import and use the Bloomberg one?

I maybe have 50 classes that use Bloomberg API so it's going to get awkward to keep replacing the import statements when I want to flip from one to another.

Thanks
Coordinator
May 7, 2014 at 7:37 PM
redonion,

Unfortunately I don't know a good solution to your problem. I can't make use of a preprocessor to select imports in the Java version. In the C++ version, I can use a preprocessor directive to select include files (see this file). As a result, the developer only needs to comment/uncomment a single line in just one file in order to switch between BEmu and the actual BB API for the whole project. (in the C# version, I can also make use of C#'s more limited preprocessor to achieve the same result)

I can think of two workable alternatives:
  1. Use a Java preprocessor from some third-party. See the discussion here.
  2. Use a factory pattern that can select between the BEmu and BB API classes. You could have a RequestFactory that returns objects that internally have either a BEmu Request object or a BB API Request object. This would involve extra classes for each of the BB API classes you intend to use (Element, Request, Session, etc.) Also, the code that you would write would not look like BB API code. It would still be able to call the BB API, but it wouldn't look like the example BB API code that you've probably seen.
My experience with Java is pretty limited, so I don't know if there's a better solution.
May 8, 2014 at 10:23 AM
Edited May 8, 2014 at 10:24 AM
Hi all, in a previous post I commented something about this.
The code renaming to work with the official API is necessary? I mean, is it because of a legal issue with using the package "com.blombergblp.blpapi"? Replacing the jar would be faster and easier.
I think that using the official packages names "com.blombergblp.blpapi", rather than "com.bemu.BEmu", would be compatible with code pointing to the official API. At least with the public API classes. But I'm not sure if this could cause a legal conflict with Bloomberg.

For instance, the Request class would be com.blombergblp.blpapi.Request, instead of com.bemu.BEmu.Request. In this way, there wouldn't have need of changing the import statements.
Coordinator
May 8, 2014 at 3:10 PM
pichulines,

After my original response in this thread, I remembered your post. I've started looking at what this would involve, but I think that it is something I should move forward with. If I understand this right, if I rename the package to com.bloomberg.blpapi, then a developer will simply have to remove the reference to the BEmu com.bloobmerg.blpapi.jar file, and replace it a reference to Bloomberg's com.bloobmerg.blpapi.jar file.

Thanks again.

-Robinson664
Coordinator
May 8, 2014 at 9:23 PM
Check out my latest release. I made the changes that user pichulines recommended. My java package is now called com.bloomberg.blpapi. In order to switch between the BEmu and the actual Bloomberg API, you just need to update your project's references. Let me know how this works for you.

Thank you for your interest in my project.

-Robinson664
May 9, 2014 at 3:17 PM
Robinson, thanks for this new release. I think it's a key step towards the project ease of use. I'll try it.