Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: net/jxta/ext/config/Profile.java


1   /*
2    *  Copyright (c) 2001 Sun Microsystems, Inc.  All rights
3    *  reserved.
4    *
5    *  Redistribution and use in source and binary forms, with or without
6    *  modification, are permitted provided that the following conditions
7    *  are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright
10   *  notice, this list of conditions and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright
13   *  notice, this list of conditions and the following disclaimer in
14   *  the documentation and/or other materials provided with the
15   *  distribution.
16   *
17   *  3. The end-user documentation included with the redistribution,
18   *  if any, must include the following acknowledgment:
19   *  "This product includes software developed by the
20   *  Sun Microsystems, Inc. for Project JXTA."
21   *  Alternately, this acknowledgment may appear in the software itself,
22   *  if and wherever such third-party acknowledgments normally appear.
23   *
24   *  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"
25   *  must not be used to endorse or promote products derived from this
26   *  software without prior written permission. For written
27   *  permission, please contact Project JXTA at http://www.jxta.org.
28   *
29   *  5. Products derived from this software may not be called "JXTA",
30   *  nor may "JXTA" appear in their name, without prior written
31   *  permission of Sun.
32   *
33   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36   *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
37   *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40   *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42   *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43   *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44   *  SUCH DAMAGE.
45   *  ====================================================================
46   *
47   *  This software consists of voluntary contributions made by many
48   *  individuals on behalf of Project JXTA.  For more
49   *  information on Project JXTA, please see
50   *  <http://www.jxta.org/>.
51   *
52   *  This license is based on the BSD license adopted by the Apache Foundation.
53   *
54   *  $Id: Profile.java,v 1.23 2004/10/30 02:22:11 gonzo Exp $
55   */
56  package net.jxta.ext.config;
57  
58  import java.net.URL;
59  import java.util.HashMap;
60  import java.util.Iterator;
61  
62  import java.io.InputStream;
63  
64  import org.apache.log4j.Level;
65  import org.apache.log4j.Logger;
66  
67  /**
68   *  A JXTA configurator that can parse an XML resource and in turn construct the
69   *  relevant <code>PlatformConfig</code>.<br>
70   *  <br>
71   *  All addresses are of the form URI. Addresses that do not specify a scheme
72   *  will be defaulted accordingly. Further, <code>RendezVous</code> and <code>Relay</code>
73   *  addresses that do not specify a host wil be replaced with the corresponding
74   *  boostrap results. If a scheme is specified only bootstrap results with
75   *  matching schemes will be retained. All other addresses that do not specify a
76   *  host will, in turn, be replaced with the local host. All fields have backing
77   *  defaults enabling one to seed a configuration with a partial yet valid
78   *  resource file.<br>
79   *  <br>
80   *  An example ResourceConfigurator"profile" is as follows:<br>
81   *  <br>
82   *  <pre>
83   * &lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
84   *
85   * &lt;!--
86   * &lt;!DOCTYPE xsd:schema SYSTEM "http://www.w3c.org/2001/XMLSchema.dtd"&gt;
87   * --&gt;
88   *
89   * &lt;xsd:schema xmlns:jxta="http://www.jxta.org/net/jxta/ext/config"
90   *   xmlns:xsd="http://www.w3c.org/2001/XMLSchema.dtd"&gt;
91   *
92   *   &lt;xsd:annotation&gt;
93   *     &lt;xsd:documentation xml:lang="en"&gt;
94   *     JXTA Configuration
95   *
96   *     see http://www.jxta.org for more info.
97   *     &lt;/xsd:documentation&gt;
98   *   &lt;/xsd:annotation&gt;
99   *
100  *   &lt;xsd:complexType name="jxta"&gt;
101  *     &lt;xsd:sequence&gt;
102  *       &lt;xsd:element name="peer" type="jxta:Peer" minOccurs="1" maxOccurs="1"/&gt;
103  *       &lt;xsd:element name="network" type="jxta:Network" minOccurs="1"
104  *         maxOccurs="1"/&gt;
105  *       &lt;xsd:element name="transport" type="jxta:Transport" minOccurs="1"
106  *         maxOccurs="1"/&gt;
107  *       &lt;xsd:element name="service" type="jxta:Service" minOccurs="1"
108  *         maxOccurs="1"/&gt;
109  *     &lt;/xsd:sequence&gt;
110  *   &lt;/xsd:complexType&gt;
111  *
112  *   &lt;xsd:complexType name="Peer"&gt;
113  *     &lt;xsd:attribute name="name" type="xsd:string" use="optional"/&gt;
114  *     &lt;xsd:attribute name="id" type="jxta:PeerID" use="optional"/&gt;
115  *     &lt;xsd:attribute name="descriptor" type="xsd:string" use="optional"/&gt;
116  *     &lt;xsd:attribute name="home" type="xsd:anyURI" use="optional"
117  *       default="file://${user.home}/.jxta"/&gt;
118  *     &lt;xsd:attribute name="trace" type="jxta:Trace" use="optional"
119  *       default="user default"/&gt;
120  *     &lt;xsd:sequence&gt;
121  *       &lt;xsd:element name="description" type="jxta:Description" minOccurs="0"
122  *         maxOccurs="unbounded"/&gt;
123  *       &lt;xsd:element name="security" type="jxta:Security" minOccurs="0"
124  *         maxOccurs="1"/&gt;
125  *       &lt;xsd:element name="rootCert" type="jxta:RootCert" minOccurs="0"
126  *         maxOccurs="1"/&gt;
127  *       &lt;xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
128  *         maxOccurs="1"/&gt;
129  *     &lt;/xsd:sequence&gt;
130  *   &lt;/xsd:complexType&gt;
131  *
132  *   &lt;xsd:complexType name="Network"&gt;
133  *     &lt;xsd:sequence&gt;
134  *       &lt;xsd:element name="rendezVous" type="jxta:RendezVous" minOccurs="0"
135  *         maxOccurs="1"/&gt;
136  *       &lt;xsd:element name="relays" type="jxta:Relays" minOccurs="0" maxOccurs="1"/&gt;
137  *     &lt;/xsd:sequence&gt;
138  *   &lt;/xsd:complexType&gt;
139  *
140  *   &lt;xsd:complexType name="Transport"&gt;
141  *     &lt;xsd:sequence&gt;
142  *       &lt;xsd:element name="tcp" type="Tcp" minOccurs="0" maxOccurs="unbounded"/&gt;
143  *       &lt;xsd:element name="http" type="Http" minOccurs="0" maxOccurs="unbounded"/&gt;
144  *     &lt;/xsd:sequence&gt;
145  *   &lt;/xsd:complexType&gt;
146  *
147  *   &lt;xsd:complexType name="Service"&gt;
148  *     &lt;xsd:sequence&gt;
149  *       &lt;xsd:element name="rendezVous" type="jxta:RendezVousService" minOccurs="0"
150  *         maxOccurs="1"/&gt;
151  *       &lt;xsd:element name="relay" type="jxta:RelayService" minOccurs="0"
152  *         maxOccurs="1"/&gt;
153  *       &lt;xsd:element name="endpoint" type="jxta:EndpointService" minOccurs="0"
154  *         maxOccurs="1"/&gt;
155  *       &lt;xsd:element name="proxy" type="jxta:ProxyService" minOccurs="0"
156  *         maxOccurs="1"/&gt;
157  *     &lt;/xsd:sequence&gt;
158  *   &lt;xsd:complextType name="Configuration"&gt;
159  *     &lt;xsd:sequence&gt;
160  *       &lt;xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
161  *         maxOccurs="unbounded"/&gt;
162  *     &lt;/xsd:sequence&gt;
163  *   &lt;/xsd:complexType&gt;
164  *
165  *   &lt;xsd:complextType name="Configuration"&gt;
166  *     &lt;xsd:sequence&gt;
167  *       &lt;xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
168  *         maxOccurs="unbounded"/&gt;
169  *     &lt;/xsd:sequence&gt;
170  *   &lt;/xsd:complexType&gt;
171  *
172  *   &lt;/xsd:complexType&gt;
173  *
174  *   &lt;xsd:complextType name="Configuration"&gt;
175  *     &lt;xsd:sequence&gt;
176  *       &lt;xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
177  *         maxOccurs="unbounded"/&gt;
178  *     &lt;/xsd:sequence&gt;
179  *   &lt;/xsd:complexType&gt;
180  *
181  *   &lt;xsd:simpleType name="Trace"&gt;
182  *     &lt;xsd:restriction base="xsd:string"&gt;
183  *       &lt;xsd:enumeration value="error"/&gt;
184  *       &lt;xsd:enumeration value="warn"/&gt;
185  *       &lt;xsd:enumeration value="info"/&gt;
186  *       &lt;xsd:enumeration value="debug"/&gt;
187  *       &lt;xsd:enumeration value="user default"/&gt;
188  *     &lt;/xsd:restriction&gt;
189  *   &lt;/xsd:simpleType&gt;
190  *
191  *   &lt;xsd:complextType name="Description"&gt;
192  *     &lt;xsd:all&gt;
193  *     &lt;/xsd:all&gt;
194  *   &lt;/xsd:complextType&gt;
195  *
196  *   &lt;xsd:complexType name="Security"&gt;
197  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
198  *       default="true"/&gt;
199  *     &lt;xsd:attribute name="principal" type="xsd:string" use="required"/&gt;
200  *   &lt;/xsd:complexType&gt;
201  *
202  *   &lt;xsd:complexType name="RootCert"&gt;
203  *     &lt;xsd:simpleContext&gt;
204  *       &lt;xsd:extension base="xsd:string"&gt;
205  *         &lt;xsd:attribute name="address" type="xsd:anyURI" use="optional"/&gt;
206  *       &lt;/xsd:extension&gt;
207  *     &lt;/xsd:simpleContext&gt;
208  *   &lt;/xsd:complexType&gt;
209  *
210  *   &lt;xsd:complexType name="ProxyAddress"&gt;
211  *     &lt;xsd:simpleContent&gt;
212  *       &lt;xsd:extension base="xsd:anyURI"&gt;
213  *         &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
214  *           default="false"/&gt;
215  *       &lt;/xsd:extension&gt;
216  *     &lt;/xsd:simpleContent&gt;
217  *   &lt;/xsd:complexType&gt;
218  *
219  *   &lt;xsd:complexType name="RendezVous"&gt;
220  *     &lt;xsd:attribute name="bootstrap" type="xsd:anyURI" use="optional"/&gt;
221  *     &lt;xsd:attribute name="discovery" type="xsd:boolean" use="optional"
222  *       default="true"/&gt;
223  *     &lt;xsd:element name="address" type="jxta:Address" minOccurs="0"
224  *       maxOccurs="unbounded" default="://"/&gt;
225  *   &lt;/xsd:complexType&gt;
226  *
227  *   &lt;xsd:complexType name="Relays"&gt;
228  *     &lt;xsd:attribute name="bootstrap" type="xsd:anyURI" use="optional"/&gt;
229  *     &lt;xsd:attribute name="discovery" type="xsd:boolean" use="optional"
230  *       default="true"/&gt;
231  *     &lt;xsd:element name="address" type="jxta:Address" minOccurs="0"
232  *       maxOccurs="unbounded" default="//:"/&gt;
233  *   &lt;/xsd:complexType&gt;
234  *
235  *   &lt;xsd:element name="Address" type="xsd:anyURI"/&gt;
236  *
237  *   &lt;xsd:complexType name="Tcp"&gt;
238  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
239  *       default="true"/&gt;
240  *     &lt;xsd:sequence&gt;
241  *       &lt;xsd:element name="incoming" type="jxta:TransportEndpoint" minOccurs="0"
242  *         maxOccurs="1"/&gt;
243  *       &lt;xsd:element name="outgoing" type="jxta:TransportEndpoint" minOccurs="0"
244  *         maxOccurs="1"/&gt;
245  *       &lt;xsd:element name="TcpAddress" type="TcpAddress" minOccurs="0"
246  *         maxOccurs="unbounded"/&gt;
247  *       &lt;xsd:element name="publicAddress" type="jxta:PublicAddress" minOccurs="0"
248  *         maxOccurs="unbounded" default="http://:"/&gt;
249  *       &lt;xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
250  *         maxOccurs="1"/&gt;
251  *     &lt;/xsd:sequence&gt;
252  *   &lt;/xsd:complexType&gt;
253  *
254  *   &lt;xsd:complexType name="Http"&gt;
255  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
256  *       default="true"/&gt;
257  *     &lt;xsd:sequence&gt;
258  *       &lt;xsd:element name="incoming" type="jxta:TransportEndpoint" minOccurs="0"
259  *         maxOccurs="1"/&gt;
260  *       &lt;xsd:element name="outgoing" type="jxta:TransportEndpoint" minOccurs="0"
261  *         maxOccurs="1"/&gt;
262  *       &lt;xsd:element name="address" type="jxta:TransportAddress" minOccurs="0"
263  *         maxOccurs="unbounded" default="http://:"/&gt;
264  *       &lt;xsd:element name="publicAddress" type="jxta:PublicAddress" minOccurs="0"
265  *         maxOccurs="unbounded" default="http://:"/&gt;
266  *       &lt;xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
267  *         maxOccurs="1"/&gt;
268  *     &lt;/xsd:sequence&gt;
269  *   &lt;/xsd:complexType&gt;
270  *
271  *   &lt;xsd:complexType name="TransportEndpoint"&gt;
272  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
273  *       default="false"/&gt;
274  *   &lt;/xsd:complexType&gt;
275  *
276  *   &lt;xsd:complexType name="TcpAddress"&gt;
277  *       &lt;xsd:simpleContent&gt;
278  *       &lt;xsd:extension bae="xsd:anyURI"&gt;
279  *         &lt;xsd:attribute name="range" type="xsd:integer"&gt;
280  *           &lt;xsd:restrictive&gt;
281  *             &lt;xsd:minInclusive value="0"/&gt;
282  *             &lt;xsd:maxInclusive value="65535"/&gt;
283  *           &lt;/xsd:restrictive&gt;
284  *         &lt;/xsd:attribute&gt;
285  *         &lt;xsd:sequence&gt;
286  *           &lt;xsd:element name="multicast" type="jxta:MulticastAddress"
287  *             minOccurs="0" maxOccurs="unbounded"/&gt;
288  *         &lt;/xsd:sequence&gt;
289  *       &lt;/xsd:extension&gt;
290  *     &lt;/xsd:simpleContent&gt;
291  *   &lt;/xsd:complexType&gt;
292  *
293  *   &lt;xsd:complexType name="TransportAddress"&gt;
294  *     &lt;xsd:simpleContent&gt;
295  *       &lt;xsd:extension base="xsd:anyURI"&gt;
296  *         &lt;xsd:attribute name="range" type="xsd:integer"&gt;
297  *           &lt;xsd:restrictive&gt;
298  *             &lt;xsd:minInclusive value="0"/&gt;
299  *             &lt;xsd:maxInclusive value="65535"/&gt;
300  *           &lt;/xsd:restrictive&gt;
301  *         &lt;/xsd:attribute&gt;
302  *       &lt;/xsd:extension&gt;
303  *     &lt;/xsd:simpleContent&gt;
304  *   &lt;/xsd:complexType&gt;
305  *
306  *   &lt;xsd:complextType name="MulticastAddress"&gt;
307  *     &lt;xsd:simpleContent&gt;
308  *       &lt;xsd:extension base="xsd:anyURI"&gt;
309  *         &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
310  *           default="true"/&gt;
311  *         &lt;xsd:attribute name="size" type="xsd:nonNegativeInteger" use="optional"
312  *           default="16384"/&gt;
313  *         &lt;/xsd:extension&gt;
314  *       &lt;/xsd:simpleContent&gt;
315  *   &lt;/xsd:complextType&gt;
316  *
317  *   &lt;xsd:complexType name="PublicAddress"&gt;
318  *     &lt;xsd:attribute name="exclusive" type="xsd:boolean" use="optional"
319  *       default="false"/&gt;
320  *   &lt;/xsd:complexType&gt;
321  *
322  *   &lt;xsd:complexType name="RendezVousService"&gt;
323  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
324  *       default="false"/&gt;
325  *     &lt;xsd:sequence&gt;
326  *       &lt;xsd:element name="autoStart" type="jxta:AutoStart" minOccurs="0"
327  *         maxOccurs="1" default="0"/&gt;
328  *     &lt;/xsd:sequence&gt;
329  *   &lt;/xsd:complexType&gt;
330  *
331  *   &lt;xsd:complexType name="RelayService"&gt;
332  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
333  *       default="false"/&gt;
334  *     &lt;xsd:attribute name="queueSize" type="xsd:nonNegativeInterger"
335  *       use="optional" default="100"/&gt;
336  *     &lt;xsd:sequence&gt;
337  *       &lt;xsd:element name="incoming" type="jxta:ServiceEndpoint" minOccurs="0"
338  *         maxOccurs="1"/&gt;
339  *       &lt;xsd:element name="outgoing" type="jxta:ServiceEndpoint" minOccurs="0"
340  *         maxOccurs="1"/&gt;
341  *     &lt;/xsd:sequence&gt;
342  *   &lt;/xsd:complexType&gt;
343  *
344  *   &lt;xsd:complexType name="EndpointService"&gt;
345  *     &lt;xsd:attribute name="queueSize" type="xsd:positiveInteger" use="optional"
346  *       default="20"/&gt;
347  *   &lt;/xsd:complexType&gt;
348  *
349  *   &lt;xsd:complexType name="ProxyService"&gt;
350  *     &lt;xsd:simpleContent&gt;
351  *       &lt;xsd:extension base="xsd:anyURI"&gt;
352  *        &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
353  *          default="false"/&gt;
354  *       &lt;/xsd:extension&gt;
355  *     &lt;/xsd:simpleContent&gt;
356  *   &lt;/xsd:complexType&gt;
357  *
358  *   &lt;xsd:element name="AutoStart"&gt;
359  *     &lt;xsd:simpleContent&gt;
360  *       &lt;xsd:extension base="nonNegativeInteger"&gt;
361  *         &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
362  *           default="false"/&gt;
363  *
364  *   &lt;xsd:complexType name="Optimzer"&gt;
365  *     &lt;xsd:attribute name="class" type="xsd:string" use="required"/&gt;
366  *     &lt;xsd:sequence&gt;
367  *        &lt;xsd:element name="property" type="jxta:Property" minOccurs="0"
368  *          maxOccurs="unbounded"/&gt;
369  *     &lt;/xsd:complexType&gt;
370  *   &lt;/xsd:complexType&gt
371  *
372  *   &lt;xsd:complexType name="Property"&gt;
373  *     &lt;xsd:simpleContent&gt;
374  *       &lt;xsd:extension base="xsd:string"&gt;
375  *         &lt;xsd:attribute name="name" type="xsd:string" use="required"/&gt;
376  *       &lt;/xsd:extension&gt;
377  *     &lt;/xsd:simpleContent&gt;
378  *   &lt;/xsd:complexType&gt
379  *
380  *       &lt;/xsd:extension&gt;
381  *     &lt;/xsd:simpleContent&gt;
382  *   &lt;/xsd:element&gt;
383  *
384  *   &lt;xsd:complexType name="ServiceEndpoint"&gt;
385  *     &lt;xsd:attribute name="enabled" type="xsd:boolean" use="optional"
386  *       default="false"/&gt;
387  *     &lt;xsd:attribute name="maximum" type="xsd:positiveInteger" use="optional"
388  *       default="1"/&gt;
389  *     &lt;xsd:attribute name="lease" type="xsd:positiveInteger" use="optional"
390  *       default="7200000"/&gt;
391  *   &lt;/xsd:complexType&gt;
392  *
393  *   &lt;xsd:complexType name="Optimizer"&gt;
394  *     &lt;xsd:attribute name="class" type="xsd:string" use="required"/&gt;
395  *     &lt;xsd:sequence&gt;
396  *        &lt;xsd:element name="property" type="jxta:Property" minOccurs="0"
397  *          maxOccurs="unbounded"/&gt;
398  *     &lt;/xsd:complexType&gt;
399  *   &lt;/xsd:complexType&gt
400  *
401  *   &lt;xsd:complexType name="Property"&gt;
402  *     &lt;xsd:simpleContent&gt;
403  *       &lt;xsd:extension base="xsd:string"&gt;
404  *         &lt;xsd:attribute name="name" type="xsd:string" use="required"/&gt;
405  *       &lt;/xsd:extension&gt;
406  *     &lt;/xsd:simpleContent&gt;
407  *   &lt;/xsd:complexType&gt
408  *
409  * &lt;/xsd:schema&gt;
410  *  </pre>
411  *
412  * @author     james todd [gonzo at jxta dot org]
413  * @version    $Id: Profile.java,v 1.23 2004/10/30 02:22:11 gonzo Exp $
414  */
415 
416 public class Profile {
417 
418     /**
419      *  Prototypical <em>edge peer</em> , i.e. no RendezVous or Relay service.
420      */
421     public final static Profile EDGE = new Profile("edge.xml");
422     /**
423      *  Prototypical Tcp <em>edge peer</em> , i.e. no RendezVous or Relay service.
424      */
425     public final static Profile EDGE_TCP = new Profile("edgeTcp.xml");
426     /**
427      *  Prototypical Http <em>edge peer</em> , i.e. no RendezVous or Relay service.
428      */
429     public final static Profile EDGE_HTTP = new Profile("edgeHttp.xml");
430     /**
431      *  Prototypical <em>super peer</em> , i.e. provisions RendezVous and Relay
432      *  services.
433      */
434     public final static Profile SUPER = new Profile("super.xml");
435     /**
436      *  Prototypical <em>TCP super peer</em> , i.e. provisions TCP RendezVous
437      *  and Relay services.
438      */
439     public final static Profile SUPER_TCP = new Profile("superTcp.xml");
440     /**
441      *  Prototypical <em>HTTP super peer</em> , i.e. provisions HTTP RendezVous
442      *  and Relay services.
443      */
444     public final static Profile SUPER_HTTP = new Profile("superHttp.xml");
445     /**
446      *  Prototypical <em>rendezVous peer</em> , i.e. provisions RendezVous
447      *  services
448      */
449     public final static Profile RENDEZVOUS = new Profile("rendezVous.xml");
450     /**
451      *  Prototypical <em>TCP rendezVous peer</em> , i.e. provisions TCP
452      *  RendezVous services
453      */
454     public final static Profile RENDEZVOUS_TCP = new Profile("rendezVousTcp.xml");
455     /**
456      *  Prototypical <em>HTTP rendezVous peer</em> , i.e. provisions HTTP
457      *  RendezVous services
458      */
459     public final static Profile RENDEZVOUS_HTTP = new Profile("rendezVousHttp.xml");
460     /**
461      *  Prototypical <em>relay peer</em> , i.e. provisions Relay services.
462      */
463     public final static Profile RELAY = new Profile("relay.xml");
464     /**
465      *  Prototypical <em>TCP relay peer</em> , i.e. provisions TCP Relay
466      *  services.
467      */
468     public final static Profile RELAY_TCP = new Profile("relayTcp.xml");
469     /**
470      *  Prototypical <em>HTTP relay peer</em> , i.e. provisions HTTP Relay
471      *  services.
472      */
473     public final static Profile RELAY_HTTP = new Profile("relayHttp.xml");
474     /**
475      *  Local/loopback/standalone
476      *  services.
477      */
478     public final static Profile LOCAL = new Profile("local.xml");
479     /**
480      *  Default profile.
481      *
482      * @see    #EDGE
483      */
484     public final static Profile DEFAULT = EDGE;
485 
486 
487     /**
488      *  Container for resource keys in the form of XPath expressions.
489      *
490      * @author     james todd [gonzo at jxta dot org]
491      * @version    ${Id}
492      */
493     public static class Key {
494 
495         /**
496          *  Root path: {@value}
497          */
498         public final static String JXTA = "/jxta";
499 
500         /**
501          *  Peer: {@value}
502          */
503         public final static String PEER = JXTA + "/peer";
504         /**
505          *  Peer name: {@value}
506          */
507         public final static String PEER_NAME = PEER + "/@name";
508         /**
509          *  Peer ID: {@value}
510          */
511         public final static String PEER_ID = PEER + "/@id";
512         /**
513          *  Peer description: {@value}
514          */
515         public final static String PEER_DESCRIPTOR = PEER + "/@descriptor";
516         /**
517          *  Peer home: {@value}
518          */
519         public final static String HOME_ADDRESS = PEER + "/@home";
520         /**
521          *  Peer security: {@value}
522          */
523         public final static String SECURITY = PEER + "/security";
524         /**
525          *  Peer security enabler: {@value}
526          */
527         public final static String SECURITY_IS_ENABLED = SECURITY + "/@enabled";
528         /**
529          *  Peer principal: {@value}
530          */
531         public final static String PRINCIPAL = SECURITY + "/@principal";
532         /**
533          *  Peer root certificate: {@value}
534          */
535         public final static String ROOT_CERTIFICATE = PEER + "/rootCert";
536         /**
537          *  Peer root certificate addes: {@value}
538          */
539         public final static String ROOT_CERTIFICATE_ADDRESS = ROOT_CERTIFICATE +
540                 "/@address";
541         /**
542          *  Trace: {@value}
543          */
544         public final static String TRACE = PEER + "/@trace";
545         /**
546          *  Peer Description: {@value}
547          */
548         public final static String PEER_DESCRIPTION = PEER + "/description";
549         /**
550          *  Peer proxy address: {@value}
551          */
552         public final static String PEER_PROXY_ADDRESS = PEER + "/proxy";
553         /**
554          *  Network: {@value}
555          */
556         public final static String NETWORK = JXTA + "/network";
557         /**
558          *  RendezVous: {@value}
559          */
560         public final static String RENDEZVOUS = NETWORK + "/rendezVous";
561         /**
562          *  RendezVous boostrap: {@value}
563          */
564         public final static String RENDEZVOUS_BOOTSTRAP_ADDRESS = RENDEZVOUS +
565                 "/@bootstrap";
566         /**
567          *  RendezVous discovery enabler: {@value}
568          */
569         public final static String RENDEZVOUS_DISCOVERY_IS_ENABLED = RENDEZVOUS +
570                 "/@discovery";
571         /**
572          *  RendezVous address: {@value}
573          */
574         public final static String RENDEZVOUS_ADDRESS = RENDEZVOUS +
575                 "/address";
576         /**
577          *  Relay: {@value}
578          */
579         public final static String RELAYS = NETWORK + "/relays";
580         /**
581          *  Relay bootstrap enabler: {@value}
582          */
583         public final static String RELAYS_BOOTSTRAP_ADDRESS = RELAYS + "/@bootstrap";
584         /**
585          *  Relay discovery enabler: {@value}
586          */
587         public final static String RELAYS_DISCOVERY_IS_ENABLED = RELAYS + "/@discovery";
588         /**
589          *  Relay address: {@value}
590          */
591         public final static String RELAYS_ADDRESS = RELAYS + "/address";
592         /**
593          *  Reflection: {@value}
594          *
595          * @deprecated moved to {@link net.jxta.ext.config.optimizers.RelayOptimizer RelayOptimizer}
596          */
597         public final static String REFLECTION = NETWORK + "/reflection";
598         /**
599          *  Reflection bootstrap enabler: {@value}
600          *
601          * @deprecated move to {@link net.jxta.ext.config.optimizers.RelayOptimizer RelayOptimizer}
602          */
603         public final static String REFLECTION_BOOTSTRAP_ADDRESS = REFLECTION + "/@bootstrap";
604         /**
605          *  Transport: {@value}
606          */
607         public final static String TRANSPORT = JXTA + "/transport";
608         /**
609          *  Tcp: {@value}
610          */
611         public final static String TCP = TRANSPORT + "/tcp";
612         /**
613          *  Tcp enabler: {@value}
614          */
615         public final static String TCP_IS_ENABLED = TCP + "/@enabled";
616         /**
617          *  Tcp incoming: {@value}
618          */
619         public final static String TCP_INCOMING = TCP + "/incoming";
620         /**
621          *  Tcp incoming enabler: {@value}
622          */
623         public final static String TCP_INCOMING_IS_ENABLED = TCP_INCOMING +
624                 "/@enabled";
625         /**
626          *  Tcp outgoing: {@value}
627          */
628         public final static String TCP_OUTGOING = TCP + "/outgoing";
629         /**
630          *  Tcp outgoing enabler: {@value}
631          */
632         public final static String TCP_OUTGOING_IS_ENABLED = TCP +
633                 "/@enabled";
634         /**
635          *  Tcp address: {@value}
636          */
637         public final static String TCP_ADDRESS = TCP + "/address";
638         /**
639          *  Tcp port range: {@value}
640          */
641         public final static String TCP_PORT_RANGE = TCP_ADDRESS +
642                 "/@range";
643         /**
644          *  Tcp public address: {@value}
645          */
646         public final static String TCP_PUBLIC_ADDRESS = TCP +
647                 "/publicAddress";
648         /**
649          *  Tcp public address exclusive enabler: {@value}
650          */
651         public final static String TCP_PUBLIC_ADDRESS_EXCLUSIVE_IS_ENABLED =
652                 TCP_PUBLIC_ADDRESS + "/@exclusive";
653         /**
654          *  Tcp proxy address: {@value}
655          */
656         public final static String TCP_PROXY_ADDRESS = TCP + "/proxy";
657         /**
658          *  Tcp proxy enabler: {@value}
659          */
660         public final static String TCP_PROXY_IS_ENABLED = TCP_PROXY_ADDRESS +
661                 "/@enabled";
662         /**
663          *  Multicast: {@value}
664          */
665         public final static String MULTICAST = TCP_ADDRESS + "/multicast";
666         /**
667          *  Multicast enabler: {@value}
668          */
669         public final static String MULTICAST_IS_ENABLED = MULTICAST + "/@enabled";
670         /**
671          *  Multicast size: {@value}
672          */
673         public final static String MULTICAST_SIZE = MULTICAST + "/@size";
674         /**
675          *  Http: {@value}
676          */
677         public final static String HTTP = TRANSPORT + "/http";
678         /**
679          *  Http enabler: {@value}
680          */
681         public final static String HTTP_IS_ENABLED = HTTP + "/@enabled";
682         /**
683          *  Http incoming: {@value}
684          */
685         public final static String HTTP_INCOMING = HTTP + "/incoming";
686         /**
687          *  Http incoming enabler: {@value}
688          */
689         public final static String HTTP_INCOMING_IS_ENABLED =
690                 HTTP_INCOMING + "/@enabled";
691         /**
692          *  Http outgoing: {@value}
693          */
694         public final static String HTTP_OUTGOING = HTTP + "/outgoing";
695         /**
696          *  Http outgoing enabler: {@value}
697          */
698         public final static String HTTP_OUTGOING_IS_ENABLED =
699                 HTTP_OUTGOING + "/@enabled";
700         /**
701          *  Http address: {@value}
702          */
703         public final static String HTTP_ADDRESS = HTTP + "/address";
704         /**
705          *  Http port range: {@value}
706          */
707         public final static String HTTP_PORT_RANGE = HTTP_ADDRESS +
708                 "/@range";
709         /**
710          *  Http public address: {@value}
711          */
712         public final static String HTTP_PUBLIC_ADDRESS = HTTP +
713                 "/publicAddress";
714         /**
715          *  Http public address exclusive enabler: {@value}
716          */
717         public final static String HTTP_PUBLIC_ADDRESS_EXCLUSIVE_IS_ENABLED =
718                 HTTP_PUBLIC_ADDRESS + "/@exclusive";
719         /**
720          *  Http proxy: {@value}
721          */
722         public final static String HTTP_PROXY_ADDRESS = HTTP + "/proxy";
723         /**
724          *  Http enabler: {@value}
725          */
726         public final static String HTTP_PROXY_IS_ENABLED = HTTP_PROXY_ADDRESS +
727                 "/@enabled";
728         /**
729          *  Service: {@value}
730          */
731         public final static String SERVICE = JXTA + "/service";
732         /**
733          *  RendezVous service: {@value}
734          */
735         public final static String RENDEZVOUS_SERVICE = SERVICE + "/rendezVous";
736         /**
737          *  RendezVous service enabler: {@value}
738          */
739         public final static String RENDEZVOUS_SERVICE_IS_ENABLED =
740                 RENDEZVOUS_SERVICE + "/@enabled";
741         /**
742          *  RendezVous service auto start: {@value}
743          */
744         public final static String RENDEZVOUS_SERVICE_AUTO_START =
745                 RENDEZVOUS_SERVICE + "/autoStart";
746         /**
747          *  RendezVous service auto start enabler: {@value}
748          */
749         public final static String RENDEZVOUS_SERVICE_AUTO_START_IS_ENABLED =
750                 RENDEZVOUS_SERVICE + "/@enabled";
751         /**
752          *  Relay service: {@value}
753          */
754         public final static String RELAY_SERVICE = SERVICE + "/relay";
755         /**
756          *  Relay service enabler: {@value}
757          */
758         public final static String RELAY_SERVICE_IS_ENABLED = RELAY_SERVICE +
759                 "/@enabled";
760         /**
761          *  Relay service queue size: {@value}
762          */
763         public final static String RELAY_SERVICE_QUEUE_SIZE = RELAY_SERVICE +
764                 "/@queueSize";
765         /**
766          *  Relay service incoming: {@value}
767          */
768         public final static String RELAY_SERVICE_INCOMING = RELAY_SERVICE +
769                 "/incoming";
770         /**
771          *  Relay service incoming enabler: {@value}
772          */
773         public final static String RELAY_SERVICE_INCOMING_IS_ENABLED =
774                 RELAY_SERVICE_INCOMING + "/@enabled";
775         /**
776          *  Relay service incoming maximum connections: {@value}
777          */
778         public final static String RELAY_SERVICE_INCOMING_MAXIMUM =
779                 RELAY_SERVICE_INCOMING + "/@maximum";
780         /**
781          *  Relay service incoming lease: {@value}
782          */
783         public final static String RELAY_SERVICE_INCOMING_LEASE =
784                 RELAY_SERVICE_INCOMING + "/@lease";
785         /**
786          *  Relay service outgoing: {@value}
787          */
788         public final static String RELAY_SERVICE_OUTGOING = RELAY_SERVICE +
789                 "/outgoing";
790         /**
791          *  Relay service outgoing enabler: {@value}
792          */
793         public final static String RELAY_SERVICE_OUTGOING_IS_ENABLED =
794                 RELAY_SERVICE_OUTGOING + "/@enabled";
795         /**
796          *  Relay service outgoing maximum connections: {@value}
797          */
798         public final static String RELAY_SERVICE_OUTGOING_MAXIMUM =
799                 RELAY_SERVICE_OUTGOING + "/@maximum";
800         /**
801          *  Relay service outgoing lease: {@value}
802          */
803         public final static String RELAY_SERVICE_OUTGOING_LEASE =
804                 RELAY_SERVICE_OUTGOING + "/@lease";
805         /**
806          *  Endpoint: {@value}
807          */
808         public final static String ENDPOINT_SERVICE = SERVICE + "/endpoint";
809         /**
810          *  Endpoint outgoing queue size: {@value}
811          */
812         public final static String ENDPOINT_SERVICE_QUEUE_SIZE = ENDPOINT_SERVICE +
813                 "/@queueSize";
814         /**
815          *  Proxy service: {@value}
816          */
817         public final static String PROXY_SERVICE = SERVICE + "/proxy";
818         /**
819          *  Proxy enabler: {@value}
820          */
821         public final static String PROXY_SERVICE_IS_ENABLED = PROXY_SERVICE +
822                 "/@enabled";
823         /**
824          *  Configuration: {@value}
825          */
826         public final static String CONFIGURATION = JXTA + "/configuration";
827         /**
828          *  Optimizer: {@value}
829          */
830         public final static String CONFIGURATION_OPTIMIZER = CONFIGURATION +
831             "/optimizer";
832         /**
833          *  Optmizer Class: {@value}
834          */
835         public final static String CONFIGURATION_OPTIMIZER_CLASS =
836             CONFIGURATION_OPTIMIZER + "/@class";
837         /**
838          *  Optmizer Property Name: {@value}
839          */
840         public final static String OPTIMIZER_PROPERTY_NAME = CONFIGURATION_OPTIMIZER +
841             "[@class=''{0}'']" + "/property/@name";
842         /**
843          *  Optmizer Property Value: {@value}
844          */
845         public final static String OPTIMIZER_PROPERTY_VALUE= CONFIGURATION_OPTIMIZER +
846         "[@class=''{0}'']" + "/property[@name=''{1}'']";
847                 
848         /**
849          *  Constructor for the Key object
850          */
851         private Key() { }
852     }
853 
854     /**
855      *  Description of the Field
856      */
857     protected final static Profile SEED = new Profile("seed.xml");
858 
859     private final static String RESOURCE_BASE = "resources/";
860     private final static Logger LOG =
861             Logger.getLogger(Profile.class.getName());
862 
863     private Resource profile = new Resource();
864 
865     private static HashMap profiles;
866 
867     static {
868         profiles = new HashMap();
869 
870         profiles.put("Default", DEFAULT);
871         profiles.put("Edge", EDGE);
872         profiles.put("Edge (Tcp)", EDGE_TCP);
873         profiles.put("Edge (Http)", EDGE_HTTP);
874         profiles.put("Super", SUPER);
875         profiles.put("Super (Tcp)", SUPER_TCP);
876         profiles.put("Super (Http)", SUPER_HTTP);
877         profiles.put("Rendezvous", RENDEZVOUS);
878         profiles.put("Rendezvous (Tcp)", RENDEZVOUS_TCP);
879         profiles.put("Rendezvous (Http)", RENDEZVOUS_HTTP);
880         profiles.put("Relay", RELAY);
881         profiles.put("Relay (Tcp)", RELAY_TCP);
882         profiles.put("Relay (Http)", RELAY_HTTP);
883         profiles.put("Local", LOCAL);
884 
885     }
886 
887     /**
888      *  Instantiate a <code>Profile</code> for the named profile.
889      *
890      * @param  profile  profile name
891      * @return   associated Profile object
892      */
893     public static Profile get(String profile) {
894         profile = profile != null ? profile.trim() : profile;
895         
896         Profile p = (Profile) profiles.get(profile);
897 
898         return p != null ? p : DEFAULT;
899     }
900 
901 
902     /**
903      *  Get unsorted list of names for available profiles 
904      *
905      * @return    java.util.Iterator with profile names
906      */
907     public static Iterator getProfiles() {
908         return profiles.keySet().iterator();
909     }
910 
911     /**
912      * Add a new, named profile to the list of available profiles
913      *  
914      * @param name      profile name
915      * @param profile   profile to be added
916      */
917     public static void add(String name, Profile profile) {
918         if (null != name && null != profile) {
919             profiles.put(name, profile);
920         }               
921     }
922 
923     /**
924      *  Constructor for the Profile object.
925      *
926      * @param  profile  profile location
927      */
928     public Profile(URL profile) {
929         try {
930             this.profile.load(profile);
931         } catch (ResourceNotFoundException rnfe) {
932             if (LOG.isEnabledFor(Level.ERROR)) {
933                 LOG.error("invalid resource location", rnfe);
934             }
935         }
936     }
937     
938     public Profile(InputStream is) {
939          try {
940             this.profile.load(is);
941         } catch (ResourceNotFoundException rnfe) {
942             if (LOG.isEnabledFor(Level.ERROR)) {
943                 LOG.error("invalid resource format", rnfe);
944             }
945         }
946     }
947 
948 
949     /**
950      *  Gets the profile attribute of the Profile object
951      *
952      * @return    The profile value
953      */
954     protected Resource getProfile() {
955         return this.profile;
956     }
957 
958 
959     /**
960      *  Constructor for the Profile object
961      *
962      * @param  profile  Description of the Parameter
963      */
964     private Profile(String profile) {
965         try {
966             this.profile.load(RESOURCE_BASE + profile, Profile.class);
967         } catch (ResourceNotFoundException rnfe) {
968             if (LOG.isEnabledFor(Level.ERROR)) {
969                 LOG.error("invalid resource location", rnfe);
970             }
971         }
972     }
973 
974 }
975