KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > util > PackagePrefixChecker


1 /*
2  * @(#)PackagePrefixChecker.java 1.13 04/03/01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.util;
8
9 import java.io.File JavaDoc;
10
11 /**
12  * PackagePrefixChecker provides static utility methods for getting package prefixes.
13  * @author M. Mortazavi
14  */

15
16 public final class PackagePrefixChecker {
17
18
19     private static final String JavaDoc PACKAGE_PREFIX = "org.omg.stub.";
20
21     public static String JavaDoc packagePrefix(){ return PACKAGE_PREFIX;}
22
23     public static String JavaDoc correctPackageName (String JavaDoc p){
24         if (p==null) return p;
25         if ( hasOffendingPrefix(p))
26             {
27                return PACKAGE_PREFIX+p;
28             }
29         return p;
30     }
31
32     public static boolean isOffendingPackage(String JavaDoc p){
33         return
34             !(p==null)
35             &&
36             ( false || hasOffendingPrefix(p) );
37     }
38
39     public static boolean hasOffendingPrefix(String JavaDoc p){
40         return
41             ( p.startsWith("java.") || p.equals("java")
42                 // || p.startsWith("com.sun.") || p.equals("com.sun")
43
|| p.startsWith("net.jini.") || p.equals("net.jini")
44                 || p.startsWith("jini.") || p.equals("jini")
45                 || p.startsWith("javax.") || p.equals("javax")
46             );
47     }
48
49     public static boolean hasBeenPrefixed(String JavaDoc p){
50         return p.startsWith(packagePrefix());
51     }
52
53     public static String JavaDoc withoutPackagePrefix(String JavaDoc p){
54         if(hasBeenPrefixed(p)) return p.substring(packagePrefix().length());
55         else return p;
56     }
57
58 }
59
60
61
Popular Tags