KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > emb > ProtocolConstraints


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license. See terms of license at gnu.org.
5  */

6
7 package javax.emb;
8
9 import java.io.Serializable;
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.Map;
14
15 /**
16  * This class models constraints that restrict the selection of protocol
17  * servers, like stream servers. Instances can contain multiple kinds of
18  * constraints. Constraints come as type/value pairs, with the type defining
19  * the type of constraint and the value giving the actual constraint data “
20  * similar to a dictionary. Protocol constraints are used when publishing media
21  * for a given protocol, see MediaEntityLocalHome.publish(’) for reference. As
22  * streaming constraints have to be transferred over machine boundaries, the
23  * class implements <code>java.io.Serializable</code>.
24  *
25  * <p>This specification covers two types of constraint as binding for all
26  * implementations:
27  *
28  * <ul><li>"CLIENT_TYPE" constrains the protocol server selection indirectly
29  * by defining an array of protocol client types (Strings) that are running on
30  * a client machine. Protocol servers are only eligible for selection during
31  * publish operations if they at least support one of the given client types.
32  * Also, the metadata generated during publish requests must be suitable for
33  * one of these clients. Standardized values for this constraint type are:
34  * "Quicktime" for Apple Quicktime players, "VideoCharger" for IBM VideoCharger
35  * players, "Windows Media" for Microsoft Windows Media players, "RealPlayer"
36  * for RealNetworks players. Additional client types may be added to this list
37  * in future releases of this specification.</li>
38  *
39  * <li>"SERVER_TYPE" constrains the protocol server selection directly by
40  * defining an array of protocol server types (Strings) eligible for selection
41  * during publish requests. Standardized values for this constraint type are:
42  * ”Quicktime" for Apple Quicktime servers, "VideoCharger" for IBM VideoCharger
43  * servers, "Windows Media" for Microsoft Windows Media services, "RealSystem"
44  * for RealNetworks servers. Additional protocol server types may be added to
45  * this list in future releases of this specification.</li></ul>
46  *
47  * @version <tt>$Revision: 1.4 $</tt>
48  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo
49  * Argüello</a>
50  */

51 public final class ProtocolConstraints implements Serializable
52 {
53    public final static String CLIENT_TYPE = "CLIENT_TYPE";
54    public final static String SERVER_TYPE = "SERVER_TYPE";
55
56    private final Map constraints = Collections.synchronizedMap(new HashMap());
57
58    /**
59     * Returns the value of the constraint defined by the given type, or <code>null</code>
60     * if said constraint is not present.
61     *
62     * @param type the constraint type.
63     * @return the constraint value.
64     * @throws javax.emb.NullPointerException if the given type is <code>null</code>.
65     */

66    public Object getConstraint(String type)
67    {
68       if (type == null)
69       {
70          throw new NullPointerException();
71       }
72
73       return constraints.get(type);
74    }
75
76    /**
77     * Alters the value of the constraint defined by the given type to the given
78     * value. Passing the constraint value <code>null</code> removes a
79     * constraint type from the receiver if present.
80     *
81     * @param type the constraint type.
82     * @param value the constraint value.
83     * @throws java.lang.NullPointerException if the given type is <code>null</code>.
84     * @throws java.lang.IllegalArgumentException if the constraint type given
85     * is either "CLIENT_TYPE" or "SERVER_TYPE", and the value given is
86     * not an array of Strings.
87     *
88     */

89    public void setConstraint(String type, Object value)
90    {
91       if (type == null)
92       {
93          throw new NullPointerException();
94       }
95
96       if ((type.equals(CLIENT_TYPE) || type.equals(SERVER_TYPE))
97          && !(value instanceof String[]))
98       {
99          throw new IllegalArgumentException();
100       }
101
102       constraints.put(type, value);
103    }
104
105    /**
106     * Returns the receiver's constraint types as an array of Strings.
107     *
108     * @return an array of constraint types.
109     */

110    public String[] getConstraintTypes()
111    {
112       Collection keySet = constraints.keySet();
113       return (String[]) keySet.toArray(new String[keySet.size()]);
114    }
115 }
Popular Tags