Package com.googlecode.gwt.test.internal

Source Code of com.googlecode.gwt.test.internal.PatcherFactory

package com.googlecode.gwt.test.internal;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javassist.CtClass;
import javassist.NotFoundException;

import com.googlecode.gwt.test.exceptions.GwtTestPatchException;

class PatcherFactory {

   private static final CtClass jsoClass = GwtClassPool.getClass("com.google.gwt.core.client.JavaScriptObject");

   private final Map<String, Patcher> patchers;

   PatcherFactory(Map<String, Set<CtClass>> patchClassMap) {
      this.patchers = new HashMap<String, Patcher>();

      for (Map.Entry<String, Set<CtClass>> entry : patchClassMap.entrySet()) {
         Patcher patcher = createPatcher(entry.getValue());
         if (patcher != null) {
            patchers.put(entry.getKey(), patcher);
         }
      }
   }

   Patcher createPatcher(CtClass classToPatch) {
      Patcher patcher = patchers.get(classToPatch.getName());

      try {
         if (classToPatch.subtypeOf(jsoClass) && classToPatch != jsoClass) {
            patcher = new OverlayPatcher(patcher);
         }
      } catch (NotFoundException e) {
         // should never happen
         throw new GwtTestPatchException(e);
      }

      return patcher;

   }

   private Patcher createPatcher(Set<CtClass> patchClasses) {
      if (patchClasses != null && patchClasses.size() > 0) {
         return new AutomaticPatcher(patchClasses);
      } else {
         return null;
      }
   }

}
TOP

Related Classes of com.googlecode.gwt.test.internal.PatcherFactory

TOP
Copyright © 2018 www.massapi.com. 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.