bump product version to 4.1.6.2
[LibreOffice.git] / include / jvmaccess / classpath.hxx
blob1cc8d83ab348dbf3da2a7938b63fdc62a12ca5b0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_JVMACCESS_CLASSPATH_HXX
21 #define INCLUDED_JVMACCESS_CLASSPATH_HXX
23 #include "jvmaccessdllapi.h"
24 #include "sal/config.h"
25 #include "com/sun/star/uno/Reference.hxx"
27 #include "jni.h"
29 namespace com { namespace sun { namespace star { namespace uno {
30 class XComponentContext;
31 } } } }
33 namespace jvmaccess {
35 /**
36 Helper functions for class path handling.
38 class JVMACCESS_DLLPUBLIC ClassPath {
39 public:
40 /**
41 translates a class path into a java.net.URL[] instance.
43 @param context
44 a component context; must not be null.
46 @param environment
47 a JNI environment; must not be null.
49 @param classPath
50 a list of zero or more internal (see the
51 com.sun.star.uri.ExternalUriReferenceTranslator service) URI references,
52 where any space characters (U+0020) are ignored (and, in particular,
53 separate adjacent URI references). Any vnd.sun.star.expand URL
54 references in the list are expanded using the
55 com.sun.star.util.theMacroExpander singleton of the given context.
57 @returns
58 a local reference to a java.net.URL[] instance containing the external
59 (see the com.sun.star.uri.ExternalUriReferenceTranslator service)
60 equivalents of all the URI references in the given classPath. If null, a
61 (still pending) JNI exception occurred.
63 @throws com::sun::star::uno::RuntimeException
65 static inline ::jobjectArray
66 translateToUrls(
67 ::com::sun::star::uno::Reference<
68 ::com::sun::star::uno::XComponentContext > const & context,
69 ::JNIEnv * environment, OUString const & classPath)
71 return
72 static_cast< ::jobjectArray >(
73 doTranslateToUrls(context, environment, classPath));
76 /**
77 loads a class via a java.net.URLClassLoader.
79 @param context
80 a component context; must not be null.
82 @param environment
83 a JNI environment; must not be null.
85 @param classPath
86 a list of zero or more internal (see the
87 com.sun.star.uri.ExternalUriReferenceTranslator service) URI references,
88 where any space characters (U+0020) are ignored (and, in particular,
89 separate adjacent URI references). Any vnd.sun.star.expand URL
90 references in the list are expanded using the
91 com.sun.star.util.theMacroExpander singleton of the given context.
93 @param name
94 the Java binary name of the class to load.
96 @returns
97 a local reference to a java.lang.Class instance. If null, a (still
98 pending) JNI exception occurred.
100 @throws com::sun::star::uno::RuntimeException
102 static inline ::jclass loadClass(
103 ::com::sun::star::uno::Reference<
104 ::com::sun::star::uno::XComponentContext > const & context,
105 ::JNIEnv * environment, OUString const & classPath,
106 OUString const & name)
108 return
109 static_cast< ::jclass >(
110 doLoadClass(context, environment, classPath, name));
113 private:
114 ClassPath(); // not defined
115 ClassPath(ClassPath &); // not defined
116 ~ClassPath(); // not defined
117 void operator =(ClassPath &); // not defined
119 // Functions that replace JNIEnv, jobjectArray, and jclass with void *, so
120 // that their mangled C++ names do not depend on the JDK version used at
121 // compile time:
123 static void * doTranslateToUrls(
124 ::com::sun::star::uno::Reference<
125 ::com::sun::star::uno::XComponentContext > const & context,
126 void * environment, OUString const & classPath);
128 static void * doLoadClass(
129 ::com::sun::star::uno::Reference<
130 ::com::sun::star::uno::XComponentContext > const & context,
131 void * environment, OUString const & classPath,
132 OUString const & name);
137 #endif
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */