|
1 |
| -// Copyright 2012 Citrix Systems, Inc. Licensed under the |
2 |
| -// Apache License, Version 2.0 (the "License"); you may not use this |
3 |
| -// file except in compliance with the License. Citrix Systems, Inc. |
4 |
| -// reserves all rights not expressly granted by the License. |
5 |
| -// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
6 |
| -// Unless required by applicable law or agreed to in writing, software |
7 |
| -// distributed under the License is distributed on an "AS IS" BASIS, |
8 |
| -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 |
| -// See the License for the specific language governing permissions and |
10 |
| -// limitations under the License. |
11 |
| -// |
12 |
| -// Automatically generated by addcopyright.py at 04/03/2012 |
| 1 | +/** |
| 2 | + * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved |
| 3 | + * |
| 4 | + * This software is licensed under the GNU General Public License v3 or later. |
| 5 | + * |
| 6 | + * It is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or any later version. |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + */ |
13 | 18 | package com.cloud.exception;
|
14 | 19 |
|
15 |
| -import com.cloud.utils.IdentityProxy; |
16 | 20 | import java.util.ArrayList;
|
17 |
| -import com.cloud.utils.exception.CSExceptionErrorCode; |
| 21 | + |
18 | 22 | import com.cloud.utils.AnnotationHelper;
|
| 23 | +import com.cloud.utils.IdentityProxy; |
| 24 | +import com.cloud.utils.exception.CSExceptionErrorCode; |
19 | 25 |
|
20 | 26 | /**
|
| 27 | + * CloudException is a generic exception class that has an IdentityProxy |
| 28 | + * object in it to enable on the fly conversion of database ids to uuids |
21 | 29 | * by the API response serializer. Any exceptions that are thrown by
|
| 30 | + * command invocations must extend this class, or the RuntimeCloudException |
22 | 31 | * class, which extends RuntimeException instead of Exception like this
|
23 |
| - * class does. |
| 32 | + * class does. |
24 | 33 | */
|
25 | 34 |
|
26 | 35 | public class CloudException extends Exception {
|
27 |
| - |
28 |
| - // This holds a list of uuids and their names. Add uuid:fieldname pairs |
29 |
| - protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>(); |
30 |
| - |
31 |
| - protected Integer csErrorCode; |
32 |
| - |
33 |
| - public CloudException(String message) { |
34 |
| - super(message); |
35 |
| - setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); |
36 |
| - } |
| 36 | + |
| 37 | + // This holds a list of uuids and their names. Add uuid:fieldname pairs |
| 38 | + // if required, to this list before throwing an exception, using addProxyObject(). |
| 39 | + protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>(); |
| 40 | + |
| 41 | + // This holds an error code. Set this before throwing an exception, if applicable. |
| 42 | + protected Integer csErrorCode; |
| 43 | + |
| 44 | + public CloudException(String message) { |
| 45 | + super(message); |
| 46 | + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); |
| 47 | + } |
37 | 48 |
|
38 | 49 | public CloudException(String message, Throwable cause) {
|
39 | 50 | super(message, cause);
|
40 | 51 | setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
41 | 52 | }
|
42 |
| - |
| 53 | + |
43 | 54 | public void addProxyObject(Object voObj, Long id, String idFieldName) {
|
44 |
| - // Get the VO object's table name. |
45 |
| - String tablename = AnnotationHelper.getTableName(voObj); |
46 |
| - if (tablename != null) { |
47 |
| - addProxyObject(tablename, id, idFieldName); |
48 |
| - } |
49 |
| - return; |
| 55 | + // Get the VO object's table name. |
| 56 | + if (voObj != null) { |
| 57 | + String tablename = AnnotationHelper.getTableName(voObj); |
| 58 | + if (tablename != null) { |
| 59 | + addProxyObject(tablename, id, idFieldName); |
| 60 | + } |
| 61 | + } |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + public CloudException() { |
| 66 | + super(); |
| 67 | + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); |
| 68 | + } |
| 69 | + |
| 70 | + public void addProxyObject(String tableName, Long id, String idFieldName) { |
| 71 | + if (tableName != null) { |
| 72 | + idList.add(new IdentityProxy(tableName, id, idFieldName)); |
| 73 | + } |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + public ArrayList<IdentityProxy> getIdProxyList() { |
| 78 | + return idList; |
| 79 | + } |
| 80 | + |
| 81 | + public void setCSErrorCode(int cserrcode) { |
| 82 | + this.csErrorCode = cserrcode; |
| 83 | + } |
| 84 | + |
| 85 | + public int getCSErrorCode() { |
| 86 | + return this.csErrorCode; |
50 | 87 | }
|
51 |
| - |
52 |
| - public CloudException() { |
53 |
| - super(); |
54 |
| - setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); |
55 |
| - } |
56 |
| - |
57 |
| - public void addProxyObject(String tableName, Long id, String idFieldName) { |
58 |
| - idList.add(new IdentityProxy(tableName, id, idFieldName)); |
59 |
| - return; |
60 |
| - } |
61 |
| - |
62 |
| - public ArrayList<IdentityProxy> getIdProxyList() { |
63 |
| - return idList; |
64 |
| - } |
65 |
| - |
66 |
| - public void setCSErrorCode(int cserrcode) { |
67 |
| - this.csErrorCode = cserrcode; |
68 |
| - } |
69 |
| - |
70 |
| - public int getCSErrorCode() { |
71 |
| - return this.csErrorCode; |
72 |
| - } |
73 | 88 | }
|
0 commit comments