/**
   * Factory method for auto-adding JAXB Transformers for a Service interface.
   *
   * @param serviceClass The Service class.
   * @return The list of JAX Transformers to be added for the supplied service class.
   * @throws SwitchYardException Unsupported JAXB type defined on interface.
   */
  public static List<Transformer<?, ?>> newTransformers(Class<?> serviceClass)
      throws SwitchYardException {
    List<Transformer<?, ?>> transformers = new ArrayList<Transformer<?, ?>>();
    Set<Class<?>> inputTypeSet = new HashSet<Class<?>>();
    Set<Class<?>> outputTypeSet = new HashSet<Class<?>>();

    if (serviceClass.isInterface()) {
      Method[] serviceOperations = serviceClass.getMethods();

      for (Method serviceOperation : serviceOperations) {
        Class<?>[] inTypes = serviceOperation.getParameterTypes();
        Class<?> outType = serviceOperation.getReturnType();

        if (inTypes.length == 1) {
          inputTypeSet.add(inTypes[0]);
        }
        if (outType != null && !Void.TYPE.isAssignableFrom(outType)) {
          outputTypeSet.add(outType);
        }
      }
    }

    // Add input and output transformers...
    for (Class<?> inputType : inputTypeSet) {
      addJAXBUnmarshalTransformer(inputType, transformers);
    }
    for (Class<?> outputType : outputTypeSet) {
      addJAXBMarshalTransformer(outputType, transformers);
    }

    return transformers;
  }
Example #2
0
 /**
  * Checks whether or not a class is suitable to be adapted by TaskAdapter. If the class is of type
  * Dispatchable, the check is not performed because the method that will be executed will be
  * determined only at runtime of the actual task and not during parse time.
  *
  * <p>This only checks conditions which are additionally required for tasks adapted by
  * TaskAdapter. Thus, this method should be called by Project.checkTaskClass.
  *
  * <p>Throws a BuildException and logs as Project.MSG_ERR for conditions that will cause the task
  * execution to fail. Logs other suspicious conditions with Project.MSG_WARN.
  *
  * @param taskClass Class to test for suitability. Must not be <code>null</code>.
  * @param project Project to log warnings/errors to. Must not be <code>null</code>.
  * @see Project#checkTaskClass(Class)
  */
 public static void checkTaskClass(final Class<?> taskClass, final Project project) {
   if (!Dispatchable.class.isAssignableFrom(taskClass)) {
     // don't have to check for interface, since then
     // taskClass would be abstract too.
     try {
       final Method executeM = taskClass.getMethod("execute", (Class[]) null);
       // don't have to check for public, since
       // getMethod finds public method only.
       // don't have to check for abstract, since then
       // taskClass would be abstract too.
       if (!Void.TYPE.equals(executeM.getReturnType())) {
         final String message =
             "return type of execute() should be "
                 + "void but was \""
                 + executeM.getReturnType()
                 + "\" in "
                 + taskClass;
         project.log(message, Project.MSG_WARN);
       }
     } catch (NoSuchMethodException e) {
       final String message = "No public execute() in " + taskClass;
       project.log(message, Project.MSG_ERR);
       throw new BuildException(message);
     } catch (LinkageError e) {
       String message = "Could not load " + taskClass + ": " + e;
       project.log(message, Project.MSG_ERR);
       throw new BuildException(message, e);
     }
   }
 }
