Package com.skaringa.javaxml

Examples of com.skaringa.javaxml.DeserializerException


   * for an array.
   */
  private void computeType(ClassLoader classLoader) throws DeserializerException {

    if (!_xmlTypeName.startsWith(TYPENAME_PREFIX)) {
      throw new DeserializerException(
        "Invalid array type name prefix: " + _xmlTypeName);
    }
    String compTypeName = null;

    try {
      int i = TYPENAME_PREFIX.length();
      int s = i;

      // dimension
      while (_xmlTypeName.charAt(i) != '_') {
        ++i;
      }
      int dim;
      if (s == i) {
        dim = 1;
      }
      else {
        dim = Integer.parseInt(_xmlTypeName.substring(s, i));
      }
      int[] dimensions = new int[dim];

      // _of_
      s = i;
      i = s + "_of_".length();
      if (!_xmlTypeName.substring(s, i).equals("_of_")) {
        throw new DeserializerException(
          "Invalid array type name: _of_ expected: "
            + _xmlTypeName.substring(s, i));
      }

      // component type name
      compTypeName = _xmlTypeName.substring(i);

      Class compType;
      if (compTypeName.equals("byte")) {
        compType = byte.class;
      }
      else if (compTypeName.equals("char")) {
        compType = char.class;
      }
      else if (compTypeName.equals("double")) {
        compType = double.class;
      }
      else if (compTypeName.equals("float")) {
        compType = float.class;
      }
      else if (compTypeName.equals("int")) {
        compType = int.class;
      }
      else if (compTypeName.equals("long")) {
        compType = long.class;
      }
      else if (compTypeName.equals("short")) {
        compType = short.class;
      }
      else if (compTypeName.equals("boolean")) {
        compType = boolean.class;
      }
      else {
        compType =
          Class.forName(
            ObjectSerializer.fixJavaTypeNameForInnerClass(compTypeName),
            true,
            classLoader);
      }
      Object array = Array.newInstance(compType, dimensions);

      _type = array.getClass();
    }
    catch (ClassNotFoundException ex) {
      throw new DeserializerException(
        "can't get java class for: " + compTypeName + ": " + ex.toString());
    }
    catch (StringIndexOutOfBoundsException ex) {
      throw new DeserializerException(
        "Invalid array type name: " + _xmlTypeName);
    }
  }
View Full Code Here


    ClassLoader classLoader)
    throws DeserializerException {

    String xmlType = attrs.getValue("xsi:type");
    if (xmlType == null) {
      throw new DeserializerException(
        "Element " + elementName + " missing xsi:type attribute");
    }

    ComponentSerializer ser = (ComponentSerializer) _deserializers.get(xmlType);
    if (ser == null) {
      // handle arrays
      if (xmlType.startsWith(ArraySerializer.TYPENAME_PREFIX)) {
        ser = new ArraySerializer(xmlType);
        addSerializer(xmlType, ser);
      }
      else {
        // no serializer found - use and register new serializer
        try {
          Class c =
            Class.forName(
              ObjectSerializer.fixJavaTypeNameForInnerClass(xmlType),
              true,
              classLoader);
          ser = getAndRegisterType(c, xmlType);
        }
        catch (ClassNotFoundException e) {
          throw new DeserializerException(
            "class not found: "
              + ObjectSerializer.fixJavaTypeNameForInnerClass(xmlType));
        }
      }
    }
View Full Code Here

        // c remains null
      }
    }

    if (c == null) {
      throw new DeserializerException(
        "can't determine java type for element: " + elementName);
    }

    return getSerializer(c);
    // we must call getSerializer() here instead of getDeserializer(),
View Full Code Here

    try {
      new BigDecimal(s);
      return getSerializer(BigDecimal.class);
    } catch (NumberFormatException e) {
    }
    throw new DeserializerException("Not a number: " + s);
  }
