Example #1
0
  static {
    java.util.Properties prop = System.getProperties();
    java.lang.String vendor = prop.getProperty("java.vendor");
    java.lang.String platform_class_name;
    java.lang.Class platform_class;

    if (vendor.equals("Oracle Corporation")) {
      platform_class_name = "python.platform.JavaPlatform";
    } else if (vendor.equals("The Android Project")) {
      platform_class_name = "python.platform.AndroidPlatform";
    } else {
      throw new org.python.exceptions.RuntimeError("Unknown platform vendor '" + vendor + "'");
    }

    try {
      platform_class = java.lang.Class.forName(platform_class_name);
      impl = (python.Platform) platform_class.getConstructor().newInstance();
    } catch (ClassNotFoundException e) {
      throw new org.python.exceptions.RuntimeError(
          "Unable to find platform '" + platform_class_name + "'");
    } catch (NoSuchMethodException e) {
      throw new org.python.exceptions.RuntimeError(
          "Unable to call constructor for plaform '" + platform_class_name + "'");
    } catch (InstantiationException e) {
      throw new org.python.exceptions.RuntimeError(
          "Unable to instantiate platform '" + platform_class_name + "'");
    } catch (IllegalAccessException e) {
      throw new org.python.exceptions.RuntimeError(
          "Unable to access constructor for platform '" + platform_class_name + "'");
    } catch (java.lang.reflect.InvocationTargetException e) {
      throw new org.python.exceptions.RuntimeError(
          "Unable to invoke constructor for platform '" + platform_class_name + "'");
    }
  }
Example #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;
  }
