| /* Map lines affect the tree depth differently. | ||
| */ | ||
| -map : tableMap | columnMap | innerMap | outerMap; | ||
| -tableMap : table T_MAP node ; | ||
| -columnMap: column T_MAP node ; | ||
| -innerMap : tableColumn T_INNER tableColumn ; | ||
| -outerMap : tableColumn T_OUTER tableColumn ; | ||
| +map : tableMap | columnMap | attributeMap | innerMap | outerMap; | ||
| +tableMap : table T_MAP path ; | ||
| +columnMap : column T_MAP path ; | ||
| +attributeMap: column T_MAP attribute ; | ||
| +innerMap : tableColumn T_INNER tableColumn ; | ||
| +outerMap : tableColumn T_OUTER tableColumn ; | ||
| -include : T_IMPORT T_ID ; | ||
| +include : T_IMPORT T_ID ; | ||
| table : T_ID ; | ||
| column : T_PERIOD T_ID ; | ||
| tableColumn: table column ; | ||
| attribute : T_AT T_ID ; | ||
| element : T_ID ; | ||
| -path : element T_SLASH element ; | ||
| - | ||
| -node : element | attribute | path ; | ||
| +elementPath: element T_SLASH element ; | ||
| +path : element | elementPath; | ||
| /* Define the WHERE clause. |
| } | ||
| + @Override | ||
| + public synchronized void enterAttributeMap( | ||
| + QueryParser.AttributeMapContext ctx ) { | ||
| + addLeaf( ctx ); | ||
| + } | ||
| + | ||
| /** | ||
| * Invoked when parsing <code>^</code>. Changes context tree to its parent. |
| /** | ||
| - * Depth-first traversal. | ||
| + * Depth-first traversal. This converts all payload instances in the tree | ||
| + * to their transformed equivalent. | ||
| + * | ||
| + * @param tree The tree to transform. | ||
| + * @param depth Indicates number of spaces for indentation. | ||
| + * | ||
| + * @return The fully transformed text. | ||
| */ | ||
| protected String toString( Tree<T> tree, int depth ) { | ||
| * | ||
| * @param payload The data to transform into its opening text. | ||
| + * @return The opening for the transformed payload text. | ||
| */ | ||
| protected abstract String start( T payload ); | ||
| /** | ||
| * Called when exiting a new hierarchy in the transformation tree. | ||
| * | ||
| * @param payload The data to transform into its closing text. | ||
| + * @return The closing for the transformed payload text. | ||
| */ | ||
| protected abstract String stop( T payload ); | ||
| /** | ||
| + * Formats the start of the XMLELEMENT call. | ||
| * | ||
| * @param name The name assigned to the element. | ||
| + * | ||
| + * @return The text used for SQL/XML XMLELEMENT calls. | ||
| */ | ||
| protected String startElement( String name ) { | ||
| return String.format( "XMLELEMENT( NAME \"%s\"", name ); | ||
| } | ||
| /** | ||
| + * Formats the start of the XMLATTRIBUTES call. | ||
| + * | ||
| * @param name The name assigned to the attribute. | ||
| + * | ||
| + * @return The text used for SQL/XML XMLATTRIBUTES calls. | ||
| */ | ||
| protected String startAttributes( String name ) { | ||
| return String.format( "XMLATTRIBUTES( %s AS ", name ); | ||
| - } | ||
| - | ||
| - /** | ||
| - * Casts the payload into the proper context, then extracts the element. | ||
| - * This should not be called if the wrapped payload does not have an | ||
| - * element. | ||
| - * | ||
| - * @return The element associated with the root parser rule. | ||
| - */ | ||
| - protected QueryParser.ElementContext getElementContext() { | ||
| - return ((QueryParser.RootContext)getParserRuleContext()).element(); | ||
| } | ||
| /** | ||
| * Subclass override this to change the content returned by the parser | ||
| * rule. This is called during transformation. | ||
| + * | ||
| + * @return The token containing a transformed string for the wrapped opening. | ||
| */ | ||
| @Override | ||
| public abstract Token getStart(); | ||
| /** | ||
| * Subclass override this to change the content returned by the parser | ||
| * rule. This is called during transformation. | ||
| + * | ||
| + * @return The token containing a transformed string for the wrapped closing. | ||
| */ | ||
| @Override |
| +package com.whitemagicsoftware.rxm.tree.xml; | ||
| + | ||
| +import org.antlr.v4.runtime.ParserRuleContext; | ||
| + | ||
| +import com.whitemagicsoftware.rxm.grammar.QueryParser; | ||
| + | ||
| +public class AttributeMapContext extends ASTParserRuleContext { | ||
| + public AttributeMapContext( ParserRuleContext ctx ) { | ||
| + super( ctx ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Opens the XMLATTRIBUTES. | ||
| + */ | ||
| + @Override | ||
| + public Token getStart() { | ||
| + String e = getParserRuleContext().getText(); | ||
| + | ||
| + String s = String.format( ",%s ", startAttributes( e ) ); | ||
| + return new Token( s ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Closes the ATTRIBUTES. | ||
| + */ | ||
| + @Override | ||
| + public Token getStop() { | ||
| + return new Token( ")" ); | ||
| + } | ||
| +} | ||
| + | ||
| import org.antlr.v4.runtime.ParserRuleContext; | ||
| +import com.whitemagicsoftware.rxm.grammar.QueryParser; | ||
| + | ||
| public class ColumnMapContext extends ASTParserRuleContext { | ||
| public ColumnMapContext( ParserRuleContext ctx ) { | ||
| super( ctx ); | ||
| } | ||
| + /** | ||
| + * Opens the XMLELEMENT. | ||
| + */ | ||
| @Override | ||
| public Token getStart() { | ||
| - return new Token( "COLUMN MAP:" + toString() ); | ||
| + QueryParser.PathContext path = getPathContext(); | ||
| + String e = path.getText(); | ||
| + | ||
| + String s = String.format( ",%s, %s", startElement( e ), getColumnName() ); | ||
| + return new Token( s ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * This will return column name without the leading period. | ||
| + * | ||
| + * @return The column name, without a leading period. | ||
| + */ | ||
| + protected String getColumnName() { | ||
| + // The first child (index 0) is the leading period. | ||
| + // The second child (index 1) is the column name. | ||
| + return getColumnContext().getChild(1).getText(); | ||
| } | ||
| + /** | ||
| + * Closes the XMLELEMENT. | ||
| + */ | ||
| @Override | ||
| public Token getStop() { | ||
| return new Token( ")" ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Casts the payload into the proper context, then extracts the path. | ||
| + * | ||
| + * @return The path associated with the column map parser rule. | ||
| + */ | ||
| + protected QueryParser.PathContext getPathContext() { | ||
| + return ((QueryParser.ColumnMapContext)getParserRuleContext()).path(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Casts the payload into the proper context, then extracts the column. | ||
| + * | ||
| + * @return The column associated with the column map parser rule. | ||
| + */ | ||
| + protected QueryParser.ColumnContext getColumnContext() { | ||
| + return ((QueryParser.ColumnMapContext)getParserRuleContext()).column(); | ||
| } | ||
| } |
| return true; | ||
| } | ||
| + | ||
| + /** | ||
| + * Casts the payload into the proper context, then extracts the element. | ||
| + * | ||
| + * @return The element associated with the root parser rule. | ||
| + */ | ||
| + protected QueryParser.ElementContext getElementContext() { | ||
| + return ((QueryParser.RootContext)getParserRuleContext()).element(); | ||
| + } | ||
| } | ||
| import org.antlr.v4.runtime.ParserRuleContext; | ||
| +import com.whitemagicsoftware.rxm.grammar.QueryParser; | ||
| + | ||
| /** | ||
| * Transforms <code>element > element</code>. | ||
| @Override | ||
| public Token getStart() { | ||
| - QueryParser.ElementContext element = getElementContext(); | ||
| - String e = element.getText(); | ||
| + QueryParser.PathContext path = getPathContext(); | ||
| + String e = path.getText(); | ||
| String s = String.format( ",%s", startElement( e ) ); | ||
| public Token getStop() { | ||
| return new Token( ")" ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Casts the payload into the proper context, then extracts the path. | ||
| + * | ||
| + * @return The path associated with the table map parser rule. | ||
| + */ | ||
| + protected QueryParser.PathContext getPathContext() { | ||
| + return ((QueryParser.TableMapContext)getParserRuleContext()).path(); | ||
| } | ||
| } | ||
| +package com.whitemagicsoftware.rxm.tree.xml; | ||
| + | ||
| +import org.antlr.v4.runtime.CommonToken; | ||
| +import static org.antlr.v4.runtime.Token.MIN_USER_TOKEN_TYPE; | ||
| + | ||
| +/** | ||
| + * Avoids having to dupliate common token functionality across the different | ||
| + * parser rule contexts. | ||
| + */ | ||
| +public class Token extends CommonToken { | ||
| + public Token( String text ) { | ||
| + super( MIN_USER_TOKEN_TYPE, text ); | ||
| + } | ||
| + | ||
| + public String toString() { | ||
| + return getText(); | ||
| + } | ||
| +} | ||
| + | ||
| .*, | ||
| ^, | ||
| -company > company, | ||
| company.person_id -> person.person_id, | ||
| +company > company, | ||
| .id > @id, | ||
| .legal_name > name, |
| Author | Dave Jarvis <email> |
|---|---|
| Date | 2015-03-07 19:59:09 GMT-0800 |
| Commit | 381282746452f05c249caca7a8c8bd32433938e7 |
| Parent | d253c1b |
| Delta | 150 lines added, 25 lines removed, 125-line increase |