View Full Code Here

      transformer.transform(src, newObjectResult(inputHandler));

      obj = inputHandler.getObject();
    } catch (TransformerConfigurationException e) {
      Log.error(e);
      throw new DeserializerException(e.toString());
    } catch (TransformerException e) {
      Log.error(e);
      Throwable emb = e.getException();
      if (emb instanceof DeserializerException) {
        throw (DeserializerException) emb;
      }
      throw new DeserializerException(e.getMessage());
    }

    Log.info("deserialize - end "
        + (obj != null ? obj.getClass().getName() : "null"));
    return obj;
View Full Code Here

      JsonParser parser = new JsonParser(reader, rootType, _properties, _classLoader);
      parser.process();
      return parser.getObject();
    } catch (IOException e) {
      Log.error(e);
      throw new DeserializerException(e.getMessage());
    }
  }
View Full Code Here

      JsonParser parser = new JsonParser(reader, rootType, _properties, _classLoader);
      parser.process();
      return parser.getObject();
    } catch (IOException e) {
      Log.error(e);
      throw new DeserializerException(e.getMessage());
    }
  }
View Full Code Here

    Object obj;
    Integer objId = objHolder.getId();
    if (objHolder.isReference()) {
      obj = _objRefMap.get(objId);
      if (obj == null) {
        throw new DeserializerException("missing referenced object: i" + objId);
      }
    }
    else {
      obj =
        objHolder.getSer().endDeserialize(objHolder.getObj(), _text.toString());
      objHolder.setObj(obj);
      if (objId != null) {
        _objRefMap.put(objId, obj);
      }
    }

    try {
      ObjectDeserializerHolder parentHolder =
        (ObjectDeserializerHolder) _objHolderStack.peek();
      parentHolder.getSer().setMember(parentHolder.getObj(), name, obj);
    }
    catch (java.util.EmptyStackException e) {
      // leave the top level object at the stack
      _objHolderStack.push(objHolder);
    }
    catch (NoSuchFieldException e) {
      if (!PropertyHelper
        .parseBoolean(_propertyMap, PropertyKeys.SKIP_UNKNOWN_FIELDS)) {
        throw new DeserializerException("no such field: " + name);
      }
    }
  }
View Full Code Here

          Object declaringObject = findFirstObject(outer, objHolderStack);
          obj = ctor.newInstance(new Object[] { declaringObject });
        }
      }
    } catch (InstantiationException e) {
      throw new DeserializerException("can't instantiate class: "
          + _javaClassName);
    } catch (ClassNotFoundException e) {
      throw new DeserializerException("class not found: " + _javaClassName);
    } catch (IllegalAccessException e) {
      throw new DeserializerException("can't access default ctor of class: "
          + _javaClassName);
    } catch (NoSuchMethodException e) {
      throw new DeserializerException("no default ctor found for class: "
          + _javaClassName);
    } catch (java.lang.reflect.InvocationTargetException e) {
      throw new DeserializerException("exception in initializer: "
          + e.getMessage());
    } catch (java.lang.IllegalArgumentException e) {
      throw new DeserializerException(
          "IllegalArgument exception deserializing " + _javaClassName
              + ", parent " + parent.getClass().getName() + ": "
              + e.getMessage());
    }
View Full Code Here

   */
  public void setMember(Object parent, String name, Object value)
      throws DeserializerException, NoSuchFieldException {

    if (name == null) {
      throw new DeserializerException("member of object must have an name");
    }

    try {
      Field field = getField(parent, name);
      int modifiers = field.getModifiers();
      if (!Modifier.isFinal(modifiers)) { // avoid setting of final fields
        if (Log.isDebugEnabled()) {
          Log.debug("set " + name + " = " + value);
        }
        // set the accessibility to public
        field.setAccessible(true);
        // set the field
        field.set(parent, value);
      }
    } catch (IllegalAccessException e) {
      throw new DeserializerException("Setting " + name + " to "
          + value.getClass().getName() + "(" + value + ")"
          + " threw IllegalAccessException");
    } catch (IllegalArgumentException e) {
      throw new DeserializerException("Setting " + name + " to "
          + value.getClass().getName() + "(" + value + ")"
          + " threw IllegalArgumentException");
    }
  }
View Full Code Here

TOP

Related Classes of com.skaringa.javaxml.DeserializerException

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.