Esempio n. 1
0
 public static Class getNestedPropertyType(DynaClass bean, String name)
     throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
         ClassNotFoundException, NoSuchFieldException {
   // Resolve nested references
   while (resolver.hasNested(name)) {
     String next = resolver.next(name);
     if (resolver.isIndexed(next) || resolver.isMapped(next)) {
       String property = resolver.getProperty(next);
       Class<?> clazz = Class.forName(bean.getName());
       Class<?> detectTypeParameter =
           detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1);
       bean = WrapDynaClass.createDynaClass(detectTypeParameter);
       return getNestedPropertyType(bean, resolver.remove(name));
     }
     DynaProperty db = bean.getDynaProperty(next);
     bean = WrapDynaClass.createDynaClass(db.getType());
     name = resolver.remove(name);
   }
   if (resolver.isMapped(name) || resolver.isIndexed(name)) {
     String property = resolver.getProperty(name);
     Class<?> clazz = Class.forName(bean.getName());
     return detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1);
   }
   Class<?> type = bean.getDynaProperty(name).getType();
   return type;
 }
Esempio n. 2
0
  /**
   * Test DynaClass of a RemoteBean.
   *
   * @throws Exception
   */
  public void testGetDynaClass() throws Exception {
    MyBean sampleBean = new MyBean();

    ServerContext serverContext =
        new ServerContextImpl(sampleBean, sm, new OurHierarchicalRegistry());

    OddjobMBean test =
        new OddjobMBean(
            sampleBean, OddjobMBeanFactory.objectName(0), new OurServerSession(), serverContext);

    DynaClass dc = (DynaClass) test.invoke("getDynaClass", new Object[] {}, new String[] {});

    assertNotNull(dc);
    DynaProperty dp = dc.getDynaProperty("fruit");
    assertEquals(String.class, dp.getType());
  }