Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:30:45+00:00 2026-06-13T01:30:45+00:00

Hi I have wrapper application and a jar which runs in a service of

  • 0

Hi I have 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:30:46+00:00Added an answer on June 13, 2026 at 1:30 am

    Combine design pattern Command with a mapping of function code to commands. This has the benefit of moving the implementations to their own self-contained classes, which makes code more manageable and easier to test.

    You might want to use Design Pattern Visitor instead of modifying the command map, but depends on your circumstances.

    A common Interface for your commands

    public Interface Command {
     void action();
    }
    

    Create a bunch of concrete commands

    public class Course implements Command {
      private final String tempCommand;
      private final ParentClass parent;
    
      public Course(final String tempCommand, final ParentClass parent) {
        this.tempCommand = tempCommand;
        this.parent = parent;
      }
    
      public void action() {
        parent.setCourse(tempCommand.split(parent.getDelimiter())[1]);
      }
    };
    

    Map the preexisting function codes to commands.

      private final Map<Integer, Command> getBuiltIns() {
          Private final Map<Integer, Command> cmdMap = new HashMap<Integer, Command>();
          cmdMap.add(CONSTANTS.COURSE, new Command(tempCommand, parent));
          <etc>
         return cmdMap;
      }
    
      private final cmdMap = getBuildIns();
    

    Make a method that can add commands

    public void addCommand(final int code, final Command command) {
      // Check if code is already used, or there might be trouble
      cmdMap.add(code, command);
    }
    

    Find the command then execute.

    private void processCommand(String tempCommand) throws NumberFormatException, IOException, ELearningException 
    {
      final Command theCommand = cmdMap.get(Integer.parseInt(commandParameters[0]));
      theCommand.action();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a setup project for a .NET Service Application which uses a .NET
I have an application that runs fine on .Net 2.0 SP2, but fails to
In my application I have a wrapper over some native code, which is called
I have an application which i want to run as service on MacOS X.
I have used Spring DATA JPA in my application, which is wrapper over hibernate.
I have a small command-line application written in C that acts as a wrapper/launcher
Scenario 1: I have one wrapper Perl script which uses another Perl module and
In my project, I have a wrapper class named PlayerCluster.java , which loads the
I have a wrapper managed application(.net) over a COM Component(created using vb6) where Com
I have a fat-client application which uses EF4 to MSSQL in the data layer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.