KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > bussinessproxy > config > TargetMetaDefXmlLoader


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

15
16 package com.jdon.bussinessproxy.config;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import com.jdon.bussinessproxy.TargetMetaDef;
23 import com.jdon.container.config.app.AppConfigureCollection;
24 import com.jdon.container.pico.Startable;
25 import com.jdon.controller.config.XmlParser;
26 import com.jdon.controller.config.XmlPojoServiceParser;
27 import com.jdon.controller.config.XmlServiceParser;
28 import com.jdon.util.Debug;
29  
30
31 /**
32  * Load target service meta definition from jdonframework.xml
33  *
34  * @author banq
35  */

36 public class TargetMetaDefXmlLoader implements Startable, TargetMetaDefLoader {
37
38   private final static String JavaDoc module = TargetMetaDefXmlLoader.class.getName();
39  
40   private AppConfigureCollection appConfigureFiles;
41   private XmlParser xmlServiceParser = new XmlServiceParser();
42   private XmlParser xmlPojoServiceParser = new XmlPojoServiceParser();
43
44   /**
45    * 以service name为key, Service TargetMetaDef为value
46    */

47   private Map JavaDoc metaDefs = new HashMap JavaDoc();
48   private Map JavaDoc pojoClasses = new HashMap JavaDoc();
49
50
51   public TargetMetaDefXmlLoader(AppConfigureCollection appConfigureFiles) {
52     this.appConfigureFiles = appConfigureFiles;
53  }
54
55   public TargetMetaDef getTargetMetaDef(String JavaDoc name){
56       
57      Debug.logVerbose("[JdonFramework]metaDefs size:" + metaDefs.size(), module);
58     return (TargetMetaDef)metaDefs.get(name);
59   }
60
61   public void start() {
62     Debug.logVerbose("[JdonFramework]TargetMetaDefXmlLoader start ..... found confiures:"
63               + appConfigureFiles.getConfigList().size(), module);
64     
65     Iterator JavaDoc iter = appConfigureFiles.getConfigList().iterator();
66     while (iter.hasNext()) {
67       String JavaDoc configFileName = (String JavaDoc) iter.next();
68       Debug.logVerbose("[JdonFramework] start to load configure: " + configFileName, module);
69       Map JavaDoc mps = xmlServiceParser.load(configFileName);
70       metaDefs.putAll(mps);
71       Map JavaDoc pojoMps = xmlPojoServiceParser.load(configFileName);
72       metaDefs.putAll(pojoMps);
73     }
74   }
75
76
77   public void stop() {
78     metaDefs.clear();
79     appConfigureFiles = null;
80   }
81
82   public Map JavaDoc getMetaDefs() {
83     return metaDefs;
84   }
85
86 }
87
Popular Tags