KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > JenaRuntime


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  */

6
7 package com.hp.hpl.jena;
8
9 import java.util.* ;
10 import java.security.AccessController JavaDoc;
11
12 /** Methods and constants that define features of the curren the environment.
13  * Primarily for other parts of the Jena framework.
14  *
15  * @author Andy Seaborne
16  * @version $Id: JenaRuntime.java,v 1.4 2005/02/21 11:58:52 andy_seaborne Exp $
17  */

18
19 public class JenaRuntime
20 {
21     /** The JVM does not implement java.security (correctly) */
22     public static final String JavaDoc featureNoSecurity = "http://jena.hpl.hp.com/2004/07/feature/noSecurity" ;
23     
24     /** The JVM does not implement java.nio.charset.Charset operations (correctly) */
25     public static final String JavaDoc featureNoCharset = "http://jena.hpl.hp.com/2004/07/feature/noCharset" ;
26         
27     static Map features = new HashMap() ;
28     static {
29         if ( System.getProperty(featureNoSecurity) != null )
30             setFeature(featureNoSecurity) ;
31         if ( System.getProperty(featureNoCharset) != null )
32             setFeature(featureNoCharset) ;
33     }
34     
35     public static void setFeature(String JavaDoc featureName) { features.put(featureName, "true") ; }
36     public static boolean runUnder(String JavaDoc featureName) { return features.containsKey(featureName) ; }
37     public static boolean runNotUnder(String JavaDoc featureName) { return ! features.containsKey(featureName) ; }
38     
39     
40     static final String JavaDoc lineSeparator = getSystemProperty("line.separator", "\n") ;
41     public static String JavaDoc getLineSeparator()
42     {
43         return lineSeparator ;
44     }
45     
46     public static String JavaDoc getSystemProperty(String JavaDoc propName)
47     {
48         return getSystemProperty(propName, null) ;
49     }
50
51     public static String JavaDoc getSystemProperty(String JavaDoc propName, String JavaDoc defaultValue)
52     {
53         try {
54             return System.getProperty(propName, defaultValue) ;
55         } catch (SecurityException JavaDoc ex)
56         {
57             if ( runUnder(featureNoSecurity))
58                 return defaultValue ;
59             try {
60                 Object JavaDoc x = AccessController.doPrivileged(
61                     new sun.security.action.GetPropertyAction(propName));
62                 return (String JavaDoc)x ;
63             } catch (Exception JavaDoc ex2)
64             {
65                 // Give up
66
return defaultValue ;
67             }
68         }
69     }
70     
71 }
72
73 /*
74  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
75  * All rights reserved.
76  *
77  * Redistribution and use in source and binary forms, with or without
78  * modification, are permitted provided that the following conditions
79  * are met:
80  * 1. Redistributions of source code must retain the above copyright
81  * notice, this list of conditions and the following disclaimer.
82  * 2. Redistributions in binary form must reproduce the above copyright
83  * notice, this list of conditions and the following disclaimer in the
84  * documentation and/or other materials provided with the distribution.
85  * 3. The name of the author may not be used to endorse or promote products
86  * derived from this software without specific prior written permission.
87  *
88  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
89  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
90  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
91  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
92  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
93  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
97  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98  */
Popular Tags