KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > collection > NVPairManager


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.collection;
22
23
24
25 import org.omg.CosCollection.*;
26
27 import org.omg.CORBA.*;
28
29
30
31 public class NVPairManager {
32
33     private NVPair param[];
34
35     public NVPairManager( NVPair[] parameters ){
36
37         param = new NVPair[ parameters.length ];
38
39         for( int i=0; i<parameters.length; i++ ) {
40
41             param[i] = parameters[i];
42
43         }
44
45     };
46
47     public int find_param_idx( String JavaDoc key ){
48
49         for( int i = 0; i<param.length; i++ ){
50
51             if ( key.equals(param[i].name) ) {
52
53                 return i;
54
55             }
56
57         };
58
59         return -1;
60
61     };
62
63     public String JavaDoc find_string_param( String JavaDoc key ) throws ParameterInvalid {
64
65         int i = find_param_idx( key );
66
67         if ( i == -1 ) {
68
69             return null;
70
71         }
72
73         if( param[i].value.type().kind().value() != TCKind._tk_string ){
74
75             throw new ParameterInvalid( i, "Invalid parameter type" );
76
77         }
78
79         return param[i].value.extract_string();
80
81     };
82
83     public Integer JavaDoc find_ulong_param( String JavaDoc key ) throws ParameterInvalid {
84
85         int i = find_param_idx( key );
86
87         if ( i == -1 ) {
88
89             return null;
90
91         }
92
93         if( param[i].value.type().kind().value() != TCKind._tk_ulong ){
94
95             throw new ParameterInvalid( i, "Invalid parameter type" );
96
97         }
98
99         return new Integer JavaDoc(param[i].value.extract_ulong());
100
101     };
102
103     public Operations find_operations_param( String JavaDoc key ) throws ParameterInvalid {
104
105         int i = find_param_idx( key );
106
107         if ( i == -1 ) {
108
109             return null;
110
111         }
112
113 /*
114
115         if( !param[i].value.type().equal( OperationsHelper.type() ) ){
116
117             throw new ParameterInvalid( i, "Invalid parameter type" );
118
119         }
120
121 */

122
123         org.omg.CORBA.Object JavaDoc obj = param[i].value.extract_Object();
124
125         return OperationsHelper.narrow( obj );
126
127 // return OperationsHelper.extract(param[i].value);
128

129     };
130
131 };
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Popular Tags