1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.amsterdam.metadata;
21
22 import java.util.Iterator;
23 import java.util.ArrayList;
24 import java.net.URL;
25
26 import org.w3c.dom.Element;
27
28 import org.backsource.amsterdam.deployment.DeploymentException;
29
30 import org.backsource.utils.xml.ElementUtil;
31 import org.backsource.utils.xml.XmlException;
32 /***
33 * <p>Holds metadata about an application. An application is a unit of services
34 from one amsterdam.xml file.
35 </p>
36 *
37 * @author <a href="mailto:pra@mogul.com">Peter Antman</a>
38 * @version $Revision: 1.1.1.1 $
39 */
40
41 public class ApplicationMetaData {
42 private URL url;
43 private ArrayList services = new ArrayList();
44 private boolean useRepository = false;
45 private String name;
46 public ApplicationMetaData() {
47
48 }
49 public ApplicationMetaData(URL u) {
50 url = u;
51 }
52
53 /***
54 * <p>Get the ServiceMetaData for each Service in this application.
55 </p>
56 @return an iterator with ServuceMetaData objects.
57 */
58 public Iterator getServices() {
59 return services.iterator();
60 }
61
62 /***
63 * Use scoped repository.
64 */
65 public boolean useRepository() {
66 return useRepository;
67 }
68 /***
69 * Get optional name of application.
70 */
71 public String getName() {
72 return name;
73 }
74
75 public void importServiceXml (Element element) throws DeploymentException {
76 try {
77 try {
78 useRepository = ElementUtil.getAttributeAsBoolean(element,"scoped-classloader");
79 } catch (XmlException e) {
80 ;
81 }
82
83 name = ElementUtil.getContent(ElementUtil.getOptionalChild(element, "name"),null);
84 if ( useRepository && name==null) {
85 throw new DeploymentException("An application name is required when scoped-classloader is set to true");
86 }
87
88 Iterator iterator = ElementUtil.getElementsByTagName(element, "service").iterator();
89 while (iterator.hasNext()) {
90 Element currentService = (Element)iterator.next();
91 ServiceMetaData serviceMetaData = new ServiceMetaData(this);
92 try {
93 serviceMetaData.importXml(currentService);
94 } catch (DeploymentException e) {
95 throw new DeploymentException("Error in amsterdam.xml for Service " + serviceMetaData.getName() + ": " + e.getMessage(),e);
96 }
97 services.add(serviceMetaData);
98 }
99 } catch (XmlException e) {
100 throw new DeploymentException("Could not load amsterdam.xml: " +e,e);
101 }
102 }
103
104 }