/** * Add a {@link WindupVertexFrame} type to the list of mappings for the given pattern and {@link GraphRewrite} * event. */ public static void addMapping(GraphRewrite event, String pattern, Class<? extends WindupVertexFrame> type) { getMappings(event, pattern).add(type); }
/** * Create a new {@link FileMapping} */ public static FileMappingFrom from(String regex) { return new FileMapping(Pattern.compile(regex)); }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.jsp$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.jspx$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.tag$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.tagx$").to(JspSourceFileModel.class)) ; } }
FileMappingTo mappingTo = FileMapping.from(from).to(types.toArray(new Class[types.size()])).onParseError(FileModel.OnParseError.IGNORE); Rule rule = StringUtils.isNotBlank(id) ? mappingTo.withId(id) : mappingTo; if (rule instanceof Context) ((Context) rule).put(RuleMetadataType.RULE_XML, XmlUtil.nodeToString(element));
@Override public void preRulesetEvaluation(GraphRewrite event) LOG.info("Added " + toString()); for (Class<? extends WindupVertexFrame> type : types) addMapping(event, pattern.pattern(), type); .getMappings(event);
@Override public void beforeExecution(GraphRewrite event) { LOG.info("Registered " + FileMappingGraphChangedListener.class.getSimpleName() + "- Mapped file types will be added to the graph automatically."); event.getGraphContext().registerGraphListener(new FileMappingGraphChangedListener(event)); } }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.html$").to(HtmlFileModel.class)) .addRule(FileMapping.from(".*\\.css$").to(CssFileModel.class)) .addRule(FileMapping.from(".*\\.js$").to(JsFileModel.class)); } }
FileMappingTo mappingTo = FileMapping.from(from).to(types.toArray(new Class[types.size()])).onParseError(FileModel.OnParseError.IGNORE); Rule rule = StringUtils.isNotBlank(id) ? mappingTo.withId(id) : mappingTo; if (rule instanceof Context) ((Context) rule).put(RuleMetadataType.RULE_XML, XmlUtil.nodeToString(element));
/** * Get the list of {@link WindupVertexFrame} type mappings for the given pattern and {@link GraphRewrite} event. */ public static List<Class<? extends WindupVertexFrame>> getMappings(GraphRewrite event, String pattern) { Map<String, List<Class<? extends WindupVertexFrame>>> mappings = getMappings(event); List<Class<? extends WindupVertexFrame>> result = mappings.get(pattern); if (result == null) { result = new ArrayList<>(); mappings.put(pattern, result); } return result; }
@Override public void beforeExecution(GraphRewrite event) { LOG.info("Registered " + FileMappingGraphChangedListener.class.getSimpleName() + "- Mapped file types will be added to the graph automatically."); event.getGraphContext().registerGraphListener(new FileMappingGraphChangedListener(event)); } }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.html$").to(HtmlFileModel.class)) .addRule(FileMapping.from(".*\\.css$").to(CssFileModel.class)) .addRule(FileMapping.from(".*\\.js$").to(JsFileModel.class)); } }
@Override public void vertexPropertyChanged(Vertex vertex, String key, Object oldValue, Object setValue) { if (FileModel.FILE_PATH.equals(key)) { FileService fileService = new FileService(event.getGraphContext()); FileModel model = fileService.frame(vertex); Map<String, List<Class<? extends WindupVertexFrame>>> mappings = FileMapping .getMappings(event); for (Entry<String, List<Class<? extends WindupVertexFrame>>> entry : mappings.entrySet()) { String pattern = entry.getKey(); List<Class<? extends WindupVertexFrame>> types = entry.getValue(); if (((String) setValue).matches(pattern)) { if (!model.isDirectory()) { for (Class<? extends WindupVertexFrame> type : types) { GraphService.addTypeToModel(event.getGraphContext(), model, type); } LOG.fine("Mapped file [" + model.getFilePath() + "] matching pattern [" + pattern + "] to the following [" + types.size() + "] types: " + types); } } } } }
@Override public void beforeExecution(GraphRewrite event) { LOG.info("Registered " + FileMappingGraphChangedListener.class.getSimpleName() + "- Mapped file types will be added to the graph automatically."); event.getGraphContext().getGraph().addListener(new FileMappingGraphChangedListener(event)); } }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.jsp$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.jspx$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.tag$").to(JspSourceFileModel.class)) .addRule(FileMapping.from(".*\\.tagx$").to(JspSourceFileModel.class)) ; } }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.xml$").to(XmlFileModel.class)) .addRule(FileMapping.from(".*\\.xmi$").to(XmlFileModel.class)) .addRule(FileMapping.from(".*\\.jsf$").to(XmlFileModel.class)) .addRule(FileMapping.from(".*\\.xhtml$").to(XmlFileModel.class)) .addRule() .when(Query.fromType(XmlFileModel.class)) .perform(new AbstractIterationOperation<XmlFileModel>() { @Override public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { addXmlMetaInformation(event, context, payload); } @Override public String toString() { return "IndexXmlFilesMetadata"; } }); }
@Override public Configuration getConfiguration(GraphContext context) { return ConfigurationBuilder.begin() .addRule(FileMapping.from(".*\\.xml$").to(XmlFileModel.class)) .addRule() .when(Query.fromType(XmlFileModel.class)) .perform(new AbstractIterationOperation<FileModel>() { @Override public void perform(GraphRewrite event, EvaluationContext context, FileModel payload) { addXmlMetaInformation(event.getGraphContext(), payload); } @Override public String toString() { return "IndexXmlFilesMetadata"; } }); }