1 2 5 14 package org.jacorb.trading.impl; 15 16 17 import java.util.*; 18 import org.omg.CORBA.*; 19 import org.omg.CosTrading.*; 20 import org.omg.CosTradingRepos.*; 21 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*; 22 import org.omg.CosTradingDynamic.*; 23 import org.jacorb.trading.db.OfferDatabase; 24 import org.jacorb.trading.util.*; 25 26 27 30 public class OfferUtil 31 { 32 private OfferUtil() 33 { 34 } 35 36 37 38 public static void validateProperties( 39 OfferDatabase db, 40 Property[] exportProps, 41 String typeName, 42 TypeStruct type) 43 throws IllegalPropertyName, 44 PropertyTypeMismatch, 45 ReadonlyDynamicProperty, 46 MissingMandatoryProperty, 47 DuplicatePropertyName 48 { 49 Hashtable typeProps = new Hashtable(); 51 for (int i = 0; i < type.props.length; i++) 52 typeProps.put(type.props[i].name, type.props[i]); 53 54 Hashtable checkedProps = new Hashtable(); 56 57 for (int i = 0; i < exportProps.length; i++) 59 { 60 PropStruct ps = (PropStruct)typeProps.get(exportProps[i].name); 62 if (ps != null) 63 { 64 if (checkedProps.containsKey(exportProps[i].name)) 66 throw new DuplicatePropertyName(exportProps[i].name); 67 68 checkProperty(typeName, exportProps[i], ps); 69 checkedProps.put(exportProps[i].name, exportProps[i]); 70 } 71 72 80 if (!db.isTypeSupported(exportProps[i].value)) 81 { 82 throw new PropertyTypeMismatch(typeName, exportProps[i]); 83 } 84 } 85 86 Enumeration e = typeProps.elements(); 89 while (e.hasMoreElements()) 90 { 91 PropStruct ps = (PropStruct)e.nextElement(); 92 93 if (checkedProps.get(ps.name) == null) { 95 if (isMandatory(ps.mode)) 96 throw new MissingMandatoryProperty(typeName, ps.name); 97 } 98 } 99 } 100 101 102 public static boolean isMandatory(PropertyMode mode) 103 { 104 boolean result; 105 106 result = ( 107 mode == PropertyMode.PROP_MANDATORY || 108 mode == PropertyMode.PROP_MANDATORY_READONLY 109 ); 110 111 return result; 112 } 113 114 115 public static boolean isReadonly(PropertyMode mode) 116 { 117 boolean result; 118 119 result = ( 120 mode == PropertyMode.PROP_READONLY || 121 mode == PropertyMode.PROP_MANDATORY_READONLY 122 ); 123 124 return result; 125 } 126 127 128 129 public static void checkProperty( 130 String typeName, 131 Property prop, 132 PropStruct ps) 133 throws PropertyTypeMismatch, 134 ReadonlyDynamicProperty 135 { 136 try { 137 TypeCode propType = ps.value_type; 138 while (propType.kind() == TCKind.tk_alias) 139 propType = propType.content_type(); 140 141 142 if (PropUtil.isDynamicProperty(prop.value.type())) 143 { 144 if (isReadonly(ps.mode)) 146 throw new ReadonlyDynamicProperty(typeName, prop.name); 147 148 DynamicProp dp = DynamicPropHelper.extract(prop.value); 151 152 TypeCode tc = dp.returned_type; 153 while (tc.kind() == TCKind.tk_alias) 154 tc = tc.content_type(); 155 156 if (! tc.equal(propType)) 157 throw new PropertyTypeMismatch(typeName, prop); 158 } 159 else { 160 TypeCode tc = prop.value.type(); 163 while (tc.kind() == TCKind.tk_alias) 164 tc = tc.content_type(); 165 166 if (! tc.equal(propType)) 167 throw new PropertyTypeMismatch(typeName, prop); 168 } 169 } 170 catch (org.omg.CORBA.TypeCodePackage.BadKind e) { 171 throw new RuntimeException (); 172 } 173 } 174 } 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | Popular Tags |