KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > qvt > engine > EntryPointApplyer


1 /**
2  * copyright 2002 2004 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.qvt.engine;
21
22 import javax.jmi.reflect.*;
23
24 import java.util.*;
25
26 public class EntryPointApplyer {
27     
28   RefPackage src, target, rulesPkg;
29   Hashtable bindingTable = new Hashtable();
30   RefObject rulesUnit;
31
32   public EntryPointApplyer(RefPackage rulesPkg, RefPackage src, RefPackage target) throws Exception JavaDoc {
33     this.src = src;
34     this.target = target;
35     this.rulesPkg = rulesPkg;
36     init();
37   }
38   
39   public void applyAllUnits() throws Exception JavaDoc {
40     Iterator it = rulesPkg.refClass("RulesUnit").refAllOfClass().iterator();
41     while(it.hasNext()) {
42         RefObject rulesUnit = (RefObject) it.next();
43         applyEntryPoints(rulesUnit);
44     }
45   }
46   
47   public void applyEntryPoints(RefObject rulesUnit) throws Exception JavaDoc {
48     
49     RefObject[] rules;
50     rules = (RefObject[]) ( (Collection) rulesUnit.refGetValue("rules")
51     ).toArray(new RefObject[0]);
52
53     for(int i=0; i<rules.length; i++) {
54       if( Reflection.isOfType(rules[i],"EntryPointRule") ) {
55           applyEntryPoint( rules[i]);
56       }
57     }
58   }
59
60   void applyEntryPoint(RefObject entryPointRule) throws Exception JavaDoc {
61       // resolve entry elements
62
Object JavaDoc[] contexts = Reflection.allOfType(
63         src ,(String JavaDoc)entryPointRule.refGetValue("context")
64       ).toArray();
65       // apply rule to resolved elements
66
for(int i=0; i<contexts.length ; i++) {
67         Hashtable args = new Hashtable();
68         args.put("context", contexts[i]);
69         (new RuleBinding( bindingTable
70             ,entryPointRule, src, target, args, 0)).execute();
71       }
72   }
73   
74   void init() {
75     String JavaDoc verbose = System.getProperty("fr.lip6.modfact.qvt.engine.verbose");
76     if("true".equals(verbose)) {
77       RuleBinding.verbose = true;
78     }
79   }
80 }
81
82
Popular Tags