| /* |
| * Copyright 2005 The Apache Software Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| */ |
| package org.apache.felix.moduleloader; |
| |
| public class Util |
| { |
| public static String getClassName(String className) |
| { |
| if (className == null) |
| { |
| className = ""; |
| } |
| return (className.lastIndexOf('.') < 0) |
| ? "" : className.substring(className.lastIndexOf('.') + 1); |
| } |
| |
| public static String getClassPackage(String className) |
| { |
| if (className == null) |
| { |
| className = ""; |
| } |
| return (className.lastIndexOf('.') < 0) |
| ? "" : className.substring(0, className.lastIndexOf('.')); |
| } |
| |
| public static String getResourcePackage(String resource) |
| { |
| if (resource == null) |
| { |
| resource = ""; |
| } |
| // NOTE: The package of a resource is tricky to determine since |
| // resources do not follow the same naming conventions as classes. |
| // This code is pessimistic and assumes that the package of a |
| // resource is everything up to the last '/' character. By making |
| // this choice, it will not be possible to load resources from |
| // imports using relative resource names. For example, if a |
| // bundle exports "foo" and an importer of "foo" tries to load |
| // "/foo/bar/myresource.txt", this will not be found in the exporter |
| // because the following algorithm assumes the package name is |
| // "foo.bar", not just "foo". This only affects imported resources, |
| // local resources will work as expected. |
| String pkgName = (resource.startsWith("/")) ? resource.substring(1) : resource; |
| pkgName = (pkgName.lastIndexOf('/') < 0) |
| ? "" : pkgName.substring(0, pkgName.lastIndexOf('/')); |
| pkgName = pkgName.replace('/', '.'); |
| return pkgName; |
| } |
| } |