Package net.sourceforge.javautil.common.reflection.cache

Examples of net.sourceforge.javautil.common.reflection.cache.ClassDescriptor


   * @return The response
   */
  protected void accept (ObjectVisitorBase visitor, ObjectVisitorContext ctx) {
    visitor.visit(ctx);
    if (ctx.isContinue()) {
      ClassDescriptor descriptor = ClassCache.getFor(instance.getClass());
      Map<String, ClassProperty> properties = descriptor.getProperties();
      for (String name : properties.keySet()) {
        ClassProperty op = properties.get(name);
        Object value = op.getValue(instance);
       
        if (value == null) continue;
View Full Code Here


   * @param propertyNames The names of the properties to copy from the source to the target
   */
  public static void setProperties (Object target, Object source, String... propertyNames) {
    assert target != null && source != null : "Objects cannot be null";
   
    ClassDescriptor descT = ClassCache.getFor(target.getClass());
    ClassDescriptor descS = ClassCache.getFor(source.getClass());
   
    if (propertyNames.length == 0) {
      Map<String,ClassProperty> props = descS.getProperties();
      propertyNames = props.keySet().toArray(new String[props.size()]);
    }
   
    for (String propertyName : propertyNames) {
      descT.setPropertyValue(target, propertyName, descS.getPropertyValue(source, propertyName));
    }
  }
View Full Code Here

 
  public GroovyDSLCategoryClass (Class<?>... categoryClasses) {
    Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
   
    for (Class<?> categoryClass : categoryClasses) {
      ClassDescriptor cd = ClassCache.getFor(categoryClass);
      Map<String, List<ClassMethod>> methodMap = cd.getMethods();
      for (String name : methodMap.keySet()) {
        boolean property = name.startsWith("get") && name.length() > 3 || name.startsWith("is") && name.length() > 2;
       
        String setterName = null;
        String getterName = null;
        String propertyName = null;
        if (property) {
          getterName = name;
          setterName = name.startsWith("is") ? name.substring(2) : name.substring(3);
          propertyName = setterName.length() > 1 ? setterName.substring(0, 1).toLowerCase() + setterName.substring(1) : setterName.toLowerCase();
          setterName = "set" + setterName;
        }
       
        List<ClassMethod> methods = methodMap.get(name);
        for (ClassMethod method : methods) {
          if (method.isStatic() && method.getParameterTypes().length > 0) {
            Class forType = method.getParameterTypes()[0];
            this.addCategory(classes, forType, cd);
           
            if (forType.isPrimitive() || ReflectionUtil.isBoxedType(forType))
              this.addCategory(classes, forType.isPrimitive() ? ReflectionUtil.getBoxedType(forType) : ReflectionUtil.getPrimitiveType(forType), cd);
           
            if (property && method.getParameterTypes().length == 1) {
              ClassMethod setter = null;
              for (ClassMethod setterp : cd.getMethods(setterName)) {
                if (setterp.getParameterTypes().length == 2 && setterp.getParameterTypes()[0] == forType && setterp.getParameterTypes()[1] == method.getReturnType()) {
                  setter = setterp; break;
                }
              }
              this.properties.put(forType.getName() + ":" + propertyName, new GroovyDSLCategoryProperty(method, setter));
View Full Code Here

    boolean create = false;
    boolean start = false;
    boolean stop = false;
    boolean destroy = false;

    ClassDescriptor desc = ClassCache.getFor(managed.getClass());
   
    ClassMethod postConstruct = desc.getMethod(PostConstruct.class);
    if (postConstruct != null) {
      this.phases.add(new PojoPhase(PhaseType.INITIALIZE, "Post Construct", 0, postConstruct));
      initialize = true;
    }
   
    ClassMethod preDestroy = desc.getMethod(PreDestroy.class);
    if (preDestroy != null)
      this.phases.add(new PojoPhase(PhaseType.POSTSTOP, "Pre Destroy", 1000, preDestroy));
   
   
    ClassMethod[] methods = desc.getMethods(Phase.class);
    for (ClassMethod method : methods) {
      PojoPhase phase = new PojoPhase(method.getAnnotation(Phase.class), method);
     
      switch (phase.getType()) {
        case INSTANTIATED:
          throw new UnsupportedOperationException("Cannot specify instantiated phase");
         
        case INITIALIZE:
          if (initialize) throw new UnsupportedOperationException("Can only specify one initialize phase"); else initialize = true;
          break;
         
        case CREATE:
          if (create) throw new UnsupportedOperationException("Can only specify one create phase"); else create = true;
          break;

        case START:
          if (start) throw new UnsupportedOperationException("Can only specify one start phase"); else start = true;
          break;

        case STOP:
          if (stop) throw new UnsupportedOperationException("Can only specify one stop phase"); else stop = true;
          break;

        case DESTROY:
          if (destroy) throw new UnsupportedOperationException("Can only specify one destroy phase"); else destroy = true;
          break;
         
        default:
      }
     
      this.phases.add(phase);
    }
   
    ClassMethod[] rollbacks = desc.getMethods(LifecycleRollback.class);
    for (ClassMethod method : rollbacks) {
      LifecycleRollback lr = method.getAnnotation(LifecycleRollback.class);
      if (lr.value().length == 0) this.rollbacks.put(null, method);
      else for (PhaseType type : lr.value()) {
        this.rollbacks.put(type, method);
View Full Code Here

    IClassDependencyPool pool = this.classContext.getPool();
   
    this.loadExtension(ctx, pool, new MavenExtension(name, this));
   
    for (String name : this.extensions.keySet()) {
      ClassDescriptor cd = ClassCache.getFor(ReflectionUtil.getClass(this.extensions.get(name).className, this.classContext));

      if (this.isExtensionLoaded(cd.getDescribedClass())) continue;
     
      IWebApplicationExtension extension = (IWebApplicationExtension) cd.newInstance(this);
     
      if (!extension.shouldLoad(webXml)) continue;
     
      this.loadedExtensions.add(extension);
      if (this.extensions.get(name).settings != null) {
        cd.deserializeProperties(extension, this.extensions.get(name).settings);
      }
     
      pool = this.loadExtension(ctx, pool, extension);
    }
   
View Full Code Here

  public List<IWebApplicationExtension> findNewExtensions (ClassSource source) {
    List<IWebApplicationExtension> extensions = new ArrayList<IWebApplicationExtension>();
    for (ClassSourceMatch match : source.accept(new ClassSourceScanner("webserver.properties").addSuffixes("WebExtension")).getMatches()) {
      if (match.getType() == Type.Resource) continue;
      try {
        ClassDescriptor eclass = ClassCache.getFor( classContext.loadClass(match.getName()) );
        if (!this.isExtensionLoaded(eclass.getDescribedClass())) {
         
          boolean load = true;
          IWebApplicationExtension replace = null;
          for (IWebApplicationExtension ext : extensions) {
            if (eclass.getDescribedClass().isAssignableFrom(ext.getClass())) { load = false; break; }
            if (ext.getClass().isAssignableFrom(eclass.getDescribedClass())) {
              replace = ext; break;
            }
          }
          if (!load) continue;
          if (replace != null) { extensions.remove(replace); }
         
          IWebApplicationExtension extension = (IWebApplicationExtension) eclass.newInstance(this);
          extensions.add(extension);
         
          if (this.descriptor != null && this.descriptor.getDescriptorFor(extension) != null) {
            if (this.descriptor.getDescriptorFor(extension).getSettings() != null)
              eclass.deserializeProperties(extension, this.descriptor.getDescriptorFor(extension).getSettings());
          }
        }
      } catch (ClassNotFoundException e) {
        ThrowableManagerRegistry.caught(e);
      }
View Full Code Here

   * @param collection The list of objects of the specified type
   * @param clazz The class to use for getting properties
   * @param properties The properties of the objects that should compose the columns
   */
  public <T> UITableModelDefault (Collection<T> collection, Class<T> clazz, String... properties) {
    ClassDescriptor descriptor = ClassCache.getFor(clazz);
    for (T item : collection) {
      List<Object> rowData = new ArrayList<Object>();
      for (String property : properties) {
        Object value = descriptor.getPropertyValue(item, property);
        rowData.add( value == null ? "" : value );
      }
      this.addRow( rowData.toArray(new Object[rowData.size()]) );
    }
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.common.reflection.cache.ClassDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.