コード例 #1
0
ファイル: Fireworks.java プロジェクト: Hoot215/Merlin
 public static void detonateFirework(Location loc, FireworkEffect effects) {
   World world = loc.getWorld();
   Firework firework = (Firework) world.spawnEntity(loc, EntityType.FIREWORK);
   // Credit to codename_B
   Object nms_world = null;
   Object nms_firework = null;
   if (world_getHandle == null) {
     world_getHandle = getMethod(world.getClass(), "getHandle");
     firework_getHandle = getMethod(firework.getClass(), "getHandle");
   }
   try {
     nms_world = world_getHandle.invoke(world, (Object[]) null);
     nms_firework = firework_getHandle.invoke(firework, (Object[]) null);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   if (nms_world_broadcastEntityEffect == null) {
     nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
   }
   FireworkMeta data = (FireworkMeta) firework.getFireworkMeta();
   data.clearEffects();
   data.setPower(1);
   data.addEffect(effects);
   firework.setFireworkMeta(data);
   try {
     nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   firework.remove();
 }
コード例 #2
0
  /** java.lang.reflect.InvocationTargetException#printStackTrace(java.io.PrintWriter) */
  public void test_printStackTraceLjava_io_PrintWriter() {
    // Test for method void
    // java.lang.reflect.InvocationTargetException.printStackTrace(java.io.PrintWriter)
    try {
      PrintWriter pw;
      InvocationTargetException ite;
      String s;
      CharArrayWriter caw = new CharArrayWriter();
      pw = new PrintWriter(caw);
      ite = new InvocationTargetException(new InvocationTargetException(null));
      ite.printStackTrace(pw);

      s = caw.toString();
      assertTrue("printStackTrace failed." + s.length(), s != null && s.length() > 400);
      pw.close();

      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      pw = new PrintWriter(bao);
      ite = new InvocationTargetException(new InvocationTargetException(null));
      ite.printStackTrace(pw);

      pw.flush(); // Test will fail if this line removed.
      s = bao.toString();
      assertTrue("printStackTrace failed." + s.length(), s != null && s.length() > 400);

    } catch (Exception e) {
      fail("Exception during test : " + e.getMessage());
    }
  }
コード例 #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.wizard.Wizard#performFinish()
   */
  @Override
  public boolean performFinish() {

    final String packageName = page.getPackageName();

    /* make sure the package does exist */
    if (packageName.length() > 0) {
      WorkspaceModifyOperation createPkg =
          new NewPackageCreationOperation(page.getSourceFolder(), packageName);

      try {
        createPkg.run(null);
      } catch (InvocationTargetException e) {
        e.printStackTrace();
        return false;
      } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
      }
    }
    WorkspaceModifyOperation modifyOp =
        new NewFragmentCreationOperation(
            page.getSourceFolder(), packageName, page.getTypeName(), page.getFragmentKind());
    try {
      this.getContainer().run(false, false, modifyOp);
    } catch (InvocationTargetException e) {
      e.printStackTrace();
      return false;
    } catch (InterruptedException e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }
コード例 #4
0
ファイル: EntityUtil.java プロジェクト: vpcaiyc/gw
 public static Map<String, String> getEntityPropertiesToStringMap(
     Object entity, Map<String, String> fieldClassMapping, String... entityIdentifier) {
   Map<String, String> propertiesMap = new HashMap<String, String>();
   StringBuffer sb = new StringBuffer();
   if (entityIdentifier.length > 0) {
     for (String ei : entityIdentifier) {
       sb.append(ei + ".");
     }
   }
   String prefixStr = sb.toString();
   PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(entity.getClass());
   for (PropertyDescriptor pd : pds) {
     Method readMethod = pd.getReadMethod();
     if (null == readMethod) continue;
     Class<?> returnType = readMethod.getReturnType();
     Object returnValue = null;
     try {
       returnValue = readMethod.invoke(entity);
     } catch (IllegalArgumentException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       e.printStackTrace();
     }
     if (null != returnValue) {
       String value = "";
       if (returnType.isAssignableFrom(Set.class)) {
         continue;
       } else if (isTenwaEntity(returnType)) {
         String fieldName = null;
         if (null != fieldClassMapping) {
           fieldName = fieldClassMapping.get(returnType.getSimpleName());
         }
         if (StringUtils.isBlank(fieldName)) {
           fieldName = "id";
         }
         Method method = BeanUtils.getPropertyDescriptor(returnType, fieldName).getReadMethod();
         // System.out.println("####:"+method.getName()+","+returnValue);
         try {
           value = StringUtil.nullToString(method.invoke(returnValue));
         } catch (IllegalArgumentException e) {
           e.printStackTrace();
         } catch (IllegalAccessException e) {
           e.printStackTrace();
         } catch (InvocationTargetException e) {
           e.printStackTrace();
         }
       } else {
         if (returnType.getSimpleName().equalsIgnoreCase("double")) {
           value = MathUtil.decimal((Double) returnValue, 8);
         } else {
           value = returnValue.toString();
         }
       }
       propertiesMap.put(prefixStr + pd.getName().toLowerCase(), value);
     }
   }
   return propertiesMap;
 }
コード例 #5
0
  @Override
  public IExpr eval(final IExpr leftHandSide) {
    IExpr result = null;
    if (isRuleWithoutPatterns() && fLhsPatternExpr.equals(leftHandSide)) {
      if (fTypes.length != 0) {
        return null;
      }
      try {
        result = (IExpr) fMethod.invoke(fInstance);
      } catch (IllegalArgumentException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      } catch (IllegalAccessException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      } catch (InvocationTargetException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      }
      return result;
    }
    if (fTypes.length != fPatternMap.size()) {
      return null;
    }
    fPatternMap.initPattern();
    if (matchExpr(fLhsPatternExpr, leftHandSide)) {

      List<IExpr> args = fPatternMap.getValuesAsList();
      result = null;
      try {
        result = (IExpr) fMethod.invoke(fInstance, args.toArray());
      } catch (IllegalArgumentException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      } catch (IllegalAccessException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      } catch (InvocationTargetException e) {
        if (Config.SHOW_STACKTRACE) {
          e.printStackTrace();
        }
      }
    }
    return result;
  }
コード例 #6
0
 public static Object callMethod(
     String methodName, Object object, Class[] signature, Object[] values)
     throws NoSuchMethodException {
   Class instanceClass = object.getClass();
   Method method = null;
   while (method == null) {
     try {
       method = instanceClass.getDeclaredMethod(methodName, signature);
     } catch (NoSuchMethodException e) {
       instanceClass = instanceClass.getSuperclass();
       if (instanceClass == null) {
         throw e;
       }
     }
   }
   method.setAccessible(true);
   try {
     return method.invoke(object, values);
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     throw new NoSuchMethodException(e.toString());
   } catch (InvocationTargetException e) {
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   }
 }
コード例 #7
0
 public static Object callMethod(Object object, String methodName, int value)
     throws NoSuchMethodException {
   Class instanceClass = object.getClass();
   Method method = null;
   while (method == null) {
     try {
       method = instanceClass.getDeclaredMethod(methodName, new Class[] {Integer.TYPE});
     } catch (NoSuchMethodException e) {
       instanceClass = instanceClass.getSuperclass();
       if (instanceClass == null) {
         throw e;
       }
     }
   }
   method.setAccessible(true);
   try {
     return method.invoke(object, new Object[] {new Integer(value)});
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     throw new NoSuchMethodException(e.toString());
   } catch (InvocationTargetException e) {
     System.out.println("PopulateUtil: unable to call method " + methodName + "( " + value + ")");
     e.printStackTrace();
     throw new RuntimeException(e.getCause());
   }
 }
コード例 #8
0
ファイル: ConfigHelper.java プロジェクト: Rygbee/DL-Learner
 /**
  * @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;
 }
コード例 #9
0
  @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;
  }
コード例 #10
0
ファイル: AttributesPanel.java プロジェクト: escalope/IDK
  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();
        }
      }
    }
  }
コード例 #11
0
 @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);
 }
コード例 #12
0
ファイル: AbstractJpaDAO.java プロジェクト: liyang2012/myuum
 /**
  * * 保存实体
  *
  * @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;
 }
コード例 #13
0
  public static void pojoMappingUtility(Object pojo, Object origin) {

    Method[] methods = pojo.getClass().getDeclaredMethods();
    // System.out.printf("%d methods:%n", methods.length);

    // Method[] methods2 = origin.getClass().getDeclaredMethods();
    // System.out.printf("%d methodsOrigin:%n", methods2.length);

    for (Method method : methods) {

      // System.out.println(method.getName());
      if (method.getName().contains("set")) {
        String getMethodName = method.getName().replace("set", "get");
        try {
          method.invoke(pojo, origin.getClass().getDeclaredMethod(getMethodName).invoke(origin));
        } catch (IllegalAccessException 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();
        } catch (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SecurityException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
コード例 #14
0
  private static void initializeActionMappingProperties(
      ActionMapping actionMapping, String[] properties) {
    Method[] mappingMethods = actionMapping.getClass().getMethods();
    for (int i = 0; i < properties.length; i += 2) {
      String property = properties[i];
      String value = properties[i + 1];

      String setterName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
      Method setterMethod = null;
      for (Method mappingMethod : mappingMethods) {
        if (mappingMethod.getName().equals(setterName)
            && mappingMethod.getParameterTypes().length == 1) {
          setterMethod = mappingMethod;
          break;
        }
      }

      if (setterMethod == null) {
        continue;
      }

      try {
        setterMethod.invoke(actionMapping, value);
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #15
0
ファイル: LDAPSearchImpl.java プロジェクト: jaigates/IB
 public String buildFilter(Object obj) {
   LOG.info("Inside buildFilter");
   Field[] fld = obj.getClass().getDeclaredFields();
   StringBuffer sb = new StringBuffer();
   for (Field flds : fld) {
     try {
       String name = flds.getName();
       Class class1 = obj.getClass();
       String methodName =
           "get" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
       Method method = class1.getMethod(methodName, null);
       String value = (String) method.invoke(obj, null);
       if (value != null && value.length() > 0) sb.append(name).append("=").append(value);
     } catch (IllegalArgumentException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (SecurityException e) {
       e.printStackTrace();
     } catch (NoSuchMethodException e) {
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       e.printStackTrace();
     }
   }
   if (sb.length() > 0) {
     sb.substring(0, sb.length() - 1);
   }
   return sb.toString();
 }
コード例 #16
0
ファイル: LDAPSearchImpl.java プロジェクト: jaigates/IB
  private Object getResults(Attribute attr, Object obj) {
    try {
      String name = attr.getID().toString();
      String Value = attr.get().toString();
      Class class1 = obj.getClass();
      String methodName =
          "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
      String[] methodnameIgnot = {"-"};
      for (String ignore : methodnameIgnot) {
        methodName = methodName.replaceAll(ignore, "");
      }
      Method method = class1.getMethod(methodName, String.class);

      String value = (String) method.invoke(obj, Value);

    } catch (NamingException e) {
      e.printStackTrace();
    } 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 obj;
  }
コード例 #17
0
  /*
   * launch process config input: className and args
   */
  public void launchProcessConfig(String className, String[] args)
      throws SecurityException, NoSuchMethodException {

    try {
      Class<?> processClass = Class.forName(className);
      // System.out.print("processClass is " + processClass.toString());
      MigratableProcess process;
      process =
          (MigratableProcess)
              processClass.getConstructor(String[].class).newInstance((Object) args);
      //			process = (MigratableProcess) processClass.newInstance();
      System.out.println("MP is " + process.toString());
      processList.add(process);

    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } // TestProcess test = new TestProcess();
    catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #18
0
  ArrayList<Mob> getMobs() {
    ArrayList<Mob> realMobs = new ArrayList<Mob>();

    for (JsonMob jm : mobs) {

      Mob xyz = null;

      Class<?> cl;
      try {
        cl = Class.forName(jm.getName());

        Constructor<?> con = cl.getConstructor(float.class, float.class);
        xyz = (Mob) con.newInstance(jm.getX(), jm.getY());
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (InstantiationException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }

      xyz.setID(jm.getID());

      realMobs.add(xyz);
    }
    return realMobs;
  }
コード例 #19
0
  public static Object invokeStaticMethod(
      String class_name, String method_name, Class[] pareTyple, Object[] pareVaules) {

    try {
      Class obj_class = Class.forName(class_name);
      Method method = obj_class.getMethod(method_name, pareTyple);
      return method.invoke(null, pareVaules);
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
コード例 #20
0
  /**
   * 将对象转换为XML报文字符串
   *
   * <p>
   * <li>通过java反射对象,将对象的每一个成员变量都转换成xml的标签
   * <li>然后将获取每个变量的值,放入标签之间
   *
   * @param obj 待转换对象
   * @return xml字符串
   */
  public static String obj2Xml(Object obj) {
    StringBuffer sb = new StringBuffer();
    try {
      Class clz = obj.getClass();
      Field[] fields = clz.getDeclaredFields();
      for (Field field : fields) {
        String fieldName = field.getName();
        sb.append("<" + fieldName + ">");
        String methodName = "get" + DataTools.stringUpdateFirst(field.getName());
        // 反射得到方法
        Method m = clz.getDeclaredMethod(methodName);
        // 通过反射调用set方法
        sb.append(m.invoke(obj));
        sb.append("</" + fieldName + ">");
      }
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
コード例 #21
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());
    }
  }
コード例 #22
0
  /**
   * 为对象设置属性
   *
   * @param bean 目标对象
   * @param name 属性的名字
   * @param value 将要设置的属性值
   */
  public static void setProperty(Object bean, String name, String value) {
    Class<?> clazz = bean.getClass();
    PropertyDescriptor propertyDescriptor = findPropertyDescriptor(clazz, name);
    if (propertyDescriptor == null) {
      try {
        throw new Exception(
            "propertyDescriptor is null clazz:" + clazz.getName() + " property name:" + name);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    Class<?> type = propertyDescriptor.getPropertyType();
    Object newValue = converValue(type, value);
    Method writeMethod = propertyDescriptor.getWriteMethod();
    try {
      writeMethod.invoke(bean, newValue);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
コード例 #23
0
  /**
   * 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");
  }
コード例 #24
0
 public static XSingleComponentFactory __getComponentFactory(String sImplementationName) {
   String regClassesList = getRegistrationClasses();
   StringTokenizer t = new StringTokenizer(regClassesList, " ");
   while (t.hasMoreTokens()) {
     String className = t.nextToken();
     if (className != null && className.length() != 0) {
       try {
         Class regClass = Class.forName(className);
         Method writeRegInfo =
             regClass.getDeclaredMethod("__getComponentFactory", new Class[] {String.class});
         Object result = writeRegInfo.invoke(regClass, sImplementationName);
         if (result != null) {
           return (XSingleComponentFactory) result;
         }
       } catch (ClassNotFoundException ex) {
         ex.printStackTrace();
       } catch (ClassCastException ex) {
         ex.printStackTrace();
       } catch (SecurityException ex) {
         ex.printStackTrace();
       } catch (NoSuchMethodException ex) {
         ex.printStackTrace();
       } catch (IllegalArgumentException ex) {
         ex.printStackTrace();
       } catch (InvocationTargetException ex) {
         ex.printStackTrace();
       } catch (IllegalAccessException ex) {
         ex.printStackTrace();
       }
     }
   }
   return null;
 }
コード例 #25
0
  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();
    }
  }
コード例 #26
0
 public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey) {
   boolean bResult = true;
   String regClassesList = getRegistrationClasses();
   StringTokenizer t = new StringTokenizer(regClassesList, " ");
   while (t.hasMoreTokens()) {
     String className = t.nextToken();
     if (className != null && className.length() != 0) {
       try {
         Class regClass = Class.forName(className);
         Method writeRegInfo =
             regClass.getDeclaredMethod(
                 "__writeRegistryServiceInfo", new Class[] {XRegistryKey.class});
         Object result = writeRegInfo.invoke(regClass, xRegistryKey);
         bResult &= ((Boolean) result).booleanValue();
       } catch (ClassNotFoundException ex) {
         ex.printStackTrace();
       } catch (ClassCastException ex) {
         ex.printStackTrace();
       } catch (SecurityException ex) {
         ex.printStackTrace();
       } catch (NoSuchMethodException ex) {
         ex.printStackTrace();
       } catch (IllegalArgumentException ex) {
         ex.printStackTrace();
       } catch (InvocationTargetException ex) {
         ex.printStackTrace();
       } catch (IllegalAccessException ex) {
         ex.printStackTrace();
       }
     }
   }
   return bResult;
 }
コード例 #27
0
  @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);
    }
  }
コード例 #28
0
ファイル: SettingUtils.java プロジェクト: dalinhuang/shousu
 /**
  * 获取系统设置
  *
  * @return 系统设置
  */
 public static Setting get() {
   Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME);
   net.sf.ehcache.Element cacheElement = cache.get(Setting.CACHE_KEY);
   Setting setting;
   if (cacheElement != null) {
     setting = (Setting) cacheElement.getObjectValue();
   } else {
     setting = new Setting();
     try {
       File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile();
       Document document = new SAXReader().read(shopxxXmlFile);
       List<Element> elements = document.selectNodes("/shopxx/setting");
       for (Element element : elements) {
         String name = element.attributeValue("name");
         String value = element.attributeValue("value");
         try {
           beanUtils.setProperty(setting, name, value);
         } catch (IllegalAccessException e) {
           e.printStackTrace();
         } catch (InvocationTargetException e) {
           e.printStackTrace();
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
     cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting));
   }
   return setting;
 }
コード例 #29
0
ファイル: Engine.java プロジェクト: desko27/LittleSpaceships
  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);
    }
  }
コード例 #30
0
 /**
  * 画像のExif情報から回転角度を取得する
  *
  * <pre>
  * // Original code for Android 2.1(API Level 5 Later)
  * int rotation = 0;
  * try {
  *     ExifInterface exif = new ExifInterface(fileName);
  *     int orientation = exif.getAttributeInt(
  *               ExifInterface.TAG_ORIENTATION, 1);
  *     switch (orientation) {
  *         case 6:
  *             rotation = 90;
  *             break;
  *     }
  * } catch (IOException e) {
  *     e.printStackTrace();
  * }
  * </pre>
  *
  * @param fileName 画像のファイル名(フルパス)
  * @return 回転角度(0、90、180、270)※単位は度
  */
 public static int getRotation(String fileName) {
   int rotation = 0;
   try {
     Class<?> clazz = ExifInterface.class;
     Constructor<?> constructor = clazz.getConstructor(String.class);
     Object instance = constructor.newInstance(fileName);
     Method method = clazz.getMethod("getAttributeInt", String.class, int.class);
     if (method != null) {
       rotation = (Integer) method.invoke(instance, "Orientation");
     }
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   return rotation;
 }