KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > matching > PreparableMatcher


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.matching;
17
18 import org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.cocoon.sitemap.PatternException;
20
21 import java.util.Map JavaDoc;
22
23 /**
24  * A matcher that can prepare patterns during sitemap setup for faster match at request time.
25  * This is also a regular matcher, meaning the sitemap can decide either to prepare the pattern
26  * or to match with a request-time evaluated pattern (for {..} substitution).
27  *
28  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
29  * @version CVS $Id: PreparableMatcher.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public interface PreparableMatcher extends Matcher {
32
33     /**
34      * Prepares a pattern in a form that allows faster match. For example, a regular
35      * expression matcher can precompile the expression and return the corresponding
36      * object. This method is called once for each pattern used with a particular matcher
37      * class. The returned value is then passed back as the <code>preparedPattern</code>
38      * parameter of {@link #preparedMatch(Object, Map, Parameters)}.
39      *
40      * @param pattern The pattern to prepare. Depending on the implementation the pattern
41      * can contain wildcards or regular expressions.
42      * @return an optimized representation of the pattern.
43      * @throws PatternException if the pattern couldn't be prepared.
44      */

45     Object JavaDoc preparePattern(String JavaDoc pattern) throws PatternException;
46
47     /**
48      * Matches the prepared pattern against some values in the object model (most often the
49      * <code>Request</code>) and returns a <code>Map</code> object with replacements
50      * for wildcards contained in the pattern.
51      *
52      * @param preparedPattern The preparedPattern to match against, as returned by {@link #preparePattern(String)}.
53      * @param objectModel The <code>Map</code> with objects of the calling environment
54      * which can be used to select values this matchers matches against.
55      * @return a <code>Map</code> object with replacements for wildcards/regular-expressions
56      * contained in the pattern. If the return value is null there was no match.
57      */

58     Map JavaDoc preparedMatch(Object JavaDoc preparedPattern, Map JavaDoc objectModel, Parameters parameters) throws PatternException;
59 }
60
61
62
63
Popular Tags