private XmlUIElement getXmlUIElementFor(String typeArg) {
   if (typeToClassMappingProp == null) {
     setUpMappingsHM();
   }
   String clsName = (String) typeToClassMappingProp.get(typeArg);
   if ((clsName != null) && !(clsName.equals("*NOTFOUND*")) && !(clsName.equals("*EXCEPTION*"))) {
     try {
       Class cls = Class.forName(clsName);
       return (XmlUIElement) cls.newInstance();
     } catch (Throwable th) {
       typeToClassMappingProp.put(typeArg, "*EXCEPTION*");
       showErrorMessage(
           MessageFormat.format(
               ProvClientUtils.getString(
                   "{0} occurred when trying to get the XmlUIElement for type : {1}"),
               new Object[] {th.getClass().getName(), typeArg}));
       th.printStackTrace();
       return null;
     }
   } else if (clsName == null) {
     typeToClassMappingProp.put(typeArg, "*NOTFOUND*");
     showErrorMessage(
         MessageFormat.format(
             ProvClientUtils.getString(
                 "The type {0} does not have the corresponding XMLUIElement specified in the TypeToUIElementMapping.txt file"),
             new Object[] {typeArg}));
   }
   return null;
 }
 public Object m(String method, Object[] args) {
   try {
     Class<?> c = obj.getClass();
     Method m = null;
     if (args != null) {
       Class[] types = new Class[args.length];
       for (int i = 0; i < args.length; i++) {
         if (args[i] != null) {
           types[i] = args[i].getClass();
         } else types[i] = String.class; // FIXME, use the string type as default
       }
       m = c.getMethod(method, types);
     } else {
       m = c.getMethod(method, (Class[]) null);
     }
     // Log.e(TAG,"now call obj method:"+m.toString());
     return m.invoke(obj, args);
   } catch (NoSuchMethodException e) {
     // e.printStackTrace();
     Log.e(TAG, "Can't find method:" + method);
   } catch (SecurityException e) {
     Log.e(TAG, "Can't get method:" + method + " for security issue");
   } catch (Exception e) {
     Log.e(TAG, "call method:" + method + " failed:" + e.getMessage());
   }
   return null;
 }
Exemplo n.º 3
0
 private void checkClass(Class cls, Object obj) {
   boolean found = false;
   java.lang.Class<? extends Object> klz = obj.getClass();
   do {
     if (cls.name.equals(klz.getSimpleName())) {
       found = true;
       break;
     }
     klz = klz.getSuperclass();
   } while (klz != null);
   if (!found) {
     errors.add("Object " + obj + " should have class " + cls.name);
     return;
   }
   // Don't use klz here, we want the actual class of obj, not it's inherited root.
   String actualCls = obj.getClass().getSimpleName();
   Class concreteCls = findSubClassOf(cls.name, actualCls);
   if (concreteCls == null) {
     errors.add("No concrete subclass of " + cls.name + " corresponding to " + actualCls);
   } else {
     for (Field f : concreteCls.fields) {
       errorsForField(f, obj);
     }
   }
 }
Exemplo n.º 4
0
 static Object createObject(String className)
     throws InstantiationException, IllegalAccessException, ClassNotFoundException {
   Object object1 = null;
   Class classDefinition = Class.forName(className);
   object1 = classDefinition.newInstance();
   return object1;
 }
Exemplo n.º 5
0
 private static boolean lookForInterface(
     java.lang.Class<?> klass, String className, Set<java.lang.Class<?>> alreadyVisited) {
   if (klass.getName().equals(className)) return true;
   // did we already visit this type?
   if (!alreadyVisited.add(klass)) return false;
   // first see if it satisfies it directly
   SatisfiedTypes satisfiesAnnotation = klass.getAnnotation(SatisfiedTypes.class);
   if (satisfiesAnnotation != null) {
     for (String satisfiedType : satisfiesAnnotation.value()) {
       satisfiedType = declClassName(satisfiedType);
       int i = satisfiedType.indexOf('<');
       if (i > 0) {
         satisfiedType = satisfiedType.substring(0, i);
       }
       try {
         if (lookForInterface(
             java.lang.Class.forName(satisfiedType, true, klass.getClassLoader()),
             className,
             alreadyVisited)) {
           return true;
         }
       } catch (ClassNotFoundException e) {
         throw new RuntimeException(e);
       }
     }
   }
   // now look at this class's interfaces
   for (java.lang.Class<?> intrface : klass.getInterfaces()) {
     if (lookForInterface(intrface, className, alreadyVisited)) return true;
   }
   // no luck
   return false;
 }
Exemplo n.º 6
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 + "'");
    }
  }
Exemplo n.º 7
0
  /**
   * Returns all the annotations of this class. If there are no annotations then an empty array is
   * returned.
   *
   * @return a copy of the array containing this class' annotations.
   * @see #getDeclaredAnnotations()
   */
  public Annotation[] getAnnotations() {
    /*
     * We need to get the annotations declared on this class, plus the
     * annotations from superclasses that have the "@Inherited" annotation
     * set.  We create a temporary map to use while we accumulate the
     * annotations and convert it to an array at the end.
     *
     * It's possible to have duplicates when annotations are inherited.
     * We use a Map to filter those out.
     *
     * HashMap might be overkill here.
     */
    HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
    Annotation[] declaredAnnotations = getDeclaredAnnotations();

    for (int i = declaredAnnotations.length - 1; i >= 0; --i) {
      map.put(declaredAnnotations[i].annotationType(), declaredAnnotations[i]);
    }
    for (Class<?> sup = getSuperclass(); sup != null; sup = sup.getSuperclass()) {
      declaredAnnotations = sup.getDeclaredAnnotations();
      for (int i = declaredAnnotations.length - 1; i >= 0; --i) {
        Class<?> clazz = declaredAnnotations[i].annotationType();
        if (!map.containsKey(clazz) && clazz.isAnnotationPresent(Inherited.class)) {
          map.put(clazz, declaredAnnotations[i]);
        }
      }
    }

    /* convert annotation values from HashMap to array */
    Collection<Annotation> coll = map.values();
    return coll.toArray(new Annotation[coll.size()]);
  }
Exemplo n.º 8
0
 private static boolean arrayTypeMatch(Class<?> srcComp, Class<?> destComp) {
   if (srcComp.isPrimitive()) {
     return srcComp.equals(destComp);
   } else {
     return !destComp.isPrimitive();
   }
 }
Exemplo n.º 9
0
  /**
   * Uses 'loader' to load class 'clzz', and calls the static method 'method'. If the return value
   * does not equal 'value' (or if an exception is thrown), then a test failure is indicated.
   *
   * <p>If 'value' is null, then no equality check is performed -- the assertion fails only if an
   * exception is thrown.
   */
  protected void assertStaticCallEquals(
      ClassLoader loader, Class clzz, String method, Object value) {
    java.lang.Class<?> cls = null;
    try {
      cls = java.lang.Class.forName(clzz.getName(), true, loader);
    } catch (ClassNotFoundException e) {
    }
    assertNotNull(cls);

    java.lang.reflect.Method m = null;
    try {
      m = cls.getMethod(method);
    } catch (NoSuchMethodException e) {
    }
    assertNotNull(m);

    try {
      Object res = m.invoke(null);
      assertNotNull(res);
      if (value != null) {
        assertEquals(res, value);
      }
    } catch (InvocationTargetException | IllegalAccessException e) {
      fail("Unexpected exception thrown: " + e.getCause(), e.getCause());
    }
  }
Exemplo n.º 10
0
 @SuppressWarnings("unchecked")
 private boolean hasValidConstructor(java.lang.Class<?> aClass) {
   // The cast below is not necessary with the Java 5 compiler, but necessary with the Java 6
   // compiler,
   // where the return type of Class.getDeclaredConstructors() was changed
   // from Constructor<T>[] to Constructor<?>[]
   Constructor<? extends TestCase>[] constructors =
       (Constructor<? extends TestCase>[]) aClass.getConstructors();
   for (Constructor<? extends TestCase> constructor : constructors) {
     if (Modifier.isPublic(constructor.getModifiers())) {
       java.lang.Class<?>[] parameterTypes = constructor.getParameterTypes();
       if (parameterTypes.length == 0
           || (parameterTypes.length == 1 && parameterTypes[0] == String.class)) {
         return true;
       }
     }
   }
   Log.i(
       LOG_TAG,
       String.format(
           "TestCase class %s is missing a public constructor with no parameters "
               + "or a single String parameter - skipping",
           aClass.getName()));
   return false;
 }
