The Grimoires Shell (GShell) is a simple command line client for the Grimoires Web Service registry. The GShell provides a shell environment to interact with Grimoires service, within which a group of commands can be invoked for users to publish/inquire business/service/wsdl/metadata.
In terms of implementation, GShell consists of a Shell class that implements the shell environment, and a group of Command classes, each of which implements a registry task, for instance, publishing a service. Below we explain the Shell class and Command classes respectively.
The Shell class has implemented the following functionalities:
The Shell class need not be touched to implement a new command.
All commands extend from the Shell class in order to inherit the shell environment, for instance, the capability to communicate with the Grimoires service.
All commands implements the Command interface, which is quite simple:
public interface Command {
public void run() throws Exception;
}
All commands should provide a nullary constructor, which will be used by the Shell class to create an instance. Then the shell class will invoke the run() method of the created instance to execute the command.
In order to be runnable outside the shell, a command should also provide a public main() method. A sample command looks like:
public class PublishBusinessCommand extends Shell implements Command {
private String name;
private String description;
private BusinessDetail response;
public PublishBusinessCommand(String name, String desc) {
this.name = name;
this.description = desc;
}
public PublishBusinessCommand() {
}
private void expect() throws Exception {
out.println("==== Publish a business ====");
out.println("Input the business name:");
name = readAndParseLine();
out.println("Input the business description:");
description = readAndParseLine();
}
private void execute() throws Exception {
Save_business request = new Save_business();
request.setAuthInfo("AUTHINFO");
BusinessEntity[] businessEntities = new BusinessEntity[1];
businessEntities[0] = new BusinessEntity();
businessEntities[0].setName(new Name[] {
new Name(name)
});
businessEntities[0].setDescription(new Description[] {
new Description(description)
});
request.setBusinessEntity(businessEntities);
response = publishImpl.save_business(request);
}
private void present() throws Exception {
String businessKey = response.getBusinessEntity(0).getBusinessKey();
printEnv("Business key", businessKey);
}
public void run() throws Exception {
expect();
execute();
present();
}
public static void main(String[] args) throws Exception {
if (args.length != 3) {
help();
System.exit(1);
}
setUpStubs(args[0]);
PublishBusinessCommand cmd = new PublishBusinessCommand(args[1], args[2]);
cmd.execute();
cmd.present();
}
private static void help() {
System.out.println("java PubishBusinessCommand Grimoires_URL business_name business_description");
}
}