/** * Crates a writer instance. * * @param clazz class to instantiate. * @param os output stream to pass as constructor argument. * @return created instance. * @throws IllegalArgumentException if an error occurs during instantiation. */ private FormatWriter createWriter(WriterFactory clazz, OutputStream os) { try { return clazz.getRdfWriter(os); } catch (Exception e) { throw new IllegalArgumentException( "Error while initializing format writer " + clazz + " .", e); } }
/** * Registers a new {@link WriterFactory} to the registry. * * @param writerClass the class of the writer to be registered. * @throws IllegalArgumentException if the id or the mimetype are null or empty strings or if the * identifier has been already defined. */ public synchronized void register(WriterFactory writerClass) { if (writerClass == null) throw new NullPointerException("writerClass cannot be null."); final String id = writerClass.getIdentifier(); final String mimeType = writerClass.getMimeType(); if (id == null || id.trim().length() == 0) { throw new IllegalArgumentException("Invalid identifier returned by writer " + writerClass); } if (mimeType == null || mimeType.trim().length() == 0) { throw new IllegalArgumentException("Invalid MIME type returned by writer " + writerClass); } if (idToWriter.containsKey(id)) throw new IllegalArgumentException("The writer identifier is already declared."); writers.add(writerClass); identifiers.add(writerClass.getIdentifier()); List<WriterFactory> writerClasses = mimeToWriter.get(mimeType); if (writerClasses == null) { writerClasses = new ArrayList<WriterFactory>(); mimeToWriter.put(mimeType, writerClasses); } writerClasses.add(writerClass); idToWriter.put(id, writerClass); }
protected void writeResults() throws IOException { writeResults(writerFactory.getWriter(getPageForHistory(), finalSummary, currentTestStartTime)); }
/** * Reads the <i>MIME Type</i> specified for the given {@link FormatWriter}. * * @param writerClass writer class. * @return MIME type. */ public static String getMimeType(WriterFactory writerClass) { return writerClass.getMimeType(); }
/** * Reads the identifier specified for the given {@link FormatWriter}. * * @param writerClass writer class. * @return identifier. */ public static String getIdentifier(WriterFactory writerClass) { return writerClass.getIdentifier(); }