1 package org.apache.fulcrum.yaafi.framework.role;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.fulcrum.yaafi.framework.constant.AvalonFortressConstants;
27 import org.apache.fulcrum.yaafi.framework.constant.AvalonPhoenixConstants;
28 import org.apache.fulcrum.yaafi.framework.constant.AvalonYaafiConstants;
29 import org.apache.fulcrum.yaafi.framework.util.Validate;
30
31
32
33
34
35
36
37 public class RoleConfigurationParserImpl implements RoleConfigurationParser {
38
39 private String containerFlavour;
40
41
42
43
44
45
46 public RoleConfigurationParserImpl(String containerFlavour) {
47 Validate.notEmpty(containerFlavour, "containerFlavour");
48 this.containerFlavour = containerFlavour;
49 }
50
51
52
53
54
55
56
57
58 public RoleEntry[] parse(Configuration roleConfiguration) throws ConfigurationException {
59 Validate.notNull(roleConfiguration, "roleConfiguration");
60
61 if (AvalonYaafiConstants.AVALON_CONTAINER_YAAFI.equals(containerFlavour)) {
62 return mapFromYaafi(roleConfiguration);
63
64 }
65 if (AvalonPhoenixConstants.AVALON_CONTAINER_PHOENIX.equals(containerFlavour)) {
66 return mapFromPhoenix(roleConfiguration);
67
68 } else if (AvalonFortressConstants.AVALON_CONTAINER_FORTESS.equals(containerFlavour)) {
69 return mapFromFortress(roleConfiguration);
70
71 } else {
72 String msg = "Don't know the following container flavour : " + containerFlavour;
73 throw new IllegalArgumentException(msg);
74 }
75 }
76
77
78
79
80
81
82
83
84 private RoleEntry[] mapFromYaafi(Configuration roleConfiguration) throws ConfigurationException {
85 Validate.notNull(roleConfiguration, "roleConfiguration");
86
87 String clazzName = null;
88 String name = null;
89 String shorthand = null;
90 boolean isEarlyInit = false;
91 String description = null;
92 String componentType = null;
93 String componentFlavour = null;
94 boolean hasProxy = false;
95 ArrayList<String> interceptorList = null;
96 String logCategory = null;
97 RoleEntry roleEntry = null;
98
99 Configuration[] list = roleConfiguration.getChildren("role");
100 RoleEntry[] result = new RoleEntry[list.length];
101
102 int roleIndex = 0;
103 for (Configuration entry : list) {
104 clazzName = entry.getAttribute("default-class");
105 name = entry.getAttribute("name", clazzName);
106 shorthand = entry.getAttribute("shorthand", name);
107 isEarlyInit = entry.getAttributeAsBoolean("early-init", true);
108 description = entry.getAttribute("description", null);
109 componentType = entry.getAttribute("component-type", "avalon");
110 componentFlavour = entry.getAttribute("component-flavour", AvalonYaafiConstants.AVALON_CONTAINER_YAAFI);
111 hasProxy = entry.getAttributeAsBoolean("has-proxy", true);
112 logCategory = entry.getAttribute("logger", shorthand);
113
114
115 Configuration[] interceptorConfigList = entry.getChild("interceptors").getChildren("interceptor");
116 interceptorList = new ArrayList<String>();
117
118 for ( Configuration interceptorConfigEntry : interceptorConfigList )
119 {
120 interceptorList.add(interceptorConfigEntry.getValue("interceptor"));
121 }
122
123
124
125 roleEntry = new RoleEntryImpl(name, clazzName, shorthand, isEarlyInit, description, componentType,
126 componentFlavour, hasProxy, interceptorList, logCategory);
127
128 result[roleIndex++] = roleEntry;
129 }
130
131 return result;
132 }
133
134 private RoleEntry[] mapFromPhoenix(Configuration roleConfiguration) throws ConfigurationException {
135 Validate.notNull(roleConfiguration, "roleConfiguration");
136 throw new ConfigurationException("Not supported yet");
137 }
138
139 private RoleEntry[] mapFromFortress(Configuration roleConfiguration) throws ConfigurationException {
140 Validate.notNull(roleConfiguration, "roleConfiguration");
141 throw new ConfigurationException("Not supported yet");
142 }
143 }