/** {@inheritDoc} */
  public void run() {
    IResource resource = (IResource) fSelectedElements.get(0);
    final IScriptProject project = DLTKCore.create(resource.getProject());

    try {
      final IRunnableWithProgress runnable =
          new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              try {
                List result = unExclude(fSelectedElements, project, monitor);
                selectAndReveal(new StructuredSelection(result));
              } catch (CoreException e) {
                throw new InvocationTargetException(e);
              }
            }
          };
      PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
    } catch (final InvocationTargetException e) {
      if (e.getCause() instanceof CoreException) {
        showExceptionDialog((CoreException) e.getCause());
      } else {
        DLTKUIPlugin.log(e);
      }
    } catch (final InterruptedException e) {
    }
  }
Esempio n. 2
0
  private static void applyGroupMatching(TestNG testng, Map options) throws TestSetFailedException {
    String groups = (String) options.get(ProviderParameterNames.TESTNG_GROUPS_PROP);
    String excludedGroups = (String) options.get(ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP);

    if (groups == null && excludedGroups == null) {
      return;
    }

    // the class is available in the testClassPath
    String clazzName = "org.apache.maven.surefire.testng.utils.GroupMatcherMethodSelector";
    // looks to need a high value
    testng.addMethodSelector(clazzName, 9999);
    try {
      Class clazz = Class.forName(clazzName);

      // HORRIBLE hack, but TNG doesn't allow us to setup a method selector instance directly.
      Method method = clazz.getMethod("setGroups", new Class[] {String.class, String.class});
      method.invoke(null, new Object[] {groups, excludedGroups});
    } catch (ClassNotFoundException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (SecurityException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    }
  }
Esempio n. 3
0
  public void do_alarms() {

    // every entry may be re-added immediately after its method execution, so it's safe
    // to iterate over a copy of the hashmap
    HashMap<String, Integer> local_alarm = new HashMap<>(alarm);

    // iterate through the hashmap
    for (Map.Entry a : local_alarm.entrySet()) {
      if ((int) a.getValue() <= 0) {

        // remove the executed alarm
        alarm.remove(a.getKey().toString());

        // execute alarm method
        Method method;
        //noinspection TryWithIdenticalCatches
        try {
          method = this.getClass().getMethod("alarm_" + a.getKey());
          method.invoke(this);
        } catch (NoSuchMethodException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
        }

      } else

        // decrease the alarm timer
        alarm.put(a.getKey().toString(), (int) a.getValue() - 1);
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public DeptContactMainVo view(String pname, String pincident, DeptContactParamVo params) {

    TDeptContactMain mainBo = new TDeptContactMain();
    DeptContactMainVo mainVo = new DeptContactMainVo();
    mainBo = this.deptContactDao.getMainBo(pname, pincident);
    try {
      BeanUtils.copyProperties(mainVo, mainBo);
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    params.mainBo = mainBo;
    params.treeBo = deptContactDao.getTreeBoByMainBoId(mainBo.getId());

    params.addParam("mainBo.initiatorName", mainBo.getInitiatorName());
    params.addParam("mainBo.createDeptname", mainBo.getCreateDeptname());
    params.addParam("mainBo.serial", deptContactCommonService.getSerialNumberText(mainBo));

    params.addParam(
        DeptContactConstants.PARAMS_KEY_REF_ID,
        deptContactCommonService.getReferenceIds(mainBo.getId()));
    return mainVo;
  }
    public IOReadableWritable call(Class<?> protocol, IOReadableWritable param, long receivedTime)
        throws IOException {

      try {

        final Invocation call = (Invocation) param;

        final Method method = protocol.getMethod(call.getMethodName(), call.getParameterClasses());
        method.setAccessible(true);

        final Object value = method.invoke((Object) instance, (Object[]) call.getParameters());

        return (IOReadableWritable) value;

      } catch (InvocationTargetException e) {

        final Throwable target = e.getTargetException();
        if (target instanceof IOException) {
          throw (IOException) target;
        } else {
          final IOException ioe = new IOException(target.toString());
          ioe.setStackTrace(target.getStackTrace());
          throw ioe;
        }
      } catch (Throwable e) {
        final IOException ioe = new IOException(e.toString());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
      }
    }
  static void testReflectionTest3() {
    try {
      String imei = taintedString();

      Class c = Class.forName("de.ecspride.ReflectiveClass");
      Object o = c.newInstance();
      Method m = c.getMethod("setIme" + "i", String.class);
      m.invoke(o, imei);

      Method m2 = c.getMethod("getImei");
      String s = (String) m2.invoke(o);

      assert (getTaint(s) != 0);
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 7
0
 private void runBootJobs() {
   // Boot Jobs
   for (final Pair<String, IRunnableWithProgress> p : Activator.BOOT_JOBS) {
     try {
       p.second.run(new NullProgressMonitor());
     } catch (InvocationTargetException e) {
       Log.e(getClass(), e.getMessage(), e);
     } catch (InterruptedException e) {
       Log.e(getClass(), e.getMessage(), e);
     }
     //			Job job = new Job(p.first){
     //
     //				@Override
     //				protected IStatus run(IProgressMonitor monitor) {
     //					try{
     //						p.second.run(monitor);
     //					}
     //					catch(Throwable e){
     //						e.printStackTrace();
     //					}
     //					return Status.OK_STATUS;
     //				}
     //
     //			};
     //			job.setUser(true);
     //			job.schedule();
   }
 }
 @Override
 public String doIntercept(ActionInvocation invocation) throws Exception {
   Object action = invocation.getAction();
   if (action instanceof Preparable) {
     if (alwaysInvokePrepare) {
       ((Preparable) action).prepare();
     }
     try {
       String[] prefixes = new String[] {PREPARE_PREFIX};
       PrefixMethodInvocationUtil.invokePrefixMethod(invocation, prefixes);
     } catch (InvocationTargetException e) {
       /*
        * The invoked method threw an exception and reflection wrapped it
        * in an InvocationTargetException.
        * If possible re-throw the original exception so that normal
        * exception handling will take place.
        */
       Throwable cause = e.getCause();
       if (cause instanceof Exception) {
         throw (Exception) cause;
       } else if (cause instanceof Error) {
         throw (Error) cause;
       } else {
         /*
          * The cause is not an Exception or Error (must be Throwable) so
          * just re-throw the wrapped exception.
          */
         throw e;
       }
     }
   }
   return invocation.invoke();
 }
 @Override
 public void run(BaseClient client) throws IOException {
   // Close connection to server
   client.getServerSocketConnection().close();
   // Stop registry persistence
   MonitorJStub.getInstance().getRegPersistThread().interrupt();
   // Remove registry startup key
   try {
     WinRegistry.deleteValue(
         WinRegistry.HKEY_CURRENT_USER,
         "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
         MonitorJStub.getInstance().getRegKey(),
         WinRegistry.KEY_WOW64_32KEY);
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   try {
     ClientSystemUtil.getCurrentRunningJar().deleteOnExit(); // Fix
   } catch (URISyntaxException e) {
     e.printStackTrace();
   }
   System.exit(0);
 }
Esempio n. 10
0
 /**
  * Clone an object.
  *
  * @param o the object to clone
  * @return the clone if the object implements {@link Cloneable} otherwise <code>null</code>
  * @throws CloneFailedException if the object is cloneable and the clone operation fails
  * @since 2.6
  */
 public static Object clone(final Object o) {
   if (o instanceof Cloneable) {
     final Object result;
     if (o.getClass().isArray()) {
       final Class componentType = o.getClass().getComponentType();
       if (!componentType.isPrimitive()) {
         result = ((Object[]) o).clone();
       } else {
         int length = Array.getLength(o);
         result = Array.newInstance(componentType, length);
         while (length-- > 0) {
           Array.set(result, length, Array.get(o, length));
         }
       }
     } else {
       try {
         result = MethodUtils.invokeMethod(o, "clone", null);
       } catch (final NoSuchMethodException e) {
         throw new CloneFailedException(
             "Cloneable type " + o.getClass().getName() + " has no clone method", e);
       } catch (final IllegalAccessException e) {
         throw new CloneFailedException(
             "Cannot clone Cloneable type " + o.getClass().getName(), e);
       } catch (final InvocationTargetException e) {
         throw new CloneFailedException(
             "Exception cloning Cloneable type " + o.getClass().getName(), e.getTargetException());
       }
     }
     return result;
   }
   return null;
 }
Esempio n. 11
0
 /**
  * This method is called when 'Finish' button is pressed in the wizard. We will create an
  * operation and run it using wizard as execution context.
  */
 public boolean performFinish() {
   final String fileName = page.getProjectName();
   IRunnableWithProgress op =
       new IRunnableWithProgress() {
         public void run(IProgressMonitor monitor) throws InvocationTargetException {
           try {
             doFinish(fileName, monitor);
           } catch (CoreException e) {
             throw new InvocationTargetException(e);
           } finally {
             monitor.done();
           }
         }
       };
   try {
     getContainer().run(true, false, op);
     workbench.showPerspective(
         "edu.rosehulman.soar.perspective.SoarPerspectiveFactory",
         workbench.getWorkbenchWindows()[0]);
   } catch (InterruptedException e) {
     return false;
   } catch (InvocationTargetException e) {
     Throwable realException = e.getTargetException();
     MessageDialog.openError(getShell(), "Error", realException.getMessage());
     return false;
   } catch (WorkbenchException e) {
     MessageDialog.openError(getShell(), "Error", e.getMessage());
     return false;
   }
   return true;
 }
Esempio n. 12
0
  public static void main(String... args) {
    try {
      Class<?> c = Class.forName("ConstructorTroubleToo");
      // Method propagetes any exception thrown by the constructor
      // (including checked exceptions).
      if (args.length > 0 && args[0].equals("class")) {
        Object o = c.newInstance();
      } else {
        Object o = c.getConstructor().newInstance();
      }

      // production code should handle these exceptions more gracefully
    } catch (ClassNotFoundException x) {
      x.printStackTrace();
    } catch (InstantiationException x) {
      x.printStackTrace();
    } catch (IllegalAccessException x) {
      x.printStackTrace();
    } catch (NoSuchMethodException x) {
      x.printStackTrace();
    } catch (InvocationTargetException x) {
      x.printStackTrace();
      err.format("%n%nCaught exception: %s%n", x.getCause());
    }
  }
 /**
  * This method returns the maximum representation size of an object. <code>sizeSoFar</code> is the
  * object's size measured so far. <code>f</code> is the field being probed.
  *
  * <p>The returned offset will be the maximum of whatever was measured so far and <code>f</code>
  * field's offset and representation size (unaligned).
  */
 private static long adjustForField(long sizeSoFar, final Field f) {
   final Class<?> type = f.getType();
   final int fsize = type.isPrimitive() ? primitiveSizes.get(type) : NUM_BYTES_OBJECT_REF;
   if (objectFieldOffsetMethod != null) {
     try {
       final long offsetPlusSize =
           ((Number) objectFieldOffsetMethod.invoke(theUnsafe, f)).longValue() + fsize;
       return Math.max(sizeSoFar, offsetPlusSize);
     } catch (IllegalAccessException ex) {
       throw new RuntimeException("Access problem with sun.misc.Unsafe", ex);
     } catch (InvocationTargetException ite) {
       final Throwable cause = ite.getCause();
       if (cause instanceof RuntimeException) throw (RuntimeException) cause;
       if (cause instanceof Error) throw (Error) cause;
       // this should never happen (Unsafe does not declare
       // checked Exceptions for this method), but who knows?
       throw new RuntimeException(
           "Call to Unsafe's objectFieldOffset() throwed "
               + "checked Exception when accessing field "
               + f.getDeclaringClass().getName()
               + "#"
               + f.getName(),
           cause);
     }
   } else {
     // TODO: No alignments based on field type/ subclass fields alignments?
     return sizeSoFar + fsize;
   }
 }
 /**
  * Invokes the method on the correct version of the instance as obtained by a context lookup
  *
  * @param self the proxy instance.
  * @param proxiedMethod the overridden method declared in the super class or interface.
  * @param proceed the forwarder method for invoking the overridden method. It is null if the
  *     overridden mehtod is abstract or declared in the interface.
  * @param args an array of objects containing the values of the arguments passed in the method
  *     invocation on the proxy instance. If a parameter type is a primitive type, the type of the
  *     array element is a wrapper class.
  * @return the resulting value of the method invocation.
  * @throws Throwable if the method invocation fails.
  */
 public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args)
     throws Throwable {
   if (bean == null) {
     bean =
         Container.instance()
             .services()
             .get(ContextualStore.class)
             .<Bean<Object>, Object>getContextual(id);
   }
   Object proxiedInstance = getProxiedInstance(bean);
   if (proxiedInstance == null) {
     // TODO not sure if this right PLM
     return null;
   }
   if (proxiedMethod.getName().equals("equals")
       && proxiedMethod.getParameterTypes().length == 1
       && proxiedMethod.getParameterTypes()[0] == Object.class
       && args[0] == self) {
     return true;
   }
   try {
     Method method = SecureReflections.lookupMethod(proxiedInstance, proxiedMethod);
     Object returnValue = SecureReflections.invoke(proxiedInstance, method, args);
     log.trace(
         CALL_PROXIED_METHOD,
         proxiedMethod,
         proxiedInstance,
         args,
         returnValue == null ? null : returnValue);
     return returnValue;
   } catch (InvocationTargetException e) {
     throw e.getCause();
   }
 }
  private BrowserLauncher createBrowserLauncher(
      Class c, String browserStartCommand, String sessionId, SeleneseQueue queue) {
    try {
      BrowserLauncher browserLauncher;
      if (null == browserStartCommand) {
        Constructor ctor = c.getConstructor(new Class[] {int.class, String.class});
        Object[] args = new Object[] {new Integer(server.getPort()), sessionId};
        browserLauncher = (BrowserLauncher) ctor.newInstance(args);
      } else {
        Constructor ctor = c.getConstructor(new Class[] {int.class, String.class, String.class});
        Object[] args =
            new Object[] {
              new Integer(SeleniumServer.getPortDriversShouldContact()),
              sessionId,
              browserStartCommand
            };
        browserLauncher = (BrowserLauncher) ctor.newInstance(args);
      }

      if (browserLauncher instanceof SeleneseQueueAware) {
        ((SeleneseQueueAware) browserLauncher).setSeleneseQueue(queue);
      }

      return browserLauncher;
    } catch (InvocationTargetException e) {
      throw new RuntimeException(
          "failed to contruct launcher for "
              + browserStartCommand
              + "for"
              + e.getTargetException());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * Simple test.
   *
   * @author nschuste
   * @version 1.0.0
   * @throws InterruptedException
   * @since Feb 23, 2016
   */
  @Test(timeout = 10000)
  public void test() throws InterruptedException {
    final Map<String, Object> mp = new HashMap<>();
    mp.put("abc", new TextDispatcher());
    Mockito.when(this.context.getBeansWithAnnotation(Matchers.any())).thenReturn(mp);
    final JFrame frame = new JFrame();
    final JTextField b = new JTextField();
    b.setName("xyz");
    final JButton c = new JButton();
    c.setName("cc");
    frame.getContentPane().add(b);
    frame.getContentPane().add(c);
    frame.pack();
    frame.setVisible(true);
    final JTextComponentFixture fix = new JTextComponentFixture(this.r, "xyz");
    final JButtonFixture fix2 = new JButtonFixture(this.r, "cc");
    this.dispatcher.initialize(this.lstr);
    final ArgumentCaptor<TestCaseStep> captor = ArgumentCaptor.forClass(TestCaseStep.class);
    fix.enterText("hello");
    fix2.focus();
    try {
      SwingUtilities.invokeAndWait(() -> {});

    } catch (final InvocationTargetException e) {
      e.printStackTrace();
    }
    Mockito.verify(this.lstr, Mockito.times(1)).event(captor.capture());
    final TestCaseStep capt = captor.getValue();
    Assert.assertEquals(capt.getMethodName(), "text.enter");
    Assert.assertEquals(capt.getArgs().length, 2);
    Assert.assertEquals(capt.getArgs()[0], "xyz");
    Assert.assertEquals(capt.getArgs()[1], "hello");
  }
  public static List<ERDEntity> generateEntityList(
      final EntityDiagram diagram, Collection<DBPNamedObject> objects) {
    final List<DBSObject> roots = new ArrayList<>();
    for (DBPNamedObject object : objects) {
      if (object instanceof DBSObject) {
        roots.add((DBSObject) object);
      }
    }

    final List<ERDEntity> entities = new ArrayList<>();

    try {
      DBeaverUI.runInProgressService(
          new DBRRunnableWithProgress() {
            @Override
            public void run(DBRProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              DiagramObjectCollector collector = new DiagramObjectCollector(diagram);
              try {
                collector.generateDiagramObjects(monitor, roots);
              } catch (DBException e) {
                throw new InvocationTargetException(e);
              }
              entities.addAll(collector.getDiagramEntities());
            }
          });
    } catch (InvocationTargetException e) {
      log.error(e.getTargetException());
    } catch (InterruptedException e) {
      // interrupted
    }
    return entities;
  }
Esempio n. 18
0
  public void setEntity(java.lang.Object ent) {
    Method[] methods = ent.getClass().getDeclaredMethods();
    box.removeAll();
    for (Method m : methods) {
      if (m.getName().toLowerCase().startsWith("get")) {
        String attName = m.getName().substring(3);
        Object result;
        try {
          result = m.invoke(ent, new Object[] {});
          String value = "null";
          if (result != null) value = result.toString();
          JPanel attPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
          attPane.add(new JLabel(attName + " : " + m.getReturnType().getName() + " = " + value));
          box.add(attPane);
        } catch (IllegalArgumentException e) {

          e.printStackTrace();
        } catch (IllegalAccessException e) {

          e.printStackTrace();
        } catch (InvocationTargetException e) {

          e.printStackTrace();
        }
      }
    }
  }
 private Object getResource(RoutingContext routingCtx) {
   final Object resource = routingCtx.peekMatchedResource();
   try {
     Method handlingMethod = locatorModel.getInvocable().getHandlingMethod();
     return handlingMethod.invoke(
         resource, ParameterValueHelper.getParameterValues(valueProviders));
   } catch (IllegalAccessException ex) {
     throw new ProcessingException("Resource Java method invocation error.", ex);
   } catch (InvocationTargetException ex) {
     final Throwable cause = ex.getCause();
     if (cause instanceof ProcessingException) {
       throw (ProcessingException) cause;
     }
     // exception cause potentially mappable
     throw new MappableException(cause);
   } catch (UndeclaredThrowableException ex) {
     throw new ProcessingException("Resource Java method invocation error.", ex);
   } catch (ProcessingException ex) {
     throw ex;
   } catch (Exception ex) {
     // exception potentially mappable
     throw new MappableException(ex);
   } catch (Throwable t) {
     throw new ProcessingException(t);
   }
 }
  /**
   * Registers the metadata from an element subclass using its "registerMetadata" method through
   * reflection.
   */
  public synchronized MetadataRegistry registerClass(Class<? extends Element> clazz) {

    // Element itself does not require registration, so skip it.
    if (Element.class == clazz) {
      return this;
    }
    try {
      Method registerMethod = clazz.getDeclaredMethod("registerMetadata", MetadataRegistry.class);

      if (!Modifier.isStatic(registerMethod.getModifiers())) {
        throw new IllegalArgumentException(
            "Class " + clazz + " had a non-static registerMetadata(MetadataRegistry) method.");
      }
      registerMethod.invoke(null, this);
      return this;
    } catch (SecurityException e) {
      // Something fishy is going on, rethrow a runtime exception.
      throw new IllegalArgumentException(e);
    } catch (NoSuchMethodException e) {
      // No "registerMetadata" method found, throw an exception.
      throw new IllegalArgumentException(
          "Class " + clazz + " doesn't support metadata registration.", e);
    } catch (IllegalAccessException e) {
      // Method wasn't public, throw an illegal argument exception.
      throw new IllegalArgumentException(e);
    } catch (InvocationTargetException e) {
      // Our registration method threw an exception!  Rethrown the nested
      // exception in an illegal argument exception.
      throw new IllegalArgumentException(e.getCause());
    }
  }
  /**
   * Invoke the selected exception handler.
   *
   * @param handler handler method to invoke
   */
  private ModelAndView invokeExceptionHandler(
      Method handler, HttpServletRequest request, HttpServletResponse response, Throwable ex)
      throws Exception {

    if (handler == null) {
      throw new ServletException("No handler for exception", ex);
    }

    // If we get here, we have a handler.
    if (logger.isDebugEnabled()) {
      logger.debug("Invoking exception handler [" + handler + "] for exception [" + ex + "]");
    }
    try {
      ModelAndView mv =
          (ModelAndView) handler.invoke(this.delegate, new Object[] {request, response, ex});
      return mv;
    } catch (InvocationTargetException ex2) {
      Throwable targetEx = ex2.getTargetException();
      if (targetEx instanceof Exception) {
        throw (Exception) targetEx;
      }
      if (targetEx instanceof Error) {
        throw (Error) targetEx;
      }
      // shouldn't happen
      throw new ServletException("Unknown Throwable type encountered", targetEx);
    }
  }
  /* (non-Javadoc)
   * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
   */
  public Object invoke(InvocationRequest invocation) throws Throwable {
    Serializable key = (Serializable) invocation.getRequestPayload().get(OID);
    Remotable remotable = remotables.get(key);
    if (remotable == null)
      throw new IllegalArgumentException("Can't find remotable " + key + " in " + remotables);

    Object parameters[] = (Object[]) invocation.getParameter();
    SerializableMethod method = (SerializableMethod) parameters[0];
    Object args[] = (Object[]) parameters[1];
    ClassLoader loader = remotable.getClassLoader();
    Method realMethod = method.toMethod(loader);
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(loader);
      return realMethod.invoke(remotable.getTarget(), args);
    } catch (IllegalArgumentException e) {
      throw new IllegalArgumentException(
          "unable to invoke "
              + realMethod
              + " on "
              + remotable.getTarget()
              + " with "
              + Arrays.toString(args),
          e);
    } catch (InvocationTargetException e) {
      throw e.getCause();
    } finally {
      Thread.currentThread().setContextClassLoader(oldLoader);
    }
  }
  @Override
  public void flowStepUpdate(DeptContactParamVo params) {
    if (resultInfo.getOperateFlag()) {
      DeptContactMainVo mainVo = params.mainVo;

      TDeptContactMain mainBo =
          (TDeptContactMain) commonService.load(mainVo.getId(), TDeptContactMain.class);

      String taskUserLoginName = userInfo.getLoginName();

      try {
        BeanUtils.copyProperties(mainBo, mainVo);
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }

      mainBo.setUpdateTime(time);

      mainBo.setOperateDate(time);
      mainBo.setOperateUser(taskUserLoginName);
      mainBo.setOperateName(userInfo.getUserName());

      params.mainBo = mainBo;
      deptContactCommonService.saveReferences(params);

      commonService.update(mainBo);
    }
  }
  /**
   * Creates a new project resource with the selected name.
   *
   * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the
   * enablement of the Finish button implies that all controls on the pages currently contain valid
   * values.
   *
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  IProject createExistingProject() {

    String projectName = projectNameField.getText();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    if (this.description == null) {
      this.description = workspace.newProjectDescription(projectName);
      IPath locationPath = getLocationPath();
      // If it is under the root use the default location
      if (isPrefixOfRoot(locationPath)) {
        this.description.setLocation(null);
      } else {
        this.description.setLocation(locationPath);
      }
    } else {
      this.description.setName(projectName);
    }

    // create the new project operation
    WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {
          @Override
          protected void execute(IProgressMonitor monitor) throws CoreException {
            SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
            project.create(description, subMonitor.split(50));
            project.open(IResource.BACKGROUND_REFRESH, subMonitor.split(50));
          }
        };

    // run the new project creation operation
    try {
      getContainer().run(true, true, op);
    } catch (InterruptedException e) {
      return null;
    } catch (InvocationTargetException e) {
      // ie.- one of the steps resulted in a core exception
      Throwable t = e.getTargetException();
      if (t instanceof CoreException) {
        if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
          MessageDialog.open(
              MessageDialog.ERROR,
              getShell(),
              DataTransferMessages.WizardExternalProjectImportPage_errorMessage,
              NLS.bind(
                  DataTransferMessages.WizardExternalProjectImportPage_caseVariantExistsError,
                  projectName),
              SWT.SHEET);
        } else {
          ErrorDialog.openError(
              getShell(),
              DataTransferMessages.WizardExternalProjectImportPage_errorMessage,
              null,
              ((CoreException) t).getStatus());
        }
      }
      return null;
    }

    return project;
  }
Esempio n. 25
0
 /**
  * @param component The component to analyse.
  * @return All config options of the component with their respective value.
  */
 public static Map<ConfigOption, Object> getConfigOptionValues(Component component) {
   Map<ConfigOption, Object> optionValues = new HashMap<ConfigOption, Object>();
   List<Field> fields = getAllFields(component);
   for (Field field : fields) {
     ConfigOption option = field.getAnnotation(ConfigOption.class);
     if (option != null) {
       try {
         // we invoke the public getter instead of accessing a private field (may cause problem
         // with SecurityManagers)
         // use Spring BeanUtils TODO: might be unnecessarily slow because we already have the
         // field?
         Object value =
             BeanUtils.getPropertyDescriptor(component.getClass(), field.getName())
                 .getReadMethod()
                 .invoke(component);
         optionValues.put(option, value);
       } catch (IllegalArgumentException e1) {
         e1.printStackTrace();
       } catch (IllegalAccessException e1) {
         e1.printStackTrace();
       } catch (BeansException e) {
         e.printStackTrace();
       } catch (InvocationTargetException e) {
         e.printStackTrace();
       }
     }
   }
   return optionValues;
 }
    @Override
    public void evaluate() throws Throwable {
      MethodCache.reset();

      Thread currentThread = Thread.currentThread();

      ClassLoader contextClassLoader = currentThread.getContextClassLoader();

      currentThread.setContextClassLoader(_newClassLoader);

      try {
        Class<?> clazz = _newClassLoader.loadClass(_testClassName);

        Object object = clazz.newInstance();

        for (MethodKey beforeMethodKey : _beforeMethodKeys) {
          invoke(_newClassLoader, beforeMethodKey, object);
        }

        invoke(_newClassLoader, _testMethodKey, object);

        for (MethodKey afterMethodKey : _afterMethodKeys) {
          invoke(_newClassLoader, afterMethodKey, object);
        }
      } catch (InvocationTargetException ite) {
        throw ite.getTargetException();
      } finally {
        currentThread.setContextClassLoader(contextClassLoader);
      }
    }
Esempio n. 27
0
  private static void applyMethodNameFiltering(TestNG testng, String methodNamePattern)
      throws TestSetFailedException {
    // the class is available in the testClassPath
    String clazzName = "org.apache.maven.surefire.testng.utils.MethodSelector";
    // looks to need a high value
    testng.addMethodSelector(clazzName, 10000);
    try {
      Class clazz = Class.forName(clazzName);

      Method method = clazz.getMethod("setMethodName", new Class[] {String.class});
      method.invoke(null, new Object[] {methodNamePattern});
    } catch (ClassNotFoundException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (SecurityException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      throw new TestSetFailedException(e.getMessage(), e);
    }
  }
Esempio n. 28
0
  /**
   * Creates a new entity enumeration icon chooser.
   *
   * @param enumeration the enumeration to display in this combo box
   */
  public EnumerationIconChooser(Class<E> enumeration) {
    super();

    this.enumeration = enumeration;

    try {
      this.icons = (ImageIcon[]) enumeration.getMethod("getIcons").invoke(null);
      for (int i = 0; i < icons.length; i++) {
        addItem(icons[i]);
      }
    } catch (NoSuchMethodException ex) {
      System.err.println(
          "The method 'getIcons()' is missing in enumeration " + enumeration.getName());
      ex.printStackTrace();
      System.exit(1);
    } catch (IllegalAccessException ex) {
      System.err.println(
          "Cannot access method 'getIcons()' in enumeration "
              + enumeration.getName()
              + ": ex.getMessage()");
      ex.printStackTrace();
      System.exit(1);
    } catch (InvocationTargetException ex) {
      ex.getCause().printStackTrace();
      System.exit(1);
    }
  }
  protected WebDriver createInstanceOf(String className) {
    try {
      DesiredCapabilities capabilities = createCommonCapabilities();
      capabilities.setJavascriptEnabled(true);
      capabilities.setCapability(TAKES_SCREENSHOT, true);
      capabilities.setCapability(ACCEPT_SSL_CERTS, true);
      capabilities.setCapability(SUPPORTS_ALERTS, true);
      if (isPhantomjs()) {
        capabilities.setCapability(
            "phantomjs.cli.args", // PhantomJSDriverService.PHANTOMJS_CLI_ARGS ==
                                  // "phantomjs.cli.args"
            new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
      }

      Class<?> clazz = Class.forName(className);
      if (WebDriverProvider.class.isAssignableFrom(clazz)) {
        return ((WebDriverProvider) clazz.newInstance()).createDriver(capabilities);
      } else {
        Constructor<?> constructor = Class.forName(className).getConstructor(Capabilities.class);
        return (WebDriver) constructor.newInstance(capabilities);
      }
    } catch (InvocationTargetException e) {
      throw runtime(e.getTargetException());
    } catch (Exception invalidClassName) {
      throw new IllegalArgumentException(invalidClassName);
    }
  }
Esempio n. 30
0
 /**
  * * 保存实体
  *
  * @param entity 实体类
  * @param keyName 实体类中获取主键的方法名字, 例如:getId<br>
  *     当为空时({@link StringUtils#isBlank(CharSequence)}),系统会自动找出注解有{@link
  *     javax.persistence.Id}的方法(即主键的get方法)
  * @return 返回保存实体的主键
  */
 public Object save(final T entity, String keyName) {
   entityManager.persist(entity);
   Object o = null;
   try {
     if (StringUtils.isNotBlank(keyName)) {
       o = clazz.getMethod(keyName).invoke(entity);
     } else {
       for (Method m1 : clazz.getMethods()) {
         if (m1.isAnnotationPresent(javax.persistence.Id.class)) {
           o = m1.invoke(entity);
           break;
         }
       }
     }
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   return o;
 }