Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » XPAND FILE directive - is it possible to write to an InputStream
XPAND FILE directive - is it possible to write to an InputStream [message #527940] Sat, 17 April 2010 00:56 Go to next message
Eclipse UserFriend
Is it possible to capture the output of running a XPAND template into memory w/o having to fetch the results from a file specified with the FILE directive. Perhaps some way of specifying a InputStream as an Outlet (or Output)?

thanks
Re: XPAND FILE directive - is it possible to write to an InputStream [message #527982 is a reply to message #527940] Sat, 17 April 2010 21:39 Go to previous messageGo to next message
Eclipse UserFriend
Turns out its a lot easier to just wrap a StringBuffer with a class that implements Output:

    public class StringOutput implements Output {
        private Outlet outlet;
        private StringBuffer sb = new StringBuffer();
        private Stack<SyntaxElement> stack = new Stack<SyntaxElement>();

        @Override
        public void addOutlet(Outlet outlet) {
            this.outlet = outlet;
        }

        @Override
        public void closeFile() {
        }

        @Override
        public Outlet getOutlet(String name) {
            return outlet;
        }

        @Override
        public void openFile(String path, String outletName) {
        }

        @Override
        public SyntaxElement popStatement() {
            return stack.pop();
        }

        @Override
        public void pushStatement(SyntaxElement stmt, XpandExecutionContext ctx) {
            stack.push(stmt);
        }

        @Override
        public void write(String bytes) {
            sb.append(bytes);
        }

        public void clear() {
            sb.delete(0, sb.length());
        }

        public String toString() {
            return sb.toString();
        }
    }


Then to use it programatically:

 output = new StringOutput();
 XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
Re: XPAND FILE directive - is it possible to write to an InputStream [message #527983 is a reply to message #527940] Sat, 17 April 2010 21:39 Go to previous messageGo to next message
Eclipse UserFriend
Turns out its a lot easier to just wrap a StringBuffer with a class that implements Output:

    public class StringOutput implements Output {
        private Outlet outlet;
        private StringBuffer sb = new StringBuffer();
        private Stack<SyntaxElement> stack = new Stack<SyntaxElement>();

        @Override
        public void addOutlet(Outlet outlet) {
            this.outlet = outlet;
        }

        @Override
        public void closeFile() {
        }

        @Override
        public Outlet getOutlet(String name) {
            return outlet;
        }

        @Override
        public void openFile(String path, String outletName) {
        }

        @Override
        public SyntaxElement popStatement() {
            return stack.pop();
        }

        @Override
        public void pushStatement(SyntaxElement stmt, XpandExecutionContext ctx) {
            stack.push(stmt);
        }

        @Override
        public void write(String bytes) {
            sb.append(bytes);
        }

        public void clear() {
            sb.delete(0, sb.length());
        }

        public String toString() {
            return sb.toString();
        }
    }


Then to use it programatically:

 output = new StringOutput();
 XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
Re: XPAND FILE directive - is it possible to write to an InputStream [message #527984 is a reply to message #527940] Sat, 17 April 2010 21:40 Go to previous message
Eclipse UserFriend
Turns out its a lot easier to just wrap a StringBuffer with a class that implements Output:

    public class StringOutput implements Output {
        private Outlet outlet;
        private StringBuffer sb = new StringBuffer();
        private Stack<SyntaxElement> stack = new Stack<SyntaxElement>();

        @Override
        public void addOutlet(Outlet outlet) {
            this.outlet = outlet;
        }

        @Override
        public void closeFile() {
        }

        @Override
        public Outlet getOutlet(String name) {
            return outlet;
        }

        @Override
        public void openFile(String path, String outletName) {
        }

        @Override
        public SyntaxElement popStatement() {
            return stack.pop();
        }

        @Override
        public void pushStatement(SyntaxElement stmt, XpandExecutionContext ctx) {
            stack.push(stmt);
        }

        @Override
        public void write(String bytes) {
            sb.append(bytes);
        }

        public void clear() {
            sb.delete(0, sb.length());
        }

        public String toString() {
            return sb.toString();
        }
    }


Then to use it programatically:

 output = new StringOutput();
 XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
Previous Topic:[Xpand] Invoking templates from menus?
Next Topic:[Xtend] apply a function with multiple arguments on all elements of a list
Goto Forum:
  


Current Time: Tue Jul 15 22:47:47 EDT 2025

Powered by FUDForum. Page generated in 1.12915 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top