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