001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ken.api.notification; 017 018import java.io.Serializable; 019import java.util.Collection; 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlAnyElement; 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025import javax.xml.bind.annotation.XmlType; 026import org.kuali.rice.core.api.CoreConstants; 027import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 028import org.kuali.rice.core.api.mo.ModelBuilder; 029import org.kuali.rice.ken.api.KenApiConstants; 030import org.w3c.dom.Element; 031 032@XmlRootElement(name = NotificationResponse.Constants.ROOT_ELEMENT_NAME) 033@XmlAccessorType(XmlAccessType.NONE) 034@XmlType(name = NotificationResponse.Constants.TYPE_NAME, propOrder = { 035 NotificationResponse.Elements.MESSAGE, 036 NotificationResponse.Elements.STATUS, 037 NotificationResponse.Elements.NOTIFICATION_ID, 038 CoreConstants.CommonElements.FUTURE_ELEMENTS 039}) 040public final class NotificationResponse 041 extends AbstractDataTransferObject 042 implements NotificationResponseContract 043{ 044 045 @XmlElement(name = Elements.MESSAGE, required = false) 046 private final String message; 047 @XmlElement(name = Elements.STATUS, required = false) 048 private final String status; 049 @XmlElement(name = Elements.NOTIFICATION_ID, required = false) 050 private final Long notificationId; 051 @SuppressWarnings("unused") 052 @XmlAnyElement 053 private final Collection<Element> _futureElements = null; 054 055 /** 056 * Private constructor used only by JAXB. 057 * 058 */ 059 private NotificationResponse() { 060 this.message = null; 061 this.status = null; 062 this.notificationId = null; 063 } 064 065 private NotificationResponse(Builder builder) { 066 this.message = builder.getMessage(); 067 this.status = builder.getStatus(); 068 this.notificationId = builder.getNotificationId(); 069 } 070 071 @Override 072 public String getMessage() { 073 return this.message; 074 } 075 076 @Override 077 public String getStatus() { 078 return this.status; 079 } 080 081 @Override 082 public Long getNotificationId() { 083 return this.notificationId; 084 } 085 086 087 /** 088 * A builder which can be used to construct {@link NotificationResponse} instances. Enforces the constraints of the {@link NotificationResponseContract}. 089 * 090 */ 091 public final static class Builder 092 implements Serializable, ModelBuilder, NotificationResponseContract 093 { 094 095 private String message; 096 private String status; 097 private Long notificationId; 098 099 private Builder() { 100 this.status = KenApiConstants.RESPONSE_STATUSES.SUCCESS; 101 } 102 103 public static Builder create() { 104 return new Builder(); 105 } 106 107 public static Builder create(NotificationResponseContract contract) { 108 if (contract == null) { 109 throw new IllegalArgumentException("contract was null"); 110 } 111 Builder builder = create(); 112 builder.setMessage(contract.getMessage()); 113 builder.setStatus(contract.getStatus()); 114 builder.setNotificationId(contract.getNotificationId()); 115 return builder; 116 } 117 118 public NotificationResponse build() { 119 return new NotificationResponse(this); 120 } 121 122 @Override 123 public String getMessage() { 124 return this.message; 125 } 126 127 @Override 128 public String getStatus() { 129 return this.status; 130 } 131 132 @Override 133 public Long getNotificationId() { 134 return this.notificationId; 135 } 136 137 public void setMessage(String message) { 138 // TODO add validation of input value if required and throw IllegalArgumentException if needed 139 this.message = message; 140 } 141 142 public void setStatus(String status) { 143 // TODO add validation of input value if required and throw IllegalArgumentException if needed 144 this.status = status; 145 } 146 147 public void setNotificationId(Long notificationId) { 148 // TODO add validation of input value if required and throw IllegalArgumentException if needed 149 this.notificationId = notificationId; 150 } 151 152 } 153 154 155 /** 156 * Defines some internal constants used on this class. 157 * 158 */ 159 static class Constants { 160 161 final static String ROOT_ELEMENT_NAME = "notificationResponse"; 162 final static String TYPE_NAME = "NotificationResponseType"; 163 164 } 165 166 167 /** 168 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 169 * 170 */ 171 static class Elements { 172 173 final static String MESSAGE = "message"; 174 final static String STATUS = "status"; 175 final static String NOTIFICATION_ID = "notificationId"; 176 177 } 178 179}