Ejemplo n.º 1
0
  public JavaClassDef addClass(String name, Class type, String extension, Class javaClassDefClass)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException,
          InstantiationException {
    synchronized (_javaClassWrappers) {
      JavaClassDef def = _javaClassWrappers.get(name);

      if (def == null) {
        if (log.isLoggable(Level.FINEST)) {
          if (extension == null) {
            log.finest(L.l("PHP loading class {0} with type {1}", name, type.getName()));
          } else {
            log.finest(
                L.l(
                    "PHP loading class {0} with type {1} providing extension {2}",
                    name, type.getName(), extension));
          }
        }

        if (javaClassDefClass != null) {
          Constructor constructor =
              javaClassDefClass.getConstructor(ModuleContext.class, String.class, Class.class);

          def = (JavaClassDef) constructor.newInstance(this, name, type);
        } else {
          def = JavaClassDef.create(this, name, type);

          if (def == null) {
            def = createDefaultJavaClassDef(name, type, extension);
          }
        }

        def.setPhpClass(true);

        _javaClassWrappers.put(name, def);
        // _lowerJavaClassWrappers.put(name.toLowerCase(), def);

        _staticClasses.put(name, def);
        // _lowerStaticClasses.put(name.toLowerCase(), def);

        // def.introspect();

        if (extension != null) {
          _extensionSet.add(extension);
        }
      }

      return def;
    }
  }
Ejemplo n.º 2
0
  /** Sets fields not specified by the value. */
  @Override
  protected Value putFieldExt(Env env, StringValue name, Value value) {
    if (_object == null) {
      createJavaObject(env);
    }

    return _javaClassDef.putField(env, this, name, value);
  }
Ejemplo n.º 3
0
  @Override
  protected void printRImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    if (_object == null) {
      _object = createJavaObject(Env.getInstance());
    }

    _javaClassDef.printRImpl(env, _object, out, depth, valueSet);
  }
Ejemplo n.º 4
0
  @Override
  public void varDumpImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    if (_object == null) {
      _object = createJavaObject(Env.getInstance());
    }

    if (!_javaClassDef.varDumpImpl(env, this, _object, out, depth, valueSet)) {
      super.varDumpImpl(env, out, depth, valueSet);
    }
  }
Ejemplo n.º 5
0
  /** Adds a java class */
  public JavaClassDef getJavaClassDefinition(String className) {
    // Note, this method must not trigger an introspection to avoid
    // any race conditions.  It is only responsible for creating the
    // wrapper around the class, i.e. it's a leaf node, not a recursive not

    synchronized (_javaClassWrappers) {
      JavaClassDef def = _javaClassWrappers.get(className);

      if (def != null) {
        return def;
      }

      try {
        Class type;

        try {
          type = Class.forName(className, false, _loader);
        } catch (ClassNotFoundException e) {
          throw new ClassNotFoundException(
              L.l("'{0}' is not a known Java class: {1}", className, e.toString()), e);
        }

        def = JavaClassDef.create(this, className, type);

        if (def == null) {
          def = createDefaultJavaClassDef(className, type);
        }

        _javaClassWrappers.put(className, def);
        _javaClassWrappers.put(type.getName(), def);

        // def.introspect();

        return def;
      } catch (RuntimeException e) {
        throw e;
      } catch (Exception e) {
        throw new BiancaRuntimeException(e);
      }
    }
  }
Ejemplo n.º 6
0
  /** Gets or creates a JavaClassDef for the given class name. */
  public JavaClassDef getJavaClassDefinition(Class type, String className) {
    JavaClassDef def;

    synchronized (_javaClassWrappers) {
      def = _javaClassWrappers.get(className);

      if (def != null) {
        return def;
      }

      def = JavaClassDef.create(this, className, type);

      if (def == null) {
        def = createDefaultJavaClassDef(className, type);
      }

      _javaClassWrappers.put(className, def);
      _javaClassWrappers.put(type.getName(), def);
    }

    return def;
  }
Ejemplo n.º 7
0
  /** Returns fields not explicitly specified by this value. */
  @Override
  protected Value getFieldExt(Env env, StringValue name) {
    if (_object == null) {
      _object = createJavaObject(env);
    }

    Value parentValue = super.getFieldExt(env, name);
    if (parentValue != NullValue.NULL && parentValue != UnsetValue.UNSET) {
      return parentValue;
    }

    Value value = _javaClassDef.getField(env, this, name);
    Value biancaValue = _biancaClass.getField(env, this, name);

    if (biancaValue != null && biancaValue != UnsetValue.UNSET && biancaValue != NullValue.NULL) {
      return biancaValue;
    }

    if (value != null) {
      return value;
    } else {
      return super.getFieldExt(env, name);
    }
  }
Ejemplo n.º 8
0
 /** Creats a backing Java object for this php object. */
 private Object createJavaObject(Env env) {
   Value javaWrapper = _javaClassDef.callNew(env, new Value[0]);
   return javaWrapper.toJavaObject();
 }