- map = ResourceBundle.getBundle(type.getPackage().getName() + "."
- + name.name(), locale, new FixedResourceBundleControl());
+ try {
+ map = ResourceBundle.getBundle(type.getPackage().getName()
+ + "." + name.name(), locale,
+ new FixedResourceBundleControl());
+ } catch (Exception e) {
+ // We have no bundle for this Bundle
+ map = null;
+ }
+ }
+ }
+
+ /**
+ * Take a snapshot of the changes in memory in this {@link Bundle} made by
+ * the "set" methods ( {@link Bundle#setString(Enum, String)}...) at the
+ * current time.
+ *
+ * @return a snapshot to use with {@link Bundle#restoreChanges(Object)}
+ */
+ protected Object takeChangesSnapshot() {
+ return new HashMap<String, String>(changeMap);
+ }
+
+ /**
+ * Restore a snapshot taken with {@link Bundle}, or reset the current
+ * changes if the snapshot is NULL.
+ *
+ * @param snap
+ * the snapshot or NULL
+ */
+ @SuppressWarnings("unchecked")
+ protected void restoreChanges(Object snap) {
+ if (snap == null) {
+ changeMap.clear();
+ } else {
+ if (snap instanceof Map) {
+ changeMap = (Map<String, String>) snap;
+ } else {
+ throw new Error(
+ "Restoring changes in a Bundle must be done on a changes snapshot, "
+ + "or NULL to discard current changes");
+ }