Example usage for com.amazonaws.util DateUtils DateUtils

List of usage examples for com.amazonaws.util DateUtils DateUtils

Introduction

In this page you can find the example usage for com.amazonaws.util DateUtils DateUtils.

Prototype

DateUtils

Source Link

Usage

From source file:com.ad.mediasharing.tvmclient.Utilities.java

License:Open Source License

public static String getTimestamp() {
    return new DateUtils().formatIso8601Date(new Date());
}

From source file:com.msi.tough.rdsquery.QueryUtilV2.java

License:Apache License

public static void addNode(final XMLNode n, final String tag, final Calendar value) {
    if (value != null) {
        addNode(n, tag, new DateUtils().formatIso8601Date(value.getTime()));
    }//w w w.j av  a  2s . co  m
}

From source file:com.msi.tough.rdsquery.QueryUtilV2.java

License:Apache License

public static void addNode(final XMLNode n, final String tag, final Date value) {
    if (value != null) {
        addNode(n, tag, new DateUtils().formatIso8601Date(value));
    }/*from  w ww.j a  v  a  2 s. c  o m*/
}

From source file:com.swengle.phoebe.reflect.DynamoDBReflector.java

License:Apache License

/**
 * Returns the argument unmarshaller used to unmarshall the getter / setter
 * pair given./*w w  w  .  j av  a 2 s.  c  o m*/
 * <p>
 * Determining how to unmarshall a response, especially a numeric one,
 * requires checking it against all supported types. This is expensive, so
 * we cache a lookup table of getter method to argument unmarhsaller which
 * can be reused.
 * 
 * @param toReturn
 *            The typed domain object being unmarshalled for the client
 * @param getter
 *            The getter method being considered
 * @param setter
 *            The corresponding setter method being considered
 */
public <T> ArgumentUnmarshaller getArgumentUnmarshaller(final T toReturn, final Method getter,
        final Method setter) {
    synchronized (argumentUnmarshallerCache) {
        if (!argumentUnmarshallerCache.containsKey(getter)) {

            Class<?>[] parameterTypes = setter.getParameterTypes();
            Class<?> paramType = parameterTypes[0];
            if (parameterTypes.length != 1) {
                throw new DynamoDBMappingException("Expected exactly one agument to " + setter);
            }

            ArgumentUnmarshaller unmarshaller = null;
            if (isCustomMarshaller(getter)) {
                unmarshaller = new SUnmarshaller() {

                    @Override
                    public Object unmarshall(AttributeValue value) {
                        return getCustomMarshalledValue(toReturn, getter, value);
                    }
                };
            } else {

                // If we're dealing with a collection, we need to get the
                // underlying type out of it
                boolean isCollection = false;
                if (Set.class.isAssignableFrom(paramType)) {
                    isCollection = true;
                    Type genericType = setter.getGenericParameterTypes()[0];
                    if (genericType instanceof ParameterizedType) {
                        paramType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
                    }
                } else if (Collection.class.isAssignableFrom(paramType)) {
                    throw new DynamoDBMappingException(
                            "Only java.util.Set collection types are permitted for " + DynamoDBAttribute.class);
                }

                if (double.class.isAssignableFrom(paramType) || Double.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Double> argument = new HashSet<Double>();
                                for (String s : value.getNS()) {
                                    argument.add(Double.parseDouble(s));
                                }
                                return argument;
                            }

                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return Double.parseDouble(value.getN());
                            }
                        };
                    }
                } else if (BigDecimal.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<BigDecimal> argument = new HashSet<BigDecimal>();
                                for (String s : value.getNS()) {
                                    argument.add(new BigDecimal(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return new BigDecimal(value.getN());
                            }
                        };

                    }
                } else if (BigInteger.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<BigInteger> argument = new HashSet<BigInteger>();
                                for (String s : value.getNS()) {
                                    ((Set<BigInteger>) argument).add(new BigInteger(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return new BigInteger(value.getN());
                            }
                        };
                    }
                } else if (int.class.isAssignableFrom(paramType) || Integer.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Integer> argument = new HashSet<Integer>();
                                for (String s : value.getNS()) {
                                    argument.add(Integer.parseInt(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return Integer.parseInt(value.getN());
                            }
                        };
                    }
                } else if (float.class.isAssignableFrom(paramType) || Float.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Float> argument = new HashSet<Float>();
                                for (String s : value.getNS()) {
                                    argument.add(Float.parseFloat(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return Float.parseFloat(value.getN());
                            }
                        };
                    }
                } else if (byte.class.isAssignableFrom(paramType) || Byte.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Byte> argument = new HashSet<Byte>();
                                for (String s : value.getNS()) {
                                    argument.add(Byte.parseByte(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return Byte.parseByte(value.getN());
                            }
                        };
                    }
                } else if (long.class.isAssignableFrom(paramType) || Long.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Long> argument = new HashSet<Long>();
                                for (String s : value.getNS()) {
                                    argument.add(Long.parseLong(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return Long.parseLong(value.getN());
                            }
                        };
                    }
                } else if (boolean.class.isAssignableFrom(paramType)
                        || Boolean.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new NSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<Boolean> argument = new HashSet<Boolean>();
                                for (String s : value.getNS()) {
                                    argument.add(parseBoolean(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new NUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return parseBoolean(value.getN());
                            }
                        };
                    }
                } else if (Date.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new SSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) throws ParseException {
                                Set<Date> argument = new HashSet<Date>();
                                for (String s : value.getSS()) {
                                    argument.add(new DateUtils().parseIso8601Date(s));
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new SUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) throws ParseException {
                                return new DateUtils().parseIso8601Date(value.getS());
                            }
                        };
                    }
                } else if (Calendar.class.isAssignableFrom(paramType)) {
                    if (isCollection) {
                        unmarshaller = new SSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) throws ParseException {
                                Set<Calendar> argument = new HashSet<Calendar>();
                                for (String s : value.getSS()) {
                                    Calendar cal = GregorianCalendar.getInstance();
                                    cal.setTime(new DateUtils().parseIso8601Date(s));
                                    argument.add(cal);
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new SUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) throws ParseException {
                                Calendar cal = GregorianCalendar.getInstance();
                                cal.setTime(new DateUtils().parseIso8601Date(value.getS()));
                                return cal;
                            }
                        };
                    }
                }

                /*
                 * After checking all other supported types, enforce a
                 * String match
                 */
                else if (!String.class.isAssignableFrom(paramType)) {
                    throw new DynamoDBMappingException("Expected a String, but was " + paramType);
                } else {
                    if (isCollection) {
                        unmarshaller = new SSUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                Set<String> argument = new HashSet<String>();
                                for (String s : value.getSS()) {
                                    argument.add(s);
                                }
                                return argument;
                            }
                        };
                    } else {
                        unmarshaller = new SUnmarshaller() {

                            @Override
                            public Object unmarshall(AttributeValue value) {
                                return value.getS();
                            }
                        };
                    }
                }
            }

            argumentUnmarshallerCache.put(getter, unmarshaller);
        }
    }

    return argumentUnmarshallerCache.get(getter);
}

From source file:com.swengle.phoebe.reflect.DynamoDBReflector.java

License:Apache License

/**
 * Returns a marshaller that knows how to provide an AttributeValue for the
 * result of the getter given./*  ww w .  j a va  2s  .com*/
 */
