1 package org.kohsuke.stapler; 2 3 import java.util.List ; 4 5 8 class AncestorImpl implements Ancestor { 9 private final List <AncestorImpl> owner; 10 private final int listIndex; 11 12 private Object object; 13 private String [] tokens; 14 private int index; 15 private String contextPath; 16 17 public AncestorImpl(List <AncestorImpl> owner) { 18 this.owner = owner; 19 listIndex = owner.size(); 20 owner.add(this); 21 } 22 23 public void set(Object object, RequestImpl req ) { 24 this.object = object; 25 this.tokens = req.tokens.tokens; 26 this.index = req.tokens.idx; 27 this.contextPath = req.getContextPath(); 28 } 29 30 public Object getObject() { 31 return object; 32 } 33 34 public String getUrl() { 35 StringBuffer buf = new StringBuffer (contextPath); 36 for( int i=0; i<index; i++ ) { 37 buf.append('/'); 38 buf.append(tokens[i]); 39 } 40 return buf.toString(); 41 } 42 43 public Ancestor getPrev() { 44 if(listIndex==0) 45 return null; 46 else 47 return owner.get(listIndex-1); 48 } 49 50 public Ancestor getNext() { 51 if(listIndex==owner.size()-1) 52 return null; 53 else 54 return owner.get(listIndex+1); 55 } 56 57 public String toString() { 58 return object.toString(); 59 } 60 } 61 | Popular Tags |