@Override public int size() { return nameSpace.getVariableNames().length; }
@Override public Set<String> keySet() { final Set<String> result = new HashSet<String>(); for (final String name : nameSpace.getVariableNames()) { result.add(name); } return result; }
public static String[] getVariableNames(NameSpace ns) { if (ns == null) return new String[0]; return Stream.of(ns.getVariableNames()) .filter(name->!name.matches("_?bsh.*")) .toArray(String[]::new); }
/** */ public String [] getVariableNames() { // union of the names in the internal namespace and external map Set<String> nameSet = new HashSet<String>(); String [] nsNames = super.getVariableNames(); nameSet.addAll( Arrays.asList( nsNames ) ); nameSet.addAll( externalMap.keySet() ); return (String [])nameSet.toArray( new String[0] ); }
/** */ public String [] getVariableNames() { return Stream.concat( Stream.of(super.getVariableNames()), this.externalMap.keySet().stream() ).toArray(String[]::new); }
@Override public Set<Entry<String, Object>> entrySet() { final Set<Entry<String, Object>> result = new HashSet<Entry<String, Object>>(); for (final String name : nameSpace.getVariableNames()) { result.add(new Entry<String, Object>() { @Override public String getKey() { return name; } @Override public Object getValue() { return get(name); } @Override public Object setValue(Object value) { throw new UnsupportedOperationException(); } }); } return result; }
@Override public Collection<Object> values() { final List<Object> result = new ArrayList<Object>(); for (final String name : nameSpace.getVariableNames()) try { result.add(nameSpace.get(name, interpreter)); } catch (UtilEvalError exc) { // ignore for now } return result; }
/*package*/ static void write(NameSpace ns, ObjectOutputStream s, Filter filter) throws IOException { final String[] vars = ns.getVariableNames(); for (int j = vars != null ? vars.length : 0; --j >= 0;) { final String nm = vars[j];
String[] varNames = ns.getVariableNames(); for (int x = 0; x < varNames.length; x++) { context.put(varNames[x], bsh.get(varNames[x]));
obj = thisNameSpace; else if (varName.equals("variables")) obj = thisNameSpace.getVariableNames(); else if (varName.equals("methods")) obj = thisNameSpace.getMethodNames();
/** This is the invocation handler for the dynamic proxy. <p> Notes: Inner class for the invocation handler seems to shield this unavailable interface from JDK1.2 VM... I don't understand this. JThis works just fine even if those classes aren't there (doesn't it?) This class shouldn't be loaded if an XThis isn't instantiated in NameSpace.java, should it? */ class Handler implements InvocationHandler, java.io.Serializable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { return invokeImpl( proxy, method, args ); } catch ( TargetError te ) { // Unwrap target exception. If the interface declares that // it throws the ex it will be delivered. If not it will be // wrapped in an UndeclaredThrowable // This isn't simple because unwrapping this loses all context info. // So rewrap is better than unwrap. - fschmidt Throwable t = te.getTarget(); Class<? extends Throwable> c = t.getClass(); String msg = t.getMessage(); try {
NameSpace ns = new NameSpace(namespace,namespace.getName()+" clone"); try { for( String varName : namespace.getVariableNames() ) { ns.setLocalVariable(varName,namespace.getVariable(varName,false),false);
obj = thisNameSpace; else if (varName.equals("variables")) obj = thisNameSpace.getVariableNames(); else if (varName.equals("methods")) obj = thisNameSpace.getMethodNames();