View Javadoc

1   /*
2    * Copyright (c) 2004 Peter Antman, Mogul  <peter.antman@mogul.com>
3    *
4    * $Id: ApplicationMetaData.java,v 1.1.1.1 2004/05/19 12:22:46 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library 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 GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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              ;//Silense
81           } // end of try-catch
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           } // end of if ()
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       } // end of try-catch
102    }
103    
104 }// ApplicationMetaData