Пример #1
0
  @Override
  public String encode(Resource resource, List<String> includeAttributes) {
    try {
      x0.scimSchemasCore1.Resource xmlResource = this.internalEncode(resource, includeAttributes);

      Complex complex = resource.getClass().getAnnotation(Complex.class);
      Class<?> factory = ReflectionHelper.getFactory(complex.xmlDoc());
      XmlObject doc = (XmlObject) factory.getMethod("newInstance").invoke(null);

      String name = complex.xmlType().getName();
      String setterName = "set";
      setterName += name.substring(name.lastIndexOf('.') + 1);
      doc.getClass().getMethod(setterName, complex.xmlType()).invoke(doc, xmlResource);

      return (PRETTY_PRINT ? doc.toString() : doc.xmlText());
    } catch (FactoryNotFoundException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    } catch (SecurityException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException("Internal error, xml encode failed", e);
    }
  }
Пример #2
0
  private Object createXmlObject(Resource resource) {
    try {
      if (!resource.getClass().isAnnotationPresent(Complex.class)) {
        throw new RuntimeException(
            "Missing annotation complex on, '" + resource.getClass().getName() + "'");
      }

      Complex complexMetadata = resource.getClass().getAnnotation(Complex.class);
      Class<?> factory = ReflectionHelper.getFactory(complexMetadata.xmlType());
      Method parse = factory.getMethod("newInstance");

      return parse.invoke(null);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Internal error, encoding xml", e);
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("Internal error, encoding xml", e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Internal error, encoding xml", e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException("Internal error, encoding xml", e);
    } catch (FactoryNotFoundException e) {
      throw new RuntimeException("Internal error, encoding xml", e);
    }
  }