Example #3
0
 public GElement newGElement(java.lang.Class<? extends GElement> elementClass)
     throws NoProductException {
   try {
     Constructor<? extends GElement> constructor = elementClass.getConstructor(String.class);
     String id = IDgenerator.getInstance().generate(elementClass);
     GElement result = constructor.newInstance(id);
     result.initDefault();
     return result;
   } catch (Exception ex) {
     ex.printStackTrace();
     throw new NoProductException(elementClass.getName());
   }
 }
  static ClassLoader getSystemClassLoader() {
    // This method is called as the initialization of systemClassLoader,
    // so if there is a null value, this is the first call and we must check
    // for java.system.class.loader.
    String loader = System.getProperty("java.system.class.loader");
    ClassLoader default_sys = getSystemClassLoaderInternal();
    if (loader != null) {
      try {
        Class load_class = Class.forName(loader, true, default_sys);
        Constructor c = load_class.getConstructor(new Class[] {ClassLoader.class});
        default_sys = (ClassLoader) c.newInstance(new Object[] {default_sys});
      } catch (Exception ex) {
        throw new Error("Failed to load requested system classloader " + loader, ex);
      }
    }

    return default_sys;
  }
  private static final X509Certificate getInst(Object value) throws CertificateException {
    /*
     * This turns out not to work for now. To run under JDK1.2 we would
     * need to call beginPrivileged() but we can't do that and run
     * under JDK1.1.
     */
    String className = X509Provider;
    if (className == null || className.length() == 0) {
      // shouldn't happen, but assume corrupted properties file
      // provide access to sun implementation
      className = "com.sun.security.cert.internal.x509.X509V1CertImpl";
    }
    try {
      Class<?>[] params = null;
      if (value instanceof InputStream) {
        params = new Class<?>[] {InputStream.class};
      } else if (value instanceof byte[]) {
        params = new Class<?>[] {value.getClass()};
      } else throw new CertificateException("Unsupported argument type");
      Class<?> certClass = Class.forName(className);

      // get the appropriate constructor and instantiate it
      Constructor<?> cons = certClass.getConstructor(params);

      // get a new instance
      Object obj = cons.newInstance(new Object[] {value});
      return (X509Certificate) obj;

    } catch (ClassNotFoundException e) {
      throw new CertificateException("Could not find class: " + e);
    } catch (IllegalAccessException e) {
      throw new CertificateException("Could not access class: " + e);
    } catch (InstantiationException e) {
      throw new CertificateException("Problems instantiating: " + e);
    } catch (InvocationTargetException e) {
      throw new CertificateException("InvocationTargetException: " + e.getTargetException());
    } catch (NoSuchMethodException e) {
      throw new CertificateException("Could not find class method: " + e.getMessage());
    }
  }
  /**
   * Auto generated method signature
   *
   * @see com.pa.SecondFileService#getEmp
   * @param getEmp4
   */
  public com.pa.GetEmpResponse getEmp(com.pa.GetEmp getEmp4) throws java.rmi.RemoteException {

    org.apache.axis2.context.MessageContext _messageContext = null;
    try {
      org.apache.axis2.client.OperationClient _operationClient =
          _serviceClient.createClient(_operations[1].getName());
      _operationClient.getOptions().setAction("urn:getEmp");
      _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);

      addPropertyToOperationClient(
          _operationClient,
          org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
          "&");

      // create a message context
      _messageContext = new org.apache.axis2.context.MessageContext();

      // create SOAP envelope with that payload
      org.apache.axiom.soap.SOAPEnvelope env = null;

      env =
          toEnvelope(
              getFactory(_operationClient.getOptions().getSoapVersionURI()),
              getEmp4,
              optimizeContent(new javax.xml.namespace.QName("http://pa.com", "getEmp")),
              new javax.xml.namespace.QName("http://pa.com", "getEmp"));

      // adding SOAP soap_headers
      _serviceClient.addHeadersToEnvelope(env);
      // set the message context with that soap envelope
      _messageContext.setEnvelope(env);

      // add the message contxt to the operation client
      _operationClient.addMessageContext(_messageContext);

      // execute the operation client
      _operationClient.execute(true);

      org.apache.axis2.context.MessageContext _returnMessageContext =
          _operationClient.getMessageContext(
              org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
      org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();

      java.lang.Object object =
          fromOM(
              _returnEnv.getBody().getFirstElement(),
              com.pa.GetEmpResponse.class,
              getEnvelopeNamespaces(_returnEnv));

      return (com.pa.GetEmpResponse) object;

    } catch (org.apache.axis2.AxisFault f) {

      org.apache.axiom.om.OMElement faultElt = f.getDetail();
      if (faultElt != null) {
        if (faultExceptionNameMap.containsKey(
            new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"))) {
          // make the fault by reflection
          try {
            java.lang.String exceptionClassName =
                (java.lang.String)
                    faultExceptionClassNameMap.get(
                        new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"));
            java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
            java.lang.reflect.Constructor constructor = exceptionClass.getConstructor(String.class);
            java.lang.Exception ex = (java.lang.Exception) constructor.newInstance(f.getMessage());
            // message class
            java.lang.String messageClassName =
                (java.lang.String)
                    faultMessageMap.get(
                        new org.apache.axis2.client.FaultMapKey(faultElt.getQName(), "getEmp"));
            java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
            java.lang.Object messageObject = fromOM(faultElt, messageClass, null);
            java.lang.reflect.Method m =
                exceptionClass.getMethod("setFaultMessage", new java.lang.Class[] {messageClass});
            m.invoke(ex, new java.lang.Object[] {messageObject});

            throw new java.rmi.RemoteException(ex.getMessage(), ex);
          } catch (java.lang.ClassCastException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.ClassNotFoundException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.NoSuchMethodException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.reflect.InvocationTargetException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.IllegalAccessException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          } catch (java.lang.InstantiationException e) {
            // we cannot intantiate the class - throw the original Axis fault
            throw f;
          }
        } else {
          throw f;
        }
      } else {
        throw f;
      }
    } finally {
      if (_messageContext.getTransportOut() != null) {
        _messageContext.getTransportOut().getSender().cleanup(_messageContext);
      }
    }
  }
  public void analyze() {
    String[] phases = this.config.getPhases();

    // load each phase
    for (int ip = 0; ip < phases.length; ip++) {
      String p = phases[ip];

      PhaseData pData = this.config.getPhaseData(p);

      // load the classes
      if (pData.getName().equals("Loader")) {
        List<Map<String, File>> dirMapList = new ArrayList<Map<String, File>>();
        String[] toLoad = this.config.getInputFolderPath();
        int totalClassesToLoad = 0;
        for (int i = 0; i < toLoad.length; ++i) {
          this.progressText = "Parsing directory " + toLoad[i];
          Map<String, File> dirMap = this.getAllClasses(toLoad[i]);
          dirMapList.add(dirMap);
          totalClassesToLoad += dirMap.size();
        }
        toLoad = this.config.getToLoad();
        totalClassesToLoad += toLoad.length;
        int classesLoaded = 0;
        for (int il = 0; il < toLoad.length; il++) {
          String s = toLoad[il];
          try {
            data.add(new String[] {s});
          } catch (IOException e) {
            e.printStackTrace();
          }
          this.progressInt =
              (int) (100.0 * (++classesLoaded) / (totalClassesToLoad * phases.length));
          this.progressText = "Loading class " + pData.getName();
        }
        for (Map<String, File> dirMap : dirMapList) {
          for (Entry<String, File> e : dirMap.entrySet()) {
            try {
              data.addClass(e.getKey(), new FileInputStream(e.getValue()));
              this.progressInt =
                  (int) (100.0 * (++classesLoaded) / (totalClassesToLoad * phases.length));
              this.progressText = "Loading class " + e.getKey();
              // Thread.sleep(100);
            } catch (Exception e1) {
              e1.printStackTrace();
            }
          }
        }
      } else {
        // set the phase data
        String className = pData.getName();
        try {
          Class c = Class.forName(className);
          Constructor cons;
          IPatternFinder pf;
          if (pData.getArgs() != null && pData.getArgs().length > 0) {
            cons = c.getConstructor(new Class[] {pData.getArgs().getClass()});
            pf = (IPatternFinder) cons.newInstance(pData.getArgs());
          } else {
            cons = c.getConstructor(new Class[] {});
            pf = (IPatternFinder) cons.newInstance();
          }
          this.data.addPatternFinderPhase(p, pf);
        } catch (ClassNotFoundException
            | NoSuchMethodException
            | SecurityException
            | InstantiationException
            | IllegalAccessException
            | IllegalArgumentException
            | InvocationTargetException e) {
          e.printStackTrace();
        }
        // run all the other phases
        this.data.runPhase(p);
        this.progressInt = (int) (100.0 * (ip + 1) / phases.length);
        this.progressText = "Running phase " + pData.getName();
      }
    }
  }
  private void write(
      DataOutput objBuffer,
      Property template,
      Object obj,
      AtomicBoolean array,
      AtomicReference<String> structName,
      AtomicReference<Type> type,
      UnrealPackageReadOnly up)
      throws IOException {
    if (template instanceof ByteProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [BYTE]");
      objBuffer.writeByte((Integer) obj);
    } else if (template instanceof IntProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [INT]");
      objBuffer.writeInt((Integer) obj);
    } else if (template instanceof BoolProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [BOOL]");
      array.set((Boolean) obj);
    } else if (template instanceof FloatProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [FLOAT]");
      objBuffer.writeFloat((Float) obj);
    } else if (template instanceof ObjectProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [OBJ]");
      objBuffer.writeCompactInt((Integer) obj);
    } else if (template instanceof NameProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [NAME]");
      objBuffer.writeCompactInt((Integer) obj);
    } else if (template instanceof ArrayProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [ARRAY]");
      ArrayProperty arrayProperty = (ArrayProperty) template;

      List<Object> arrayList = (List<Object>) obj;
      objBuffer.writeCompactInt(arrayList.size());

      UnrealPackageReadOnly.ExportEntry arrayInner =
          (UnrealPackageReadOnly.ExportEntry) arrayProperty.getInner();
      String a = arrayInner.getObjectClass().getObjectName().getName();
      try {
        Class<? extends Property> pc =
            Class.forName("acmi.l2.clientmod.unreal." + a).asSubclass(Property.class);
        Property f =
            pc.getConstructor(
                    ByteBuffer.class, UnrealPackageReadOnly.ExportEntry.class, PropertiesUtil.class)
                .newInstance(
                    ByteBuffer.wrap(arrayInner.getObjectRawDataExternally())
                        .order(ByteOrder.LITTLE_ENDIAN),
                    arrayInner,
                    this);

        for (Object arrayObj : arrayList) {
          write(
              objBuffer,
              f,
              arrayObj,
              new AtomicBoolean(),
              new AtomicReference<>(),
              new AtomicReference<>(),
              up);
        }
      } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
      }
    } else if (template instanceof StructProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [STRUCT]");
      StructProperty structProperty = (StructProperty) template;
      structName.set(structProperty.getStructType().getObjectName().getName());
      writeStruct(objBuffer, structName.get(), up, (List<L2Property>) obj);
      //            if (false) { //Not used in L2?
      //                switch (structName.get()) {
      //                    case "Vector":
      //                        type.set(Type.VECTOR);
      //                        break;
      //                    case "Rotator":
      //                        type.set(Type.ROTATOR);
      //                        break;
      //                }
      //            }
    } else if (template instanceof StrProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [STR]");
      objBuffer.writeLine((String) obj);
    } else {
      throw new UnsupportedOperationException(
          template.getClass().getSimpleName() + " serialization not implemented");
    }
  }