Example #3
0
 /**
  * One and only implementation of restore state. Makes all other implementations unnecessary.
  *
  * @param context FacesContext
  * @param state the state to be restored.
  */
 public void restoreState(FacesContext context, Object state) {
   FacesContext fc = FacesContext.getCurrentInstance();
   Object[] savedState = (Object[]) state;
   component.initialState = (Boolean) savedState[savedState.length - 1];
   int length = (savedState.length - 1) / 2;
   for (int i = 0; i < length; i++) {
     Object value = savedState[i * 2 + 1];
     if (Void.TYPE.equals(value)) {
       value = null;
     }
     Serializable serializable = (Serializable) savedState[i * 2];
     if (value != null) {
       if (value instanceof Collection) {
         value = restoreAttachedState(fc, value);
       } else if (value instanceof StateHolderSaver) {
         value = ((StateHolderSaver) value).restore(context);
       } else {
         value = (value instanceof Serializable ? value : restoreAttachedState(fc, value));
       }
     }
     if (value instanceof Map) {
       for (Map.Entry<String, Object> entry : ((Map<String, Object>) value).entrySet()) {
         this.put(serializable, entry.getKey(), entry.getValue());
       }
     } else if (value instanceof List) {
       for (Object o : ((List<Object>) value)) {
         this.add(serializable, o);
       }
     } else {
       put(serializable, value);
     }
   }
 }
 protected Object invokeAsynchronous(final Method method, final InterceptorContext context)
     throws Exception {
   if (Void.TYPE.isAssignableFrom(method.getReturnType())) {
     return new AsyncVoidInterceptor(getAsynchronousExecutor()).processInvocation(context);
   } else {
     return new AsyncFutureInterceptor(getAsynchronousExecutor()).processInvocation(context);
   }
 }
 static {
   PRIMITIVE_TYPES.put(Boolean.TYPE.getName(), Boolean.TYPE);
   PRIMITIVE_TYPES.put(Character.TYPE.getName(), Character.TYPE);
   PRIMITIVE_TYPES.put(Byte.TYPE.getName(), Byte.TYPE);
   PRIMITIVE_TYPES.put(Short.TYPE.getName(), Short.TYPE);
   PRIMITIVE_TYPES.put(Integer.TYPE.getName(), Integer.TYPE);
   PRIMITIVE_TYPES.put(Long.TYPE.getName(), Long.TYPE);
   PRIMITIVE_TYPES.put(Float.TYPE.getName(), Float.TYPE);
   PRIMITIVE_TYPES.put(Double.TYPE.getName(), Double.TYPE);
   PRIMITIVE_TYPES.put(Void.TYPE.getName(), Void.TYPE);
 }
 @Override
 public Object invoke(Object p, Method m, Object[] args) throws Throwable {
   if (m_getRecordName.equals(m)) {
     return recordName;
   }
   assert Void.TYPE.equals(m.getReturnType());
   for (MetricsRecord rec : subrecs) {
     m.invoke(rec, args);
   }
   return null;
 }
  /**
   * Retieves the type number corresponding to the class of an IN, IN OUT or OUT parameter.
   *
   * <p>This method extends getTypeNr to return OTHER for primitive arrays, classes that directly
   * implement java.io.Serializable and non-primitive arrays whose base component implements
   * java.io.Serializable, allowing, for instance, arguments and return types of primitive arrays,
   * Serializable objects and arrays, of Serializable objects. Direct primitive types other than
   * those mapping directly to the internal wrapper form are not yet handled. That is, HSQLDB cannot
   * yet properly deal with CALLs involving methods with primitive byte, short, float or their
   * corresponding wrappers, due to the way internal conversion works and lack of detection and
   * narrowing code in Function to allow this. In other words, passing in or retrieving any of the
   * mentioned types always causes conversion to a wider internal wrapper which is genrally
   * incompatible under reflective invocation, resulting in an IllegalArgumentException.
   *
   * @param c a Class instance
   * @return java.sql.Types int value
   * @throws HsqlException
   */
  static int getParameterTypeNr(Class c) throws HsqlException {

    String name;
    String msg;
    int type;

    Trace.doAssert(c != null, "c is null");

    if (Void.TYPE.equals(c)) {
      return Types.NULL;
    }

    name = c.getName();
    msg = "Unsupported parameter/return value class: ";

    if (illegalParameterClasses.contains(c)) {
      throw Trace.error(Trace.WRONG_DATA_TYPE, msg + name);
    }

    type = typeAliases.get(name, Integer.MIN_VALUE);

    if (type == Integer.MIN_VALUE) {

      // byte[] is already covered as BINARY in typeAliases
      if (c.isArray()) {
        while (c.isArray()) {
          c = c.getComponentType();
        }

        if (c.isPrimitive() || java.io.Serializable.class.isAssignableFrom(c)) {
          type = OTHER;
        }
      } else if (java.io.Serializable.class.isAssignableFrom(c)) {
        type = OTHER;
      }
    }

    Trace.check(type != Integer.MIN_VALUE, Trace.WRONG_DATA_TYPE, msg + name);

    return type;
  }
