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