FileDocCategorySizeDatePackage
HardwareProperties.javaAPI DocAndroid 1.5 API5509Wed May 06 22:41:10 BST 2009com.android.sdklib.avd

HardwareProperties

public class HardwareProperties extends Object

Fields Summary
private static final Pattern
PATTERN_PROP
private static final String
HW_PROP_NAME
private static final String
HW_PROP_TYPE
private static final String
HW_PROP_DEFAULT
private static final String
HW_PROP_ABSTRACT
private static final String
HW_PROP_DESC
Constructors Summary
Methods Summary
public static java.util.ListparseHardwareDefinitions(java.io.File file, com.android.sdklib.ISdkLog log)
Parses the hardware definition file.

param
file the property file to parse
param
log the ISdkLog object receiving warning/error from the parsing.
return
the map of (key,value) pairs, or null if the parsing failed.

        try {
            FileInputStream fis = new FileInputStream(file);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));

            List<HardwareProperty> map = new ArrayList<HardwareProperty>();

            String line = null;
            HardwareProperty prop = null;
            while ((line = reader.readLine()) != null) {
                if (line.length() > 0 && line.charAt(0) != '#") {
                    Matcher m = PATTERN_PROP.matcher(line);
                    if (m.matches()) {
                        String valueName = m.group(1);
                        String value = m.group(2);

                        if (HW_PROP_NAME.equals(valueName)) {
                            prop = new HardwareProperty();
                            prop.mName = value;
                            map.add(prop);
                        }
                        
                        if (prop == null) {
                            log.warning("Error parsing '%1$s': missing '%2$s'",
                                    file.getAbsolutePath(), HW_PROP_NAME);
                            return null;
                        }
                        
                        if (HW_PROP_TYPE.equals(valueName)) {
                            prop.mType = ValueType.getEnum(value);
                        } else if (HW_PROP_DEFAULT.equals(valueName)) {
                            prop.mDefault = value;
                        } else if (HW_PROP_ABSTRACT.equals(valueName)) {
                            prop.mAbstract = value;
                        } else if (HW_PROP_DESC.equals(valueName)) {
                            prop.mDescription = value;
                        }
                    } else {
                        log.warning("Error parsing '%1$s': \"%2$s\" is not a valid syntax",
                                file.getAbsolutePath(), line);
                        return null;
                    }
                }
            }
            
            return map;
        } catch (FileNotFoundException e) {
            // this should not happen since we usually test the file existence before
            // calling the method.
            // Return null below.
        } catch (IOException e) {
            if (log != null) {
                log.warning("Error parsing '%1$s': %2$s.", file.getAbsolutePath(),
                        e.getMessage());
            }
        }

        return null;