1 33 34 package bsh; 35 36 45 52 class BlockNameSpace extends NameSpace 53 { 54 public BlockNameSpace( NameSpace parent ) 55 throws EvalError 56 { 57 super( parent, parent.getName()+ "/BlockNameSpace" ); 58 } 59 60 70 75 public void setVariable( 76 String name, Object value, boolean strictJava, boolean recurse ) 77 throws UtilEvalError 78 { 79 if ( weHaveVar( name ) ) 80 super.setVariable( name, value, strictJava, false ); 82 else 83 getParent().setVariable( name, value, strictJava, recurse ); 85 } 86 87 93 public void setBlockVariable( String name, Object value ) 94 throws UtilEvalError 95 { 96 super.setVariable( name, value, false, false ); 97 } 98 99 104 private boolean weHaveVar( String name ) 105 { 106 try { 108 return super.getVariableImpl( name, false ) != null; 109 } catch ( UtilEvalError e ) { return false; } 110 } 111 112 127 128 132 144 145 private NameSpace getNonBlockParent() 146 { 147 NameSpace parent = super.getParent(); 148 if ( parent instanceof BlockNameSpace ) 149 return ((BlockNameSpace)parent).getNonBlockParent(); 150 else 151 return parent; 152 } 153 154 161 This getThis( Interpreter declaringInterpreter ) { 162 return getNonBlockParent().getThis( declaringInterpreter ); 163 } 164 165 168 public This getSuper( Interpreter declaringInterpreter ) { 169 return getNonBlockParent().getSuper( declaringInterpreter ); 170 } 171 172 175 public void importClass(String name) { 176 getParent().importClass( name ); 177 } 178 179 182 public void importPackage(String name) { 183 getParent().importPackage( name ); 184 } 185 186 public void setMethod(String name, BshMethod method) 187 throws UtilEvalError 188 { 189 getParent().setMethod( name, method ); 190 } 191 } 192 193 | Popular Tags |