Package java.lang.reflect

Examples of java.lang.reflect.AccessibleObject


    }
       
    // get the actual arguments
    final Sequence args[] = getArguments(contextSequence, contextItem);

    AccessibleObject bestMethod = candidateMethods.get(0);
    int conversionPrefs[] = getConversionPreferences(bestMethod, args);

    for (AccessibleObject nextMethod : candidateMethods) {
      int prefs[] = getConversionPreferences(nextMethod, args);
      for (int j = 0; j < prefs.length; j++) {
        if (prefs[j] < conversionPrefs[j]) {
          bestMethod = nextMethod;
          conversionPrefs = prefs;
          break;
        }
      }
    }
//    LOG.debug("calling method " + bestMethod.toString());
    Class<?> paramTypes[] = null;
    boolean isStatic = true;
    if (bestMethod instanceof Constructor<?>)
      {paramTypes = ((Constructor<?>) bestMethod).getParameterTypes();}
    else {
      paramTypes = ((Method) bestMethod).getParameterTypes();
      isStatic = Modifier.isStatic(((Method) bestMethod).getModifiers());
    }

    final Object[] params = new Object[isStatic ? args.length : args.length - 1];
    if (isStatic) {
      for (int i = 0; i < args.length; i++) {
        params[i] = args[i].toJavaObject(paramTypes[i]);
      }
    } else {
      for (int i = 1; i < args.length; i++) {
        params[i - 1] = args[i].toJavaObject(paramTypes[i - 1]);
      }
    }
       
        Sequence result;
    if (bestMethod instanceof Constructor<?>) {
      try {
        final Object object = ((Constructor<?>) bestMethod).newInstance(params);
                result = new JavaObjectValue(object);
      } catch (final IllegalArgumentException e) {
        throw new XPathException(this,
          "illegal argument to constructor "
            + bestMethod.toString()
            + ": "
            + e.getMessage(),
          e);
      } catch (final Exception e) {
        if (e instanceof XPathException)
          {throw (XPathException) e;}
        else
          {throw new XPathException(this,
            "exception while calling constructor "
              + bestMethod.toString()
              + ": "
              + e.getMessage(),
            e);}
      }
    } else {
      try {
        Object invocationResult;
        if (isStatic)
                    {invocationResult = ((Method) bestMethod).invoke(null, params);}
        else {
                    invocationResult =
            ((Method) bestMethod).invoke(
              args[0].toJavaObject(myClass),
              params);
        }
                result = XPathUtil.javaObjectToXPath(invocationResult, getContext());
      } catch (final IllegalArgumentException e) {
        throw new XPathException(this,
          "illegal argument to method "
            + bestMethod.toString()
            + ": "
            + e.getMessage(),
          e);
      } catch (final Exception e) {
        if (e instanceof XPathException)
          {throw (XPathException) e;}
        else
          {throw new XPathException(this,
            "exception while calling method "
              + bestMethod.toString()
              + ": "
              + e.getMessage(),
            e);}
      }
    }