Exemplo n.º 11
0
 void initResources() {
   final java.lang.Class clazz = this.getClass();
   if (resourceBundle != null) {
     try {
       if (images == null) {
         images = new org.eclipse.swt.graphics.Image[imageLocations.length];
         for (int i = 0; i < imageLocations.length; ++i) {
           java.io.InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
           org.eclipse.swt.graphics.ImageData source =
               new org.eclipse.swt.graphics.ImageData(sourceStream);
           org.eclipse.swt.graphics.ImageData mask = source.getTransparencyMask();
           images[i] = new org.eclipse.swt.graphics.Image(null, source, mask);
           try {
             sourceStream.close();
           } catch (java.io.IOException e) {
             e.printStackTrace();
           }
         }
       }
       return;
     } catch (java.lang.Throwable t) {
     }
   }
   java.lang.String error =
       resourceBundle != null
           ? getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new java.lang.RuntimeException(error);
 }
Exemplo n.º 12
0
 public void initResources() {
   final java.lang.Class clazz = org.eclipse.swt.examples.paint.PaintExample.class;
   if (resourceBundle != null) {
     try {
       for (int i = 0; i < tools.length; ++i) {
         org.eclipse.swt.examples.paint.Tool tool = tools[i];
         java.lang.String id = tool.group + '.' + tool.name;
         java.io.InputStream sourceStream =
             clazz.getResourceAsStream(getResourceString(id + ".image"));
         org.eclipse.swt.graphics.ImageData source =
             new org.eclipse.swt.graphics.ImageData(sourceStream);
         org.eclipse.swt.graphics.ImageData mask = source.getTransparencyMask();
         tool.image = new org.eclipse.swt.graphics.Image(null, source, mask);
         try {
           sourceStream.close();
         } catch (java.io.IOException e) {
           e.printStackTrace();
         }
       }
       return;
     } catch (java.lang.Throwable t) {
     }
   }
   java.lang.String error =
       resourceBundle != null
           ? getResourceString("error.CouldNotLoadResources")
           : "Unable to load resources";
   freeResources();
   throw new java.lang.RuntimeException(error);
 }
 public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
     try {
         // This works for classes that aren't actually wrapping anything
         return iface.cast(this);
     } catch (ClassCastException cce) {
         throw SQLError.createSQLException("Unable to unwrap to " + iface.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
     }
 }
Exemplo n.º 14
0
 /**
  * Casts this {@code Class} to represent a subclass of the specified class. If successful, this
  * {@code Class} is returned; otherwise a {@code ClassCastException} is thrown.
  *
  * @param clazz the required type.
  * @return this {@code Class} cast as a subclass of the given type.
  * @throws ClassCastException if this {@code Class} cannot be cast to the specified type.
  */
 @SuppressWarnings("unchecked")
 public <U> Class<? extends U> asSubclass(Class<U> clazz) {
   if (clazz.isAssignableFrom(this)) {
     return (Class<? extends U>) this;
   }
   String actualClassName = this.getName();
   String desiredClassName = clazz.getName();
   throw new ClassCastException(actualClassName + " cannot be cast to " + desiredClassName);
 }
Exemplo n.º 15
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;
  }
Exemplo n.º 16
0
 public GridElement cloneFromMe() {
   try {
     java.lang.Class<? extends GridElement> cx = this.getClass(); // get class of dynamic object
     GridElement c = cx.newInstance();
     c.setPanelAttributes(getPanelAttributes()); // copy states
     c.setRectangle(getRectangle());
     getDiagramHandler().setHandlerAndInitListeners(c);
     return c;
   } catch (Exception e) {
     log.error("Error at calling CloneFromMe() on entity", e);
   }
   return null;
 }
Exemplo n.º 17
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());
   }
 }
 /** Override toString */
 public String toString() {
   String strId = "ClassifierContextDecl";
   String name = null;
   try {
     java.lang.Class cls = this.getClass();
     java.lang.reflect.Method method = cls.getMethod("getName", new java.lang.Class[] {});
     name = (String) method.invoke(this, new Object[] {});
     if (name != null && name.length() == 0) name = null;
   } catch (Exception e) {
   }
   if (name == null) return strId;
   else return strId + " '" + name + "'";
 }
