1 22 23 28 29 package org.xquark.mapper.metadata; 30 31 import java.io.StringWriter ; 32 33 import org.xquark.mapper.RepositoryConnection; 34 import org.xquark.mapper.util.Tabulator; 35 import org.xquark.xml.xdbc.*; 36 37 41 42 public class CollectionInfo implements Cloneable , Configurable 43 { 44 private static final String RCSRevision = "$Revision: 1.1 $"; 45 private static final String RCSName = "$Name: $"; 46 47 public static final String TYPE_PROPERTY 51 = "http://www.xquark.org/repository/collection/properties/type"; 52 public static final String BUCKET_ID_SIZE_PROPERTY 53 = "http://www.xquark.org/repository/collection/properties/bucketIDSizeInBits"; 54 55 56 private static final String [] SUPPORTED_PROPERTIES 57 = new String [] { 58 RepositoryConnection.TEXT_LENGTH_PROPERTY, 59 RepositoryConnection.EXTRA_DATA_LENGTH_PROPERTY, 60 RepositoryConnection.DESC_PROPERTY, 61 RepositoryConnection.DOC_OID_SIZE_PROPERTY, 62 RepositoryConnection.DOC_OID_PREALLOCATION_SIZE, 63 RepositoryConnection.MAPPING_ID_PROPERTY}; 64 65 67 71 72 private static final String [] SUPPORTED_FEATURES 73 = new String [] {RepositoryConnection.USE_SCHEMA_PREFIXES_FEATURE}; 74 75 81 public static final byte SYSTEM = 0x00; 82 83 85 public static final byte USER = 0x01; 86 87 91 94 protected byte collectionType = USER; 95 96 98 protected String description; 99 100 protected byte docOIDSize = RepositoryConstants.DID_SIZE_DEFAULT_VALUE; 101 protected short docOIDPrealloc = 1; 102 104 105 protected int maxTextLength = RepositoryConstants.DEFAULT_DATA_LENGTH; 106 107 protected int maxExtraDataLength = RepositoryConstants.DEFAULT_DATA_LENGTH; 108 109 112 protected String mappingURI = ""; 113 114 118 protected boolean useSchemaPrefixes = false; 119 120 private boolean writeProtected = true; 121 122 125 public CollectionInfo() {} 126 127 public CollectionInfo(byte type, int textLength) 128 { 129 collectionType = type; 130 maxTextLength = maxExtraDataLength = textLength; 131 132 } 133 134 public CollectionInfo(boolean writeProtected) 135 { 136 setWriteProtected(writeProtected); 137 } 138 139 142 public CollectionInfo(Configurable config) 143 { 144 try { 145 collectionType = Byte.parseByte((String )config.getProperty(TYPE_PROPERTY)); 146 maxTextLength = Integer.parseInt((String )config.getProperty(RepositoryConnection.TEXT_LENGTH_PROPERTY)); 147 maxExtraDataLength = Integer.parseInt((String )config.getProperty(RepositoryConnection.EXTRA_DATA_LENGTH_PROPERTY)); 148 mappingURI = (String )config.getProperty(RepositoryConnection.MAPPING_ID_PROPERTY); 149 description = (String )config.getProperty(RepositoryConnection.DESC_PROPERTY); 150 setDocOIDSize(Byte.parseByte((String )config.getProperty(RepositoryConnection.DOC_OID_SIZE_PROPERTY))); 151 docOIDPrealloc = Short.parseShort((String )config.getProperty(RepositoryConnection.DOC_OID_PREALLOCATION_SIZE)); 152 useSchemaPrefixes = config.getFeature(RepositoryConnection.USE_SCHEMA_PREFIXES_FEATURE); 154 } 155 catch (XMLDBCException e) { 156 } 158 } 159 160 public void setWriteProtected(boolean mode) 161 { 162 writeProtected = mode; 163 } 164 165 168 public String toString() 169 { 170 StringWriter out = new StringWriter (); 171 Tabulator tabulator = new Tabulator 172 ( 173 out, 174 79, 175 new int[] {0, 40} 176 ); 177 178 if (description != null && description.length() > 0) 179 { 180 tabulator.addItem("Description:"); 181 tabulator.addItem(description); 182 } 183 if (mappingURI.length() != 0) 184 { 185 tabulator.addItem("Mapping file:"); 186 tabulator.addItem(mappingURI); 187 tabulator.addItem("Use Schema prefixes :"); 188 tabulator.addItem(String.valueOf(useSchemaPrefixes)); 189 } 190 tabulator.addItem("Text length:"); 191 tabulator.addItem(String.valueOf(maxTextLength)); 192 tabulator.addItem("Extra data length:"); 193 tabulator.addItem(String.valueOf(maxExtraDataLength)); 194 tabulator.addItem("Document ID size in bits:"); 195 tabulator.addItem(String.valueOf(docOIDSize)); 196 tabulator.addItem("Document OID preallocation size:"); 197 tabulator.addItem(String.valueOf(docOIDSize)); 198 201 return out.toString(); 202 } 203 204 207 public Object clone() 208 { 209 Object copy = null; 210 try { 211 copy = super.clone(); 212 } 213 catch(CloneNotSupportedException e) { 214 } 215 return copy; 216 } 217 218 public void setProperty(String propertyId, Object value) throws XMLDBCNotRecognizedException, XMLDBCNotSupportedException 219 { 220 if (writeProtected) 222 throw new XMLDBCNotSupportedException("This object is read-only."); 223 224 if (propertyId.equals(TYPE_PROPERTY)) 225 { 226 if (value instanceof String ) 227 collectionType = Byte.parseByte((String )value); 228 else if (value instanceof Number ) 229 collectionType = ((Number )value).byteValue(); 230 else 231 throw new XMLDBCNotSupportedException("Property value type is not supported."); 232 } 233 else if (propertyId.equals(RepositoryConnection.TEXT_LENGTH_PROPERTY)) 234 { 235 if (value instanceof String ) 236 maxTextLength = Integer.parseInt((String )value); 237 else if (value instanceof Number ) 238 maxTextLength = ((Number )value).intValue(); 239 else 240 throw new XMLDBCNotSupportedException("Property value type is not supported."); 241 } 242 else if (propertyId.equals(RepositoryConnection.EXTRA_DATA_LENGTH_PROPERTY)) 243 { 244 if (value instanceof String ) 245 maxExtraDataLength = Integer.parseInt((String )value); 246 else if (value instanceof Number ) 247 maxExtraDataLength = ((Number )value).intValue(); 248 else 249 throw new XMLDBCNotSupportedException("Property value type is not supported."); 250 } 251 else if (propertyId.equals(RepositoryConnection.DOC_OID_SIZE_PROPERTY)) 252 { 253 if (value instanceof String ) 254 setDocOIDSize(Byte.parseByte((String )value)); 255 else if (value instanceof Number ) 256 setDocOIDSize(((Number )value).byteValue()); 257 else 258 throw new XMLDBCNotSupportedException("Property value type is not supported."); 259 } 260 else if (propertyId.equals(RepositoryConnection.DOC_OID_PREALLOCATION_SIZE)) 261 { 262 if (value instanceof String ) 263 docOIDPrealloc = Short.parseShort((String )value); 264 else if (value instanceof Number ) 265 docOIDPrealloc = ((Number )value).shortValue(); 266 else 267 throw new XMLDBCNotSupportedException("Property value type is not supported."); 268 } 269 else if (propertyId.equals(RepositoryConnection.MAPPING_ID_PROPERTY)) 279 { 280 if (value instanceof String ) 281 mappingURI = (String )value; 282 else 283 throw new XMLDBCNotSupportedException("Property value type is not supported."); 284 } 285 else if (propertyId.equals(RepositoryConnection.DESC_PROPERTY)) 286 { 287 if (value instanceof String ) 288 description = (String )value; 289 else 290 throw new XMLDBCNotSupportedException("Property value type is not supported."); 291 } 292 else 293 throw new XMLDBCNotRecognizedException("Unkown property " + propertyId); 294 } 295 296 public Object getProperty(String propertyId) throws XMLDBCNotRecognizedException 297 { 298 if (propertyId.equals(TYPE_PROPERTY)) 299 return Byte.toString(collectionType); 300 else if (propertyId.equals(RepositoryConnection.TEXT_LENGTH_PROPERTY)) 301 return Integer.toString(maxTextLength); 302 else if (propertyId.equals(RepositoryConnection.EXTRA_DATA_LENGTH_PROPERTY)) 303 return Integer.toString(maxExtraDataLength); 304 else if (propertyId.equals(RepositoryConnection.DOC_OID_SIZE_PROPERTY)) 305 return Byte.toString(docOIDSize); 306 else if (propertyId.equals(RepositoryConnection.DOC_OID_PREALLOCATION_SIZE)) 307 return Integer.toString(docOIDPrealloc); 308 else if (propertyId.equals(RepositoryConnection.MAPPING_ID_PROPERTY)) 311 return mappingURI; 312 else if (propertyId.equals(RepositoryConnection.DESC_PROPERTY)) 313 return description; 314 else 315 throw new XMLDBCNotRecognizedException("Unkown property " + propertyId); 316 } 317 318 public boolean getFeature(String name) throws XMLDBCNotRecognizedException 319 { 320 if (name.equals(RepositoryConnection.USE_SCHEMA_PREFIXES_FEATURE)) 321 return useSchemaPrefixes; 322 else 323 throw new XMLDBCNotRecognizedException("Unkown feature " + name); 324 } 325 326 public void setFeature(String name, boolean state) throws XMLDBCNotRecognizedException, XMLDBCNotSupportedException 327 { 328 if (writeProtected) 330 throw new XMLDBCNotSupportedException("This object is read-only."); 331 332 if (name.equals(RepositoryConnection.USE_SCHEMA_PREFIXES_FEATURE)) 333 useSchemaPrefixes = state; 334 else 335 throw new XMLDBCNotRecognizedException("Unkown feature " + name); 336 } 337 338 public String [] getFeatureList() 339 { 340 return SUPPORTED_FEATURES; 341 } 342 343 public String [] getPropertyList() 344 { 345 return SUPPORTED_PROPERTIES; 346 } 347 348 public String getMappingID() 349 { 350 return mappingURI; 351 } 352 353 public String getDescription() 354 { 355 return description; 356 } 357 358 public int getMaxTextLength() 359 { 360 return maxTextLength; 361 } 362 363 public int getMaxExtraDataLength() 364 { 365 return maxExtraDataLength; 366 } 367 368 public byte getType() 369 { 370 return collectionType; 371 } 372 373 public byte getDocOIDSize() 374 { 375 return docOIDSize; 376 } 377 378 public short getDocOIDPreallocationSize() 379 { 380 return docOIDPrealloc; 381 } 382 383 388 public void setMappingID(String uri) 389 { 390 mappingURI = uri; 391 } 392 393 public void setDescription(String description) 394 { 395 this.description = description; 396 } 397 398 public void setMaxTextLength(int maxLength) 399 { 400 maxTextLength = maxLength; 401 } 402 403 public void setMaxExtraDataLength(int maxLength) 404 { 405 maxExtraDataLength = maxLength; 406 } 407 408 public void setType(byte type) 409 { 410 collectionType = type; 411 } 412 413 public void setDocOIDSize(byte docSize) 414 { 415 if (docSize < RepositoryConstants.DID_SIZE_MIN_VALUE) 416 docOIDSize = RepositoryConstants.DID_SIZE_MIN_VALUE; 417 else if (docSize > RepositoryConstants.DID_SIZE_MAX_VALUE) 418 docOIDSize = RepositoryConstants.DID_SIZE_MAX_VALUE; 419 else 420 docOIDSize = docSize; 421 } 422 423 public void setDocOIDPreallocationSize(short size) 424 { 425 docOIDPrealloc = size; 426 } 427 428 } 433 | Popular Tags |