001    package org.crsh.command;
002    
003    import org.crsh.text.ShellPrintWriter;
004    
005    import java.util.ArrayList;
006    import java.util.Collections;
007    import java.util.List;
008    import java.util.Map;
009    
010    /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
011    class InnerInvocationContext<P> implements InvocationContext<Void, P> {
012    
013      /** . */
014      final InvocationContext<?, ?> outter;
015    
016      /** . */
017      final Class<? extends P> producedType;
018    
019      /** . */
020      List<P> products;
021    
022      /** . */
023      final boolean piped;
024    
025      InnerInvocationContext(
026        InvocationContext<?, ?> outter,
027        Class<? extends P> producedType,
028        boolean piped) {
029        this.outter = outter;
030        this.products = Collections.emptyList();
031        this.producedType = producedType;
032        this.piped = piped;
033      }
034    
035      public int getWidth() {
036        return outter.getWidth();
037      }
038    
039      public String getProperty(String propertyName) {
040        return outter.getProperty(propertyName);
041      }
042    
043      public String readLine(String msg, boolean echo) {
044        return outter.readLine(msg, echo);
045      }
046    
047      public ShellPrintWriter getWriter() {
048        return outter.getWriter();
049      }
050    
051      public boolean isPiped() {
052        return piped;
053      }
054    
055      public Iterable<Void> consume() throws IllegalStateException {
056        throw new IllegalStateException();
057      }
058    
059      public void produce(P product) {
060        if (products.isEmpty()) {
061          products = new ArrayList<P>();
062        }
063        products.add(product);
064      }
065    
066      public Map<String, Object> getSession() {
067        return outter.getSession();
068      }
069    
070      public Map<String, Object> getAttributes() {
071        return outter.getAttributes();
072      }
073    }