public ArgumentMarshaller getArgumentMarshaller(final Method getter) {

    synchronized (argumentMarshallerCache) {
        if (!argumentMarshallerCache.containsKey(getter)) {
            ArgumentMarshaller marshaller = null;

            if (isCustomMarshaller(getter)) {
                marshaller = new ArgumentMarshaller() {

                    @Override
                    public AttributeValue marshall(Object obj) {
                        return getCustomerMarshallerAttributeValue(getter, obj);
                    }
                };
            } else {

                Class<?> returnType = getter.getReturnType();
                if (Set.class.isAssignableFrom(returnType)) {
                    Type genericType = getter.getGenericReturnType();
                    if (genericType instanceof ParameterizedType) {
                        returnType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
                    }

                    if (Date.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                List<String> timestamps = new LinkedList<String>();
                                for (Object o : (Set<?>) obj) {
                                    timestamps.add(new DateUtils().formatIso8601Date((Date) o));
                                }
                                return new AttributeValue().withSS(timestamps);
                            }
                        };
                    } else if (Calendar.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                List<String> timestamps = new LinkedList<String>();
                                for (Object o : (Set<?>) obj) {
                                    timestamps.add(new DateUtils().formatIso8601Date(((Calendar) o).getTime()));
                                }
                                return new AttributeValue().withSS(timestamps);
                            }
                        };
                    } else if (boolean.class.isAssignableFrom(returnType)
                            || Boolean.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                List<String> booleanAttributes = new ArrayList<String>();
                                for (Object b : (Set<?>) obj) {
                                    if (b == null || !(Boolean) b) {
                                        booleanAttributes.add("0");
                                    } else {
                                        booleanAttributes.add("1");
                                    }
                                }
                                return new AttributeValue().withNS(booleanAttributes);
                            }
                        };
                    } else if (returnType.isPrimitive() || Number.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                List<String> attributes = new ArrayList<String>();
                                for (Object o : (Set<?>) obj) {
                                    attributes.add(String.valueOf(o));
                                }
                                return new AttributeValue().withNS(attributes);
                            }
                        };
                    } else {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                List<String> attributes = new ArrayList<String>();
                                for (Object o : (Set<?>) obj) {
                                    attributes.add(String.valueOf(o));
                                }
                                return new AttributeValue().withSS(attributes);
                            }
                        };
                    }
                } else if (Collection.class.isAssignableFrom(returnType)) {
                    throw new DynamoDBMappingException("Non-set collections aren't supported: "
                            + (getter.getDeclaringClass() + "." + getter.getName()));
                } else {
                    if (Date.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                return new AttributeValue()
                                        .withS(new DateUtils().formatIso8601Date((Date) obj));
                            }
                        };
                    } else if (Calendar.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                return new AttributeValue()
                                        .withS(new DateUtils().formatIso8601Date(((Calendar) obj).getTime()));
                            }
                        };
                    } else if (boolean.class.isAssignableFrom(returnType)
                            || Boolean.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                if (obj == null || !(Boolean) obj) {
                                    return new AttributeValue().withN("0");
                                } else {
                                    return new AttributeValue().withN("1");
                                }
                            }
                        };
                    } else if (returnType.isPrimitive() || Number.class.isAssignableFrom(returnType)) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                return new AttributeValue().withN(String.valueOf(obj));
                            }
                        };
                    } else if (returnType == String.class) {
                        marshaller = new ArgumentMarshaller() {

                            @Override
                            public AttributeValue marshall(Object obj) {
                                return new AttributeValue().withS(String.valueOf(obj));
                            }
                        };
                    } else {
                        throw new DynamoDBMappingException(
                                "Unsupported type: " + returnType + " for " + getter);
                    }
                }
            }
            argumentMarshallerCache.put(getter, marshaller);
        }
    }

    return argumentMarshallerCache.get(getter);
}

From source file:com.truesys.mapici.utils.Utilities.java

License:Open Source License

public static String getTimestamp() {
    String timestamp = "";
    try {/* w w  w  .  j  a va 2 s .co  m*/
        timestamp = new DateUtils().formatIso8601Date(new Date());
    } catch (Exception ex) {
        System.out.println("Mapici Utilities: " + ex.getMessage());
    }
    return timestamp;
}