Example #8
0
 /** @see https://github.com/wordnik/swagger-core/wiki/datatypes */
 protected static SwaggerDataType convertToSwaggerType(SwaggerModel models, Class<?> type) {
   if (Void.TYPE.equals(type)) {
     return new SwaggerDataType("void");
   } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
     return new SwaggerDataType("integer", "int32");
   } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
     return new SwaggerDataType("integer", "int64");
   } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
     return new SwaggerDataType("number", "float");
   } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
     return new SwaggerDataType("number", "double");
   } else if (Byte.TYPE.equals(type) || Byte.class.isAssignableFrom(type)) {
     return new SwaggerDataType("string", "byte");
   } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
     return new SwaggerDataType("boolean");
   } else if (Number.class.isAssignableFrom(type)) {
     return new SwaggerDataType("number");
   } else if (String.class.equals(type)) {
     return new SwaggerDataType("string");
   } else if (Date.class.equals(type)) {
     return new SwaggerDataType("string", "date-time");
   } else if (type.isEnum()) {
     return new SwaggerDataType("string");
   } else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
     return new SwaggerDataType("array");
   } else {
     // it's a custom type, we need to create a model for it (if it does not already exist)
     String typeName = type.getName();
     if (!models.containsKey(typeName)) {
       // Reserve a spot for this type, avoids circular references to cause a StackOverflow, see
       // AMDATUWEB-10...
       models.put(typeName, null);
       // Overwrite the item with the actual model definition...
       models.put(typeName, convertToSwaggerModel(models, type));
     }
     return new SwaggerDataType(type.getName());
   }
 }
  /**
   * Retrieves the SQL data type corrsponding to the Class of the "widest" internal represention in
   * which instances of the specified Class can fit without a non-trivial conversion via
   * Column.convertObject(Object,int).
   *
   * <p>By trivial, it is meant converting an Object, o, to a JavaObject holder for o.
   */
  static int getWidestTypeNrNoConvert(Class c) {

    if (c == null || Void.TYPE.equals(c)) {
      return NULL;
    }

    if (Boolean.class.equals(c)) {
      return BIT;
    } else if (String.class.equals(c)) {
      return LONGVARCHAR;
    } else if (Binary.class.equals(c)) {
      return LONGVARBINARY;
    } else if (Integer.class.equals(c)) {
      return INTEGER;
    } else if (Long.class.equals(c)) {
      return BIGINT;
    } else if (Double.class.equals(c)) {
      return DOUBLE;
    } else if (java.sql.Date.class.isAssignableFrom(c)) {
      return DATE;
    } else if (java.sql.Time.class.isAssignableFrom(c)) {
      return TIME;
    } else if (java.sql.Timestamp.class.isAssignableFrom(c)) {
      return TIMESTAMP;
    } else if (java.math.BigDecimal.class.equals(c)) {
      return DECIMAL;
    }

    // Others, including JavaObject, must be converted.
    // We could check for Serializable.class.isAssignableFrom(c)
    // here and throw if not, but that will be picked up in the
    // conversion, so it's redundant here.
    // In other words, please note the NoConvert suffix
    // of the method name.  It's there for a reason.
    return OTHER;
  }
  @Override
  public MBeanInfo getMBeanInfo() {

    MBeanAttributeInfo[] attributes =
        new MBeanAttributeInfo[] {
          // TODO mnowa: add/correct attributes here
          new MBeanAttributeInfo(
              "Imei", String.class.getName(), "IMEI's digits string", true, true, false),
          new MBeanAttributeInfo(
              "MapProtocolVersion",
              MapProtocolVersion.class.getName(),
              "MAP protocol version",
              true,
              true,
              false),
          new MBeanAttributeInfo(
              "MapProtocolVersion_Value",
              String.class.getName(),
              "MAP protocol version",
              true,
              false,
              false),
          new MBeanAttributeInfo(
              "CheckImeiClientAction",
              CheckImeiClientAction.class.getName(),
              "The mode of CheckImeiClient work. When manual response user can manually send CheckImei request, when VAL_AUTO_SendCheckImeiRequest the tester sends CheckImei requests without dealay (load test)",
              true,
              true,
              false),
          new MBeanAttributeInfo(
              "CheckImeiClientAction_Value",
              String.class.getName(),
              "The mode of CheckImeiClient work. When manual response user can manually send CheckImei request, when VAL_AUTO_SendCheckImeiRequest the tester sends CheckImei requests without dealay (load test)",
              true,
              false,
              false),
          new MBeanAttributeInfo(
              "MaxConcurrentDialogs",
              int.class.getName(),
              "The count of maximum active MAP dialogs when the auto sending mode",
              true,
              true,
              false),
          new MBeanAttributeInfo(
              "OneNotificationFor100Dialogs",
              boolean.class.getName(),
              "If true there will be only one notification per every 100 sent dialogs (recommended for the auto sending mode)",
              true,
              true,
              true),
        };

    MBeanParameterInfo[] performCheckImeiParam =
        new MBeanParameterInfo[] {
          new MBeanParameterInfo("imei", String.class.getName(), "IMEI's digits string")
        };
    MBeanParameterInfo[] signString =
        new MBeanParameterInfo[] {
          new MBeanParameterInfo("val", String.class.getName(), "Index number or value")
        };

    MBeanOperationInfo[] operations =
        new MBeanOperationInfo[] {
          new MBeanOperationInfo(
              "performCheckImeiRequest",
              "Send CheckIMEI request for provided IMEI",
              performCheckImeiParam /*signString*/,
              String.class.getName(),
              MBeanOperationInfo.ACTION),
          new MBeanOperationInfo(
              "putMapProtocolVersion",
              "MAP protocol version: " + "1, 2 or 3",
              signString,
              Void.TYPE.getName(),
              MBeanOperationInfo.ACTION),
          new MBeanOperationInfo(
              "closeCurrentDialog",
              "Closing the current dialog",
              null,
              String.class.getName(),
              MBeanOperationInfo.ACTION),
          new MBeanOperationInfo(
              "putCheckImeiClientAction",
              "The mode of CheckImeiClient work. 1:VAL_MANUAL_OPERATION,2:VAL_AUTO_SendCheckImeiRequest",
              signString,
              Void.TYPE.getName(),
              MBeanOperationInfo.ACTION),
        };
    return new MBeanInfo(
        TestCheckImeiClientMan.class.getName(),
        "CheckImeiClient test parameters management",
        attributes,
        null,
        operations,
        null);
  }
 public MethodInvokingCorrelationStrategy(Object object, Method method) {
   Assert.notNull(object, "'object' must not be null");
   Assert.notNull(method, "'method' must not be null");
   Assert.isTrue(!Void.TYPE.equals(method.getReturnType()), "Method return type must not be void");
   this.processor = new MethodInvokingMessageProcessor<Object>(object, method);
 }
