KLeine Änderungen ChainableResourceBundle

git-svn-id: https://svn.libreccm.org/ccm/trunk@2131 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-04-17 07:18:29 +00:00
parent bfe6e76882
commit 450ae5a649
2 changed files with 65 additions and 50 deletions

View File

@ -32,6 +32,9 @@ public interface ChainableResourceBundle {
* which normally has protected access. If you have a PropertyResourceBundle * which normally has protected access. If you have a PropertyResourceBundle
* or a ListResourceBundle, this will simply delegate to the * or a ListResourceBundle, this will simply delegate to the
* handleGetObject(String key) method. * handleGetObject(String key) method.
*
* @param key
* @return
*/ */
public Object handleGetObject(String key); public Object handleGetObject(String key);
@ -40,6 +43,8 @@ public interface ChainableResourceBundle {
* which normally has protected access. If you have a PropertyResourceBundle * which normally has protected access. If you have a PropertyResourceBundle
* or a ListResourceBundle, this will simply delegate to the * or a ListResourceBundle, this will simply delegate to the
* getKeys() method. * getKeys() method.
*
* @return
*/ */
public Enumeration getKeys(); public Enumeration<String> getKeys();
} }

View File

@ -43,29 +43,33 @@ import java.util.ResourceBundle;
* </code></pre> * </code></pre>
*/ */
public class ChainedResourceBundle extends ResourceBundle { public class ChainedResourceBundle extends ResourceBundle {
private List m_bundles; private final List<ChainableResourceBundle> bundles;
private List m_keys; private final List<String> keys;
public ChainedResourceBundle() { public ChainedResourceBundle() {
super(); super();
m_bundles = new LinkedList(); bundles = new LinkedList<ChainableResourceBundle>();
m_keys = new LinkedList(); keys = new LinkedList<String>();
} }
/** /**
* this wraps the PropertyResourceBundle in a ChainableResourceBundle * this wraps the PropertyResourceBundle in a ChainableResourceBundle
* and then delegates to addBundle(ChainableResourceBundle bundle); * and then delegates to addBundle(ChainableResourceBundle bundle);
*
* @param bundle
*/ */
public void addBundle(PropertyResourceBundle bundle) { public void addBundle(final PropertyResourceBundle bundle) {
addBundle(new ChainablePropertyResourceBundle(bundle)); addBundle(new ChainablePropertyResourceBundle(bundle));
} }
/** /**
* this wraps the PropertyResourceBundle in a ChainableResourceBundle * this wraps the PropertyResourceBundle in a ChainableResourceBundle
* and then delegates to addBundle(ChainableResourceBundle bundle); * and then delegates to addBundle(ChainableResourceBundle bundle);
*
* @param bundle
*/ */
public void addBundle(ListResourceBundle bundle) { public void addBundle(final ListResourceBundle bundle) {
addBundle(new ChainableListResourceBundle(bundle)); addBundle(new ChainableListResourceBundle(bundle));
} }
@ -73,32 +77,32 @@ public class ChainedResourceBundle extends ResourceBundle {
* This adds bundles to this chained resource. The bundles * This adds bundles to this chained resource. The bundles
* are examined for the key in the order that they are added. * are examined for the key in the order that they are added.
*/ */
private void addBundle(ChainableResourceBundle bundle) { private void addBundle(final ChainableResourceBundle bundle) {
m_bundles.add(bundle); bundles.add(bundle);
Enumeration enu = bundle.getKeys(); final Enumeration<String> enu = bundle.getKeys();
while (enu.hasMoreElements()) { while (enu.hasMoreElements()) {
m_keys.add(enu.nextElement()); keys.add(enu.nextElement());
} }
} }
public void putBundle(PropertyResourceBundle bundle) { public void putBundle(final PropertyResourceBundle bundle) {
putBundle(new ChainablePropertyResourceBundle(bundle)); putBundle(new ChainablePropertyResourceBundle(bundle));
}
public void putBundle(ListResourceBundle bundle) {
putBundle(new ChainableListResourceBundle(bundle));
} }
private void putBundle(ChainableResourceBundle bundle) { public void putBundle(final ListResourceBundle bundle) {
m_bundles.add(0,bundle); putBundle(new ChainableListResourceBundle(bundle));
Enumeration enu = bundle.getKeys(); }
List bundleKeys = new LinkedList();
private void putBundle(final ChainableResourceBundle bundle) {
bundles.add(0, bundle);
final Enumeration<String> enu = bundle.getKeys();
final List<String> bundleKeys = new LinkedList<String>();
while (enu.hasMoreElements()) { while (enu.hasMoreElements()) {
bundleKeys.add(enu.nextElement()); bundleKeys.add(enu.nextElement());
} }
m_keys.addAll(0, bundleKeys); keys.addAll(0, bundleKeys);
} }
/** /**
* Because this particular bundle is just a wrapper around other bundles, * Because this particular bundle is just a wrapper around other bundles,
* this method will return null so that the ResourceBundle can then * this method will return null so that the ResourceBundle can then
@ -106,20 +110,24 @@ public class ChainedResourceBundle extends ResourceBundle {
* @param key * @param key
* @return * @return
*/ */
@Override
public Object handleGetObject(final String key) { public Object handleGetObject(final String key) {
Iterator iter = m_bundles.iterator(); final Iterator<ChainableResourceBundle> iter = bundles.iterator();
Object object = null; Object object = null;
while (iter.hasNext() && object == null) { ChainableResourceBundle bundle;
object = ((ChainableResourceBundle)iter.next()).handleGetObject(key); while (iter.hasNext() && object == null) {
} bundle = iter.next();
object = bundle.handleGetObject(key);
//object = iter.next().handleGetObject(key);
}
return object; return object;
} }
public Enumeration getKeys() { @Override
return Collections.enumeration(m_keys); public Enumeration<String> getKeys() {
return Collections.enumeration(keys);
} }
/** /**
* This is basically a way to allow us to set the parent. The javadoc * This is basically a way to allow us to set the parent. The javadoc
* for these methods can be found by looking at the javadoc for * for these methods can be found by looking at the javadoc for
@ -127,57 +135,59 @@ public class ChainedResourceBundle extends ResourceBundle {
* an internal PropertyResourceBundle. * an internal PropertyResourceBundle.
*/ */
private class ChainablePropertyResourceBundle private class ChainablePropertyResourceBundle
implements ChainableResourceBundle { implements ChainableResourceBundle {
private PropertyResourceBundle m_wrappedBundle = null; private final PropertyResourceBundle wrappedBundle;
/** /**
* This creates a new Bundle that delegates everything to the * This creates a new Bundle that delegates everything to the
* passed in bundle and sets the parent of the passed in bundle * passed in bundle and sets the parent of the passed in bundle
* to the passed in ResourceBundle * to the passed in ResourceBundle
*/ */
public ChainablePropertyResourceBundle(PropertyResourceBundle bundle) { public ChainablePropertyResourceBundle(final PropertyResourceBundle bundle) {
super(); super();
m_wrappedBundle = bundle; wrappedBundle = bundle;
}
public Object handleGetObject(String key) {
return m_wrappedBundle.handleGetObject(key);
} }
public Enumeration getKeys() { @Override
return m_wrappedBundle.getKeys(); public Object handleGetObject(final String key) {
return wrappedBundle.handleGetObject(key);
} }
@Override
public Enumeration<String> getKeys() {
return wrappedBundle.getKeys();
}
} }
/** /**
* This is basically a way to allow us to set the parent. The javadoc * This is basically a way to allow us to set the parent. The javadoc
* for these methods can be found by looking at the javadoc for * for these methods can be found by looking at the javadoc for
* PropertyResourceBundle since this delegate everything to * PropertyResourceBundle since this delegate everything to
* an internal PropertyResourceBundle. * an internal PropertyResourceBundle.
*/ */
private class ChainableListResourceBundle private class ChainableListResourceBundle implements ChainableResourceBundle {
implements ChainableResourceBundle {
private ListResourceBundle m_wrappedBundle = null; private final ListResourceBundle m_wrappedBundle;
/** /**
* This creates a new Bundle that delegates everything to the * This creates a new Bundle that delegates everything to the
* passed in bundle and sets the parent of the passed in bundle * passed in bundle and sets the parent of the passed in bundle
* to the passed in ResourceBundle * to the passed in ResourceBundle
*/ */
public ChainableListResourceBundle(ListResourceBundle bundle) { public ChainableListResourceBundle(final ListResourceBundle bundle) {
super(); super();
m_wrappedBundle = bundle; m_wrappedBundle = bundle;
} }
public Object handleGetObject(String key) { public Object handleGetObject(final String key) {
return m_wrappedBundle.handleGetObject(key); return m_wrappedBundle.handleGetObject(key);
} }
public Enumeration getKeys() { public Enumeration<String> getKeys() {
return m_wrappedBundle.getKeys(); return m_wrappedBundle.getKeys();
} }
} }
} }