01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.cocoon.components.source.impl;
19:
20: import java.io.IOException;
21: import java.net.MalformedURLException;
22: import java.util.Map;
23:
24: import org.apache.avalon.framework.context.Context;
25: import org.apache.avalon.framework.context.ContextException;
26: import org.apache.avalon.framework.context.Contextualizable;
27: import org.apache.avalon.framework.logger.AbstractLogEnabled;
28: import org.apache.avalon.framework.service.ServiceException;
29: import org.apache.avalon.framework.service.ServiceManager;
30: import org.apache.avalon.framework.service.Serviceable;
31: import org.apache.avalon.framework.thread.ThreadSafe;
32:
33: import org.apache.excalibur.source.Source;
34: import org.apache.excalibur.source.SourceFactory;
35:
36: import org.apache.cocoon.components.ContextHelper;
37:
38: /**
39: * A factory for 'module:' sources (see {@link ModuleSource}).
40: *
41: * @author <a href="mailto:danielf@nada.kth.se">Daniel Fagerstrom</a>
42: */
43:
44: public class ModuleSourceFactory extends AbstractLogEnabled implements
45: SourceFactory, Serviceable, Contextualizable, ThreadSafe {
46:
47: private ServiceManager manager;
48: private Context context;
49:
50: /**
51: * Servicable Interface
52: */
53: public void service(ServiceManager manager) throws ServiceException {
54: this .manager = manager;
55: }
56:
57: /**
58: * Contextualizable, get the object model
59: */
60: public void contextualize(Context context) throws ContextException {
61: this .context = context;
62: }
63:
64: /**
65: * Get a {@link ModuleSource} object.
66: *
67: * @param location The URI to resolve - this URI includes the scheme.
68: * @param parameters this is optional and not used here
69: */
70: public Source getSource(String location, Map parameters)
71: throws IOException, MalformedURLException {
72:
73: Map objectModel = ContextHelper.getObjectModel(this .context);
74: return new ModuleSource(objectModel, location, this .manager,
75: getLogger());
76: }
77:
78: /**
79: * Release a {@link Source} object.
80: */
81: public void release(Source source) {
82: // Do nothing here
83: }
84:
85: }
|