src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java

Print this page

        

*** 40,51 **** public class HierMemDirCtx implements DirContext { static private final boolean debug = false; private static final NameParser defaultParser = new HierarchicalNameParser(); ! protected Hashtable myEnv; ! protected Hashtable bindings; protected Attributes attrs; protected boolean ignoreCase = false; protected NamingException readOnlyEx = null; protected NameParser myParser = defaultParser; --- 40,51 ---- public class HierMemDirCtx implements DirContext { static private final boolean debug = false; private static final NameParser defaultParser = new HierarchicalNameParser(); ! protected Hashtable<String, Object> myEnv; ! protected Hashtable<Name, Object> bindings; protected Attributes attrs; protected boolean ignoreCase = false; protected NamingException readOnlyEx = null; protected NameParser myParser = defaultParser;
*** 68,92 **** public HierMemDirCtx(boolean ignoreCase) { this(null, ignoreCase, false); } ! public HierMemDirCtx(Hashtable environment, boolean ignoreCase) { this(environment, ignoreCase, false); } ! protected HierMemDirCtx(Hashtable environment, boolean ignoreCase, ! boolean useFac) { myEnv = environment; this.ignoreCase = ignoreCase; init(); this.alwaysUseFactory = useFac; } private void init() { attrs = new BasicAttributes(ignoreCase); ! bindings = new Hashtable(11, 0.75f); } public Object lookup(String name) throws NamingException { return lookup(myParser.parse(name)); } --- 68,92 ---- public HierMemDirCtx(boolean ignoreCase) { this(null, ignoreCase, false); } ! public HierMemDirCtx(Hashtable<String, Object> environment, boolean ignoreCase) { this(environment, ignoreCase, false); } ! protected HierMemDirCtx(Hashtable<String, Object> environment, ! boolean ignoreCase, boolean useFac) { myEnv = environment; this.ignoreCase = ignoreCase; init(); this.alwaysUseFactory = useFac; } private void init() { attrs = new BasicAttributes(ignoreCase); ! bindings = new Hashtable<>(11, 0.75f); } public Object lookup(String name) throws NamingException { return lookup(myParser.parse(name)); }
*** 324,357 **** } bindings.put(newname, oldBinding); } ! public NamingEnumeration list(String name) throws NamingException { return list(myParser.parse(name)); } ! public NamingEnumeration list(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false); return ctx.doList(); } ! protected NamingEnumeration doList () throws NamingException { return new FlatNames(bindings.keys()); } ! public NamingEnumeration listBindings(String name) throws NamingException { return listBindings(myParser.parse(name)); } ! public NamingEnumeration listBindings(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx)doLookup(name, false); return ctx.doListBindings(alwaysUseFactory); } ! protected NamingEnumeration doListBindings(boolean useFactory) throws NamingException { return new FlatBindings(bindings, myEnv, useFactory); } public void destroySubcontext(String name) throws NamingException { --- 324,357 ---- } bindings.put(newname, oldBinding); } ! public NamingEnumeration<NameClassPair> list(String name) throws NamingException { return list(myParser.parse(name)); } ! public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false); return ctx.doList(); } ! protected NamingEnumeration<NameClassPair> doList () throws NamingException { return new FlatNames(bindings.keys()); } ! public NamingEnumeration<Binding> listBindings(String name) throws NamingException { return listBindings(myParser.parse(name)); } ! public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx)doLookup(name, false); return ctx.doListBindings(alwaysUseFactory); } ! protected NamingEnumeration<Binding> doListBindings(boolean useFactory) throws NamingException { return new FlatBindings(bindings, myEnv, useFactory); } public void destroySubcontext(String name) throws NamingException {
*** 445,476 **** Name result = (Name)(prefix.clone()); result.addAll(name); return result; } public Object addToEnvironment(String propName, Object propVal) throws NamingException { ! myEnv = (myEnv == null) ? ! new Hashtable(11, 0.75f) : (Hashtable)myEnv.clone(); return myEnv.put(propName, propVal); } public Object removeFromEnvironment(String propName) throws NamingException { if (myEnv == null) return null; ! myEnv = (Hashtable)myEnv.clone(); return myEnv.remove(propName); } ! public Hashtable getEnvironment() throws NamingException { if (myEnv == null) { ! return new Hashtable(5, 0.75f); } else { ! return (Hashtable)myEnv.clone(); } } public Attributes getAttributes(String name) throws NamingException { --- 445,480 ---- Name result = (Name)(prefix.clone()); result.addAll(name); return result; } + @SuppressWarnings("unchecked") // clone() public Object addToEnvironment(String propName, Object propVal) throws NamingException { ! myEnv = (myEnv == null) ! ? new Hashtable<String, Object>(11, 0.75f) ! : (Hashtable<String, Object>)myEnv.clone(); return myEnv.put(propName, propVal); } + @SuppressWarnings("unchecked") // clone() public Object removeFromEnvironment(String propName) throws NamingException { if (myEnv == null) return null; ! myEnv = (Hashtable<String, Object>)myEnv.clone(); return myEnv.remove(propName); } ! @SuppressWarnings("unchecked") // clone() ! public Hashtable<String, Object> getEnvironment() throws NamingException { if (myEnv == null) { ! return new Hashtable<>(5, 0.75f); } else { ! return (Hashtable<String, Object>)myEnv.clone(); } } public Attributes getAttributes(String name) throws NamingException {
*** 527,540 **** throw new IllegalArgumentException( "Cannot modify without an attribute"); } // turn it into a modification Enumeration and pass it on ! NamingEnumeration attrEnum = attrs.getAll(); ModificationItem[] mods = new ModificationItem[attrs.size()]; for (int i = 0; i < mods.length && attrEnum.hasMoreElements(); i++) { ! mods[i] = new ModificationItem(mod_op, (Attribute)attrEnum.next()); } modifyAttributes(name, mods); } --- 531,544 ---- throw new IllegalArgumentException( "Cannot modify without an attribute"); } // turn it into a modification Enumeration and pass it on ! NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); ModificationItem[] mods = new ModificationItem[attrs.size()]; for (int i = 0; i < mods.length && attrEnum.hasMoreElements(); i++) { ! mods[i] = new ModificationItem(mod_op, attrEnum.next()); } modifyAttributes(name, mods); }
*** 562,572 **** protected static Attributes applyMods(ModificationItem[] mods, Attributes orig) throws NamingException { ModificationItem mod; Attribute existingAttr, modAttr; ! NamingEnumeration modVals; for (int i = 0; i < mods.length; i++) { mod = mods[i]; modAttr = mod.getAttribute(); --- 566,576 ---- protected static Attributes applyMods(ModificationItem[] mods, Attributes orig) throws NamingException { ModificationItem mod; Attribute existingAttr, modAttr; ! NamingEnumeration<?> modVals; for (int i = 0; i < mods.length; i++) { mod = mods[i]; modAttr = mod.getAttribute();
*** 617,647 **** } return orig; } ! public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } ! public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } ! public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { return search(myParser.parse(name), matchingAttributes, attributesToReturn); } ! public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { HierMemDirCtx target = (HierMemDirCtx) doLookup(name, false); --- 621,651 ---- } return orig; } ! public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } ! public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } ! public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { return search(myParser.parse(name), matchingAttributes, attributesToReturn); } ! public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { HierMemDirCtx target = (HierMemDirCtx) doLookup(name, false);
*** 654,664 **** new ContainmentFilter(matchingAttributes), cons, this, myEnv, false); // alwaysUseFactory ignored because objReturnFlag == false } ! public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException { DirContext target = (DirContext) doLookup(name, false); --- 658,668 ---- new ContainmentFilter(matchingAttributes), cons, this, myEnv, false); // alwaysUseFactory ignored because objReturnFlag == false } ! public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException { DirContext target = (DirContext) doLookup(name, false);
*** 669,696 **** SearchControls.ONELEVEL_SCOPE), stringfilter, cons, this, myEnv, alwaysUseFactory); } ! public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { String strfilter = SearchFilter.format(filterExpr, filterArgs); return search(name, strfilter, cons); } ! public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException { return search(myParser.parse(name), filter, cons); } ! public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { return search(myParser.parse(name), filterExpr, filterArgs, cons); --- 673,700 ---- SearchControls.ONELEVEL_SCOPE), stringfilter, cons, this, myEnv, alwaysUseFactory); } ! public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { String strfilter = SearchFilter.format(filterExpr, filterArgs); return search(name, strfilter, cons); } ! public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException { return search(myParser.parse(name), filter, cons); } ! public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { return search(myParser.parse(name), filterExpr, filterArgs, cons);
*** 759,773 **** public void setNameParser(NameParser parser) { myParser = parser; } ! // Class for enumerating name/class pairs ! private class FlatNames implements NamingEnumeration { ! Enumeration names; ! FlatNames (Enumeration names) { this.names = names; } public boolean hasMoreElements() { try { --- 763,780 ---- public void setNameParser(NameParser parser) { myParser = parser; } ! /* ! * Common base class for FlatNames and FlatBindings. ! * Inheritors can implement different NamingEnumeration<T> interfaces. ! */ ! private class BaseFlatNames { ! Enumeration<Name> names; ! BaseFlatNames (Enumeration<Name> names) { this.names = names; } public boolean hasMoreElements() { try {
*** 779,822 **** public boolean hasMore() throws NamingException { return names.hasMoreElements(); } ! public Object nextElement() { try { return next(); } catch (NamingException e) { throw new NoSuchElementException(e.toString()); } } ! public Object next() throws NamingException { ! Name name = (Name)names.nextElement(); String className = bindings.get(name).getClass().getName(); return new NameClassPair(name.toString(), className); } public void close() { names = null; } } // Class for enumerating bindings ! private final class FlatBindings extends FlatNames { ! private Hashtable bds; ! private Hashtable env; private boolean useFactory; ! FlatBindings(Hashtable bindings, Hashtable env, boolean useFactory) { super(bindings.keys()); this.env = env; this.bds = bindings; this.useFactory = useFactory; } ! public Object next() throws NamingException { ! Name name = (Name)names.nextElement(); HierMemDirCtx obj = (HierMemDirCtx)bds.get(name); Object answer = obj; if (useFactory) { --- 786,840 ---- public boolean hasMore() throws NamingException { return names.hasMoreElements(); } ! public NameClassPair nextElement() { try { return next(); } catch (NamingException e) { throw new NoSuchElementException(e.toString()); } } ! public NameClassPair next() throws NamingException { ! Name name = names.nextElement(); String className = bindings.get(name).getClass().getName(); return new NameClassPair(name.toString(), className); } public void close() { names = null; } } + // Class for enumerating name/class pairs + private class FlatNames extends BaseFlatNames + implements NamingEnumeration<NameClassPair> { + FlatNames (Enumeration<Name> names) { + super(names); + } + } + // Class for enumerating bindings ! private final class FlatBindings extends BaseFlatNames ! implements NamingEnumeration<Binding> { ! private Hashtable<Name, Object> bds; ! private Hashtable<String, Object> env; private boolean useFactory; ! FlatBindings(Hashtable<Name, Object> bindings, ! Hashtable<String, Object> env, ! boolean useFactory) { super(bindings.keys()); this.env = env; this.bds = bindings; this.useFactory = useFactory; } ! public Binding next() throws NamingException { ! Name name = names.nextElement(); HierMemDirCtx obj = (HierMemDirCtx)bds.get(name); Object answer = obj; if (useFactory) {
*** 834,843 **** --- 852,869 ---- } } return new Binding(name.toString(), answer); } + + public Binding nextElement() { + try { + return next(); + } catch (NamingException e) { + throw new NoSuchElementException(e.toString()); + } + } } public class HierContextEnumerator extends ContextEnumerator { public HierContextEnumerator(Context context, int scope) throws NamingException {
*** 847,857 **** protected HierContextEnumerator(Context context, int scope, String contextName, boolean returnSelf) throws NamingException { super(context, scope, contextName, returnSelf); } ! protected NamingEnumeration getImmediateChildren(Context ctx) throws NamingException { return ((HierMemDirCtx)ctx).doListBindings(false); } protected ContextEnumerator newEnumerator(Context ctx, int scope, --- 873,883 ---- protected HierContextEnumerator(Context context, int scope, String contextName, boolean returnSelf) throws NamingException { super(context, scope, contextName, returnSelf); } ! protected NamingEnumeration<Binding> getImmediateChildren(Context ctx) throws NamingException { return ((HierMemDirCtx)ctx).doListBindings(false); } protected ContextEnumerator newEnumerator(Context ctx, int scope,
*** 870,887 **** final class HierarchicalName extends CompoundName { private int hashValue = -1; // Creates an empty name HierarchicalName() { ! super(new Enumeration() { public boolean hasMoreElements() {return false;} ! public Object nextElement() {throw new NoSuchElementException();} }, HierarchicalNameParser.mySyntax); } ! HierarchicalName(Enumeration comps, Properties syntax) { super(comps, syntax); } HierarchicalName(String n, Properties syntax) throws InvalidNameException { super(n, syntax); --- 896,913 ---- final class HierarchicalName extends CompoundName { private int hashValue = -1; // Creates an empty name HierarchicalName() { ! super(new Enumeration<String>() { public boolean hasMoreElements() {return false;} ! public String nextElement() {throw new NoSuchElementException();} }, HierarchicalNameParser.mySyntax); } ! HierarchicalName(Enumeration<String> comps, Properties syntax) { super(comps, syntax); } HierarchicalName(String n, Properties syntax) throws InvalidNameException { super(n, syntax);
*** 905,920 **** return hashValue; } public Name getPrefix(int posn) { ! Enumeration comps = super.getPrefix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } public Name getSuffix(int posn) { ! Enumeration comps = super.getSuffix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } public Object clone() { return (new HierarchicalName(getAll(), mySyntax)); --- 931,946 ---- return hashValue; } public Name getPrefix(int posn) { ! Enumeration<String> comps = super.getPrefix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } public Name getSuffix(int posn) { ! Enumeration<String> comps = super.getSuffix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } public Object clone() { return (new HierarchicalName(getAll(), mySyntax));