/** * Add or replace a custom trace type * * @param category The custom parser category * @param definitionName The custom parser definition name to add or replace */ public void addCustomTraceType(String category, String definitionName) { String traceTypeId = null; ITmfTrace trace = null; if (category.equals(CUSTOM_TXT_CATEGORY)) { traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + definitionName; CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(definitionName); if (def != null) { trace = new CustomTxtTrace(def); } } else if (category.equals(CUSTOM_XML_CATEGORY)) { traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + definitionName; CustomXmlTraceDefinition def = CustomXmlTraceDefinition.load(definitionName); if (def != null) { trace = new CustomXmlTrace(def); } } if (traceTypeId != null && trace != null) { TraceTypeHelper helper = fTraceTypes.get(traceTypeId); if (helper != null) { helper.getTrace().dispose(); } TraceTypeHelper tt = new TraceTypeHelper( traceTypeId, category, definitionName, trace, false, TraceElementType.TRACE); fTraceTypes.put(traceTypeId, tt); // Deregister trace as signal handler because it is only used for validation TmfSignalManager.deregister(trace); } }
/** * @param traceType the trace type * @return <code>true</code> it is a directory trace type else else <code>false</code> */ public boolean isDirectoryTraceType(String traceType) { if (traceType != null) { TraceTypeHelper traceTypeHelper = getTraceType(traceType); if (traceTypeHelper != null) { return traceTypeHelper.isDirectoryTraceType(); } } throw new IllegalArgumentException("Invalid trace type string: " + traceType); // $NON-NLS-1$ }
/** * Checks if a trace is a valid directory trace * * @param path the file name (and path) * @return <code>true</code> if the trace is a valid directory trace else <code>false</code> */ public boolean isDirectoryTrace(String path) { final Iterable<TraceTypeHelper> traceTypeHelpers = getTraceTypeHelpers(); for (TraceTypeHelper traceTypeHelper : traceTypeHelpers) { if (traceTypeHelper.isDirectoryTraceType() && traceTypeHelper.validate(path).isOK()) { return true; } } return false; }
/** * Validate a trace type * * @param traceTypeName the trace category (canonical name) * @param fileName the file name (and path) * @return true if the trace is of a valid type */ public boolean validate(String traceTypeName, String fileName) { if (traceTypeName != null && !traceTypeName.isEmpty()) { final TraceTypeHelper traceTypeHelper = fTraceTypes.get(traceTypeName); if (!traceTypeHelper.validate(fileName).isOK()) { return false; } } return true; }
/** * Remove a custom trace type * * @param category The custom parser category * @param definitionName The custom parser definition name to add or replace */ public void removeCustomTraceType(String category, String definitionName) { if (category.equals(CUSTOM_TXT_CATEGORY)) { String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + definitionName; TraceTypeHelper helper = fTraceTypes.remove(traceTypeId); if (helper != null) { helper.getTrace().dispose(); } } else if (category.equals(CUSTOM_XML_CATEGORY)) { String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + definitionName; TraceTypeHelper helper = fTraceTypes.remove(traceTypeId); if (helper != null) { helper.getTrace().dispose(); } } }
/** * Returns a list of "category:tracetype , ..." sorted by given comparator. * * <p>Returns only trace types, not experiment types * * @param comparator Comparator class (type String) or null for alphabetical order. * @return sorted list according to the given comparator */ public String[] getAvailableTraceTypes(Comparator<String> comparator) { // Generate the list of Category:TraceType to populate the ComboBox List<String> traceTypes = new ArrayList<>(); for (String key : this.fTraceTypes.keySet()) { TraceTypeHelper tt = this.fTraceTypes.get(key); if (!tt.isExperimentType()) { traceTypes.add(tt.getCategoryName() + SEPARATOR + tt.getName()); } } if (comparator == null) { Collections.sort(traceTypes); } else { Collections.sort(traceTypes, comparator); } // Format result return traceTypes.toArray(new String[traceTypes.size()]); }