01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.repository;
17:
18: import java.util.*;
19: import java.text.MessageFormat;
20:
21: /**
22: * A concurrent update happened to some repository-managed entity.
23: */
24: public class ConcurrentUpdateException extends RepositoryException
25: implements LocalizedException {
26: private String objectType;
27: private String objectId;
28:
29: private static final String OBJECT_TYPE = "objectType";
30: private static final String OBJECT_ID = "objectId";
31:
32: public ConcurrentUpdateException(String objectType, String objectId) {
33: this .objectType = objectType;
34: this .objectId = objectId;
35: }
36:
37: public ConcurrentUpdateException(Map state) {
38: this .objectType = (String) state.get(OBJECT_TYPE);
39: this .objectId = (String) state.get(OBJECT_ID);
40: }
41:
42: /**
43: * Returns the type of object to which this exception applies.
44: * This is usually the class name (but can be something else).
45: */
46: public String getObjectType() {
47: return objectType;
48: }
49:
50: public String getObjectId() {
51: return objectId;
52: }
53:
54: public String getMessage() {
55: return getMessage(Locale.US);
56: }
57:
58: public String getMessage(Locale locale) {
59: ResourceBundle bundle = ResourceBundle.getBundle(
60: "org/outerj/daisy/repository/messages", locale);
61: String message = bundle
62: .getString("concurrent-update-exception");
63: String typeName;
64: try {
65: typeName = bundle.getString(objectType + ".shortName");
66: } catch (MissingResourceException e) {
67: typeName = objectType;
68: }
69: return MessageFormat.format(message, typeName, objectId);
70: }
71:
72: public Map<String, String> getState() {
73: Map<String, String> state = new HashMap<String, String>();
74: state.put(OBJECT_TYPE, objectType);
75: state.put(OBJECT_ID, objectId);
76: return state;
77: }
78: }
|