1 /** 2 * Copyright 2005-2016 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.krad.data; 17 18 import java.io.Serializable; 19 20 import org.apache.commons.lang.StringUtils; 21 22 23 /** 24 * MaterializeOption is used when calling the 25 * {@link DataObjectWrapper#materializeReferencedObjects(MaterializeOption...)} method to adjust the behavior of the 26 * method. 27 * 28 * See the constants defined within the class for the available options and descriptions. 29 * 30 * @author Kuali Rice Team (rice.collab@kuali.org) 31 */ 32 public class MaterializeOption implements Serializable { 33 private static final long serialVersionUID = 1L; 34 35 /** 36 * Specify that only references should be materialized. Adding this disables the default of refreshing both 37 * references and collections. 38 */ 39 public static MaterializeOption REFERENCES = new MaterializeOption("org.kuali.rice.krad.data.REFERENCES"); 40 41 /** 42 * Specify that only collections should be materialized. Adding this disables the default of refreshing both 43 * references and collections. 44 */ 45 public static MaterializeOption COLLECTIONS = new MaterializeOption("org.kuali.rice.krad.data.COLLECTIONS"); 46 47 /** 48 * Specify that references and/or collections which are saved when the wrapped object is saved should also be 49 * refreshed. 50 * 51 * <b>CAUTION:</b> This has the potential to overwrite previously updated data. This will effectively reset all 52 * child objects to their current saved state. 53 */ 54 public static MaterializeOption UPDATE_UPDATABLE_REFS = new MaterializeOption( 55 "org.kuali.rice.krad.data.UPDATE_UPDATABLE_REFS"); 56 57 /** 58 * If this option is set, when the foreign key fields do not point to a saved object (per the persistence provider), 59 * the object reference will be nulled out. 60 * 61 * Without this option, the object in that reference (if any) will be left alone if a valid object is not found. 62 */ 63 public static MaterializeOption NULL_INVALID_REFS = new MaterializeOption( 64 "org.kuali.rice.krad.data.NULL_INVALID_REFS"); 65 66 /** 67 * Specify that non-lazy-loaded references should also be reloaded from the persistence provider. 68 */ 69 public static MaterializeOption INCLUDE_EAGER_REFS = new MaterializeOption( 70 "org.kuali.rice.krad.data.INCLUDE_EAGER_REFS"); 71 72 private final String optionId; 73 74 /** 75 * Sets the option Id 76 * 77 * @param optionId 78 * cannot be null or blank. 79 */ 80 public MaterializeOption(String optionId) { 81 if (StringUtils.isBlank(optionId)) { 82 throw new IllegalArgumentException("optionId must not be a null or blank value"); 83 } 84 this.optionId = optionId; 85 } 86 87 /** 88 * Gets the option id. 89 * 90 * @return not null or blank. 91 */ 92 public String getOptionId() { 93 return this.optionId; 94 } 95 96 @Override 97 public String toString() { 98 return optionId; 99 } 100 }