示例#1
0
    public Mixin create() {
      if (classes == null && delegates == null) {
        throw new IllegalStateException("Either classes or delegates must be set");
      }
      switch (style) {
        case STYLE_INTERFACES:
          if (classes == null) {
            Route r = route(delegates);
            classes = r.classes;
            route = r.route;
          }
          break;
        case STYLE_BEANS:
          // fall-through
        case STYLE_EVERYTHING:
          if (classes == null) {
            classes = ReflectUtils.getClasses(delegates);
          } else {
            if (delegates != null) {
              Class[] temp = ReflectUtils.getClasses(delegates);
              if (classes.length != temp.length) {
                throw new IllegalStateException(
                    "Specified classes are incompatible with delegates");
              }
              for (int i = 0; i < classes.length; i++) {
                if (!classes[i].isAssignableFrom(temp[i])) {
                  throw new IllegalStateException(
                      "Specified class "
                          + classes[i]
                          + " is incompatible with delegate class "
                          + temp[i]
                          + " (index "
                          + i
                          + ")");
                }
              }
            }
          }
      }
      setNamePrefix(classes[ReflectUtils.findPackageProtected(classes)].getName());

      return (Mixin)
          super.create(KEY_FACTORY.newInstance(style, ReflectUtils.getNames(classes), route));
    }
示例#2
0
 Route(Object[] delegates) {
   Map map = new HashMap();
   ArrayList collect = new ArrayList();
   for (int i = 0; i < delegates.length; i++) {
     Class delegate = delegates[i].getClass();
     collect.clear();
     ReflectUtils.addAllInterfaces(delegate, collect);
     for (Iterator it = collect.iterator(); it.hasNext(); ) {
       Class iface = (Class) it.next();
       if (!map.containsKey(iface)) {
         map.put(iface, new Integer(i));
       }
     }
   }
   classes = new Class[map.size()];
   route = new int[map.size()];
   int index = 0;
   for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
     Class key = (Class) it.next();
     classes[index] = key;
     route[index] = ((Integer) map.get(key)).intValue();
     index++;
   }
 }
示例#3
0
 protected Object firstInstance(Class type) {
   return ((Mixin) ReflectUtils.newInstance(type)).newInstance(delegates);
 }