Exemplo n.º 19
0
 @Override
 public ExecuteContext execute(ExecuteContext context) throws Exception {
   int pos = classFilePath.lastIndexOf(File.separatorChar);
   String folder = classFilePath.substring(0, pos);
   String file = classFilePath.substring(pos + 1);
   file = file.replace(".class", "");
   FileSystemClassLoader loader = new FileSystemClassLoader(folder);
   java.lang.Class<?> classs = loader.findClass(file);
   Object obj = classs.newInstance();
   Method method = classs.getMethod("run");
   method.invoke(obj);
   return context;
 }
Exemplo n.º 20
0
 private List<Class<?>> buildClassesList(
     List<Class<?>> result, Set<String> seen, boolean publicOnly) {
   for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
     for (Class<?> f : c.getClassCache().getDeclaredClasses(false, publicOnly)) {
       String s = f.toString();
       if (!seen.contains(s)) {
         result.add(f);
         seen.add(s);
       }
     }
   }
   return result;
 }
Exemplo n.º 21
0
  /**
   * Gets the checklist for an element.
   *
   * @param dm is the element
   * @return a checklist
   */
  public static Checklist getChecklistFor(Object dm) {
    Checklist cl;

    java.lang.Class cls = dm.getClass();
    while (cls != null) {
      cl = lookupChecklist(cls);
      if (cl != null) {
        return cl;
      }
      cls = cls.getSuperclass();
    }
    return null;
  }
Exemplo n.º 22
0
 public Entity CloneFromMe() {
   try { // LME
     java.lang.Class<? extends Entity> cx = this.getClass(); // get class of dynamic object
     Entity c = cx.newInstance();
     c.setState(this.getPanelAttributes()); // copy states
     c.setBounds(this.getBounds());
     return c;
   } catch (InstantiationException e) {
     System.err.println("UMLet -> Entity/" + this.getClass().toString() + ": " + e);
   } catch (IllegalAccessException e) {
     System.err.println("UMLet -> Entity/" + this.getClass().toString() + ": " + e);
   }
   return null;
 }
Exemplo n.º 23
0
 private static boolean classExtendsClass(java.lang.Class<?> klass, String className) {
   if (klass == null) return false;
   if (klass.getName().equals(className)) return true;
   if ((className.equals("ceylon.language.Basic"))
       && klass != java.lang.Object.class
       && !isSubclassOfString(klass)
       // && klass!=java.lang.String.class
       && !klass.isAnnotationPresent(Class.class)
       && (!klass.isInterface() || !klass.isAnnotationPresent(Ceylon.class))) {
     // TODO: this is broken for a Java class that
     //      extends a Ceylon class
     return true;
   }
   Class classAnnotation = klass.getAnnotation(Class.class);
   if (classAnnotation != null) {
     String superclassName = declClassName(classAnnotation.extendsType());
     int i = superclassName.indexOf('<');
     if (i > 0) {
       superclassName = superclassName.substring(0, i);
     }
     if (superclassName.isEmpty()) {
       return false;
     }
     try {
       return classExtendsClass(
           java.lang.Class.forName(superclassName, true, klass.getClassLoader()), className);
     } catch (ClassNotFoundException e) {
       throw new RuntimeException(e);
     }
   }
   return classExtendsClass(klass.getSuperclass(), className);
 }
Exemplo n.º 24
0
 private static void appendTypeName(StringBuilder out, Class<?> c) {
   if (c == null) {
     out.append("null");
   } else {
     int dimensions = 0;
     while (c.isArray()) {
       c = c.getComponentType();
       dimensions++;
     }
     out.append(c.getName());
     for (int d = 0; d < dimensions; d++) {
       out.append("[]");
     }
   }
 }
