Showing the changes to java/pkg/com/sun/script/util/BindingsImpl.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,85 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.script.util; | |
| 27 | +import java.util.*; | |
| 28 | +import javax.script.Bindings; | |
| 29 | + | |
| 30 | +/* | |
| 31 | + * Abstract super class for Bindings implementations. Handles | |
| 32 | + * global and local scopes. | |
| 33 | + * | |
| 34 | + * @author Mike Grogan | |
| 35 | + * @since 1.6 | |
| 36 | + */ | |
| 37 | +public abstract class BindingsImpl extends BindingsBase { | |
| 38 | + | |
| 39 | + //get method delegates to global if key is not defined in | |
| 40 | + //base class or local scope | |
| 41 | + protected Bindings global = null; | |
| 42 | + | |
| 43 | + //get delegates to local scope | |
| 44 | + protected Bindings local = null; | |
| 45 | + | |
| 46 | + public void setGlobal(Bindings n) { | |
| 47 | + global = n; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setLocal(Bindings n) { | |
| 51 | + local = n; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public Set<Map.Entry<String, Object>> entrySet() { | |
| 55 | + return new BindingsEntrySet(this); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public Object get(Object key) { | |
| 59 | + checkKey(key); | |
| 60 | + | |
| 61 | + Object ret = null; | |
| 62 | + if ((local != null) && (null != (ret = local.get(key)))) { | |
| 63 | + return ret; | |
| 64 | + } | |
| 65 | + | |
| 66 | + ret = getImpl((String)key); | |
| 67 | + | |
| 68 | + if (ret != null) { | |
| 69 | + return ret; | |
| 70 | + } else if (global != null) { | |
| 71 | + return global.get(key); | |
| 72 | + } else { | |
| 73 | + return null; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + public Object remove(Object key) { | |
| 78 | + checkKey(key); | |
| 79 | + Object ret = get(key); | |
| 80 | + if (ret != null) { | |
| 81 | + removeImpl((String)key); | |
| 82 | + } | |
| 83 | + return ret; | |
| 84 | + } | |
| 85 | +} | |