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 * <?xml version="1.0" encoding="utf-8" standalone="no"?>
84 *
85 * <!--
86 * <!DOCTYPE xsd:schema SYSTEM "http://www.w3c.org/2001/XMLSchema.dtd">
87 * -->
88 *
89 * <xsd:schema xmlns:jxta="http://www.jxta.org/net/jxta/ext/config"
90 * xmlns:xsd="http://www.w3c.org/2001/XMLSchema.dtd">
91 *
92 * <xsd:annotation>
93 * <xsd:documentation xml:lang="en">
94 * JXTA Configuration
95 *
96 * see http://www.jxta.org for more info.
97 * </xsd:documentation>
98 * </xsd:annotation>
99 *
100 * <xsd:complexType name="jxta">
101 * <xsd:sequence>
102 * <xsd:element name="peer" type="jxta:Peer" minOccurs="1" maxOccurs="1"/>
103 * <xsd:element name="network" type="jxta:Network" minOccurs="1"
104 * maxOccurs="1"/>
105 * <xsd:element name="transport" type="jxta:Transport" minOccurs="1"
106 * maxOccurs="1"/>
107 * <xsd:element name="service" type="jxta:Service" minOccurs="1"
108 * maxOccurs="1"/>
109 * </xsd:sequence>
110 * </xsd:complexType>
111 *
112 * <xsd:complexType name="Peer">
113 * <xsd:attribute name="name" type="xsd:string" use="optional"/>
114 * <xsd:attribute name="id" type="jxta:PeerID" use="optional"/>
115 * <xsd:attribute name="descriptor" type="xsd:string" use="optional"/>
116 * <xsd:attribute name="home" type="xsd:anyURI" use="optional"
117 * default="file://${user.home}/.jxta"/>
118 * <xsd:attribute name="trace" type="jxta:Trace" use="optional"
119 * default="user default"/>
120 * <xsd:sequence>
121 * <xsd:element name="description" type="jxta:Description" minOccurs="0"
122 * maxOccurs="unbounded"/>
123 * <xsd:element name="security" type="jxta:Security" minOccurs="0"
124 * maxOccurs="1"/>
125 * <xsd:element name="rootCert" type="jxta:RootCert" minOccurs="0"
126 * maxOccurs="1"/>
127 * <xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
128 * maxOccurs="1"/>
129 * </xsd:sequence>
130 * </xsd:complexType>
131 *
132 * <xsd:complexType name="Network">
133 * <xsd:sequence>
134 * <xsd:element name="rendezVous" type="jxta:RendezVous" minOccurs="0"
135 * maxOccurs="1"/>
136 * <xsd:element name="relays" type="jxta:Relays" minOccurs="0" maxOccurs="1"/>
137 * </xsd:sequence>
138 * </xsd:complexType>
139 *
140 * <xsd:complexType name="Transport">
141 * <xsd:sequence>
142 * <xsd:element name="tcp" type="Tcp" minOccurs="0" maxOccurs="unbounded"/>
143 * <xsd:element name="http" type="Http" minOccurs="0" maxOccurs="unbounded"/>
144 * </xsd:sequence>
145 * </xsd:complexType>
146 *
147 * <xsd:complexType name="Service">
148 * <xsd:sequence>
149 * <xsd:element name="rendezVous" type="jxta:RendezVousService" minOccurs="0"
150 * maxOccurs="1"/>
151 * <xsd:element name="relay" type="jxta:RelayService" minOccurs="0"
152 * maxOccurs="1"/>
153 * <xsd:element name="endpoint" type="jxta:EndpointService" minOccurs="0"
154 * maxOccurs="1"/>
155 * <xsd:element name="proxy" type="jxta:ProxyService" minOccurs="0"
156 * maxOccurs="1"/>
157 * </xsd:sequence>
158 * <xsd:complextType name="Configuration">
159 * <xsd:sequence>
160 * <xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
161 * maxOccurs="unbounded"/>
162 * </xsd:sequence>
163 * </xsd:complexType>
164 *
165 * <xsd:complextType name="Configuration">
166 * <xsd:sequence>
167 * <xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
168 * maxOccurs="unbounded"/>
169 * </xsd:sequence>
170 * </xsd:complexType>
171 *
172 * </xsd:complexType>
173 *
174 * <xsd:complextType name="Configuration">
175 * <xsd:sequence>
176 * <xsd:element name="optimizer" type="jxta:Optimizer" minOccurs="0"
177 * maxOccurs="unbounded"/>
178 * </xsd:sequence>
179 * </xsd:complexType>
180 *
181 * <xsd:simpleType name="Trace">
182 * <xsd:restriction base="xsd:string">
183 * <xsd:enumeration value="error"/>
184 * <xsd:enumeration value="warn"/>
185 * <xsd:enumeration value="info"/>
186 * <xsd:enumeration value="debug"/>
187 * <xsd:enumeration value="user default"/>
188 * </xsd:restriction>
189 * </xsd:simpleType>
190 *
191 * <xsd:complextType name="Description">
192 * <xsd:all>
193 * </xsd:all>
194 * </xsd:complextType>
195 *
196 * <xsd:complexType name="Security">
197 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
198 * default="true"/>
199 * <xsd:attribute name="principal" type="xsd:string" use="required"/>
200 * </xsd:complexType>
201 *
202 * <xsd:complexType name="RootCert">
203 * <xsd:simpleContext>
204 * <xsd:extension base="xsd:string">
205 * <xsd:attribute name="address" type="xsd:anyURI" use="optional"/>
206 * </xsd:extension>
207 * </xsd:simpleContext>
208 * </xsd:complexType>
209 *
210 * <xsd:complexType name="ProxyAddress">
211 * <xsd:simpleContent>
212 * <xsd:extension base="xsd:anyURI">
213 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
214 * default="false"/>
215 * </xsd:extension>
216 * </xsd:simpleContent>
217 * </xsd:complexType>
218 *
219 * <xsd:complexType name="RendezVous">
220 * <xsd:attribute name="bootstrap" type="xsd:anyURI" use="optional"/>
221 * <xsd:attribute name="discovery" type="xsd:boolean" use="optional"
222 * default="true"/>
223 * <xsd:element name="address" type="jxta:Address" minOccurs="0"
224 * maxOccurs="unbounded" default="://"/>
225 * </xsd:complexType>
226 *
227 * <xsd:complexType name="Relays">
228 * <xsd:attribute name="bootstrap" type="xsd:anyURI" use="optional"/>
229 * <xsd:attribute name="discovery" type="xsd:boolean" use="optional"
230 * default="true"/>
231 * <xsd:element name="address" type="jxta:Address" minOccurs="0"
232 * maxOccurs="unbounded" default="//:"/>
233 * </xsd:complexType>
234 *
235 * <xsd:element name="Address" type="xsd:anyURI"/>
236 *
237 * <xsd:complexType name="Tcp">
238 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
239 * default="true"/>
240 * <xsd:sequence>
241 * <xsd:element name="incoming" type="jxta:TransportEndpoint" minOccurs="0"
242 * maxOccurs="1"/>
243 * <xsd:element name="outgoing" type="jxta:TransportEndpoint" minOccurs="0"
244 * maxOccurs="1"/>
245 * <xsd:element name="TcpAddress" type="TcpAddress" minOccurs="0"
246 * maxOccurs="unbounded"/>
247 * <xsd:element name="publicAddress" type="jxta:PublicAddress" minOccurs="0"
248 * maxOccurs="unbounded" default="http://:"/>
249 * <xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
250 * maxOccurs="1"/>
251 * </xsd:sequence>
252 * </xsd:complexType>
253 *
254 * <xsd:complexType name="Http">
255 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
256 * default="true"/>
257 * <xsd:sequence>
258 * <xsd:element name="incoming" type="jxta:TransportEndpoint" minOccurs="0"
259 * maxOccurs="1"/>
260 * <xsd:element name="outgoing" type="jxta:TransportEndpoint" minOccurs="0"
261 * maxOccurs="1"/>
262 * <xsd:element name="address" type="jxta:TransportAddress" minOccurs="0"
263 * maxOccurs="unbounded" default="http://:"/>
264 * <xsd:element name="publicAddress" type="jxta:PublicAddress" minOccurs="0"
265 * maxOccurs="unbounded" default="http://:"/>
266 * <xsd:element name="proxy" type="jxta:ProxyAddress" minOccurs="0"
267 * maxOccurs="1"/>
268 * </xsd:sequence>
269 * </xsd:complexType>
270 *
271 * <xsd:complexType name="TransportEndpoint">
272 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
273 * default="false"/>
274 * </xsd:complexType>
275 *
276 * <xsd:complexType name="TcpAddress">
277 * <xsd:simpleContent>
278 * <xsd:extension bae="xsd:anyURI">
279 * <xsd:attribute name="range" type="xsd:integer">
280 * <xsd:restrictive>
281 * <xsd:minInclusive value="0"/>
282 * <xsd:maxInclusive value="65535"/>
283 * </xsd:restrictive>
284 * </xsd:attribute>
285 * <xsd:sequence>
286 * <xsd:element name="multicast" type="jxta:MulticastAddress"
287 * minOccurs="0" maxOccurs="unbounded"/>
288 * </xsd:sequence>
289 * </xsd:extension>
290 * </xsd:simpleContent>
291 * </xsd:complexType>
292 *
293 * <xsd:complexType name="TransportAddress">
294 * <xsd:simpleContent>
295 * <xsd:extension base="xsd:anyURI">
296 * <xsd:attribute name="range" type="xsd:integer">
297 * <xsd:restrictive>
298 * <xsd:minInclusive value="0"/>
299 * <xsd:maxInclusive value="65535"/>
300 * </xsd:restrictive>
301 * </xsd:attribute>
302 * </xsd:extension>
303 * </xsd:simpleContent>
304 * </xsd:complexType>
305 *
306 * <xsd:complextType name="MulticastAddress">
307 * <xsd:simpleContent>
308 * <xsd:extension base="xsd:anyURI">
309 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
310 * default="true"/>
311 * <xsd:attribute name="size" type="xsd:nonNegativeInteger" use="optional"
312 * default="16384"/>
313 * </xsd:extension>
314 * </xsd:simpleContent>
315 * </xsd:complextType>
316 *
317 * <xsd:complexType name="PublicAddress">
318 * <xsd:attribute name="exclusive" type="xsd:boolean" use="optional"
319 * default="false"/>
320 * </xsd:complexType>
321 *
322 * <xsd:complexType name="RendezVousService">
323 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
324 * default="false"/>
325 * <xsd:sequence>
326 * <xsd:element name="autoStart" type="jxta:AutoStart" minOccurs="0"
327 * maxOccurs="1" default="0"/>
328 * </xsd:sequence>
329 * </xsd:complexType>
330 *
331 * <xsd:complexType name="RelayService">
332 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
333 * default="false"/>
334 * <xsd:attribute name="queueSize" type="xsd:nonNegativeInterger"
335 * use="optional" default="100"/>
336 * <xsd:sequence>
337 * <xsd:element name="incoming" type="jxta:ServiceEndpoint" minOccurs="0"
338 * maxOccurs="1"/>
339 * <xsd:element name="outgoing" type="jxta:ServiceEndpoint" minOccurs="0"
340 * maxOccurs="1"/>
341 * </xsd:sequence>
342 * </xsd:complexType>
343 *
344 * <xsd:complexType name="EndpointService">
345 * <xsd:attribute name="queueSize" type="xsd:positiveInteger" use="optional"
346 * default="20"/>
347 * </xsd:complexType>
348 *
349 * <xsd:complexType name="ProxyService">
350 * <xsd:simpleContent>
351 * <xsd:extension base="xsd:anyURI">
352 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
353 * default="false"/>
354 * </xsd:extension>
355 * </xsd:simpleContent>
356 * </xsd:complexType>
357 *
358 * <xsd:element name="AutoStart">
359 * <xsd:simpleContent>
360 * <xsd:extension base="nonNegativeInteger">
361 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
362 * default="false"/>
363 *
364 * <xsd:complexType name="Optimzer">
365 * <xsd:attribute name="class" type="xsd:string" use="required"/>
366 * <xsd:sequence>
367 * <xsd:element name="property" type="jxta:Property" minOccurs="0"
368 * maxOccurs="unbounded"/>
369 * </xsd:complexType>
370 * </xsd:complexType>
371 *
372 * <xsd:complexType name="Property">
373 * <xsd:simpleContent>
374 * <xsd:extension base="xsd:string">
375 * <xsd:attribute name="name" type="xsd:string" use="required"/>
376 * </xsd:extension>
377 * </xsd:simpleContent>
378 * </xsd:complexType>
379 *
380 * </xsd:extension>
381 * </xsd:simpleContent>
382 * </xsd:element>
383 *
384 * <xsd:complexType name="ServiceEndpoint">
385 * <xsd:attribute name="enabled" type="xsd:boolean" use="optional"
386 * default="false"/>
387 * <xsd:attribute name="maximum" type="xsd:positiveInteger" use="optional"
388 * default="1"/>
389 * <xsd:attribute name="lease" type="xsd:positiveInteger" use="optional"
390 * default="7200000"/>
391 * </xsd:complexType>
392 *
393 * <xsd:complexType name="Optimizer">
394 * <xsd:attribute name="class" type="xsd:string" use="required"/>
395 * <xsd:sequence>
396 * <xsd:element name="property" type="jxta:Property" minOccurs="0"
397 * maxOccurs="unbounded"/>
398 * </xsd:complexType>
399 * </xsd:complexType>
400 *
401 * <xsd:complexType name="Property">
402 * <xsd:simpleContent>
403 * <xsd:extension base="xsd:string">
404 * <xsd:attribute name="name" type="xsd:string" use="required"/>
405 * </xsd:extension>
406 * </xsd:simpleContent>
407 * </xsd:complexType>
408 *
409 * </xsd:schema>
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