001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/shared/mgt/factories/HomeFactoryBase.java $
003: * $Id: HomeFactoryBase.java 20050 2007-01-02 19:37:37Z john.ellis@rsmart.com $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.mgt.factories;
021:
022: import java.util.Hashtable;
023: import java.util.Iterator;
024: import java.util.Map;
025:
026: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
027: import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
028: import org.sakaiproject.metaobj.shared.model.Id;
029:
030: /**
031: * Created by IntelliJ IDEA.
032: * User: John Ellis
033: * Date: May 14, 2004
034: * Time: 4:22:36 PM
035: * To change this template use File | Settings | File Templates.
036: */
037: public abstract class HomeFactoryBase implements HomeFactory {
038:
039: private Map homesByExternalId = null;
040: private Object homesByExternalIdLock = new Object();
041:
042: public void reload() {
043: if (homesByExternalId == null) {
044: homesByExternalId = new Hashtable();
045: }
046: homesByExternalId.clear();
047: for (Iterator j = getHomes().entrySet().iterator(); j.hasNext();) {
048: ReadableObjectHome home = (ReadableObjectHome) j.next();
049: home.refresh();
050: homesByExternalId.put(home.getExternalType(), home);
051: }
052: }
053:
054: public ReadableObjectHome findHomeByExternalId(String externalId,
055: Id worksiteId) {
056: if (homesByExternalId == null) {
057: synchronized (homesByExternalIdLock) {
058: if (homesByExternalId == null) {
059: homesByExternalId = new Hashtable();
060: for (Iterator j = getHomes().entrySet().iterator(); j
061: .hasNext();) {
062: Map.Entry entry = (Map.Entry) j.next();
063: ReadableObjectHome home = (ReadableObjectHome) entry
064: .getValue();
065: homesByExternalId.put(home.getExternalType(),
066: home);
067: }
068: }
069: }
070: }
071: return (ReadableObjectHome) homesByExternalId.get(externalId);
072: }
073:
074: protected void addHome(ReadableObjectHome newHome) {
075: homesByExternalId.put(newHome.getExternalType(), newHome);
076: }
077:
078: public Map getHomes(Class requiredHomeType) {
079: Map newMap = new Hashtable();
080: Map homes = getHomes();
081:
082: for (Iterator i = homes.keySet().iterator(); i.hasNext();) {
083: Object key = i.next();
084:
085: if (requiredHomeType.isInstance(homes.get(key))) {
086: newMap.put(key, homes.get(key));
087: }
088: }
089:
090: return newMap;
091: }
092:
093: public Map getWorksiteHomes(Id worksiteId) {
094: return getHomes();
095: }
096:
097: public Map getWorksiteHomes(Id worksiteId, boolean includeHidden) {
098: return getHomes();
099: }
100:
101: }
|