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) 2000 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 29 /* 30 * Copyright (C) 1996 Active Software, Inc. 31 * All rights reserved. 32 * 33 * @(#) Attribute.java 1.25 - last change made 07/30/96 34 */ 35 36 package sunsoft.jws.visual.rt.base; 37 38 /** 39 * Storage for a single attribute. 40 * 41 * @version 1.25, 07/30/96 42 */ 43 public class Attribute implements Cloneable { 44 /** 45 * Name of this attribute. 46 */ 47 private String name; 48 49 /** 50 * The full class name of the type of the value of this attribute. 51 */ 52 private String type; 53 54 /** 55 * The actual value of this attribute. It is of the type specified 56 * by the type field. 57 */ 58 private Object value; 59 60 /** 61 * The default value of this attribute. It is of the type specified 62 * by the type field. 63 */ 64 private Object defaultValue; 65 66 /** 67 * Contains description flags about the nature of this attribute. 68 */ 69 private int flags; 70 71 /** 72 * The constructor initializes the value for the attribute. 73 * The initial value of the attribute is set to be the same 74 * as the default value. If the default value is not a simple 75 * type, you 76 * may want to set the value again after cloning the default value, 77 * otherwise, directly setting internal members of the value will 78 * change 79 * the default value as well. 80 */ Attribute(String name, String type, Object defaultValue, int flags)81 public Attribute(String name, String type, Object defaultValue, 82 int flags) { 83 this.name = name; 84 this.type = type; 85 86 // throwOnBadType is commented out for performance reasons. 87 // Shadow class construction is 15% faster with this 88 // commented out. 89 // 90 // throwOnBadType(defaultValue); 91 92 this.value = defaultValue; 93 this.defaultValue = defaultValue; 94 this.flags = flags; 95 } 96 throwOnBadType(Object checkee)97 private void throwOnBadType(Object checkee) { 98 // allow null 99 if (checkee == null) 100 return; 101 102 if (checkee.getClass().getName().equals(type)) 103 return; // FIX for 4059234 104 105 // type must pass "instance of" test (except for null) 106 Class typeClass = null; 107 try { 108 typeClass = Global.util.getClassLoader().loadClass(type); 109 } catch (ClassNotFoundException e) { 110 throw new Error(Global.fmtMsg( 111 "sunsoft.jws.visual.rt.base.Attribute.ClassNotFound", type)); 112 } 113 114 if (typeClass.isInstance(checkee)) 115 return; 116 117 throw new Error(Global.fmtMsg( 118 "sunsoft.jws.visual.rt.base.Attribute.IllegalAttribute", 119 name, type, checkee.getClass().getName(), checkee)); 120 } 121 getName()122 public String getName() { 123 return (name); 124 } 125 getType()126 public String getType() { 127 return (type); 128 } 129 getDefaultValue()130 public Object getDefaultValue() { 131 return (defaultValue); 132 } 133 setDefaultValue(Object value)134 void setDefaultValue(Object value) { 135 defaultValue = value; 136 } 137 isModified()138 public boolean isModified() { 139 if (value == null) 140 return (defaultValue != null); 141 else 142 return (!value.equals(defaultValue)); 143 } 144 145 /** 146 * Resets the value to the default 147 */ reset()148 public void reset() { 149 setValue(defaultValue); 150 } 151 getValue()152 public Object getValue() { 153 return (value); 154 } 155 156 /** 157 * Sets the value of the attribute. 158 */ setValue(Object value)159 public void setValue(Object value) { 160 // Commented out the "does new value equal old value" 161 // check, because: 162 // 1) Setting a value to "null" can cause a null pointer 163 // exception 164 // 2) Some attributes may not implement equals properly 165 throwOnBadType(value); 166 167 168 this.value = value; 169 } 170 getFlags()171 public int getFlags() { 172 return (flags); 173 } 174 addFlags(int flags)175 public void addFlags(int flags) { 176 this.flags = (this.flags | flags); 177 } 178 flagged(int flags)179 public boolean flagged(int flags) { 180 return ((flags & this.flags) != 0); 181 } 182 183 /** 184 * Shallow clone for this attribute. It's not a deep clone, 185 * only the 186 * references to the value and default value are cloned, 187 * not the actual 188 * values themselves. 189 */ clone()190 public Object clone() { 191 Object retval; 192 try { 193 retval = super.clone(); 194 } 195 catch (CloneNotSupportedException e) { 196 throw new Error(e.getMessage()); 197 } 198 return (retval); 199 } 200 } 201