KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > publisher > serverimpl > resolving > ResolveDefinition


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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.outerj.daisy.publisher.serverimpl.resolving;
17
18 import org.outerj.daisy.repository.query.PredicateExpression;
19 import org.outerj.daisy.repository.query.QueryException;
20 import org.outerj.daisy.repository.Document;
21 import org.outerj.daisy.repository.Version;
22 import org.outerj.daisy.publisher.PublisherException;
23
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 public class ResolveDefinition {
29     private List JavaDoc resolveRules = new ArrayList JavaDoc();
30
31     protected void addRule(String JavaDoc expressionString, PredicateExpression expression, String JavaDoc publisherRequestName) {
32         resolveRules.add(new ResolveRule(expressionString, expression, publisherRequestName));
33     }
34
35     public String JavaDoc resolve(Document document, Version version) throws PublisherException {
36         Iterator JavaDoc resolveRulesIt = resolveRules.iterator();
37         while (resolveRulesIt.hasNext()) {
38             ResolveRule rule = (ResolveRule)resolveRulesIt.next();
39             try {
40                 if (rule.expression.evaluate(document, version))
41                     return rule.publisherRequestName;
42             } catch (QueryException e) {
43                 throw new PublisherException("Error evaluating expression in publisher request mapping: " + rule.expressionString, e);
44             }
45         }
46         return null;
47     }
48
49     static class ResolveRule {
50         String JavaDoc expressionString;
51         PredicateExpression expression;
52         String JavaDoc publisherRequestName;
53
54         public ResolveRule(String JavaDoc expressionString, PredicateExpression expression, String JavaDoc publisherRequestName) {
55             this.expressionString = expressionString;
56             this.expression = expression;
57             this.publisherRequestName = publisherRequestName;
58         }
59     }
60 }
61
Popular Tags