001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.service;
019:
020: import java.util.List;
021: import java.util.ArrayList;
022: import java.util.Iterator;
023:
024: /**
025: * ServiceValidationException
026: */
027: public class ServiceValidationException extends GenericServiceException {
028:
029: protected List messages = new ArrayList();
030: protected List missingFields = new ArrayList();
031: protected List extraFields = new ArrayList();
032: protected String errorMode = null;
033: protected ModelService service = null;
034:
035: public ServiceValidationException(ModelService service,
036: List missingFields, List extraFields, String errorMode) {
037: super ();
038: this .service = service;
039: this .errorMode = errorMode;
040: if (missingFields != null) {
041: this .missingFields = missingFields;
042: }
043: if (extraFields != null) {
044: this .extraFields = extraFields;
045: }
046: }
047:
048: public ServiceValidationException(String str, ModelService service) {
049: super (str);
050: this .service = service;
051: }
052:
053: public ServiceValidationException(String str, ModelService service,
054: List missingFields, List extraFields, String errorMode) {
055: super (str);
056: this .service = service;
057: this .errorMode = errorMode;
058: if (missingFields != null) {
059: this .missingFields = missingFields;
060: }
061: if (extraFields != null) {
062: this .extraFields = extraFields;
063: }
064: }
065:
066: public ServiceValidationException(String str, Throwable nested,
067: ModelService service) {
068: super (str, nested);
069: this .service = service;
070: }
071:
072: public ServiceValidationException(String str, Throwable nested,
073: ModelService service, List missingFields, List extraFields,
074: String errorMode) {
075: super (str, nested);
076: this .service = service;
077: this .errorMode = errorMode;
078: if (missingFields != null) {
079: this .missingFields = missingFields;
080: }
081: if (extraFields != null) {
082: this .extraFields = extraFields;
083: }
084: }
085:
086: public ServiceValidationException(List messages,
087: ModelService service, List missingFields, List extraFields,
088: String errorMode) {
089: super ();
090: this .messages = messages;
091: this .service = service;
092: this .errorMode = errorMode;
093: if (missingFields != null) {
094: this .missingFields = missingFields;
095: }
096: if (extraFields != null) {
097: this .extraFields = extraFields;
098: }
099: }
100:
101: public ServiceValidationException(List messages,
102: ModelService service, String errorMode) {
103: this (messages, service, null, null, errorMode);
104: }
105:
106: public List getExtraFields() {
107: return extraFields;
108: }
109:
110: public List getMissingFields() {
111: return missingFields;
112: }
113:
114: public List getMessageList() {
115: if (this .messages == null || this .messages.size() == 0) {
116: return null;
117: }
118: return this .messages;
119: }
120:
121: public ModelService getModelService() {
122: return service;
123: }
124:
125: public String getMode() {
126: return errorMode;
127: }
128:
129: public String getServiceName() {
130: if (service != null) {
131: return service.name;
132: } else {
133: return null;
134: }
135: }
136:
137: public String getMessage() {
138: String msg = super .getMessage();
139: if (this .messages != null && this .messages.size() > 0) {
140: if (msg != null) {
141: msg += "\n";
142: } else {
143: msg = "";
144: }
145: Iterator i = this.messages.iterator();
146: while (i.hasNext()) {
147: msg += i.next();
148: }
149: }
150: return msg;
151: }
152: }
|