xref: /onnv-gate/usr/src/lib/libslp/javalib/com/sun/slp/ServerAttribute.java (revision 7298:b69e27387f74)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7298SMark.J.Nelson@Sun.COM  * Common Development and Distribution License (the "License").
6*7298SMark.J.Nelson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate //  ServerAttribute.java: Attribute created on the server side only.
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Thu Apr 23 08:53:49 1998
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Fri May  1 10:35:22 1998
320Sstevel@tonic-gate //  Update Count:     9
330Sstevel@tonic-gate //
340Sstevel@tonic-gate 
350Sstevel@tonic-gate package com.sun.slp;
360Sstevel@tonic-gate 
370Sstevel@tonic-gate import java.util.*;
380Sstevel@tonic-gate import java.io.*;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /**
410Sstevel@tonic-gate  * The ServerAttribute class models attributes on the server side.
420Sstevel@tonic-gate  * The primary difference is that values substitute AttributeString
430Sstevel@tonic-gate  * objects for String objects, so attributes compare according to the
440Sstevel@tonic-gate  * rules of SLP matching rather than by string equality. Also,
450Sstevel@tonic-gate  * an AttributeString object for the id is included, for pattern
460Sstevel@tonic-gate  * matching against the id.
470Sstevel@tonic-gate  *
480Sstevel@tonic-gate  * @author James Kempf
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate class ServerAttribute extends ServiceLocationAttribute {
520Sstevel@tonic-gate 
530Sstevel@tonic-gate     // The id as an attribute string.
540Sstevel@tonic-gate 
550Sstevel@tonic-gate     AttributeString idPattern = null;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate     // Construct a new ServerAttribute object. Substitute AttributeString
580Sstevel@tonic-gate     //  objects for strings.
590Sstevel@tonic-gate 
ServerAttribute(String id_in, Vector values_in, Locale locale)600Sstevel@tonic-gate     ServerAttribute(String id_in, Vector values_in, Locale locale)
610Sstevel@tonic-gate 	throws IllegalArgumentException {
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	super(id_in, values_in);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	idPattern = new AttributeString(id, locale);
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	// Substitute for string values.
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	if (values != null) {
700Sstevel@tonic-gate 	    Object o = values.elementAt(0);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	    if (o instanceof String) {
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 		int i, n = values.size();
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 		for (i = 0; i < n; i++) {
770Sstevel@tonic-gate 		    String s = (String)values.elementAt(i);
780Sstevel@tonic-gate 		    AttributeString as = new AttributeString(s, locale);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 		    values.setElementAt(as, i);
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 		}
830Sstevel@tonic-gate 	   }
840Sstevel@tonic-gate 	}
850Sstevel@tonic-gate     }
860Sstevel@tonic-gate 
870Sstevel@tonic-gate     // Construct a ServerAttribute object from a ServiceLocationAttribute
880Sstevel@tonic-gate     //  object.
890Sstevel@tonic-gate 
ServerAttribute(ServiceLocationAttribute attr, Locale locale)900Sstevel@tonic-gate     ServerAttribute(ServiceLocationAttribute attr, Locale locale) {
910Sstevel@tonic-gate 	this(attr.id, attr.getValues(), locale);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     }
940Sstevel@tonic-gate 
950Sstevel@tonic-gate     // Get values by changing the attribute string objects into strings.
960Sstevel@tonic-gate 
getValues()970Sstevel@tonic-gate     public Vector getValues() {
980Sstevel@tonic-gate 	Vector v = super.getValues();
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	if ((v != null) &&
1010Sstevel@tonic-gate 	    (v.elementAt(0) instanceof AttributeString)) {
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	    int i, n = v.size();
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	    for (i = 0; i < n; i++) {
1060Sstevel@tonic-gate 		v.setElementAt(v.elementAt(i).toString(), i);
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	   }
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	return v;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate     }
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate }
116