1 Reply Latest reply: Nov 20, 2012 9:34 AM by JasonBatzlaff RSS

    Initializing Configurator session thru CIO

    Akhil Agarwal

      I am looking for a 'sample java code' to understand how to initialize Configurator session thru CIO.

      I did go thru the 'Oracle Configurator Extensions and Interface Object Developer’s Guide' , but the sample code provided over there is too simple.
      I am looking for something more, a sample code which can help me understand how to 'choose options', 'populate value' thru the CIO.

        • 1. Re: Initializing Configurator session thru CIO

          I have an example of working with initializing a Configurator session. In my first example, I started by doing all of the java within a JSP. Eventually, I was able to put the java into specific classes and call these classes and methods from a JSP. In my scenario, the JSP was the vehicle for launching the application, but it is not required. I am sure you can do the same from a pure-java program as well.

          An example of the important Java aspects that were used are listed below:
          //Set some default variable values
          String dbcFileName = "<path to DBC file>";
          CIO cio;
          Context context;
          String errMessage = "No errors";
          IRuntimeNode rootNode = null;
          Configuration cfg = null;
          //set the context and create the cio object
          context = new CZWebAppsContext(dbcFileName);
          cio = new CIO(); // Create shared global CIO
          // Create the ConfigParameters object and set non-default parameters
          int modelId = 34272620;
          String lineId = "155184891"; //used to pass oe line id as client_line
          ConfigParameters cp = new ConfigParameters(modelId);
          java.util.Calendar modelLookupDate = Calendar.getInstance(); //current date and time
          //start the configuration using the cio object previously created
          try {
            cp.addUserParam("client_line", lineId);
            cfg = cio.startConfiguration(cp, context);
            rootNode = (IRuntimeNode)cfg.getRootBomModel();
          } catch (Exception e) {
            errMessage = e.getMessage();
          //This part was important.  For some reason, when you launch the model, the ROOT node is NOT selected as we would normally expect
          //This part of the code will select the top/root node of the configuration.
          String exceptionOutput = "no errors";
          if (rootNode instanceof StateNode) {
               StateNode stateRootNode = (StateNode)rootNode;
               try {
                    ConfigTransaction tr = cfg.beginConfigTransaction();
               } catch (Exception e) {
                    exceptionOutput = "Exception Encountered: " + e.getMessage();
          //Here you can now begin side-affecting the model using your standard CIO calls (eg. set values, select options, etc.).  Be sure to use Config Transactions.
          //I have noticed that if you have CXs that you want to execute at the end of the configuration, you will need specifically tell the config object to execute the event.
          //I don't recall exactly how this was called, but it should be documented in the JavaDoc or in the CX Guide.
          //Now we have to close out the session
          String errMessageB = "No errors";
          long configHdrId = 0;
          long configRevNbr = 0;
          boolean configValid = false;
          boolean configComplete = false;
          try {
            configHdrId = cfg.getConfigHeaderIdLong();
            configRevNbr = cfg.getConfigHeaderRevisionLong();
            configValid = cfg.isValid();
            configComplete = cfg.isComplete();
          } catch (Exception e) {
            errMessageB = e.getMessage();
          Edited by: JasonBatzlaff on Nov 20, 2012 7:33 AM