Ejemplo n.º 1
0
  public static String classLoaderToString(ClassLoader cl) {
    if (cl == null) return NULL;

    if (cl == ClassLoader.getSystemClassLoader()) return "system";

    StringBuffer sb = new StringBuffer();
    sb.append(
        "hashCode: "
            + System.identityHashCode(cl)
            + " (parent "
            + ClassUtil.classLoaderToString(cl.getParent())
            + ")");
    return sb.toString();
  }
Ejemplo n.º 2
0
  public Object createInstance(String className, Class desiredClass) {
    Object instance;

    if (className == null || className.length() == 0) {
      instance = new ASObject();
    } else if (className.startsWith(">")) // Handle [RemoteClass] (no server alias)
    {
      instance = new ASObject();
      ((ASObject) instance).setType(className);
    } else {
      SerializationContext context = getSerializationContext();
      if ((context.instantiateTypes || className.startsWith("flex."))
          && className.indexOf("activity") == -1) {
        instance = ClassUtil.createDefaultInstance(desiredClass, null);
        //            	instance = createInstanceFromClassName(className);
      } else {
        // Just return type info with an ASObject...
        instance = new ASObject();
        ((ASObject) instance).setType(className);
      }
    }
    return instance;
  }
Ejemplo n.º 3
0
 /**
  * Creates the default instance of the class and verifies that it matches with the expected class
  * type, if one passed in.
  *
  * @param cls The class to create.
  * @param expectedInstance The expected class type.
  * @return The default instance of the class.
  */
 public static Object createDefaultInstance(Class cls, Class expectedInstance) {
   return ClassUtil.createDefaultInstance(cls, expectedInstance, false /*validate*/);
 }
Ejemplo n.º 4
0
  /** {@inheritDoc} */
  public void setValue(Object instance, String propertyName, Object value) {
    BeanProperty bp = getBeanProperty(instance, propertyName);

    if (bp != null) {
      if (bp.isWrite()) {
        try {
          Class desiredPropClass = bp.getType();
          TypeMarshaller marshaller = TypeMarshallingContext.getTypeMarshaller();
          value = marshaller.convert(value, desiredPropClass);
          ClassUtil.validateAssignment(instance, propertyName, value);
          bp.set(instance, value);
        } catch (Exception e) {
          SerializationContext context = getSerializationContext();

          // Log ignore failed property set errors
          if (Log.isWarn() && logPropertyErrors(context)) {
            Logger log = Log.getLogger(LOG_CATEGORY);
            log.warn(
                "Failed to set property {0} on type {1}.",
                new Object[] {propertyName, getAlias(instance)}, e);
          }

          if (!ignorePropertyErrors(context)) {
            // Failed to get property '{propertyName}' on type '{className}'.
            MessageException ex = new MessageException();
            ex.setMessage(
                FAILED_PROPERTY_WRITE_ERROR, new Object[] {propertyName, getAlias(instance)});
            ex.setRootCause(e);
            throw ex;
          }
        }
      } else {
        SerializationContext context = getSerializationContext();

        if (Log.isWarn() && logPropertyErrors(context)) {
          Logger log = Log.getLogger(LOG_CATEGORY);
          log.warn(
              "Property {0} not writable on class {1}",
              new Object[] {propertyName, getAlias(instance)});
        }

        if (!ignorePropertyErrors(context)) {
          // Property '{propertyName}' not writable on class '{alias}'.
          MessageException ex = new MessageException();
          ex.setMessage(
              NON_WRITABLE_PROPERTY_ERROR, new Object[] {propertyName, getAlias(instance)});
          throw ex;
        }
      }
    } else {
      SerializationContext context = getSerializationContext();

      if (Log.isWarn() && logPropertyErrors(context)) {
        Logger log = Log.getLogger(LOG_CATEGORY);
        log.warn(
            "Ignoring set property {0} for type {1} as a setter could not be found.",
            new Object[] {propertyName, getAlias(instance)});
      }

      if (!ignorePropertyErrors(context)) {
        // Property '{propertyName}' not found on class '{alias}'.
        MessageException ex = new MessageException();
        ex.setMessage(UNKNOWN_PROPERTY_ERROR, new Object[] {propertyName, getAlias(instance)});
        throw ex;
      }
    }
  }