xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/ServerAttribute.java (revision 69ed0c8ece2346b34605e2c9567c9f7b0dad5dc8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  ServerAttribute.java: Attribute created on the server side only.
28 //  Author:           James Kempf
29 //  Created On:       Thu Apr 23 08:53:49 1998
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Fri May  1 10:35:22 1998
32 //  Update Count:     9
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.io.*;
39 
40 /**
41  * The ServerAttribute class models attributes on the server side.
42  * The primary difference is that values substitute AttributeString
43  * objects for String objects, so attributes compare according to the
44  * rules of SLP matching rather than by string equality. Also,
45  * an AttributeString object for the id is included, for pattern
46  * matching against the id.
47  *
48  * @author James Kempf
49  */
50 
51 class ServerAttribute extends ServiceLocationAttribute {
52 
53     // The id as an attribute string.
54 
55     AttributeString idPattern = null;
56 
57     // Construct a new ServerAttribute object. Substitute AttributeString
58     //  objects for strings.
59 
60     ServerAttribute(String id_in, Vector values_in, Locale locale)
61 	throws IllegalArgumentException {
62 
63 	super(id_in, values_in);
64 
65 	idPattern = new AttributeString(id, locale);
66 
67 	// Substitute for string values.
68 
69 	if (values != null) {
70 	    Object o = values.elementAt(0);
71 
72 	    if (o instanceof String) {
73 
74 		int i, n = values.size();
75 
76 		for (i = 0; i < n; i++) {
77 		    String s = (String)values.elementAt(i);
78 		    AttributeString as = new AttributeString(s, locale);
79 
80 		    values.setElementAt(as, i);
81 
82 		}
83 	   }
84 	}
85     }
86 
87     // Construct a ServerAttribute object from a ServiceLocationAttribute
88     //  object.
89 
90     ServerAttribute(ServiceLocationAttribute attr, Locale locale) {
91 	this(attr.id, attr.getValues(), locale);
92 
93     }
94 
95     // Get values by changing the attribute string objects into strings.
96 
97     public Vector getValues() {
98 	Vector v = super.getValues();
99 
100 	if ((v != null) &&
101 	    (v.elementAt(0) instanceof AttributeString)) {
102 
103 	    int i, n = v.size();
104 
105 	    for (i = 0; i < n; i++) {
106 		v.setElementAt(v.elementAt(i).toString(), i);
107 
108 	   }
109 	}
110 
111 	return v;
112 
113     }
114 
115 }
116