001/** 002 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 003 * This file is part of the LDP4j Project: 004 * http://www.ldp4j.org/ 005 * 006 * Center for Open Middleware 007 * http://www.centeropenmiddleware.com/ 008 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 009 * Copyright (C) 2014 Center for Open Middleware. 010 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 011 * Licensed under the Apache License, Version 2.0 (the "License"); 012 * you may not use this file except in compliance with the License. 013 * You may obtain a copy of the License at 014 * 015 * http://www.apache.org/licenses/LICENSE-2.0 016 * 017 * Unless required by applicable law or agreed to in writing, software 018 * distributed under the License is distributed on an "AS IS" BASIS, 019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 020 * See the License for the specific language governing permissions and 021 * limitations under the License. 022 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 023 * Artifact : org.ldp4j.framework:ldp4j-application-api:0.2.0 024 * Bundle : ldp4j-application-api-0.2.0.jar 025 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 026 */ 027package org.ldp4j.application.ext; 028 029import java.util.concurrent.atomic.AtomicReference; 030 031import org.ldp4j.application.data.constraints.Constraints; 032 033/** 034 * This exception may be thrown by an LDP4j Application if the data to be used 035 * in an operation is not valid. 036 */ 037public class InvalidContentException extends ApplicationUsageException { 038 039 private static final long serialVersionUID = 1090034112299823596L; 040 private final Constraints constraints; 041 042 private final AtomicReference<String> id; 043 044 /** 045 * Create a new instance with a message, a cause, and constraints. 046 * 047 * @param message 048 * the description of the failure. 049 * @param cause 050 * the underlying cause of the failure. 051 * @param constraints 052 * the constraints that are not satisfied by the input data. 053 */ 054 public InvalidContentException(String message, Throwable cause, Constraints constraints) { 055 super(message, cause); 056 this.constraints = constraints; 057 this.id=new AtomicReference<String>(null); 058 } 059 060 /** 061 * Create a new instance with a message and constraints. 062 * 063 * @param message 064 * the description of the failure. 065 * @param constraints 066 * the constraints that are not satisfied by the input data. 067 */ 068 public InvalidContentException(String message, Constraints constraints) { 069 this(message,null,constraints); 070 } 071 072 /** 073 * Create a new instance with a cause, constraints, and a default message. 074 * 075 * @param cause 076 * the underlying cause of the failure. 077 * @param constraints 078 * the constraints that are not satisfied by the input data. 079 */ 080 public InvalidContentException(Throwable cause, Constraints constraints) { 081 this("Invalid content",cause,constraints); 082 } 083 084 /** 085 * Return the constaints that were not satisfied by the input data. 086 * 087 * @return the unsatisfied constraints 088 */ 089 public Constraints getConstraints() { 090 return constraints; 091 } 092 093 /** 094 * Enrich the exception with the identifier of the report that will be used 095 * to acknowledge the users about the constraint failure. 096 * 097 * @param id 098 * the identifier of the report. 099 */ 100 public final void setConstraintsId(String id) { 101 this.id.set(id); 102 } 103 104 /** 105 * Return the identifier of the report that will be used to acknowledge the 106 * users about the failed constraints. 107 * 108 * @return the identifier of the constraint failure report. 109 */ 110 public final String getConstraintsId() { 111 return this.id.get(); 112 } 113 114}