Exemple #1
0
  /**
   * forward an execute request to a helper instance associated with the rule
   *
   * @param recipient the recipient of the method from which execution of this rule was triggered or
   *     null if it was a static method
   * @param args the arguments of the method from which execution of this rule was triggered
   */
  private void execute(Object recipient, Object[] args) throws ExecuteException {
    // type check and createHelperAdapter the rule now if it has not already been done

    if (ensureTypeCheckedCompiled()) {

      // create a helper and get it to execute the rule
      // eventually we will create a subclass of helper for each rule and createHelperAdapter
      // an implementation of execute from the rule source. for now we create a generic
      // helper and call the generic execute method which interprets the rule
      HelperAdapter helper;
      try {
        Constructor constructor = helperImplementationClass.getConstructor(Rule.class);
        helper = (HelperAdapter) constructor.newInstance(this);
        // helper = (RuleHelper)helperClass.newInstance();
        // helper.setRule(this);
        helper.execute(recipient, args);
      } catch (NoSuchMethodException e) {
        // should not happen!!!
        System.out.println(
            "cannot find constructor "
                + helperImplementationClass.getCanonicalName()
                + "(Rule) for helper class");
        e.printStackTrace(System.out);
        return;
      } catch (InvocationTargetException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (InstantiationException e) {
        // should not happen
        System.out.println(
            "cannot create instance of " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (IllegalAccessException e) {
        // should not happen
        System.out.println("cannot access " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (ClassCastException e) {
        // should not happen
        System.out.println("cast exception " + helperImplementationClass.getCanonicalName());
        e.printStackTrace(System.out);
        return;
      } catch (EarlyReturnException e) {
        throw e;
      } catch (ThrowException e) {
        throw e;
      } catch (ExecuteException e) {
        System.out.println(getName() + " : " + e);
        throw e;
      } catch (Throwable throwable) {
        System.out.println(getName() + " : " + throwable);
        throw new ExecuteException(getName() + "  : caught " + throwable, throwable);
      }
    }
  }
    public void actionPerformed(ActionEvent e) {
      try {
        JMenuItem tmp = (JMenuItem) e.getSource();

        if (tmp == sudNew) {
          //	generateNewSud();
          generateNewSud();
          tmp.setEnabled(false);
        } else if (tmp == sudOpen) {
          doLoad();
        } else if (tmp == sudSaveAs) {
          doSave();
        } else if (tmp == opDiffEasy) {
          diff = GV.DIFF_EASY;
        } else if (tmp == opDiffNormal) {
          diff = GV.DIFF_NORMAL;
        } else if (tmp == opDiffHard) {
          diff = GV.DIFF_HARD;
        } else if (tmp == opDiffCustom) {
          doCustomDiff();
        } else if (tmp == opND1) {
          nD = NumDistributuon.evenlyFilled3x3Cubes;
        } else if (tmp == opND2) {
          nD = NumDistributuon.evenlyDistributedNumbers;
        } else if (tmp == opND3) {
          nD = NumDistributuon.random;
        } else if (tmp == helpAbout) {
          doAbout();
        } else if (tmp == sudExit) {
          doExit();
        } else if (tmp == sudSolve) {

          // doSolve();
          boolean b = checkIfSolved();
          System.out.println(b);
          // if(!checkIfSolved())

          if (!checkIfSolved()) {
            System.out.println("Inside if");
            doNotSolved();

          } else {
            doSolved();
          }

        } else if (tmp == sudCreate) {
          doCreate();
        } else if (tmp == sudClear) {
          doClear();
        }
      } catch (ClassCastException ex) {
        ex.printStackTrace();
      }
    }
    public void actionPerformed(ActionEvent e) {
      try {
        JButton tmp = (JButton) e.getSource();
        tmp.requestFocus();
        tmp.getText();
        if (lastBut != null) {
          lastBut.setForeground(Color.BLACK);
        }
        lastBut = tmp;
        lastBut.setForeground(Color.BLUE);

      } catch (ClassCastException ex) {
        ex.printStackTrace();
      }
    }
  public void update(Observable arg0, Object arg1) {
    try {
      FieldVals fv = (FieldVals) arg1;
      gg.getGrid().setField(fv.getY(), fv.getX(), fv.getVal());
      boolean b = gg.getGrid().isGridSolved();
      // -----------------------------------------------------------------------------------

      // boolean b = true;
      /*
       * if(b) { sGrid.repaint(); doSolved(); }
       */

      // -----------------------------------------------------------------------------------
    } catch (ClassCastException ex) {
      ex.printStackTrace();
    }
  }
  public static void main(String[] args) {

    // example query
    String query = "SELECT ?s ?p ?o from <sesame> WHERE { ?s ?p ?o }";

    try {

      VirtuosoAdminListener _report = null;

      VirtuosoRepository rep =
          new VirtuosoRepository("sesame", "jdbc:virtuoso://localhost:1111", "dba", "dba");

      rep.clear(_report);

      File dataFile = new File("virtuoso_driver/data.nt");
      rep.addData(dataFile, null, RDFFormat.NTRIPLES, false, _report);

      // execute query

      QueryResultsTable result = rep.performTableQuery(null, query);

      System.out.println("result.getRowCount = " + result.getRowCount());

    } catch (AccessDeniedException ade) {
      System.out.println("Access denied.");
      System.out.println(ade.getMessage());
    } catch (FileNotFoundException fnfe) {
      System.out.println("File not found.");
      System.out.println(fnfe.getMessage());
    } catch (IOException ioe) {
      System.out.println("I/O error.");
      System.out.println(ioe.getMessage());
    } catch (QueryEvaluationException qee) {
      System.out.println("QueryEvaluationException.");
      System.out.println(qee.getMessage());
    } catch (MalformedQueryException mqe) {
      System.out.println("Malformed query - SimpleExample.");
      System.out.println(mqe.getMessage());
      mqe.printStackTrace();
    } catch (ClassCastException cce) {
      System.out.println("ClassCastException repository.");
      System.out.println(cce.getMessage());
      cce.printStackTrace();
    }
  }
    public void actionPerformed(ActionEvent e) {
      try {
        JButton tmp = (JButton) e.getSource();

        if (tmp == bUp[0]) {
          generateNewSud();
          tmp.setEnabled(false);
        } else if (tmp == bUp[1]) {
          doCreate();
        } else if (tmp == bUp[2]) {
          doLoad();
        } else if (tmp == bUp[3]) {
          doSave();
        } else if (tmp == bUp[6]) {
          doClear();
        } else if (tmp == bUp[8]) {
          // doSolve();
          // -----------------------------------------------
          System.out.println("Button is clicked");
          boolean b = checkIfSolved();

          System.out.println(b);
          // if(!checkIfSolved())

          if (!checkIfSolved()) {
            System.out.println("Inside if");
            doNotSolved();
          } else {
            doSolved();
          }

          // doSolved();

          // -----------------------------------------------
        } else if (tmp == bUp[9]) {
          doExit();
        }
      } catch (ClassCastException ex) {
        ex.printStackTrace();
      }
    }
  /**
   * if any error in code, exiting in case of trbrl: open up a warning dialog, and return false;
   *
   * <p>algo:
   *
   * <p>. add providers
   *
   * <p>. open keystoreSource . open keystoreKstTarget . select aliasSource pointing to valid
   * kprSource . get respective keySource & crtsSource
   *
   * <p>. create new keypair . create new certificate of type X.509 . assign new entry to open
   * [JKS-JCEKS-PKCS12-BKS-UBER] keystore . save [JKS-JCEKS-PKCS12-BKS-UBER] keystore
   */
  protected boolean _doJob_(KeyStore kstOpenSource, KeyStore kstOpenTarget, File fleOpenKstTarget) {
    String strMethod = "_doJob_(kstOpenSource, kstOpenTarget, fleOpenKstTarget)";

    if (kstOpenSource == null || kstOpenTarget == null || fleOpenKstTarget == null)
      MySystem.s_printOutExit(this, strMethod, "nil arg");

    // --
    // . select aliasSource and password pointing to valid kprSource

    // ----
    // get aliases

    // NEW

    String[] strsAliasPKTCSource = UtilKstAbs.s_getStrsAliasPKTC(super._frmOwner_, kstOpenSource);

    if (strsAliasPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil strsAliasPKTCSource");
    }

    String[] strsAliasSKSource = UtilKstAbs.s_getStrsAliasSK(super._frmOwner_, kstOpenSource);

    if (strsAliasSKSource == null) {
      MySystem.s_printOutExit(strMethod, "nil strsAliasPKTCSource");
    }

    // --
    // get arrays for dialogTableSelectKeypair
    // TC versus PK
    Boolean[] boosIsTCEntryPKTCSource =
        UtilKstAbs.s_getBoosEntryTcr(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (boosIsTCEntryPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil boosIsTCEntryPKTCSource");
    }

    Boolean[] boosValidDatePKTCSource =
        UtilKstAbs.s_getBoosValidDatePKTC(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (boosValidDatePKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil boosValidDatePKTCSource");
    }

    Boolean[] boosSelfSignedCertPKTCSource =
        UtilKstAbs.s_getBoosSelfSigned(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (boosSelfSignedCertPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil boosSelfSignedCertPKTCSource");
    }

    Boolean[] boosTrustedCertPKTCSource =
        UtilKstAbs.s_getBoosTrusted(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (boosTrustedCertPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil boosTrustedCertPKTCSource");
    }

    String[] strsSizeKeyPublPKTCSource =
        UtilKstAbs.s_getStrsSizeKeyPubl(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (strsSizeKeyPublPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil strsSizeKeyPublPKTCSource");
    }

    String[] strsTypeCertPKTCSource =
        UtilKstAbs.s_getStrsTypeCertificatePKTC(
            super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (strsTypeCertPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil strsTypeCertPKTCSource");
    }

    String[] strsAlgoSigCertPKTCSource =
        UtilKstAbs.s_getStrsAlgoSigCertPKTC(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (strsAlgoSigCertPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil strsAlgoSigCertPKTCSource");
    }

    Date[] dtesLastModifiedPKTCSource =
        UtilKstAbs.s_getDtesLastModified(super._frmOwner_, kstOpenSource, strsAliasPKTCSource);

    if (dtesLastModifiedPKTCSource == null) {
      MySystem.s_printOutExit(strMethod, "nil dtesLastModifiedPKTCSource");
    }

    Date[] dtesLastModifiedSKSource =
        UtilKstAbs.s_getDtesLastModified(super._frmOwner_, kstOpenSource, strsAliasSKSource);

    if (dtesLastModifiedSKSource == null) {
      MySystem.s_printOutExit(strMethod, "nil dtesLastModifiedPKTCSource");
    }

    /*String[] strsAliasSource = UtilKstAbs.s_getStrsAlias(
        super._frmOwner_,

        kstOpenSource);

    if (strsAliasSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil strsAliasSource");
        return false;
    }

    // ----
    // check for existing aliases

    if (strsAliasSource.length < 1)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutWarning(this, strMethod, "strsAliasSource.length < 1");

        String strBody = "source keystore does not contain any entry.";


        OPAbstract.s_showDialogInfo(
            super._frmOwner_, strBody);

        return false;
    }

    // --
    // fill in table for dialogSelect

    Boolean[] boosEntryTcrSource = UtilKstAbs.s_getBoosEntryTcr(
        super._frmOwner_, kstOpenSource, strsAliasSource);

    if (boosEntryTcrSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosEntryTcrSource");
        return false;
    }

    Boolean[] boosEntryKprSource = UtilKstAbs.s_getBoosEntryKpr(
        super._frmOwner_, kstOpenSource, strsAliasSource);

    if (boosEntryKprSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosEntryKprSource");
        return false;
    }

    Boolean[] boosSelfSignedCertSource = UtilKstAbs.s_getBoosSelfSigned(
        super._frmOwner_, kstOpenSource, strsAliasSource);

    if (boosSelfSignedCertSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosSelfSignedCertSource");
        return false;
    }


    Boolean[] boosTrustedCertSource =
        UtilKstAbs.s_getBoosTrusted(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (boosTrustedCertSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosTrustedCertSource");
        return false;
    }

    String[] strsSizeKeyPublSource = UtilKstAbs.s_getStrsSizeKeyPubl(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (strsSizeKeyPublSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil strsSizeKeyPublSource");
        return false;
    }

    String[] strsAlgoKeyPublSource = UtilKstAbs.s_getStrsAlgoKeyPubl(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (strsAlgoKeyPublSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil strsAlgoKeyPublSource");
        return false;
    }

    String[] strsTypeCertSource = UtilKstAbs.s_getStrsTypeCertificatePKTC(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (strsTypeCertSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil strsTypeCertSource");
        return false;
    }

    String[] strsAlgoSigCertSource = UtilKstAbs.s_getStrsAlgoSigCertPKTC(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (strsAlgoSigCertSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil strsAlgoSigCertSource");
        return false;
    }

    Date[] dtesLastModifiedSource = UtilKstAbs.s_getDtesLastModified(super._frmOwner_, kstOpenSource, strsAliasSource);

    if (dtesLastModifiedSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil dtesLastModifiedSource");
        return false;
    }

    // ----

    Boolean[] boosTypeCertX509Source = super._getBoosTypeCertX509_(kstOpenSource, strsAliasSource);

    if (boosTypeCertX509Source == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosTypeCertX509Source");
        return false;
    }

    Boolean[] boosElligibleSource = super._getBoosElligibleAny_(
        boosEntryKprSource, strsAlgoKeyPublSource,
        boosTypeCertX509Source);

    if (boosElligibleSource == null)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "nil boosElligibleSource");
        return false;
    }

    // --
    // clean-up
    boosTypeCertX509Source = null;

    // ---
    // check for elligible entry

    boolean blnElligible = false;

    for (int i=0; i<boosElligibleSource.length; i++)
    {
        if (boosElligibleSource[i].booleanValue() == true)
        {
            blnElligible = true;
            break;
        }
    }

    if (! blnElligible)
    {
        super._setEnabledCursorWait_(false);
        MySystem.s_printOutError(this, strMethod, "! blnElligible");

        String strBody = "source keystore does not contain any keypair entry\n either of type RSA, or of type DSA, with an X.509 certificate .";

        OPAbstract.s_showDialogInfo(
            super._frmOwner_, strBody);

        return false;
    }*/

    // --
    // assign default cursor

    super._setEnabledCursorWait_(false);

    // ----

    /*DTblEntryKprOpenKPAny dlgSource = new DTblEntryKprOpenKPAny(
    super._frmOwner_,
    super._strTitleAppli_,
    kstOpenSource
    );*/

    DTblsKstSelPKOpen dlgSource =
        new DTblsKstSelPKOpen(
            super._frmOwner_,
            kstOpenSource,
            super._strPathAbsKst_,
            "Import private key from other keystore - step 1/2: source");

    if (!dlgSource.init()) MySystem.s_printOutExit(this, strMethod, "failed");

    //
    if (!dlgSource.load(
        strsAliasPKTCSource,
        boosIsTCEntryPKTCSource,
        boosValidDatePKTCSource,
        boosSelfSignedCertPKTCSource,
        boosTrustedCertPKTCSource,
        strsSizeKeyPublPKTCSource,
        strsTypeCertPKTCSource,
        strsAlgoSigCertPKTCSource,
        dtesLastModifiedPKTCSource,
        // below: about SK (Secret Key)
        strsAliasSKSource,
        dtesLastModifiedSKSource

        /*boosElligibleSource, strsAliasSource,
        boosEntryKprSource,
        boosEntryTcrSource,
        boosSelfSignedCertSource,
        boosTrustedCertSource,
        strsAlgoKeyPublSource,
        strsSizeKeyPublSource,
        strsTypeCertSource,
        strsAlgoSigCertSource, dtesLastModifiedSource*/ )) {
      MySystem.s_printOutExit(this, strMethod, "failed");
    }

    dlgSource.setVisible(true);

    // ---
    char[] chrsPasswdKprSource = dlgSource.getPassword();

    if (chrsPasswdKprSource == null) {
      MySystem.s_printOutTrace(this, strMethod, "nil chrsPasswdKprSource, aborted by user");
      return false;
    }

    String strAliasKprSource = dlgSource.getAlias();

    if (strAliasKprSource == null) {
      MySystem.s_printOutTrace(this, strMethod, "nil strAliasKprSource, aborted by user");
      return false;
    }

    // super._setEnabledCursorWait_(true);

    // at this level, user selected keypair (got alias & password)

    // --
    // . get respective keySource & crtsSource

    // ----
    // x) get privateKey

    PrivateKey pkySource = null;

    try {
      pkySource =
          (PrivateKey)
              UtilKstAbs.s_getKey(
                  super._frmOwner_, kstOpenSource, strAliasKprSource, chrsPasswdKprSource);
    } catch (ClassCastException excClassCast) {
      excClassCast.printStackTrace();
      MySystem.s_printOutExit(this, strMethod, "excClassCast caught");
    }

    if (pkySource == null) {
      MySystem.s_printOutError(this, strMethod, "nil pkySource");
      return false;
    }

    // ----
    // x) get X509Certificates

    X509Certificate[] crtsX509UnorderedSource =
        UtilCrtX509.s_getX509CertificateChain(
            kstOpenSource,
            strAliasKprSource,
            false // blnOrderChain !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            );

    if (crtsX509UnorderedSource == null) {
      MySystem.s_printOutError(this, strMethod, "nil crtsX509UnorderedSource");
      return false;
    }

    // -----

    if (!__createNewEntry__(kstOpenTarget, pkySource, crtsX509UnorderedSource)) {
      super._setEnabledCursorWait_(false);
      MySystem.s_printOutError(this, strMethod, "failed");
      return false;
    }

    // ----
    // save kstOpenTarget

    if (super._chrsPasswdKst_ == null) {
      MySystem.s_printOutError(this, strMethod, "nil super._chrsPasswdKst_");
      return false;
    }

    // ----

    if (!super._saveKeyStore_(kstOpenTarget, fleOpenKstTarget, super._chrsPasswdKst_)) {
      MySystem.s_printOutError(this, strMethod, "failed");
      return false;
    }

    // ending
    return true;
  }
  /*
   * Create and open a Connection.
   * <p>
   * There are 2 ways to find a connection implementation.
   * 1. Get the class name from a system property generated in the form of:
   * <pre>
   *    j2me.{connection protocol}.protocol
   * </pre>
   * 2. Use the class root (see getClassRoot) and the connection
   * protocol to dynamically construct a class name in the the form of:
   * <pre>
   *   {class root}.j2me.{connection protocol}.Protocol
   * </pre>
   * The connection protocol is parsed from the <code>name</code> parameter
   * which takes the form of:
   * <pre>
   *   {connection protocol}:{protocol specific part}
   * </pre>
   * In order to avoid problems with illegal
   * class file names, all the '-' characters in the connection protocol
   * are automatically converted into '_' characters.
   * <p>
   * Additionally the protocol specific part is parsed from the name
   * parameter and passed to the connection's factory method.
   *
   * @param name             The URL for the connection
   * @param mode             The access mode
   * @param timeouts         A flag to indicate that the caller
   *                         wants timeout exceptions
   *
   * @return                 A new Connection object
   *
   * @exception IllegalArgumentException If a parameter is invalid.
   * @exception ConnectionNotFoundException If the target of the
   *   name cannot be found, or if the requested protocol type
   *   is not supported.
   * @exception IOException If some other kind of I/O error occurs.
   * @exception IllegalArgumentException If a parameter is invalid.
   */
  public Connection open(String name, int mode, boolean timeouts) throws IOException {
    String oemPrefix = "";
    /* Test for null argument */
    if (name == null) {
      throw new IllegalArgumentException("Null URL");
    }
    try {
      /*
       * Check for OEM specific http and https handler override.
       */
      oemPrefix =
          (String)
              java.security.AccessController.doPrivileged(
                  new GetPropertyAction("oem.http.handler.prefix", ""));
    } catch (Throwable t) {
      // do nothing
    }

    if (name.startsWith("http")) {
      name = oemPrefix + name;
    }

    /* Look for : as in "http:", "file:", or whatever */
    int colon = name.indexOf(':');
    if (colon == -1) {
      throw new IllegalArgumentException("Illegal protocol");
    }
    try {
      String protocol;

      /* Strip off the protocol name */
      protocol = name.substring(0, colon).toLowerCase();
      checkProtocol(protocol);
      /* Strip off the rest of the string */
      name = name.substring(colon + 1);

      /*
       * Convert all the '-' characters in the protocol
       * name to '_' characters (dashes are not allowed
       * in class names).  This operation creates garbage
       * only if the protocol name actually contains dashes
       */
      protocol = protocol.replace('-', '_');

      /*
       * Use the platform and protocol names to look up
       * a class to implement the connection
       */
      String className = getClassRoot() + "." + "j2me" + "." + protocol + ".Protocol";
      Class clazz = Class.forName(className, true, getProtocolClassLoader());

      /* Construct a new instance of the protocol */
      ConnectionBaseInterface uc = (ConnectionBaseInterface) clazz.newInstance();

      /* Open the connection, and return it */
      return uc.openPrim(name, mode, timeouts);
    } catch (InstantiationException x) {
      throw new IOException(x.toString());
    } catch (IllegalAccessException x) {
      throw new IOException(x.toString());
    } catch (ClassCastException x) {
      throw new IOException(x.toString());
    } catch (ClassNotFoundException x) {
      throw new ConnectionNotFoundException("The requested protocol does not exist " + name);
    }
  }