KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > controller > config > XmlPojoServiceParser


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.controller.config;
17
18
19 import java.util.Map JavaDoc;
20
21 import java.util.List JavaDoc;
22
23 import java.util.Iterator JavaDoc;
24 import com.jdon.bussinessproxy.meta.POJOTargetMetaDef;
25 import com.jdon.util.Debug;
26
27 import org.jdom.Element;
28
29
30 public class XmlPojoServiceParser extends XmlParser{
31   private final static String JavaDoc module = XmlPojoServiceParser.class.getName();
32
33
34   public void parse(Element root, Map JavaDoc mps) throws Exception JavaDoc {
35     Debug.logVerbose("[JdonFramework] enter XmlPojoServiceParser .", module);
36     List JavaDoc services = root.getChildren("services");
37     Iterator JavaDoc iter = services.iterator();
38     while (iter.hasNext()) {
39       Element service = (Element) iter.next();
40       if (service.getChildren("pojoService") != null) {
41         Iterator JavaDoc ii = service.getChildren("pojoService").iterator();
42         while (ii.hasNext()) {
43           Element pojoService = (Element) ii.next();
44           parsePOJOServiceConfig(pojoService, mps);
45         }
46       }
47       if (service.getChildren("component") != null) {
48           Iterator JavaDoc ii = service.getChildren("component").iterator();
49           while (ii.hasNext()) {
50             Element pojoService = (Element) ii.next();
51             parsePOJOServiceConfig(pojoService, mps);
52           }
53        }
54     }
55   }
56
57   /**
58    * parse POJOService Config
59    * @param pojoService Element
60    * @param mps Map
61    * @throws Exception
62    */

63   private void parsePOJOServiceConfig(Element pojoService, Map JavaDoc mps) throws
64       Exception JavaDoc {
65     String JavaDoc name = pojoService.getAttributeValue("name");
66     String JavaDoc className = pojoService.getAttributeValue("class");
67     Debug.logVerbose("[JdonFramework] pojoService/component name=" + name + " class=" + className,
68                      module);
69
70     if ( (className == null) || (className.equals("")))
71       throw new Exception JavaDoc("className is null ");
72
73     List JavaDoc mappings = pojoService.getChildren("constructor");
74     String JavaDoc[] constructors = null;
75     if ((mappings != null) && (mappings.size() != 0)) {
76       Debug.logVerbose("[JdonFramework] constructor parameters number:" + mappings.size() +
77                        " for pojoservice " + name, module);
78       constructors = new String JavaDoc[mappings.size()];
79       int j = 0;
80       Iterator JavaDoc i = mappings.iterator();
81       while (i.hasNext()) {
82         Element constructor = (Element) i.next();
83         String JavaDoc value = constructor.getAttributeValue("value");
84         Debug.logVerbose("[JdonFramework] pojoService constructor=" + value, module);
85         constructors[j] = value;
86         j++;
87       }
88     }
89
90     POJOTargetMetaDef pojoMetaDef = null;
91     if (constructors != null)
92       pojoMetaDef = new POJOTargetMetaDef(name, className, constructors);
93     else
94       pojoMetaDef = new POJOTargetMetaDef(name, className);
95     mps.put(name, pojoMetaDef);
96
97   }
98 }
99
Popular Tags