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.krad.data; 017 018import java.io.Serializable; 019 020import org.apache.commons.lang.StringUtils; 021 022 023/** 024 * MaterializeOption is used when calling the 025 * {@link DataObjectWrapper#materializeReferencedObjects(MaterializeOption...)} method to adjust the behavior of the 026 * method. 027 * 028 * See the constants defined within the class for the available options and descriptions. 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032public class MaterializeOption implements Serializable { 033 private static final long serialVersionUID = 1L; 034 035 /** 036 * Specify that only references should be materialized. Adding this disables the default of refreshing both 037 * references and collections. 038 */ 039 public static MaterializeOption REFERENCES = new MaterializeOption("org.kuali.rice.krad.data.REFERENCES"); 040 041 /** 042 * Specify that only collections should be materialized. Adding this disables the default of refreshing both 043 * references and collections. 044 */ 045 public static MaterializeOption COLLECTIONS = new MaterializeOption("org.kuali.rice.krad.data.COLLECTIONS"); 046 047 /** 048 * Specify that references and/or collections which are saved when the wrapped object is saved should also be 049 * refreshed. 050 * 051 * <b>CAUTION:</b> This has the potential to overwrite previously updated data. This will effectively reset all 052 * child objects to their current saved state. 053 */ 054 public static MaterializeOption UPDATE_UPDATABLE_REFS = new MaterializeOption( 055 "org.kuali.rice.krad.data.UPDATE_UPDATABLE_REFS"); 056 057 /** 058 * If this option is set, when the foreign key fields do not point to a saved object (per the persistence provider), 059 * the object reference will be nulled out. 060 * 061 * Without this option, the object in that reference (if any) will be left alone if a valid object is not found. 062 */ 063 public static MaterializeOption NULL_INVALID_REFS = new MaterializeOption( 064 "org.kuali.rice.krad.data.NULL_INVALID_REFS"); 065 066 /** 067 * Specify that non-lazy-loaded references should also be reloaded from the persistence provider. 068 */ 069 public static MaterializeOption INCLUDE_EAGER_REFS = new MaterializeOption( 070 "org.kuali.rice.krad.data.INCLUDE_EAGER_REFS"); 071 072 private final String optionId; 073 074 /** 075 * Sets the option Id 076 * 077 * @param optionId 078 * cannot be null or blank. 079 */ 080 public MaterializeOption(String optionId) { 081 if (StringUtils.isBlank(optionId)) { 082 throw new IllegalArgumentException("optionId must not be a null or blank value"); 083 } 084 this.optionId = optionId; 085 } 086 087 /** 088 * Gets the option id. 089 * 090 * @return not null or blank. 091 */ 092 public String getOptionId() { 093 return this.optionId; 094 } 095 096 @Override 097 public String toString() { 098 return optionId; 099 } 100}