1 26 27 package com.opensugar.cube; 28 29 import java.util.Hashtable ; 30 import java.util.StringTokenizer ; 31 import java.util.Vector ; 32 import java.util.Enumeration ; 33 34 public class NamedPropertySet { 47 48 public static final String SPECIFICATION_VERSION = "specification-version"; 51 52 private String name; 54 private Hashtable propertySet; 56 57 public static NamedPropertySet[] createNamedPropertySets( String description ) { 65 if ( description == null ) { 67 return null; 68 } 69 70 StringTokenizer tokens = new StringTokenizer ( description, "," ); 72 Vector tmp = new Vector (); 73 String token; 74 while ( tokens.hasMoreTokens() ) { 75 token = tokens.nextToken(); 76 tmp.addElement( createNamedPropertySet( token ) ); 78 } 79 NamedPropertySet[] ret = new NamedPropertySet[ tmp.size() ]; 81 tmp.copyInto( ret ); 82 return ret; 83 } 84 85 public static NamedPropertySet createNamedPropertySet( String description ) { 91 if ( description == null ) { 93 return null; 94 } 95 96 String name; 97 Hashtable propertySet = new Hashtable (); 98 99 StringTokenizer tokens = new StringTokenizer ( description, ";" ); 101 name = tokens.nextToken().trim(); 103 int n = name.indexOf( "=" ); 105 if ( n != -1 ) { 106 throw new IllegalArgumentException ( "= sign found in name" ); 107 } 108 109 String token; 110 while ( tokens.hasMoreTokens() ) { 114 token = tokens.nextToken().trim(); 115 n = token.indexOf( "=" ); 116 if ( n < 0 ) { 117 throw new IllegalArgumentException ( "= expected but not found" ); 118 } 119 if ( n < 1 ) { 120 throw new IllegalArgumentException ( "No property name found" ); 121 } 122 if ( n == token.length() ) { 123 throw new IllegalArgumentException ( "No property value found" ); 124 } 125 propertySet.put( token.substring( 0, n ), token.substring( n + 1, token.length() ) ); 126 } 127 128 return new NamedPropertySet( name, propertySet ); 130 } 131 132 public NamedPropertySet( String name, Hashtable propertySet ) { 133 this.name = name; 134 this.propertySet = propertySet; 135 } 136 137 public String getName() { 138 return name; 139 } 140 141 public Enumeration getPropertyNames() { 142 return propertySet.keys(); 143 } 144 145 public Object getProperty( String key ) { 146 return propertySet.get( key ); 147 } 148 149 } 150 | Popular Tags |