嗨,我有包装应用程序和一个在包装应用程序服务中运行的 jar。在完整的解决方案中,Jar 是我的产品,我不能辱骂用户,但我需要通过针对从套接字接收的命令注册函数来赋予他们扩展功能的自由。他们可以在包装应用程序中做到这一点。我已经有一些来自 flex UI 的命令,它们的处理方式如下:
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;
}
}
这是在我的 Jar 中,我希望用户能够在包装应用程序中添加任意数量的案例作为函数。此外,最好将现有案例放在用于在包装器应用程序中注册命令和函数的相同哈希映射中。
我需要知道正确的设计模式和一些如何去做的建议。
提前致谢。