Last active
December 22, 2015 17:38
-
-
Save louismrose/6507057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DynamicSectionOutputBuffer implements IOutputBuffer { | |
private final StringBuilder buffer = new StringBuilder(); | |
@Override | |
public void printdyn(Object o) { | |
buffer.append(o); | |
} | |
@Override | |
public String toString() { | |
return buffer.toString(); | |
} | |
// We don't need to provide a sensible implementation for the remaining methods | |
@Override | |
public void chop(int numberOfCharacters) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void print(Object o) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void println() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void println(Object o) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void prinx(Object o) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public String getSpaces(int howMany) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public void setContentType(String name) throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public String preserve(String id, boolean enabled, String contents) | |
throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public String preserve(String startComment, String endComment, String id, | |
boolean enabled, String contents) throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public String startPreserve(String id, boolean enabled) | |
throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public String startPreserve(String startComment, String endComment, | |
String id, boolean enabled) throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public String stopPreserve() throws EglRuntimeException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public void stop() throws EglStoppedException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public int getCurrentLineNumber() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public int getCurrentColumnNumber() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public int getOffset() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public void formatWith(Formatter formatter) { | |
// TODO Auto-generated method stub | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenerationRule { | |
public void generateAll(IEglContext context, EglTemplateFactory templateFactory, EgxModule module) throws EolRuntimeException { | |
... | |
// Store the original OutputBufferFactory so that we can restore it later | |
IOutputBufferFactory originalOutputBufferFactory = templateFactory.getContext().getOutputBufferFactory(); | |
// Create our own OutputBufferFactory | |
templateFactory.getContext().setOutputBufferFactory(new IOutputBufferFactory() { | |
// This is the method that EGL now calls to obtain a new IOutputBuffer | |
@Override | |
public IOutputBuffer create() { | |
// Instead of creating the normal EGL OutputBuffer, we create our own | |
// implementation of IOutputBuffer which only captures the text emitted | |
// by dynamic sections. | |
return new DynamicSectionOutputBuffer(); | |
} | |
}); | |
// Create a template that we can use to compute a signature | |
EglTemplate signatureTemplate = templateFactory.load(template); | |
// If present, add the source parameter in the EGX rule to the EGL template | |
if (sourceParameter != null) { | |
signatureTemplate.populate(sourceParameter.getName(), o); | |
} | |
// Add any parameters specified in the EGX rule to the EGL template | |
for (Object key : parameters.keySet()) { | |
signatureTemplate.populate(key + "", parameters.get(key)); | |
} | |
// Obtain the output from appending only the dynamic sections to the buffer | |
String dynamicSectionText = signatureTemplate.process(); | |
System.err.println(dynamicSectionText); | |
// Restore the original OutputBufferFactory so that any new templates will | |
// use the default EGL OutputBuffer rather than our special OutputBuffer | |
templateFactory.getContext().setOutputBufferFactory(originalOutputBufferFactory); | |
.... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment