← Prev in month
← Prev in thread
Next in thread →
Next in month →
JAVA-1: Source code for SCAClientFactory proposal
Hi,
I have an action item to write some code to show SCAClient as an interface and SCAClientFactory as a concrete
class and still allow vendors to plug in implementations that provide the
vendor specific functionality.
The main reasons for doing this include:
Since SCAClient is an
interface, it can be mocked for testing purposes
SCAClientFactory allows vendors to plug in an
implementation without modifying the SCAClientFactory class
The SCA API jar can be shipped
without modification by the vendors
What I will do is run you through the main points of the
code and how it works. The code could do with more polish before it is
considered complete.
SCA Client Perspective
The scenario is fairly simple – some code that is
running outside of the SCA Domain wants to lookup and use a Service that is
inside the domain.
The following code shows how the HelloService could be looked up and invoked from
unmanaged SCA Code.
final String serviceURI = "SomeHelloServiceURI";
final URI domainURI = new URI("SomeDomainURI");
final SCAClient scaClient = SCAClientFactory.createSCAClient();
final HelloService helloService =
scaClient.getService(HelloService.class, serviceURI, domainURI);
final String reply = helloService.sayHello("Mark");
The client first calls SCAClientFactory.createSCAClient() that returns
an instance of SCAClient. This SCAClient instance can then be used to look
up the HelloService
SCAClient Interface
The main change from Mike’s original proposal is to make
SCAClient an
interface rather than a class. The main reason for this is that it allows
mocking of the SCAClient so that it
can be unit tested.
The new definition of SCAClient interface would be:
public interface SCAClient {
<T> T getService(Class<T> interfaze,
String serviceURI, URI domainURI)
throws NoSuchServiceException, NoSuchDomainException;
}
SCAClientFactory class
The SCAClientFactory class is responsible
for providing the indirection from the user’s generic SCA code and the
vendor’s implementation of the SCA Runtime. The user’s code will
ask it for a SCAClient via the createSCAClient() method.
The SCAClientFactory class
provides this indirection to the vendor’s implementation by attempting to
discover the class name of the vendor’s implementation using:
The org.oasisopen.sca.SCAClientFactory System
Property
The META-INF/services/org.oasisopen.sca.SCAClientFactory
file.
It is important to note that this class does not need to be
updated by the Vendor to include their implementation. All the Vendor needs to
do is set the System Property or provide the correct services file
What does the Vendor need to do?
The Vendor will need to provide a class that will be able to
look up a Service in their SCA Runtime. To do this, they need to:
Provide an implementation of
the org.oasisopen.sca.SCAClientFactorySPI interface
Provide a META-INF/services/org.oasisopen.sca.SCAClientFactory file
that points to their implementation class
The SCAClientFactorySPI interface
has a single method that the vendors need to implement:
public interface SCAClientFactorySPI {
SCAClient createSCAClient();
}
Source Code
I have attached a ZIP file that contains the source code for
the above. The ZIP file contains:
Implementation of SCAClient and SCAClientFactory in the org.oasisopen.sca package
Implementation of SCAClientFactorySPI in the org.oasisopen.sca.spi package
A sample implementation of the SCAClientFactorySPI in the
com.myscaruntime.impl
package
A unit test that looks up the HelloService using
the SCAClientFactory
An Eclipse project file
When loading the Eclipse project file, you may need to set
the target JDK to match the JDK you have installed. To do this simply:
Select the Properties menu item
on the Project menu.
Select the Java Build Path in
the list on the left hand side
Select the JRE System Library
on the right hand side
Press the Edit button
Make sure the workspace default
JRE is selected and press Finish
Press OK
I would appreciate your thoughts/comments on this proposal.
Thanks,
Mark
Mark Combellack| Software Developer| Avaya | Eastern Business Park | St. Mellons | Cardiff |
CF3 5EA | Voice: +44 (0) 29 2081 7624 |
JAVA-1_Code_Proposal.zip
← Prev in month
← Prev in thread
Next in thread →
Next in month →