KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > session > selection > MediaSelector


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.webapps.session.selection;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.avalon.framework.service.ServiceException;
22 import org.apache.avalon.framework.service.ServiceManager;
23 import org.apache.avalon.framework.service.Serviceable;
24 import org.apache.avalon.framework.thread.ThreadSafe;
25 import org.apache.cocoon.selection.Selector;
26 import org.apache.cocoon.webapps.session.MediaManager;
27
28 /**
29  * This selector uses the media management.
30  *
31  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
32  * @version CVS $Id: MediaSelector.java 30932 2004-07-29 17:35:38Z vgritsenko $
33 */

34 public final class MediaSelector
35 implements Serviceable, Selector, ThreadSafe {
36
37     private ServiceManager manager;
38
39     /**
40      * Selector
41      */

42     public boolean select (String JavaDoc expression, Map JavaDoc objectModel, Parameters parameters) {
43         MediaManager mediaManager = null;
44         boolean result;
45         try {
46             mediaManager = (MediaManager) this.manager.lookup( MediaManager.ROLE );
47             result = mediaManager.testMedia(expression);
48         } catch (Exception JavaDoc local) {
49             // ignore me
50
result = false;
51         } finally {
52             this.manager.release(mediaManager );
53         }
54         return result;
55     }
56     
57     /* (non-Javadoc)
58      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
59      */

60     public void service(ServiceManager manager) throws ServiceException {
61         this.manager = manager;
62     }
63
64 }
65
66
67
Popular Tags