1 /*
2 * #%L
3 * DocumentToLargeException.java - mongodb-async-driver - Allanbank Consulting, Inc.
4 * %%
5 * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc.
6 * %%
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package com.allanbank.mongodb.error;
21
22 import com.allanbank.mongodb.MongoDbException;
23 import com.allanbank.mongodb.bson.Document;
24
25 /**
26 * DocumentToLargeException is thrown to report that an attempt was made to
27 * serialize a Document that is over the maximum size limit.
28 *
29 * @api.yes This class is part of the driver's API. Public and protected members
30 * will be deprecated for at least 1 non-bugfix release (version
31 * numbers are <major>.<minor>.<bugfix>) before being
32 * removed or modified.
33 * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved
34 */
35 public class DocumentToLargeException extends MongoDbException {
36
37 /** Serialization exception for the class. */
38 private static final long serialVersionUID = 8235621460369360624L;
39
40 /** The document that was too big. */
41 private final Document myDocument;
42
43 /** The maximum size for a document. */
44 private final int myMaximumSize;
45
46 /** The size of the document that violated the maximum size. */
47 private final int mySize;
48
49 /**
50 * Creates a new DocumentToLargeException.
51 *
52 * @param size
53 * The size of the document that violated the maximum size.
54 * @param maximum
55 * The maximum size for a document.
56 * @param document
57 * The document that was too big.
58 */
59 public DocumentToLargeException(final int size, final int maximum,
60 final Document document) {
61 super("Attempted to serialize a document of size " + size
62 + " when current maximum is " + maximum + ".");
63
64 mySize = size;
65 myMaximumSize = maximum;
66 myDocument = document;
67 }
68
69 /**
70 * Returns the document that was too big.
71 *
72 * @return The document that was too big.
73 */
74 public Document getDocument() {
75 return myDocument;
76 }
77
78 /**
79 * Returns the maximum size for a document.
80 *
81 * @return The maximum size for a document.
82 */
83 public int getMaximumSize() {
84 return myMaximumSize;
85 }
86
87 /**
88 * Returns the size of the document that violated the maximum size.
89 *
90 * @return The size of the document that violated the maximum size.
91 */
92 public int getSize() {
93 return mySize;
94 }
95 }