Exemplo n.º 25
0
 /**
  * Get the package for the specified class. The class's class loader is used to find the package
  * instance corresponding to the specified class. If the class loader is the bootstrap class
  * loader, which may be represented by {@code null} in some implementations, then the set of
  * packages loaded by the bootstrap class loader is searched to find the package.
  *
  * <p>Packages have attributes for versions and specifications only if the class loader created
  * the package instance with the appropriate attributes. Typically those attributes are defined in
  * the manifests that accompany the classes.
  *
  * @param class the class to get the package of.
  * @return the package of the class. It may be null if no package information is available from
  *     the archive or codebase.
  */
 static Package getPackage(Class<?> c) {
   String name = c.getName();
   int i = name.lastIndexOf('.');
   if (i != -1) {
     name = name.substring(0, i);
     ClassLoader cl = c.getClassLoader();
     if (cl != null) {
       return cl.getPackage(name);
     } else {
       return getSystemPackage(name);
     }
   } else {
     return null;
   }
 }
 public Object f(String member) {
   try {
     Class<?> c = obj.getClass();
     Field f = null;
     f = c.getField(member);
     return f.get(obj);
   } catch (NoSuchFieldException e) {
     Log.e(TAG, "Can't find member:" + member);
   } catch (SecurityException e) {
     Log.e(TAG, "Can't get member:" + member + " for security issue");
   } catch (Exception e) {
     Log.e(TAG, "call member:" + member + " failed");
   }
   return null;
 }
 public Object getFieldValue(String member) {
   try {
     Class<?> c = obj.getClass();
     Field field = c.getDeclaredField(member);
     field.setAccessible(true);
     return field.get(obj);
   } catch (NoSuchFieldException e) {
     Log.e(TAG, "Can't find member:" + member);
   } catch (SecurityException e) {
     Log.e(TAG, "Can't get member:" + member + " for security issue");
   } catch (Exception e) {
     Log.e(TAG, "call member:" + member + " failed");
   }
   return null;
 }
Exemplo n.º 28
0
  public java.sql.Connection getDbConnection(java.lang.String userName, java.lang.String passWord)
      throws java.sql.SQLException {

    java.sql.Connection connection = null;

    try {

      java.lang.Class.forName("org.postgresql.Driver");

    } catch (java.lang.ClassNotFoundException cnf) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), cnf.getMessage());
    }

    try {

      connection =
          java.sql.DriverManager.getConnection(
              "jdbc:postgresql://" + this.dbServerIp + ":" + dbPort + "/" + activeDatabase,
              userName,
              passWord);

    } catch (java.sql.SQLException sqlExec) {

      javax.swing.JOptionPane.showMessageDialog(
          new javax.swing.JFrame(), "ERROR : Logon denied due to incorrect password!");
    }

    return connection;
  }
  private void compile() {
    Class[] staticLib = new Class[1];

    Class[] dynamicLib = new Class[1];
    context = new Object[1];
    Class[] dotLib = {Object.class, String.class, Class.class, java.util.Date.class};
    try {
      staticLib[0] = java.lang.Class.forName("java.lang.Math");

      pro = new ValueProvider();
      dynamicLib[0] = pro.getClass();
      context[0] = pro;

      res = new Resolver();

    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Can not find class for JEL!", e);
    }

    try {
      lib = new Library(staticLib, dynamicLib, dotLib, res, null);
      lib.markStateDependent("random", null);
    } catch (gnu.jel.CompilationException ec1) {
      throw new RuntimeException("Can not compile JEL Library!", ec1);
    }

    try {
      compExpression = Evaluator.compile(parsedExpression, lib, Boolean.TYPE);
    } catch (gnu.jel.CompilationException ec2) {
      throw new RuntimeException("Can not compile JEL Expression: " + expression, ec2);
    }
  }
  /*
   * Create a new ObjectStreamClass_1_3_1 from a loaded class.
   * Don't call this directly, call lookup instead.
   */
  private ObjectStreamClass_1_3_1(
      java.lang.Class cl, ObjectStreamClass_1_3_1 superdesc, boolean serial, boolean extern) {
    ofClass = cl; /* created from this class */

    if (Proxy.isProxyClass(cl)) {
      forProxyClass = true;
    }

    name = cl.getName();
    superclass = superdesc;
    serializable = serial;
    if (!forProxyClass) {
      // proxy classes are never externalizable
      externalizable = extern;
    }

    /*
     * Enter this class in the table of known descriptors.
     * Otherwise, when the fields are read it may recurse
     * trying to find the descriptor for itself.
     */
    insertDescriptorFor(this);

    /*
     * The remainder of initialization occurs in init(), which is called
     * after the lock on the global class descriptor table has been
     * released.
     */
  }