KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > intake > xmlmodel > AppData


1 package org.apache.fulcrum.intake.xmlmodel;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache Turbine" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache Turbine", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import java.util.ArrayList JavaDoc;
58 import java.util.Iterator JavaDoc;
59 import java.util.List JavaDoc;
60 import org.xml.sax.Attributes JavaDoc;
61
62 /**
63  * A class for holding application data structures.
64  *
65  * @author <a HREF="mailto:jmcnally@collab.net>John McNally</a>
66  * @version $Id: AppData.java,v 1.1 2004/11/12 10:25:47 epugh Exp $
67  */

68 public class AppData
69     implements java.io.Serializable JavaDoc
70 {
71
72     private List JavaDoc inputs;
73     private String JavaDoc basePackage;
74
75     /**
76      * Default Constructor
77      */

78     public AppData()
79     {
80         inputs = new ArrayList JavaDoc();
81     }
82
83     /**
84      * Imports the top level element from an XML specification
85      */

86     public void loadFromXML (Attributes JavaDoc attrib)
87     {
88         String JavaDoc basePkg = attrib.getValue("basePackage");
89         if ( basePkg == null )
90         {
91             setBasePackage("");
92         }
93         else
94         {
95             if ( basePkg.charAt(basePkg.length()-1) != '.' )
96             {
97                 setBasePackage(basePkg + '.');
98             }
99             else
100             {
101                 setBasePackage(basePkg);
102             }
103         }
104     }
105
106     /**
107      * Return a collection of input sections (<group>)
108      */

109     public List JavaDoc getGroups()
110     {
111         return inputs;
112     }
113
114     /**
115      * Get a XmlGroup with the given name.
116      *
117      * @param groupName a <code>String</code> value
118      * @return a <code>XmlGroup</code> value
119      */

120     public XmlGroup getGroup(String JavaDoc groupName)
121         throws Exception JavaDoc
122     {
123         if (groupName == null)
124         {
125             throw new Exception JavaDoc (
126                 "Intake AppData.getGroup(groupName) is null");
127         }
128         XmlGroup group = null;
129         Iterator JavaDoc iter = inputs.iterator();
130         do
131         {
132             group = (XmlGroup)iter.next();
133
134         } while (!group.getName().equals(groupName));
135
136         return group;
137     }
138
139     /**
140      * An utility method to add a new input group from
141      * an xml attribute.
142      */

143     public XmlGroup addGroup(Attributes JavaDoc attrib)
144     {
145         XmlGroup input = new XmlGroup();
146         input.loadFromXML(attrib);
147         addGroup(input);
148         return input;
149     }
150
151     /**
152      * Add an input group to the vector and sets the
153      * AppData property to this AppData
154      */

155     public void addGroup(XmlGroup input)
156     {
157         input.setAppData(this);
158         inputs.add(input);
159     }
160
161
162     /**
163      * Get the base package String that will be appended to
164      * any mapToObjects
165      *
166      * @return value of basePackage.
167      */

168     public String JavaDoc getBasePackage()
169     {
170         return basePackage;
171     }
172
173     /**
174      * Get the base package String that will be appended to
175      * any mapToObjects
176      *
177      * @param v Value to assign to basePackage.
178      */

179     public void setBasePackage(String JavaDoc v)
180     {
181         this.basePackage = v;
182     }
183
184     /**
185      * Creats a string representation of this AppData.
186      * The representation is given in xml format.
187      */

188     public String JavaDoc toString()
189     {
190         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
191
192         result.append ("<input-data>\n");
193         for (Iterator JavaDoc iter = inputs.iterator() ; iter.hasNext() ;)
194         {
195             result.append (iter.next());
196         }
197         result.append ("</input-data>");
198         return result.toString();
199   }
200 }
201
202
Popular Tags