BasicKernel.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.kernel.bo.common;
017 
018 import java.net.URLConnection;
019 
020 import org.qedeq.base.utility.YodaUtility;
021 
022 
023 /**
024  * This class provides basic informations about the kernel.
025  *
026  @author  Michael Meyling
027  */
028 public final class BasicKernel implements KernelProperties {
029 
030 
031     /** Version of this kernel. */
032     private static final String KERNEL_VERSION = "0.04.06";
033 
034     /** Version dependent directory of this kernel. */
035     private static final String KERNEL_VERSION_DIRECTORY = KERNEL_VERSION.replace('.''_');
036 
037     /** Version code . */
038     private static final String KERNEL_CODE_NAME = "gaffsie";
039 
040     /** Kernel version dedication. */
041     private static final String KERNEL_DEDICATED
042         "dedicated to the the blade runner Rick Deckard and the glittering c-beams in the dark "
043             "near the Tannh\u00e4user Gate";
044 
045     /** Descriptive version information of this kernel. */
046     private static final String DESCRIPTIVE_KERNEL_VERSION
047         "Hilbert II - Version " + KERNEL_VERSION + " (" + KERNEL_CODE_NAME + ") ["
048         + getBuildIdFromManifest() "] " + KERNEL_DEDICATED;
049 
050     /** Maximal supported rule version of this kernel. */
051     private static final String MAXIMAL_RULE_VERSION = "1.01.00";
052 
053     /**
054      * Constructor.
055      */
056     public BasicKernel() {
057         // nothing to do
058     }
059 
060     /**
061      * Get build information from JAR manifest file. Is also non empty string if no manifest
062      * information is available.
063      *
064      @return  Implementation-version.
065      */
066     private static String getBuildIdFromManifest() {
067         String build = BasicKernel.class.getPackage().getImplementationVersion();
068         if (build == null) {
069             build = "no regular build";
070         }
071         return build;
072     }
073 
074     public String getBuildId() {
075         return getBuildIdFromManifest();
076     }
077 
078     public final String getKernelVersion() {
079         return KERNEL_VERSION;
080     }
081 
082     public final String getKernelCodeName() {
083         return KERNEL_CODE_NAME;
084     }
085 
086     public final String getKernelVersionDirectory() {
087         return KERNEL_VERSION_DIRECTORY;
088     }
089 
090     public final String getDescriptiveKernelVersion() {
091         return DESCRIPTIVE_KERNEL_VERSION;
092     }
093 
094     public final String getDedication() {
095         return KERNEL_DEDICATED;
096     }
097 
098     public final String getMaximalRuleVersion() {
099         return MAXIMAL_RULE_VERSION;
100     }
101 
102     public final boolean isRuleVersionSupported(final String ruleVersion) {
103         // FIXME 20130113 m31: this must change if we really want to use it
104         return MAXIMAL_RULE_VERSION.equals(ruleVersion);
105     }
106 
107     /**
108      * This class ist just for solving the lazy loading problem thread save.
109      * see <a href="http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom">
110      * Initialization_on_demand_holder_idiom</a>.
111      */
112     private static final class LazyHolderTimeoutMethods {
113 
114         /** Lazy initialized constant that knows about the existence of the method
115          <code>URLConnection.setConnectTimeout</code>. This depends on the currently running
116          * JVM. */
117         private static final boolean IS_SET_CONNECTION_TIMEOUT_SUPPORTED = YodaUtility.existsMethod(
118             URLConnection.class, "setConnectTimeout",
119             new Class[] {Integer.TYPE});
120 
121         /** Lazy initialized constant that knows about the existence of the method
122          <code>URLConnection.setReadTimeout</code>. This depends on the currently running
123          * JVM. */
124         private static final boolean IS_SET_READ_TIMEOUT_SUSPPORTED = YodaUtility.existsMethod(
125             URLConnection.class, "setReadTimeout",
126             new Class[] {Integer.TYPE});
127 
128         /**
129          * Hidden constructor.
130          */
131         private LazyHolderTimeoutMethods() {
132             // nothing to do
133         }
134 
135     }
136 
137     public boolean isSetConnectionTimeOutSupported() {
138         return LazyHolderTimeoutMethods.IS_SET_CONNECTION_TIMEOUT_SUPPORTED;
139     }
140 
141     public boolean isSetReadTimeoutSupported() {
142         return LazyHolderTimeoutMethods.IS_SET_READ_TIMEOUT_SUSPPORTED;
143     }
144 
145 }