Android Open Source - objenesis Platform Description






From Project

Back to project page objenesis.

License

The source code is released under:

Apache License

If you think the Android project objenesis listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2006-2015 the original author or authors.
 *//from  www  .  j  a v  a  2s  .  c  om
 * 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.objenesis.strategy;

import java.lang.reflect.Field;

import org.objenesis.ObjenesisException;

/**
 * List of constants describing the currently used platform.
 * 
 * @author Henri Tremblay
 */
public final class PlatformDescription {

   /** JVM_NAME prefix for JRockit */
   public static final String JROCKIT = "BEA";

   /** JVM_NAME prefix for GCJ */
   public static final String GNU = "GNU libgcj";

   /** JVM_NAME prefix for Sun Java HotSpot */
   public static final String SUN = "Java HotSpot";

   /** JVM_NAME prefix for the OpenJDK */
   public static final String OPENJDK = "OpenJDK";

   /** JVM_NAME prefix for Aonix PERC */
   public static final String PERC = "PERC";

   /** JVM_NAME prefix for Dalvik/Android */
   public static final String DALVIK = "Dalvik";

   /** Java specification version */
   public static final String SPECIFICATION_VERSION = System
      .getProperty("java.specification.version");

   /** JVM version */
   public static final String VM_VERSION = System.getProperty("java.runtime.version");

   /** JVM version */
   public static final String VM_INFO = System.getProperty("java.vm.info");

   /** Vendor version */
   public static final String VENDOR_VERSION = System.getProperty("java.vm.version");

   /** Vendor name */
   public static final String VENDOR = System.getProperty("java.vm.vendor");

   /** JVM name */
   public static final String JVM_NAME = System.getProperty("java.vm.name");

   /** Android version. Will be 0 for none android platform */
   public static final int ANDROID_VERSION = getAndroidVersion();

   /**
    * Check if the current JVM is of the type passed in parameter. Normally, this will be a constant
    * from this class. We basically do
    * <code>System.getProperty("java.vm.name").startWith(name)</code>.
    * 
    * @param name jvm name we are looking for
    * @return if it's the requested JVM
    */
   public static boolean isThisJVM(String name) {
      return JVM_NAME.startsWith(name);
   }

   private static int getAndroidVersion() {
      if(!isThisJVM(DALVIK)) {
         return 0;
      }
      return getAndroidVersion0();
   }

   private static int getAndroidVersion0() {
      Class<?> clazz;
      try {
         clazz = Class.forName("android.os.Build$VERSION");
      }
      catch(ClassNotFoundException e) {
         throw new ObjenesisException(e);
      }
      Field field;
      try {
         field = clazz.getField("SDK_INT");
      }
      catch(NoSuchFieldException e) {
         // Might be a really old API (before 4), go for SDK
         return getOldAndroidVersion(clazz);
      }
      int version;
      try {
         version = (Integer) field.get(null);
      }
      catch(IllegalAccessException e) {
         throw new RuntimeException(e);
      }
      return version;
   }

   private static int getOldAndroidVersion(Class<?> versionClass) {
      Field field;
      try {
         field = versionClass.getField("SDK");
      }
      catch(NoSuchFieldException e) {
         throw new ObjenesisException(e);
      }
      String version;
      try {
         version = (String) field.get(null);
      }
      catch(IllegalAccessException e) {
         throw new RuntimeException(e);
      }
      return Integer.parseInt(version);
   }

   private PlatformDescription() {
   }
}




Java Source Code List

org.objenesis.ObjenesisBase.java
org.objenesis.ObjenesisException.java
org.objenesis.ObjenesisHelper.java
org.objenesis.ObjenesisSerializer.java
org.objenesis.ObjenesisStd.java
org.objenesis.Objenesis.java
org.objenesis.benchmark.ConcurrentGetInstantiator.java
org.objenesis.benchmark.CreateObject.java
org.objenesis.instantiator.ObjectInstantiator.java
org.objenesis.instantiator.SerializationInstantiatorHelper.java
org.objenesis.instantiator.android.Android10Instantiator.java
org.objenesis.instantiator.android.Android17Instantiator.java
org.objenesis.instantiator.android.Android18Instantiator.java
org.objenesis.instantiator.android.AndroidSerializationInstantiator.java
org.objenesis.instantiator.basic.AccessibleInstantiator.java
org.objenesis.instantiator.basic.ConstructorInstantiator.java
org.objenesis.instantiator.basic.FailingInstantiator.java
org.objenesis.instantiator.basic.NewInstanceInstantiator.java
org.objenesis.instantiator.basic.NullInstantiator.java
org.objenesis.instantiator.basic.ObjectInputStreamInstantiator.java
org.objenesis.instantiator.basic.ObjectStreamClassInstantiator.java
org.objenesis.instantiator.gcj.GCJInstantiatorBase.java
org.objenesis.instantiator.gcj.GCJInstantiator.java
org.objenesis.instantiator.gcj.GCJSerializationInstantiator.java
org.objenesis.instantiator.jrockit.JRockitLegacyInstantiator.java
org.objenesis.instantiator.perc.PercInstantiator.java
org.objenesis.instantiator.perc.PercSerializationInstantiator.java
org.objenesis.instantiator.sun.SunReflectionFactoryHelper.java
org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.java
org.objenesis.instantiator.sun.SunReflectionFactorySerializationInstantiator.java
org.objenesis.instantiator.sun.UnsafeFactoryInstantiator.java
org.objenesis.strategy.BaseInstantiatorStrategy.java
org.objenesis.strategy.InstantiatorStrategy.java
org.objenesis.strategy.PlatformDescription.java
org.objenesis.strategy.SerializingInstantiatorStrategy.java
org.objenesis.strategy.SingleInstantiatorStrategy.java
org.objenesis.strategy.StdInstantiatorStrategy.java
org.objenesis.tck.CandidateLoader.java
org.objenesis.tck.Main.java
org.objenesis.tck.Reporter.java
org.objenesis.tck.TCK.java
org.objenesis.tck.TextReporter.java
org.objenesis.tck.android.ObjenesisTest.java
org.objenesis.tck.android.TckInstrumentation.java
org.objenesis.tck.candidates.ConstructorThrowingException.java
org.objenesis.tck.candidates.ConstructorWithArguments.java
org.objenesis.tck.candidates.ConstructorWithMandatoryArguments.java
org.objenesis.tck.candidates.DefaultPackageConstructor.java
org.objenesis.tck.candidates.DefaultPrivateConstructor.java
org.objenesis.tck.candidates.DefaultProtectedConstructor.java
org.objenesis.tck.candidates.DefaultPublicConstructor.java
org.objenesis.tck.candidates.NoConstructor.java
org.objenesis.tck.candidates.SerializableConstructorThrowingException.java
org.objenesis.tck.candidates.SerializableConstructorWithArguments.java
org.objenesis.tck.candidates.SerializableConstructorWithMandatoryArguments.java
org.objenesis.tck.candidates.SerializableDefaultPackageConstructor.java
org.objenesis.tck.candidates.SerializableDefaultPrivateConstructor.java
org.objenesis.tck.candidates.SerializableDefaultProtectedConstructor.java
org.objenesis.tck.candidates.SerializableDefaultPublicConstructor.java
org.objenesis.tck.candidates.SerializableNoConstructor.java
org.objenesis.tck.candidates.SerializableReplacer.java
org.objenesis.tck.candidates.SerializableResolver.java
org.objenesis.tck.candidates.SerializableWithAncestorThrowingException.java