示例#1
0
 public <BLOCK extends Block> BLOCK newBlock(
     String name, Class<BLOCK> cls, Class itemClass, String title) {
   try {
     int id = config.getBlock(name, 4095).getInt();
     Constructor<BLOCK> ctor = cls.getConstructor(int.class);
     BLOCK block = ctor.newInstance(id);
     String qualName = assetKey + ":" + name;
     block.setUnlocalizedName(qualName);
     // block.func_111022_d(qualName.toLowerCase()); // Set default icon name
     // block.func_111022_d(qualName); // Set default icon name
     block.setTextureName(qualName); // Set default icon name
     GameRegistry.registerBlock(block, itemClass);
     if (title != null) {
       LanguageRegistry.addName(block, title);
       if (clientSide) {
         // System.out.printf("%s: BaseMod.newBlock: %s: creative tab = %s\n",
         //	this, block.getUnlocalizedName(), block.getCreativeTabToDisplayOn());
         if (block.getCreativeTabToDisplayOn() == null && !title.startsWith("["))
           block.setCreativeTab(CreativeTabs.tabMisc);
       }
     }
     if (block instanceof IBlock) registeredBlocks.add((IBlock) block);
     return block;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#2
0
  public static Object loadFrame(
      JopSession session, String className, String instance, boolean scrollbar)
      throws ClassNotFoundException {

    if (className.indexOf(".pwg") != -1) {
      GrowFrame frame =
          new GrowFrame(
              className, session.getGdh(), instance, new GrowFrameCb(session), session.getRoot());
      frame.validate();
      frame.setVisible(true);
    } else {
      Object frame;
      if (instance == null) instance = "";

      JopLog.log(
          "JopSpider.loadFrame: Loading frame \"" + className + "\" instance \"" + instance + "\"");
      try {
        Class clazz = Class.forName(className);
        try {
          Class argTypeList[] =
              new Class[] {session.getClass(), instance.getClass(), boolean.class};
          Object argList[] = new Object[] {session, instance, new Boolean(scrollbar)};
          System.out.println("JopSpider.loadFrame getConstructor");
          Constructor constructor = clazz.getConstructor(argTypeList);

          try {
            frame = constructor.newInstance(argList);
          } catch (Exception e) {
            System.out.println(
                "Class instanciation error: "
                    + className
                    + " "
                    + e.getMessage()
                    + " "
                    + constructor);
            return null;
          }
          // frame = clazz.newInstance();
          JopLog.log("JopSpider.loadFrame openFrame");
          openFrame(frame);
          return frame;
        } catch (NoSuchMethodException e) {
          System.out.println("NoSuchMethodException: Unable to get frame constructor " + className);
        } catch (Exception e) {
          System.out.println(
              "Exception: Unable to get frame class " + className + " " + e.getMessage());
        }
      } catch (ClassNotFoundException e) {
        System.out.println("Class not found: " + className);
        throw new ClassNotFoundException();
      }
      return null;
    }
    return null;
  }
示例#3
0
 public <ITEM extends Item> ITEM newItem(String name, Class<ITEM> cls, String title) {
   try {
     int id = config.getItem(name, 31743).getInt();
     Constructor<ITEM> ctor = cls.getConstructor(int.class);
     ITEM item = ctor.newInstance(id);
     String qualName = assetKey + ":" + name;
     item.setUnlocalizedName(qualName);
     // item.func_111206_d(qualName.toLowerCase()); // Set default icon name
     // item.func_111206_d(qualName); // Set default icon name
     item.setTextureName(qualName); // Set default icon name
     LanguageRegistry.addName(item, title);
     if (clientSide) {
       if (item.getCreativeTab() == null) item.setCreativeTab(CreativeTabs.tabMisc);
     }
     // System.out.printf("BaseMod.newItem: %s unlocalizedName = %s title = %s\n",
     //	item, item.getUnlocalizedName(), title);
     return item;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  public static void main(String[] args) throws Exception {
    System.out.println(
        "Checking that all known MBeans that are "
            + "NotificationBroadcasters have sane "
            + "MBeanInfo.getNotifications()");

    System.out.println("Checking platform MBeans...");
    checkPlatformMBeans();

    URL codeBase = ClassLoader.getSystemResource("javax/management/MBeanServer.class");
    if (codeBase == null) {
      throw new Exception("Could not determine codeBase for " + MBeanServer.class);
    }

    System.out.println();
    System.out.println("Looking for standard MBeans...");
    String[] classes = findStandardMBeans(codeBase);

    System.out.println("Testing standard MBeans...");
    for (int i = 0; i < classes.length; i++) {
      String name = classes[i];
      Class<?> c;
      try {
        c = Class.forName(name);
      } catch (Throwable e) {
        System.out.println(name + ": cannot load (not public?): " + e);
        continue;
      }
      if (!NotificationBroadcaster.class.isAssignableFrom(c)) {
        System.out.println(name + ": not a NotificationBroadcaster");
        continue;
      }
      if (Modifier.isAbstract(c.getModifiers())) {
        System.out.println(name + ": abstract class");
        continue;
      }

      NotificationBroadcaster mbean;
      Constructor<?> constr;
      try {
        constr = c.getConstructor();
      } catch (Exception e) {
        System.out.println(name + ": no public no-arg constructor: " + e);
        continue;
      }
      try {
        mbean = (NotificationBroadcaster) constr.newInstance();
      } catch (Exception e) {
        System.out.println(name + ": no-arg constructor failed: " + e);
        continue;
      }

      check(mbean);
    }

    System.out.println();
    System.out.println("Testing some explicit cases...");

    check(new RelationService(false));
    /*
      We can't do this:
        check(new RequiredModelMBean());
      because the Model MBean spec more or less forces us to use the
      names GENERIC and ATTRIBUTE_CHANGE for its standard notifs.
    */
    checkRMIConnectorServer();

    System.out.println();
    if (!suspicious.isEmpty()) System.out.println("SUSPICIOUS CLASSES: " + suspicious);

    if (failed.isEmpty()) System.out.println("TEST PASSED");
    else {
      System.out.println("TEST FAILED: " + failed);
      System.exit(1);
    }
  }