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/HomeFactoryImpl.java $
003: * $Id: HomeFactoryImpl.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;
021:
022: import java.util.Hashtable;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.metaobj.shared.model.Id;
030: import org.sakaiproject.metaobj.utils.xml.SchemaFactory;
031:
032: /**
033: * Created by IntelliJ IDEA.
034: * User: John Ellis
035: * Date: Apr 9, 2004
036: * Time: 12:46:02 PM
037: * To change this template use File | Settings | File Templates.
038: */
039: public class HomeFactoryImpl implements HomeFactory {
040: protected final Log logger = LogFactory.getLog(getClass());
041: private List homeFactories = null;
042:
043: public boolean handlesType(String objectType) {
044:
045: for (Iterator i = homeFactories.iterator(); i.hasNext();) {
046: if (((HomeFactory) i.next()).handlesType(objectType)) {
047: return true;
048: }
049: }
050:
051: return false;
052: }
053:
054: public ReadableObjectHome getHome(String objectType) {
055:
056: for (Iterator i = homeFactories.iterator(); i.hasNext();) {
057: HomeFactory testFactory = (HomeFactory) i.next();
058: if (testFactory.handlesType(objectType)) {
059: return testFactory.getHome(objectType);
060: }
061: }
062:
063: return null;
064: }
065:
066: public ReadableObjectHome findHomeByExternalId(String externalId,
067: Id worksiteId) {
068:
069: for (Iterator i = getHomeFactories().iterator(); i.hasNext();) {
070: ReadableObjectHome home = ((HomeFactory) i.next())
071: .findHomeByExternalId(externalId, worksiteId);
072: if (home != null) {
073: return home;
074: }
075: }
076:
077: return null;
078: }
079:
080: public Map getHomes() {
081: Map homes = new Hashtable();
082:
083: for (Iterator i = getHomeFactories().iterator(); i.hasNext();) {
084: homes.putAll(((HomeFactory) i.next()).getHomes());
085: }
086:
087: return homes;
088: }
089:
090: public Map getWorksiteHomes(Id worksiteId) {
091: return getWorksiteHomes(worksiteId, false);
092: }
093:
094: public Map getWorksiteHomes(Id worksiteId, boolean includeHidden) {
095: Map homes = new Hashtable();
096:
097: for (Iterator i = getHomeFactories().iterator(); i.hasNext();) {
098: homes.putAll(((HomeFactory) i.next()).getWorksiteHomes(
099: worksiteId, includeHidden));
100: }
101:
102: return homes;
103: }
104:
105: public Map getHomes(Class requiredHomeType) {
106: Map homes = new Hashtable();
107:
108: for (Iterator i = getHomeFactories().iterator(); i.hasNext();) {
109: homes.putAll(((HomeFactory) i.next())
110: .getHomes(requiredHomeType));
111: }
112:
113: return homes;
114: }
115:
116: public void reload() {
117: SchemaFactory.getInstance().reload();
118: for (Iterator j = getHomes().values().iterator(); j.hasNext();) {
119: ReadableObjectHome home = (ReadableObjectHome) j.next();
120: home.refresh();
121: }
122: }
123:
124: public List getHomeFactories() {
125: return homeFactories;
126: }
127:
128: public void setHomeFactories(List homeFactories) {
129: this.homeFactories = homeFactories;
130: }
131: }
|