View Full Code Here


   */
  private ConstrainedExecutable findExecutableMetaData(ExecutableElement executable) {

    List<ConstrainedParameter> parameterConstraints = getParameterMetaData( executable );
    boolean isCascading = executable.getAccessibleObject().isAnnotationPresent( Valid.class );
    AccessibleObject member = executable.getAccessibleObject();

    Map<Class<?>, Class<?>> groupConversions = getGroupConversions(
        member.getAnnotation( ConvertGroup.class ),
        member.getAnnotation( ConvertGroup.List.class )
    );

    Map<ConstraintType, List<ConstraintDescriptorImpl<?>>> executableConstraints = partition(
        findConstraints(
            executable.getAccessibleObject(),
View Full Code Here

      JsValueGlue.set(jsValue, classLoader, dispIdOracle, field.getType(),
          javaDispatch.getFieldValue(dispId));
      return;
    } else {
      MethodAdaptor method = javaDispatch.getMethod(dispId);
      AccessibleObject obj = method.getUnderlyingObject();
      DispatchMethod64 dispMethod = (DispatchMethod64) WrappersCache.getWrapperForObject(classLoader, obj);
      if (dispMethod == null) {
        dispMethod = new MethodDispatch64(classLoader, dispIdOracle, method);
        WrappersCache.putWrapperForObject(classLoader, obj, dispMethod);
      }
View Full Code Here

      JsValueGlue.set(jsValue, classLoader, dispIdOracle, field.getType(),
          javaDispatch.getFieldValue(dispId));
      return;
    } else {
      MethodAdaptor method = javaDispatch.getMethod(dispId);
      AccessibleObject obj = method.getUnderlyingObject();
      DispatchMethod32/*64*/ dispMethod = (DispatchMethod32/*64*/)WrappersCache.getWrapperForObject(classLoader, obj);
      if (dispMethod == null) {
        dispMethod = new MethodDispatch32/*64*/(classLoader, dispIdOracle, method);
        WrappersCache.putWrapperForObject(classLoader, obj, dispMethod);
      }
View Full Code Here

        // Native code will eat an extra ref.
        LowLevelWebKit.gcProtect(jsContext, jsval);
        return jsval;
      } else {
        MethodAdaptor method = javaDispatch.getMethod(dispId);
        AccessibleObject obj = method.getUnderlyingObject();
        DispatchMethod<?> dispMethod = (DispatchMethod<?>) classLoader.getWrapperForObject(obj);
        if (dispMethod == null) {
          dispMethod = new MethodDispatch<H>(classLoader, method);
          classLoader.putWrapperForObject(obj, dispMethod);
        }
View Full Code Here

          if ((flags & COM.DISPATCH_METHOD) != 0) {
            // This is a method call.
            return callMethod(classLoader, getTarget(), params, method);
          } else if (flags == COM.DISPATCH_PROPERTYGET) {
            // The function is being accessed as a property.
            AccessibleObject obj = method.getUnderlyingObject();
            IDispatchImpl dispMethod = (IDispatchImpl) classLoader.getWrapperForObject(obj);
            if (dispMethod == null || dispMethod.refCount < 1) {
              dispMethod = new MethodDispatch(classLoader, method);
              classLoader.putWrapperForObject(obj, dispMethod);
            }
View Full Code Here

                Object.class.getDeclaredMethod("toString"));
          } catch (Throwable e) {
            throw new RuntimeException(
                "Failed to get Object.toString() method", e);
          }
          AccessibleObject obj = toStringMethod.getUnderlyingObject();
          IDispatchImpl dispMethod = (IDispatchImpl) classLoader.getWrapperForObject(obj);
          if (dispMethod == null || dispMethod.refCount < 1) {
            dispMethod = new MethodDispatch(classLoader, toStringMethod);
            classLoader.putWrapperForObject(obj, dispMethod);
          }
View Full Code Here

        Field field = javaDispatch.getField(dispId);
        JsValueGlue.set(jsValue, classLoader, field.getType(),
            javaDispatch.getFieldValue(dispId));
      } else {
        MethodAdaptor method = javaDispatch.getMethod(dispId);
        AccessibleObject obj = method.getUnderlyingObject();
        DispatchMethod dispMethod = (DispatchMethod) classLoader.getWrapperForObject(obj);
        if (dispMethod == null) {
          dispMethod = new MethodDispatch(classLoader, method);
          classLoader.putWrapperForObject(obj, dispMethod);
        }
View Full Code Here

            {
                UnitOfWork uow = module.newUnitOfWork();
                try {
                    EntityComposite configuration = uow.get( EntityComposite.class, identity );
                    AssociationStateHolder state = spi.stateOf( configuration );
                    AccessibleObject accessor = propertyNames.get( name );
                    Property<Object> property = state.propertyFor( accessor );
                    return property.get();
                } catch ( Exception ex ) {
                    throw new ReflectionException( ex, "Could not get attribute " + name );
                } finally {
View Full Code Here

            {
                UnitOfWork uow = module.newUnitOfWork();
                try {
                    EntityComposite configuration = uow.get( EntityComposite.class, identity );
                    AssociationStateHolder state = spi.stateOf( configuration );
                    AccessibleObject accessor = propertyNames.get( attribute.getName() );
                    Property<Object> property = state.propertyFor( accessor );
                    property.set( attribute.getValue() );
                    try {
                        uow.complete();
                    } catch ( UnitOfWorkCompletionException e ) {
View Full Code Here

TOP

Related Classes of java.lang.reflect.AccessibleObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.