1 package org.apache.beehive.controls.runtime.generator.apt; 2 3 20 21 import com.sun.mirror.apt.Filer; 22 23 import java.io.*; 24 import java.util.*; 25 26 51 public class ControlClientManifest 52 { 53 public final static String CLIENT_NAME_PROP = ".client.name"; 54 public final static String BEEHIVE_VERSION_PROP = ".beehive.version"; 55 public final static String FILE_EXTENSION = ".controls.properties"; 56 57 63 public ControlClientManifest( File f ) throws FileNotFoundException, IOException 64 { 65 if ( !f.exists() ) 66 throw new FileNotFoundException( "Control manifest file=" + f + " not found"); 67 68 FileInputStream fis = new FileInputStream( f ); 69 _properties.load( fis ); 70 71 String client = _properties.getProperty( CLIENT_NAME_PROP ); 72 if ( client == null || client.equals("") ) 73 throw new IOException( "Control client manifest missing client name" ); 74 } 75 76 80 public ControlClientManifest( String client ) 81 { 82 if ( client == null || client.equals("") ) 83 throw new RuntimeException ( "Missing or empty client name" ); 84 85 _properties.setProperty( CLIENT_NAME_PROP, client ); 86 } 87 88 91 public String getControlClient() 92 { 93 return _properties.getProperty( CLIENT_NAME_PROP ); 94 } 95 96 101 public void addControlType( String intf, String impl ) 102 { 103 _properties.setProperty( intf, impl ); 104 } 105 106 109 public List<String > getControlTypes() 110 { 111 ArrayList<String > l = new ArrayList<String >(); 112 113 Set keys = _properties.keySet(); 114 for ( Object k : keys ) 115 { 116 String propname = (String )k; 117 if ( propname.equals( CLIENT_NAME_PROP ) ) 118 continue; 119 120 l.add( propname ); 121 } 122 123 return l; 124 } 125 126 130 public String getDefaultImpl( String controlType ) 131 { 132 return (String )_properties.get( controlType ); 133 } 134 135 142 public void emit( Filer f, String pkg, File mf, String csn ) throws IOException 143 { 144 PrintWriter pw = f.createTextFile( Filer.Location.CLASS_TREE, pkg, mf, csn ); 145 146 pw.println( "# Apache Beehive Controls client manifest (auto-generated, do not edit!)"); 147 Set props = _properties.keySet(); 148 for ( Object p : props ) 149 { 150 String name = (String )p; 151 String value = _properties.getProperty( name ); 152 pw.println( name + "=" + value ); 153 } 154 155 pw.flush(); 156 pw.close(); 157 } 158 159 private Properties _properties = new Properties(); 160 } 161 162 | Popular Tags |