(file) Return to JMPIProviderModule.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / JMPI

  1 schuur 1.1 //%////////////-*-c++-*-///////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000 - 2003 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5            //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7            // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10            // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12            //
 13            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22 schuur 1.1 //==============================================================================
 23            //
 24            // Author: Chip Vincent (cvincent@us.ibm.com)
 25            //
 26            // Modified By:
 27            //      Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
 28            //		Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
 29            //     Mike Day, IBM (mdday@us.ibm.com)
 30            //     Adrian Schuur, IBM (schuur@de.ibm.com)
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #include "JMPIProviderModule.h"
 35            
 36            #include <Pegasus/Common/Destroyer.h>
 37            #include <Pegasus/Common/FileSystem.h>
 38            #include <Pegasus/Common/MessageLoader.h> //l10n
 39            #include <Pegasus/Config/ConfigManager.h>
 40            #include <Pegasus/ProviderManager2/JMPI/JMPIProvider.h>
 41            #include <Pegasus/ProviderManager2/JMPI/JMPIProviderManager.h>
 42            
 43 schuur 1.1 PEGASUS_NAMESPACE_BEGIN
 44            
 45            JMPIProviderModule::JMPIProviderModule(const String & fileName,
 46                                                   const String & interfaceName)
 47                : _fileName(fileName),
 48                _interfaceName(interfaceName),
 49                _ref_count(0),
 50                _library(0)
 51            {
 52               Uint32 i=fileName.find(".jar:");
 53               if (i==PEG_NOT_FOUND) {
 54                  String msg="Invalid Location format for Java providers: "+fileName;
 55                  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,msg);
 56               }
 57               String jar=fileName.subString(0,i+4);
 58               _className=fileName.subString(i+5);
 59            
 60               if (jar[0]!='/')
 61                  _fileName=JMPIProviderManager::resolveFileName(jar);
 62               else _fileName=jar;
 63            }
 64 schuur 1.1 
 65            JMPIProviderModule::~JMPIProviderModule(void)
 66            {
 67            }
 68            
 69            ProviderVector JMPIProviderModule::load(const String & providerName)
 70            {
 71               ProviderVector pv;
 72               JvmVector *jv;
 73            
 74               JNIEnv *env=JMPIjvm::attachThread(&jv);
 75               pv.jProvider=JMPIjvm::getProvider(env,_fileName,_className,
 76                    providerName.getCString(),&pv.jProviderClass);
 77               JMPIjvm::detachThread();
 78            
 79                if (pv.jProvider == 0) {
 80                    String s0 = "ProviderLoadFailure";
 81                    throw Exception(MessageLoaderParms("ProviderManager.JMPIProviderModule.CANNOT_LOAD_LIBRARY",
 82                        "$0 ($1:$2):Cannot load library",
 83                        s0,
 84                        _fileName,
 85 schuur 1.1             providerName));
 86                }
 87            
 88                _ref_count++;
 89            
 90                return pv;
 91            }
 92            
 93            void JMPIProviderModule::unloadModule(void)
 94            {
 95                _ref_count--;
 96            
 97                if(_ref_count.value() > 0)
 98                    return;
 99            
100                _ref_count = 0;
101            
102                if(_library != 0)
103                {
104                    System::unloadDynamicLibrary(_library);
105                    _library = 0;
106 schuur 1.1     }
107            }
108            
109            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2