KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > containers > ContainerFactoryProxy


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution S�rl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * Contributor(s):
36  * 22-AUG-2003, Jahia Solutions Sarl, Fulco Houkes
37  *
38  * ----- END LICENSE BLOCK -----
39  */

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 JavaDoc;
50
51
52 /**
53  * Container Factory Proxy
54  *
55  * @author Khue Nguyen <a HREF="mailto:khue@jahia.org">khue@jahia.org</a>
56  */

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 JavaDoc cachedFieldsFromContainers;
72     private Hashtable JavaDoc cachedContainersFromContainerLists;
73     private Hashtable JavaDoc cachedContainerListsFromContainers;
74
75     //--------------------------------------------------------------------------
76
/**
77      *
78      * @param loadFlag
79      * @param jParams
80      * @param loadRequest
81      * @param cachedFieldsFromContainers
82      * @param cachedContainersFromContainerLists
83      * @param cachedContainerListsFromContainers
84      */

85     public ContainerFactoryProxy (int loadFlag_,
86                                        ParamBean jParams_,
87                                        EntryLoadRequest loadRequest_,
88                                        Hashtable JavaDoc cachedFieldsFromContainers_,
89                                        Hashtable JavaDoc cachedContainersFromContainerLists_,
90                                        Hashtable JavaDoc cachedContainerListsFromContainers_)
91     {
92         this.jParams = jParams_;
93         this.loadRequest = loadRequest_;
94         this.cachedFieldsFromContainers = cachedFieldsFromContainers_;
95         if ( this.cachedFieldsFromContainers == null ){
96             this.cachedFieldsFromContainers = new Hashtable JavaDoc();
97         }
98         this.cachedContainersFromContainerLists = cachedContainersFromContainerLists_;
99         if ( this.cachedContainersFromContainerLists == null ){
100             this.cachedContainersFromContainerLists = new Hashtable JavaDoc();
101         }
102         this.cachedContainerListsFromContainers = cachedContainerListsFromContainers_;
103         if ( this.cachedContainerListsFromContainers == null ){
104             this.cachedContainerListsFromContainers = new Hashtable JavaDoc();
105         }
106     }
107
108     /**
109      * Load this container's sub containers list if not already loaded
110      *
111      * @param container
112      * @param loadFlag, LOAD_FIELDS, LOAD_SUBCONTAINER_LISTS or LOAD_FIELD_AND_SUBCONTAINER_LISTS
113      */

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     /**
164      * @return the fieldsBeingLoaded
165      */

166     private boolean isFieldsBeingLoaded() {
167         return fieldsBeingLoaded;
168     }
169
170     /**
171      * @param fieldsBeingLoaded the fieldsBeingLoaded to set
172      */

173     private void setFieldsBeingLoaded(boolean fieldsBeingLoaded_) {
174         this.fieldsBeingLoaded = fieldsBeingLoaded_;
175     }
176
177     /**
178      * @return the containerListsBeingLoaded
179      */

180     private boolean isContainerListsBeingLoaded() {
181         return containerListsBeingLoaded;
182     }
183
184     /**
185      * @param containerListsBeingLoaded the containerListsBeingLoaded to set
186      */

187     private void setContainerListsBeingLoaded(boolean containerListsBeingLoaded_) {
188         this.containerListsBeingLoaded = containerListsBeingLoaded_;
189     }
190 }
191
Popular Tags