Example #12
0
 public static boolean isVoid(ResolvedType returnType) {
   return Void.class.equals(returnType.getErasedType())
       || Void.TYPE.equals(returnType.getErasedType());
 }
 /** Returns {@code true} if the method return type is void, {@code false} otherwise. */
 public boolean isVoid() {
   return Void.TYPE.equals(getReturnType().getParameterType());
 }
  public static boolean isInterceptorMethod(
      InterceptionType interceptionType, MethodMetadata method, boolean forTargetClass) {

    if (!method.getSupportedInterceptionTypes().contains(interceptionType)) {
      return false;
    }

    if (interceptionType.isLifecycleCallback()) {
      if (!Void.TYPE.equals(method.getReturnType())) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "does not have a void return type");
        }
        return false;
      }

      Class<?>[] parameterTypes = method.getJavaMethod().getParameterTypes();

      if (forTargetClass && parameterTypes.length != 0) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "is defined on the target class and does not have 0 arguments");
        }
        return false;
      }

      if (!forTargetClass && parameterTypes.length != 1) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "does not have exactly one parameter");
        }
        return false;
      }

      if (parameterTypes.length == 1
          && !InvocationContext.class.isAssignableFrom(parameterTypes[0])) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "its single argument is not a "
                  + InvocationContext.class.getName());
        }
        return false;
      }

      return true;
    } else {
      if (!Object.class.equals(method.getReturnType())) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "does not return a "
                  + OBJECT_CLASS_NAME);
        }
        return false;
      }

      Class<?>[] parameterTypes = method.getJavaMethod().getParameterTypes();

      if (parameterTypes.length != 1) {
        if (LOG.isWarnEnabled()) {
          LOG.debug(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "does not have exactly 1 parameter");
        }
        return false;
      }

      if (!InvocationContext.class.isAssignableFrom(parameterTypes[0])) {
        if (LOG.isWarnEnabled()) {
          LOG.debug(
              getStandardIgnoredMessage(interceptionType, method.getJavaMethod())
                  + "does not have a "
                  + InvocationContext.class.getName()
                  + " parameter ");
        }
        return false;
      }

      return true;
    }
  }
