Package com.alexgilleran.icesoap.annotation

Examples of com.alexgilleran.icesoap.annotation.XMLField


   * @param fieldXPaths
   *            The repository to add fields too
   */
  private void addXPathFieldsToRepo(Class<?> targetClass, XPathRepository<Field> fieldXPaths) {
    for (Field field : targetClass.getDeclaredFields()) {
      XMLField xPath = field.getAnnotation(XMLField.class);

      if (xPath != null) {
        // Annotation is not present: do nothing for this field.
        XPathRepository<XPathElement> xpathsFromField;

        if (!xPath.value().equals(XMLField.DEFAULT_XPATH_STRING)) {
          // If the XPath has a value specified, compile it
          xpathsFromField = compileXPath(xPath, field);

          addRootToRelativeXPaths(xpathsFromField);
        } else {
View Full Code Here


    Field fieldToSet = fieldXPaths.get(pullParser.getCurrentElement());

    if (fieldToSet != null) {
      try {
        String textNodeValue = pullParser.getCurrentValue();
        XMLField annotation = fieldToSet.getAnnotation(XMLField.class);
        boolean hasProcessor = hasProcessor(fieldToSet);

        if (!needsParser(fieldToSet)) {
          Object valueToSet;

          if (hasProcessor) {
            Processor processor = annotation.processor().newInstance();
            valueToSet = processor.process(textNodeValue);
          } else {
            valueToSet = convertToFieldType(fieldToSet, textNodeValue);
          }
View Full Code Here

   *            The string to parse to the correct type.
   * @return The string's value as the appropriate type.
   * @throws XMLParseException
   */
  private Object convertToFieldType(Field field, String valueString) throws XMLParsingException {
    XMLField annotation = field.getAnnotation(XMLField.class);

    if (int.class.isAssignableFrom(field.getType())) {
      return Integer.parseInt(valueString);
    } else if (long.class.isAssignableFrom(field.getType())) {
      return Long.parseLong(valueString);
    } else if (float.class.isAssignableFrom(field.getType())) {
      return Float.parseFloat(valueString);
    } else if (double.class.isAssignableFrom(field.getType())) {
      return Double.parseDouble(valueString);
    } else if (boolean.class.isAssignableFrom(field.getType())) {
      return Boolean.parseBoolean(valueString);
    } else if (BigDecimal.class.isAssignableFrom(field.getType())) {
      return new BigDecimal(valueString);
    } else if (Date.class.isAssignableFrom(field.getType())) {
      try {
        return new SimpleDateFormat(annotation.dateFormat()).parse(valueString);
      } catch (ParseException e) {
        throw new XMLParsingException("Encountered date parsing exception when parsing " + field.toString()
            + " with format " + field.getAnnotation(XMLField.class).dateFormat() + " for value "
            + valueString, e);
      }
View Full Code Here

TOP

Related Classes of com.alexgilleran.icesoap.annotation.XMLField

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.