コード例 #1
0
 /**
  * This method returns a JDO proxy.
  *
  * @param <T> The type of object being dealt with.
  * @param type The source object.
  * @param resource The resource.
  * @return The result.
  * @throws BasicJDOException
  */
 public static <T> T createJDOProxy(
     Class typeRef,
     PersistanceSession persistanceSession,
     PersistanceResource resource,
     OntologySession ontologySession)
     throws BasicJDOException {
   try {
     Class type = typeRef;
     if (Enhancer.isEnhanced(typeRef)) {
       type = typeRef.getSuperclass();
     }
     T result;
     if (Resource.class.isAssignableFrom(type)) {
       BasicJDOResourceInvocationHandler handler =
           new BasicJDOResourceInvocationHandler(persistanceSession, resource, ontologySession);
       result =
           (T)
               Proxy.newProxyInstance(
                   Thread.currentThread().getContextClassLoader(),
                   new Class[] {Resource.class},
                   handler);
     } else {
       BasicJDOInvocationHandler handler =
           new BasicJDOInvocationHandler(type, persistanceSession, resource, ontologySession);
       result = (T) Enhancer.create(type, new Class[] {Resource.class}, handler);
       handler.initObject(result);
     }
     return result;
   } catch (Exception ex) {
     throw new BasicJDOException(
         "Failed to create the JDO proxy [" + typeRef.getName() + "] :" + ex.getMessage(), ex);
   }
 }
コード例 #2
0
 /**
  * @param factory
  * @param value
  */
 public void invoke(ConfigurableListableBeanFactory factory, String value) {
   for (Map.Entry<Field, List<Class>> entry : targets.entrySet()) {
     Field field = entry.getKey();
     for (Class clazz : entry.getValue()) {
       Map map = factory.getBeansOfType(clazz);
       for (Object target : map.values()) {
         try {
           Object convert = convert(field.getType(), value);
           if (Enhancer.isEnhanced(target.getClass())) {
             Object source = getCGLIBSource(target, clazz);
             field.set(source, convert);
           } else {
             field.set(target, convert);
           }
         } catch (IllegalAccessException e) {
           logger.warn(
               "Can't set value: "
                   + value
                   + "in field: "
                   + field.getName()
                   + "because of: "
                   + e.getMessage());
         }
       }
     }
   }
 }
コード例 #3
0
ファイル: CGLIBMapper.java プロジェクト: micromax/xstream
 @Override
 public String serializedClass(final Class<?> type) {
   final String serializedName = super.serializedClass(type);
   if (type == null) {
     return serializedName;
   }
   final String typeName = type.getName();
   return typeName.equals(serializedName)
           && typeName.indexOf(DEFAULT_NAMING_MARKER) > 0
           && Enhancer.isEnhanced(type)
       ? alias
       : serializedName;
 }
  @SuppressWarnings({"unchecked"})
  @Test
  public void testEventHandlerCallsRedirectToAdapter() throws Throwable {
    Object result1 =
        testSubject.postProcessBeforeInitialization(new AnnotatedCommandHandler(), "beanName");
    Object postProcessedBean = testSubject.postProcessAfterInitialization(result1, "beanName");

    assertTrue(Enhancer.isEnhanced(postProcessedBean.getClass()));
    assertTrue(postProcessedBean instanceof CommandHandler);
    assertTrue(postProcessedBean instanceof AnnotatedCommandHandler);

    CommandHandler<MyCommand> commandHandler = (CommandHandler<MyCommand>) postProcessedBean;
    AnnotatedCommandHandler annotatedCommandHandler = (AnnotatedCommandHandler) postProcessedBean;
    CommandMessage<MyCommand> myCommand = GenericCommandMessage.asCommandMessage(new MyCommand());
    commandHandler.handle(myCommand, null);

    assertEquals(1, annotatedCommandHandler.getInvocationCount());
  }
コード例 #5
0
ファイル: Augmenter.java プロジェクト: nvreynolds/selenium
  @SuppressWarnings({"unchecked"})
  protected <X> X performAugmentation(CompoundHandler handler, X from) {
    if (handler.isNeedingApplication()) {
      Class<?> superClass = from.getClass();
      while (Enhancer.isEnhanced(superClass)) {
        superClass = superClass.getSuperclass();
      }

      Enhancer enhancer = new Enhancer();
      enhancer.setCallback(handler);
      enhancer.setSuperclass(superClass);

      Set<Class<?>> interfaces = Sets.newHashSet();
      interfaces.addAll(ImmutableList.copyOf(from.getClass().getInterfaces()));
      interfaces.addAll(handler.getInterfaces());
      enhancer.setInterfaces(interfaces.toArray(new Class<?>[interfaces.size()]));

      return (X) enhancer.create();
    }

    return from;
  }
コード例 #6
0
 public boolean canConvert(Class type) {
   return (Enhancer.isEnhanced(type) && type.getName().indexOf(DEFAULT_NAMING_MARKER) > 0)
       || type == CGLIBMapper.Marker.class;
 }