Example #15
-1
  /**
   * Creates a gateway instance for the given <code>gatewayInterface</code>. The returned instance
   * is a Proxy that implements that interface.
   *
   * @param gatewayInterface The interface declaring the gateway methods
   * @param <T> The interface declaring the gateway methods
   * @return A Proxy implementation implementing the given interface
   */
  @SuppressWarnings("unchecked")
  public <T> T createGateway(Class<T> gatewayInterface) {
    Map<Method, InvocationHandler> dispatchers = new HashMap<Method, InvocationHandler>();
    for (Method gatewayMethod : gatewayInterface.getMethods()) {
      MetaDataExtractor[] extractors = extractMetaData(gatewayMethod.getParameterAnnotations());

      InvocationHandler dispatcher =
          new DispatchOnInvocationHandler(
              commandBus, retryScheduler,
              dispatchInterceptors, extractors);
      final Class<?>[] arguments = gatewayMethod.getParameterTypes();
      if (Future.class.equals(gatewayMethod.getReturnType())) {
        // no wrapping
      } else if (arguments.length >= 3
          && TimeUnit.class.isAssignableFrom(arguments[arguments.length - 1])
          && (long.class.isAssignableFrom(arguments[arguments.length - 2])
              || int.class.isAssignableFrom(arguments[arguments.length - 2]))) {
        dispatcher =
            wrapToReturnWithTimeoutInArguments(
                dispatcher, arguments.length - 2, arguments.length - 1);
      } else {
        Timeout timeout = gatewayMethod.getAnnotation(Timeout.class);
        if (timeout == null) {
          timeout = gatewayMethod.getDeclaringClass().getAnnotation(Timeout.class);
        }
        if (timeout != null) {
          dispatcher = wrapToReturnWithFixedTimeout(dispatcher, timeout.value(), timeout.unit());
        } else if (!Void.TYPE.equals(gatewayMethod.getReturnType())
            || gatewayMethod.getExceptionTypes().length > 0) {
          dispatcher = wrapToWaitForResult(dispatcher);
        } else {
          dispatcher = wrapToFireAndForget(dispatcher);
        }
      }
      Class<?>[] declaredExceptions = gatewayMethod.getExceptionTypes();
      if (!contains(declaredExceptions, TimeoutException.class)) {
        dispatcher = wrapToReturnNullOnTimeout(dispatcher);
      }
      if (!contains(declaredExceptions, InterruptedException.class)) {
        dispatcher = wrapToReturnNullOnInterrupted(dispatcher);
      }
      dispatcher = wrapUndeclaredExceptions(dispatcher, declaredExceptions);
      dispatchers.put(gatewayMethod, dispatcher);
    }

    return gatewayInterface.cast(
        Proxy.newProxyInstance(
            gatewayInterface.getClassLoader(),
            new Class[] {gatewayInterface},
            new GatewayInvocationHandler(
                dispatchers, commandBus, retryScheduler, dispatchInterceptors)));
  }