001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.collection;
022:
023: import org.omg.CosCollection.*;
024:
025: import org.omg.CORBA.*;
026:
027: public class NVPairManager {
028:
029: private NVPair param[];
030:
031: public NVPairManager(NVPair[] parameters) {
032:
033: param = new NVPair[parameters.length];
034:
035: for (int i = 0; i < parameters.length; i++) {
036:
037: param[i] = parameters[i];
038:
039: }
040:
041: };
042:
043: public int find_param_idx(String key) {
044:
045: for (int i = 0; i < param.length; i++) {
046:
047: if (key.equals(param[i].name)) {
048:
049: return i;
050:
051: }
052:
053: }
054: ;
055:
056: return -1;
057:
058: };
059:
060: public String find_string_param(String key) throws ParameterInvalid {
061:
062: int i = find_param_idx(key);
063:
064: if (i == -1) {
065:
066: return null;
067:
068: }
069:
070: if (param[i].value.type().kind().value() != TCKind._tk_string) {
071:
072: throw new ParameterInvalid(i, "Invalid parameter type");
073:
074: }
075:
076: return param[i].value.extract_string();
077:
078: };
079:
080: public Integer find_ulong_param(String key) throws ParameterInvalid {
081:
082: int i = find_param_idx(key);
083:
084: if (i == -1) {
085:
086: return null;
087:
088: }
089:
090: if (param[i].value.type().kind().value() != TCKind._tk_ulong) {
091:
092: throw new ParameterInvalid(i, "Invalid parameter type");
093:
094: }
095:
096: return new Integer(param[i].value.extract_ulong());
097:
098: };
099:
100: public Operations find_operations_param(String key)
101: throws ParameterInvalid {
102:
103: int i = find_param_idx(key);
104:
105: if (i == -1) {
106:
107: return null;
108:
109: }
110:
111: /*
112:
113: if( !param[i].value.type().equal( OperationsHelper.type() ) ){
114:
115: throw new ParameterInvalid( i, "Invalid parameter type" );
116:
117: }
118:
119: */
120:
121: org.omg.CORBA.Object obj = param[i].value.extract_Object();
122:
123: return OperationsHelper.narrow(obj);
124:
125: // return OperationsHelper.extract(param[i].value);
126:
127: };
128:
129: };
|