Exemplo n.º 1
0
 @Override
 public void actionPerformed(java.awt.event.ActionEvent evt) {
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           JFileChooser fileChooser = MainFrame.getFileChooser();
           fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter());
           fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
           fileChooser.setMultiSelectionEnabled(false);
           if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
             File file = fileChooser.getSelectedFile();
             try {
               MainFrame.lockGUI("Serializing JAPE Transducer...");
               FileOutputStream out = new FileOutputStream(file);
               ObjectOutputStream s = new ObjectOutputStream(out);
               serialize(s);
               s.close();
               out.close();
             } catch (IOException ioe) {
               JOptionPane.showMessageDialog(
                   MainFrame.getInstance(),
                   "Error!\n" + ioe.toString(),
                   "GATE",
                   JOptionPane.ERROR_MESSAGE);
               ioe.printStackTrace(Err.getPrintWriter());
             } finally {
               MainFrame.unlockGUI();
             }
           }
         }
       };
   Thread thread = new Thread(runnable, "Transduer Serialization");
   thread.setPriority(Thread.MIN_PRIORITY);
   thread.start();
 }
Exemplo n.º 2
0
  /**
   * Loads any custom operators and annotation accessors into the ConstraintFactory.
   *
   * @throws ResourceInstantiationException
   */
  protected void initCustomConstraints() throws ResourceInstantiationException {
    // Load operators
    if (operators != null) {
      for (String opName : operators) {
        Class<? extends ConstraintPredicate> clazz = null;
        try {
          clazz =
              Class.forName(opName, true, Gate.getClassLoader())
                  .asSubclass(ConstraintPredicate.class);
        } catch (ClassNotFoundException e) {
          // if couldn't find it that way, try with current thread class loader
          try {
            clazz =
                Class.forName(opName, true, Thread.currentThread().getContextClassLoader())
                    .asSubclass(ConstraintPredicate.class);
          } catch (ClassNotFoundException e1) {
            throw new ResourceInstantiationException(
                "Cannot load class for operator: " + opName, e1);
          }
        } catch (ClassCastException cce) {
          throw new ResourceInstantiationException(
              "Operator class '" + opName + "' must implement ConstraintPredicate");
        }

        // instantiate an instance of the class so can get the operator string
        try {
          ConstraintPredicate predicate = clazz.newInstance();
          String opSymbol = predicate.getOperator();
          // now store it in ConstraintFactory
          Factory.getConstraintFactory().addOperator(opSymbol, clazz);
        } catch (Exception e) {
          throw new ResourceInstantiationException(
              "Cannot instantiate class for operator: " + opName, e);
        }
      }
    }

    // Load annotationAccessors
    if (annotationAccessors != null) {
      for (String accessorName : annotationAccessors) {
        Class<? extends AnnotationAccessor> clazz = null;
        try {
          clazz =
              Class.forName(accessorName, true, Gate.getClassLoader())
                  .asSubclass(AnnotationAccessor.class);
        } catch (ClassNotFoundException e) {
          // if couldn't find it that way, try with current thread class loader
          try {
            clazz =
                Class.forName(accessorName, true, Thread.currentThread().getContextClassLoader())
                    .asSubclass(AnnotationAccessor.class);
          } catch (ClassNotFoundException e1) {
            throw new ResourceInstantiationException(
                "Cannot load class for accessor: " + accessorName, e1);
          }
        } catch (ClassCastException cce) {
          throw new ResourceInstantiationException(
              "Operator class '" + accessorName + "' must implement AnnotationAccessor");
        }

        // instantiate an instance of the class so can get the meta-property name string
        try {
          AnnotationAccessor aa = clazz.newInstance();
          String accSymbol = (String) aa.getKey();
          // now store it in ConstraintFactory
          Factory.getConstraintFactory().addMetaProperty(accSymbol, clazz);
        } catch (Exception e) {
          throw new ResourceInstantiationException(
              "Cannot instantiate class for accessor: " + accessorName, e);
        }
      }
    }
  }