KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > orb > PropertyParser


1 /*
2  * @(#)PropertyParser.java 1.11 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.spi.orb ;
8
9 import java.util.List JavaDoc ;
10 import java.util.LinkedList JavaDoc ;
11 import java.util.Map JavaDoc ;
12 import java.util.HashMap JavaDoc ;
13 import java.util.Iterator JavaDoc ;
14 import java.util.Properties JavaDoc ;
15
16 import com.sun.corba.se.impl.orb.ParserAction ;
17 import com.sun.corba.se.impl.orb.ParserActionFactory ;
18
19 public class PropertyParser {
20     private List JavaDoc actions ;
21
22     public PropertyParser( )
23     {
24     actions = new LinkedList JavaDoc() ;
25     }
26
27     public PropertyParser add( String JavaDoc propName,
28     Operation action, String JavaDoc fieldName )
29     {
30     actions.add( ParserActionFactory.makeNormalAction( propName,
31         action, fieldName ) ) ;
32     return this ;
33     }
34
35     public PropertyParser addPrefix( String JavaDoc propName,
36     Operation action, String JavaDoc fieldName, Class JavaDoc componentType )
37     {
38     actions.add( ParserActionFactory.makePrefixAction( propName,
39         action, fieldName, componentType ) ) ;
40     return this ;
41     }
42
43     /** Return a map from field name to value.
44     */

45     public Map JavaDoc parse( Properties JavaDoc props )
46     {
47     Map JavaDoc map = new HashMap JavaDoc() ;
48     Iterator JavaDoc iter = actions.iterator() ;
49     while (iter.hasNext()) {
50         ParserAction act = (ParserAction)(iter.next()) ;
51     
52         Object JavaDoc result = act.apply( props ) ;
53         
54         // A null result means that the property was not set for
55
// this action, so do not override the default value in this case.
56
if (result != null)
57         map.put( act.getFieldName(), result ) ;
58     }
59
60     return map ;
61     }
62
63     public Iterator JavaDoc iterator()
64     {
65     return actions.iterator() ;
66     }
67 }
68
Popular Tags