1 40 41 package org.jahia.services.containers; 42 43 import org.apache.log4j.Logger; 44 import org.jahia.data.containers.*; 45 import org.jahia.exceptions.JahiaException; 46 import org.jahia.params.ParamBean; 47 import org.jahia.services.version.EntryLoadRequest; 48 49 import java.util.Hashtable ; 50 51 52 57 58 public class ContainerFactoryProxy { 59 60 public static final int LOAD_FIELDS = 1; 61 public static final int LOAD_SUBCONTAINER_LISTS = 2; 62 public static final int LOAD_FIELD_AND_SUBCONTAINER_LISTS = LOAD_FIELDS | LOAD_SUBCONTAINER_LISTS; 63 64 private static Logger logger = Logger.getLogger (ContainerFactoryProxy.class); 65 66 private boolean containerListsBeingLoaded = false; 67 private boolean fieldsBeingLoaded = false; 68 69 private ParamBean jParams; 70 private EntryLoadRequest loadRequest; 71 private Hashtable cachedFieldsFromContainers; 72 private Hashtable cachedContainersFromContainerLists; 73 private Hashtable cachedContainerListsFromContainers; 74 75 85 public ContainerFactoryProxy (int loadFlag_, 86 ParamBean jParams_, 87 EntryLoadRequest loadRequest_, 88 Hashtable cachedFieldsFromContainers_, 89 Hashtable cachedContainersFromContainerLists_, 90 Hashtable cachedContainerListsFromContainers_) 91 { 92 this.jParams = jParams_; 93 this.loadRequest = loadRequest_; 94 this.cachedFieldsFromContainers = cachedFieldsFromContainers_; 95 if ( this.cachedFieldsFromContainers == null ){ 96 this.cachedFieldsFromContainers = new Hashtable (); 97 } 98 this.cachedContainersFromContainerLists = cachedContainersFromContainerLists_; 99 if ( this.cachedContainersFromContainerLists == null ){ 100 this.cachedContainersFromContainerLists = new Hashtable (); 101 } 102 this.cachedContainerListsFromContainers = cachedContainerListsFromContainers_; 103 if ( this.cachedContainerListsFromContainers == null ){ 104 this.cachedContainerListsFromContainers = new Hashtable (); 105 } 106 } 107 108 114 public void load(JahiaContainer container, int loadFlag){ 115 if ( container == null ){ 116 return; 117 } 118 try { 119 if ( loadFlag == LOAD_FIELD_AND_SUBCONTAINER_LISTS && !isFieldsBeingLoaded() && !isContainerListsBeingLoaded()){ 120 setContainerListsBeingLoaded(true); 121 setFieldsBeingLoaded(true); 122 ContainerFactory.getInstance() 123 .fullyLoadContainer(container, 124 loadFlag, jParams, loadRequest, 125 cachedFieldsFromContainers, 126 cachedContainersFromContainerLists, 127 cachedContainerListsFromContainers); 128 setContainerListsBeingLoaded(false); 129 setFieldsBeingLoaded(false); 130 } else if ( loadFlag == LOAD_FIELDS && !isFieldsBeingLoaded()){ 131 setFieldsBeingLoaded(true); 132 boolean isContainerListsLoadedState = 133 container.isContainerListsLoaded(); 134 container.setContainerListsLoaded(true); 135 ContainerFactory.getInstance() 136 .fullyLoadContainer(container, 137 loadFlag, jParams, loadRequest, 138 cachedFieldsFromContainers, 139 cachedContainersFromContainerLists, 140 cachedContainerListsFromContainers); 141 container.setContainerListsLoaded(isContainerListsLoadedState); 142 setFieldsBeingLoaded(false); 143 } else if ( loadFlag == LOAD_SUBCONTAINER_LISTS && !isContainerListsBeingLoaded()){ 144 setContainerListsBeingLoaded(true); 145 boolean isFieldsLoadedState = 146 container.isFieldsLoaded(); 147 container.setFieldsLoaded(true); 148 ContainerFactory.getInstance() 149 .fullyLoadContainer(container, 150 loadFlag, jParams, loadRequest, 151 cachedFieldsFromContainers, 152 cachedContainersFromContainerLists, 153 cachedContainerListsFromContainers); 154 container.setFieldsLoaded(isFieldsLoadedState); 155 setContainerListsBeingLoaded(false); 156 } 157 } catch ( JahiaException je){ 158 logger.debug("Exception occured when loading Container [" 159 + container.getID() + "]", je); 160 } 161 } 162 163 166 private boolean isFieldsBeingLoaded() { 167 return fieldsBeingLoaded; 168 } 169 170 173 private void setFieldsBeingLoaded(boolean fieldsBeingLoaded_) { 174 this.fieldsBeingLoaded = fieldsBeingLoaded_; 175 } 176 177 180 private boolean isContainerListsBeingLoaded() { 181 return containerListsBeingLoaded; 182 } 183 184 187 private void setContainerListsBeingLoaded(boolean containerListsBeingLoaded_) { 188 this.containerListsBeingLoaded = containerListsBeingLoaded_; 189 } 190 } 191 | Popular Tags |