Пример #1
0
  /**
   * Parses a constructor type definition
   *
   * @param docConstructor
   * @return
   */
  protected static Constructor ParseConstructor(ConstructorDoc docConstructor) {
    assert (docConstructor != null);

    Constructor xmlConstructor = new Constructor();

    xmlConstructor.name = docConstructor.name();
    xmlConstructor.comment = docConstructor.commentText();
    xmlConstructor.scope = DetermineScope(docConstructor);
    xmlConstructor.isVarArgs = docConstructor.isVarArgs();
    xmlConstructor.isDefault =
        docConstructor.position().line() == docConstructor.containingClass().position().line();

    Parameter[] parameters = docConstructor.parameters();

    if (parameters != null && parameters.length > 0) {
      ParamTag[] paramComments = docConstructor.paramTags();

      ArrayList<Param> methodList = new ArrayList<Param>();

      for (Parameter parameter : parameters) {
        ParamTag paramComment = null;

        // look to see if this parameter has comments
        // if so, paramComment will be set
        for (ParamTag testParam : paramComments) {
          String testParamName = testParam.parameterName();
          if (testParamName != null) {
            if (testParamName.compareTo(parameter.name()) == 0) {
              paramComment = testParam;
              break;
            }
          }
        }

        methodList.add(ParseParameter(parameter, paramComment));
      }

      xmlConstructor.parameters = methodList.toArray(new Param[] {});
    } else {
      log.debug("No parameters for method: " + docConstructor.name());
    }

    // parse annotations for the constructor
    xmlConstructor.annotationInstances =
        ParseAnnotationInstances(docConstructor.annotations(), docConstructor.qualifiedName());

    return xmlConstructor;
  }
Пример #2
0
  private static void generateCtor(
      ClassFileWriter cfw, String adapterName, String superName, Constructor<?> superCtor) {
    short locals = 3; // this + factory + delegee
    Class<?>[] parameters = superCtor.getParameterTypes();

    // Note that we swapped arguments in app-facing constructors to avoid
    // conflicting signatures with serial constructor defined below.
    if (parameters.length == 0) {
      cfw.startMethod(
          "<init>",
          "(Laurora/javascript/Scriptable;" + "Laurora/javascript/ContextFactory;)V",
          ClassFileWriter.ACC_PUBLIC);

      // Invoke base class constructor
      cfw.add(ByteCode.ALOAD_0); // this
      cfw.addInvoke(ByteCode.INVOKESPECIAL, superName, "<init>", "()V");
    } else {
      StringBuilder sig =
          new StringBuilder(
              "(Laurora/javascript/Scriptable;" + "Laurora/javascript/ContextFactory;");
      int marker = sig.length(); // lets us reuse buffer for super signature
      for (Class<?> c : parameters) {
        appendTypeString(sig, c);
      }
      sig.append(")V");
      cfw.startMethod("<init>", sig.toString(), ClassFileWriter.ACC_PUBLIC);

      // Invoke base class constructor
      cfw.add(ByteCode.ALOAD_0); // this
      short paramOffset = 3;
      for (Class<?> parameter : parameters) {
        paramOffset += generatePushParam(cfw, paramOffset, parameter);
      }
      locals = paramOffset;
      sig.delete(1, marker);
      cfw.addInvoke(ByteCode.INVOKESPECIAL, superName, "<init>", sig.toString());
    }

    // Save parameter in instance variable "delegee"
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.add(ByteCode.ALOAD_1); // first arg: Scriptable delegee
    cfw.add(ByteCode.PUTFIELD, adapterName, "delegee", "Laurora/javascript/Scriptable;");

    // Save parameter in instance variable "factory"
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.add(ByteCode.ALOAD_2); // second arg: ContextFactory instance
    cfw.add(ByteCode.PUTFIELD, adapterName, "factory", "Laurora/javascript/ContextFactory;");

    cfw.add(ByteCode.ALOAD_0); // this for the following PUTFIELD for self
    // create a wrapper object to be used as "this" in method calls
    cfw.add(ByteCode.ALOAD_1); // the Scriptable delegee
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.addInvoke(
        ByteCode.INVOKESTATIC,
        "aurora/javascript/JavaAdapter",
        "createAdapterWrapper",
        "(Laurora/javascript/Scriptable;"
            + "Ljava/lang/Object;"
            + ")Laurora/javascript/Scriptable;");
    cfw.add(ByteCode.PUTFIELD, adapterName, "self", "Laurora/javascript/Scriptable;");

    cfw.add(ByteCode.RETURN);
    cfw.stopMethod(locals);
  }
Пример #3
0
 static Provider getSunPKCS11(String config) throws Exception {
   Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
   Constructor cons = clazz.getConstructor(new Class[] {String.class});
   Object obj = cons.newInstance(new Object[] {config});
   return (Provider) obj;
 }
  /*
   * Does the real work of creating an AppletAudioClip from an InputStream.
   * This function is used by both constructors.
   */
  void createAppletAudioClip(InputStream in) throws IOException {

    // If we haven't initialized yet, we need to find the AudioClip constructor using reflection.
    // We'll use com.sun.media.sound.JavaSoundAudioClip to implement AudioClip if the Java Sound
    // extension is installed.  Otherwise, we use sun.audio.SunAudioClip.

    if (acConstructor == null) {

      if (DEBUG) System.out.println("Initializing AudioClip constructor.");

      try {

        acConstructor =
            (Constructor)
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction() {

                      public Object run()
                          throws NoSuchMethodException, SecurityException, ClassNotFoundException {

                        Class acClass = null;

                        try {

                          // attempt to load the Java Sound extension class JavaSoundAudioClip

                          acClass =
                              Class.forName(
                                  "com.sun.media.sound.JavaSoundAudioClip",
                                  true,
                                  ClassLoader
                                      .getSystemClassLoader()); // may throw ClassNotFoundException

                          if (DEBUG) System.out.println("Loaded JavaSoundAudioClip");

                        } catch (ClassNotFoundException e) {

                          acClass =
                              Class.forName(
                                  "sun.audio.SunAudioClip",
                                  true,
                                  null); // may throw ClassNotFoundException

                          if (DEBUG) System.out.println("Loaded SunAudioClip");
                        }

                        Class[] parms = new Class[1];
                        parms[0] =
                            Class.forName(
                                "java.io.InputStream"); // may throw ClassNotFoundException
                        return acClass.getConstructor(
                            parms); // may throw NoSuchMethodException or SecurityException
                      }
                    });

      } catch (PrivilegedActionException e) {

        if (DEBUG) System.out.println("Got a PrivilegedActionException: " + e.getException());

        // e.getException() may be a NoSuchMethodException, SecurityException, or
        // ClassNotFoundException.
        // however, we throw an IOException to avoid changing the interfaces....

        throw new IOException("Failed to get AudioClip constructor: " + e.getException());
      }
    } // if not initialized

    // Now instantiate the AudioClip object using the constructor we discovered above.

    try {

      Object[] args = new Object[] {in};
      audioClip = (AudioClip) acConstructor.newInstance(args); // may throw InstantiationException,
      // IllegalAccessException,
      // IllegalArgumentException,
      // InvocationTargetException

    } catch (Exception e3) {

      // no matter what happened, we throw an IOException to avoid changing the interfaces....
      throw new IOException("Failed to construct the AudioClip: " + e3);
    }
  }