Ejemplo n.º 1
0
 public static Object read(InputStream is, XMLContext context) {
   try {
     Unmarshaller unmarshaller =
         context.createUnmarshaller(); // FIXME initialization is not thread safe
     unmarshaller.setWhitespacePreserve(true);
     Object object = unmarshaller.unmarshal(new InputSource(is));
     return object;
   } catch (MarshalException e) {
     throw new JRRuntimeException(e);
   } catch (ValidationException e) {
     throw new JRRuntimeException(e);
   }
 }
Ejemplo n.º 2
0
  public static Object read(Node node, Mapping mapping) {
    Object object = null;

    try {
      Unmarshaller unmarshaller = new Unmarshaller(mapping);
      unmarshaller.setWhitespacePreserve(true);
      object = unmarshaller.unmarshal(node);
    } catch (MappingException e) {
      throw new JRRuntimeException(e);
    } catch (MarshalException e) {
      throw new JRRuntimeException(e);
    } catch (ValidationException e) {
      throw new JRRuntimeException(e);
    }

    return object;
  }
Ejemplo n.º 3
0
  public static Object read(InputStream is, Mapping mapping) {
    Object object = null;

    try {
      Unmarshaller unmarshaller =
          new Unmarshaller(mapping); // FIXME initialization is not thread safe
      unmarshaller.setWhitespacePreserve(true);
      object = unmarshaller.unmarshal(new InputSource(is));
    } catch (MappingException e) {
      throw new JRRuntimeException(e);
    } catch (MarshalException e) {
      throw new JRRuntimeException(e);
    } catch (ValidationException e) {
      throw new JRRuntimeException(e);
    }

    return object;
  }
  private static Unmarshaller getUnmarshaller(String configFile, Class<?> classToUse) {
    //		String configFile = configFilesMap.get(classToUse);
    InputSource inputSource =
        new InputSource(RedmineXMLParser.class.getResourceAsStream(configFile));
    ClassLoader cl = RedmineXMLParser.class.getClassLoader();
    // Note: Castor XML is packed in a separate OSGI bundle, so
    // must set the classloader so that Castor will see our classes
    Mapping mapping = new Mapping(cl);
    mapping.loadMapping(inputSource);

    Unmarshaller unmarshaller;
    try {
      unmarshaller = new Unmarshaller(mapping);
    } catch (MappingException e) {
      throw new RuntimeException(e);
    }
    unmarshaller.setClass(classToUse);
    unmarshaller.setWhitespacePreserve(true);
    return unmarshaller;
  }