001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/entity/tags/sakai_2-4-1/entity-impl/impl/src/java/org/sakaiproject/entity/impl/EntityManagerComponent.java $
003: * $Id: EntityManagerComponent.java 7396 2006-04-06 03:46:58Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.entity.impl;
021:
022: import java.util.HashSet;
023: import java.util.List;
024: import java.util.Set;
025: import java.util.Vector;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.entity.api.EntityManager;
030: import org.sakaiproject.entity.api.EntityProducer;
031: import org.sakaiproject.entity.api.Reference;
032: import org.sakaiproject.util.Validator;
033:
034: /**
035: * <p>
036: * EntityManagerComponent is an implementation of the EntityManager.
037: * </p>
038: */
039: public class EntityManagerComponent implements EntityManager {
040: /** Our logger. */
041: protected static Log M_log = LogFactory
042: .getLog(EntityManagerComponent.class);
043:
044: /** Set of EntityProducer services. */
045: protected Set m_producers = new HashSet();
046:
047: /**********************************************************************************************************************************************************************************************************************************************************
048: * Constructors, Dependencies and their setter methods
049: *********************************************************************************************************************************************************************************************************************************************************/
050:
051: /**********************************************************************************************************************************************************************************************************************************************************
052: * Init and Destroy
053: *********************************************************************************************************************************************************************************************************************************************************/
054:
055: /**
056: * Final initialization, once all dependencies are set.
057: */
058: public void init() {
059: try {
060: M_log.info("init()");
061: } catch (Throwable t) {
062: }
063: }
064:
065: /**
066: * Returns to uninitialized state.
067: */
068: public void destroy() {
069: M_log.info("destroy()");
070: }
071:
072: /**********************************************************************************************************************************************************************************************************************************************************
073: * EntityManager implementation
074: *********************************************************************************************************************************************************************************************************************************************************/
075:
076: /**
077: * @inheritDoc
078: */
079: public List getEntityProducers() {
080: List rv = new Vector();
081: rv.addAll(m_producers);
082:
083: return rv;
084: }
085:
086: /**
087: * @inheritDoc
088: */
089: public void registerEntityProducer(EntityProducer manager,
090: String referenceRoot) {
091: // TODO: referenceRoot
092: m_producers.add(manager);
093: }
094:
095: /**
096: * @inheritDoc
097: */
098: public Reference newReference(String refString) {
099: return new ReferenceComponent(refString);
100: }
101:
102: /**
103: * @inheritDoc
104: */
105: public Reference newReference(Reference copyMe) {
106: return new ReferenceComponent(copyMe);
107: }
108:
109: /**
110: * @inheritDoc
111: */
112: public List newReferenceList() {
113: return new ReferenceVectorComponent();
114: }
115:
116: /**
117: * @inheritDoc
118: */
119: public List newReferenceList(List copyMe) {
120: return new ReferenceVectorComponent(copyMe);
121: }
122:
123: /**
124: * @inheritDoc
125: */
126: public boolean checkReference(String ref) {
127: // the rules:
128: // Null is rejected
129: // all blank is rejected
130: // INVALID_CHARS_IN_RESOURCE_ID characters are rejected
131:
132: Reference r = newReference(ref);
133:
134: // just check the id... %%% need more? -ggolden
135: String id = r.getId();
136:
137: if (id == null)
138: return false;
139: if (id.trim().length() == 0)
140: return false;
141:
142: // we must reject certain characters that we cannot even escape and get into Tomcat via a URL
143: for (int i = 0; i < id.length(); i++) {
144: if (Validator.INVALID_CHARS_IN_RESOURCE_ID.indexOf(id
145: .charAt(i)) != -1)
146: return false;
147: }
148:
149: return true;
150: }
151: }
|