/** * Initializes the xmlizers. * * @param info is the name of the root method. * @param ctrl is the controller to be used to initialize the xmlizers and to which to hook up the * xmlizers to xmlize the dependence information. * @return a map of xmlizers and the associated writers. * @throws IllegalStateException when output directory is unspecified. * @pre rootname != null and ctrl != null * @post result != null */ private Map<StmtAndMethodBasedDependencyXMLizer<?, ?>, Writer> initXMLizers( final Map info, final ProcessingController ctrl) { final Map<StmtAndMethodBasedDependencyXMLizer<?, ?>, Writer> _result = new HashMap<StmtAndMethodBasedDependencyXMLizer<?, ?>, Writer>(); if (getXmlOutputDir() == null) { LOGGER.error("Please specify an output directory while using the xmlizer."); throw new IllegalStateException( "Please specify an output directory while using the xmlizer."); } for (final Iterator<Comparable<?>> _i = AbstractDependencyAnalysis.IDENTIFIERS.iterator(); _i.hasNext(); ) { final Object _id = _i.next(); final Collection< IDependencyAnalysis<? extends Stmt, SootMethod, ?, ? extends Stmt, SootMethod, ?>> _col = (Collection) info.get(_id); if (_col != null) { for (final Iterator< IDependencyAnalysis< ? extends Stmt, SootMethod, ?, ? extends Stmt, SootMethod, ?>> _j = _col.iterator(); _j.hasNext(); ) { final IDependencyAnalysis<? extends Stmt, SootMethod, ?, ? extends Stmt, SootMethod, ?> _da = _j.next(); String _providedFileName = (String) info.get(FILE_NAME_ID); if (_providedFileName == null) { _providedFileName = getDAPartOfFileName(_da); } final String _filename = getFileName(_providedFileName); filenames.add(_filename); final File _f = new File(getXmlOutputDir() + File.separator + _filename); try { final FileWriter _writer = new FileWriter(_f); final StmtAndMethodBasedDependencyXMLizer<?, ?> _xmlizer = getXMLizerFor(_writer, _da); if (_xmlizer == null) { LOGGER.error( "No xmlizer specified for dependency calculated by " + _da.getClass() + ". No xml file written."); _writer.close(); } else { _xmlizer.hookup(ctrl); _result.put(_xmlizer, _writer); } } catch (IOException _e) { LOGGER.error("Failed to write the xml file based on " + _da.getClass(), _e); } } } } return _result; }
/** * Retrives the xmlizer for the given dependence analysis based on the properties. * * @param <T1> is the type of the dependent entity. * @param <E2> is the type of the dependee entity. * @param writer to be used by the xmlizer. * @param da is the dependence analysis for which the xmlizer is requested. * @return the xmlizer. * @pre writer != null and da != null * @post result != null */ private <T1 extends Stmt, E2 extends Stmt> StmtAndMethodBasedDependencyXMLizer<T1, E2> getXMLizerFor( final Writer writer, final IDependencyAnalysis<T1, SootMethod, ?, E2, SootMethod, ?> da) { StmtAndMethodBasedDependencyXMLizer<T1, E2> _result = null; final List<IDependencyAnalysis.DependenceSort> _t = new ArrayList<IDependencyAnalysis.DependenceSort>(da.getIds()); Collections.sort(_t); final String _xmlizerId = _t.toString(); final String _temp = PROPERTIES.getProperty(_xmlizerId); if (_temp.equals(DependencyXMLizer.STMT_LEVEL_DEPENDENCY)) { try { _result = new StmtAndMethodBasedDependencyXMLizer<T1, E2>( new CustomXMLOutputter(writer), getIdGenerator(), da); } catch (final UnsupportedEncodingException _e) { LOGGER.error( "UTF-8 encoding is unsupported. Now, this contradicts the documentation!!", _e); } } else { LOGGER.error("Unknown dependency xmlizer type requested. Bailing on this."); } return _result; }
/** * Retrieves the part of the filename based on the given analysis. * * @param da to be used to base the name. * @return the derived name. * @pre da != null * @post result != null */ String getDAPartOfFileName(final IDependencyAnalysis<?, ?, ?, ?, ?, ?> da) { final List<IDependencyAnalysis.DependenceSort> _t = new ArrayList<IDependencyAnalysis.DependenceSort>(da.getIds()); Collections.sort(_t); return _t + ":" + da.getDirection() + ":" + da.getClass().getName(); }