Hi,
I have an wrapper application and a jar which runs in a service of wrapper app. In the complete solution the Jar is my product which I can't revile to users, but I need to give them the liberty to extend the functionality by registering function against a command received from socket. They can do it in the wrapper application. I already have some commands coming from flex UI and they are processed like following:
private void processCommand(String tempCommand) throws NumberFormatException, IOException, ELearningException
{
ApplicationLog.log("Command Queue " + tempCommand, true);
String[] commandParameters = tempCommand.split("#");
switch (Integer.parseInt(commandParameters[0]))
{
case CONSTANTS.INITIALIZE:
if (this.m_isInitialized)
break;
else
{
InitializeTeacherJar.instantiate(tempCommand.split("#")[1], this.baseContext, tempCommand.split("#")[2]);
parent = InitializeTeacherJar.getInstance();
parent.setMyFlexServer(this.m_localServerSocket);
parent.setMyFlexSocket(this.m_localSocket);
this.m_isInitialized = true;
}
break;
case CONSTANTS.LOGIN:
/**
* Store student details in hash map
*/
this.writeToStudentJava(tempCommand, JavaServerThreadForTeacher.getIpAddress().getHostAddress());
if(tempCommand.split("#")[1].equalsIgnoreCase(CONSTANTS.SUCCESS))
{
HashMap<String, ArrayList<String>> temp = parent.getStudentIPList();
ArrayList<String> value= new ArrayList<String>();
value.add(tempCommand.split("#")[3]);
value.add("present");
temp.put(tempCommand.split("#")[2], value);
parent.setStudentIPList(temp);
if (StudentUtility.studentCounter < 0)
StudentUtility.studentCounter = 0;
StudentUtility.studentCounter = StudentUtility.studentCounter + 1;
parent.getMyFlexSocket().getOutputStream().write((CONSTANTS.PING + parent.getDelimiter() + StudentUtility.studentCounter).getBytes());
System.out.print("StudentUtility.studentCounter :: "+StudentUtility.studentCounter);
}
break;
case CONSTANTS.COURSE:
parent.setCourse(tempCommand.split(parent.getDelimiter())[1]);
break;
case CONSTANTS.ACTION:
parent.performAction(tempCommand, commandParameters[3]);
parent.getMyFlexSocket().getOutputStream().write((CONSTANTS.PING + parent.getDelimiter() + StudentUtility.studentCounter).getBytes());
break;
case CONSTANTS.INTERACTIVE:
if (commandParameters[1].equalsIgnoreCase(CONSTANTS.Play)) {
parent.playAudio(commandParameters[2], true);
} else if (commandParameters[1].equalsIgnoreCase(CONSTANTS.Record)) {
parent.startAudioRecording(commandParameters[2], true);
} else {
parent.playAudio(commandParameters[2], false);
}
case CONSTANTS.TTL:
this.m_isWifiConnected();
break;
case CONSTANTS.DELETE:
parent.deleteFile(commandParameters[1], true);
// deleteRecording(commandParameters[3],
// commandParameters[1]
// + commandParameters[2]);
// deleteEveryThing(Environment.getExternalStorageDirectory()
// .getAbsolutePath() + "/" + commandParameters[2]);
// deleteEveryThing(pathToSave + "/Response/" + course + "/"
// + commandParameters[1]);
break;
case CONSTANTS.RESTART:
StudentUtility.sendToEveryStudent(tempCommand);
StudentUtility.displayOnProjector(tempCommand);
parent.setStudentIPList(new HashMap<String, ArrayList<String>>());
parent.setCourse("");
break;
case CONSTANTS.EXIT:
StudentUtility.displayOnProjector(tempCommand);
StudentUtility.sendToEveryStudent(tempCommand);
break;
default:
break;
}
}
This is inside my Jar and I want users to be able to add any number of cases as functions in wrapper application. More over, preferably, I would like to put the existing cases in the same hash map used for registering commands and functions in wrapper application.
I need to know the correct design pattern and some advice how to go about it.
Thanks in advance.
Regards
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment