Java Code Examples for java.lang.reflect.Constructor

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project activemq-apollo, under directory /apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/.

Source file: BaseDataStreamMarshaller.java

  33 
vote

private Throwable createThrowable(UTF8Buffer className,UTF8Buffer message){
  try {
    Class clazz=Class.forName(className.toString(),false,BaseDataStreamMarshaller.class.getClassLoader());
    Constructor constructor=clazz.getConstructor(new Class[]{UTF8Buffer.class});
    return (Throwable)constructor.newInstance(new Object[]{message.toString()});
  }
 catch (  Throwable e) {
    return new Throwable(className + ": " + message);
  }
}
 

Example 2

From project android-inject, under directory /src/test/java/com/teamcodeflux/android/inject/.

Source file: AndroidInjectTest.java

  33 
vote

@Test(expected=InvocationTargetException.class) public void shouldNotAllowInstantiationUsingReflection() throws Exception {
  Constructor defaultConstructor=AndroidInject.class.getDeclaredConstructors()[0];
  defaultConstructor.setAccessible(true);
  defaultConstructor.newInstance((Object[])null);
  fail("Should not be allowed");
}
 

Example 3

From project arastreju, under directory /arastreju.sge/src/main/java/org/arastreju/sge/.

Source file: Arastreju.java

  33 
vote

/** 
 * Private constructor.
 * @param profile path to the profile file.
 */
@SuppressWarnings("rawtypes") private Arastreju(final ArastrejuProfile profile){
  this.profile=profile;
  String factoryClass=profile.getProperty(ArastrejuProfile.GATE_FACTORY);
  try {
    final Constructor constructor=Class.forName(factoryClass).getConstructor(ArastrejuProfile.class);
    this.factory=(ArastrejuGateFactory)constructor.newInstance(profile);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 4

From project android_5, under directory /src/aarddict/android/.

Source file: N2EpdController.java

  32 
vote

public static void exitA2Mode(){
  System.err.println("aarddict::exitA2Mode");
  vCurrentNode=0;
  try {
    Class epdControllerClass=Class.forName("android.hardware.EpdController");
    Class epdControllerRegionClass=Class.forName("android.hardware.EpdController$Region");
    Class epdControllerRegionParamsClass=Class.forName("android.hardware.EpdController$RegionParams");
    Class epdControllerWaveClass=Class.forName("android.hardware.EpdController$Wave");
    Object[] waveEnums=null;
    if (epdControllerWaveClass.isEnum()) {
      waveEnums=epdControllerWaveClass.getEnumConstants();
    }
    Object[] regionEnums=null;
    if (epdControllerRegionClass.isEnum()) {
      regionEnums=epdControllerRegionClass.getEnumConstants();
    }
    Constructor RegionParamsConstructor=epdControllerRegionParamsClass.getConstructor(new Class[]{Integer.TYPE,Integer.TYPE,Integer.TYPE,Integer.TYPE,epdControllerWaveClass,Integer.TYPE});
    Object localRegionParams=RegionParamsConstructor.newInstance(new Object[]{0,0,600,800,waveEnums[3],16});
    Method epdControllerSetRegionMethod=epdControllerClass.getMethod("setRegion",new Class[]{String.class,epdControllerRegionClass,epdControllerRegionParamsClass});
    epdControllerSetRegionMethod.invoke(null,new Object[]{"aarddicteadingView",regionEnums[2],localRegionParams});
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 5

From project aunit, under directory /junit/src/main/java/com/toolazydogs/aunit/internal/.

Source file: LexerFactory.java

  32 
vote

public Lexer generate(CharStream input) throws Exception {
  Class<L> wc=getWrapperClass();
  Constructor c=wc.getConstructor(CharStream.class);
  LexerWrapper wrapper=(LexerWrapper)c.newInstance(input);
  if (lexerSetup != null) {
    lexerSetup.config((L)wrapper);
  }
  wrapper.setFailOnError(failOnError);
  return (Lexer)wrapper;
}
 

Example 6

From project byteman, under directory /agent/src/main/java/org/jboss/byteman/rule/expression/.

Source file: NewExpression.java

  32 
vote

public List<Constructor> pruneCandidates(List<Constructor> candidates,int argIdx,Class argClazz){
  for (int i=0; i < candidates.size(); ) {
    Constructor c=candidates.get(i);
    Class nextClazz=c.getParameterTypes()[argIdx];
    if (nextClazz != argClazz) {
      candidates.remove(i);
    }
 else {
      i++;
    }
  }
  return candidates;
}
 

Example 7

From project c3p0, under directory /src/java/com/mchange/v2/c3p0/impl/.

Source file: C3P0JavaBeanObjectFactory.java

  32 
vote

protected Object createBlankInstance(Class beanClass) throws Exception {
  if (IdentityTokenized.class.isAssignableFrom(beanClass)) {
    Constructor ctor=beanClass.getConstructor(CTOR_ARG_TYPES);
    return ctor.newInstance(CTOR_ARGS);
  }
 else   return super.createBlankInstance(beanClass);
}
 

Example 8

From project cascading, under directory /src/core/cascading/util/.

Source file: Util.java

  32 
vote

public static Object createProtectedObject(Class type,Object[] parameters,Class[] parameterTypes){
  try {
    Constructor constructor=type.getDeclaredConstructor(parameterTypes);
    constructor.setAccessible(true);
    return constructor.newInstance(parameters);
  }
 catch (  Exception exception) {
    LOG.error("unable to instantiate type: {}, with exception: {}",type.getName(),exception);
    throw new FlowException("unable to instantiate type: " + type.getName(),exception);
  }
}
 

Example 9

From project Aion-Extreme, under directory /AE-go_GameServer/src/com/aionemu/gameserver/model/quests/.

Source file: ConditionFactory.java

  31 
vote

public static QuestCondition newCondition(String name,NamedNodeMap attr) throws QuestEngineException {
  try {
    if (conditions.containsKey(name)) {
      Constructor con=conditions.get(name).getConstructor(new Class<?>[]{NamedNodeMap.class});
      return (QuestCondition)con.newInstance(new Object[]{attr});
    }
  }
 catch (  InstantiationException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
catch (  IllegalAccessException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
catch (  IllegalArgumentException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
catch (  InvocationTargetException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
catch (  NoSuchMethodException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
catch (  SecurityException ex) {
    throw new QuestEngineException("Error on QuestCondition \"" + name + "\".",ex);
  }
  throw new QuestEngineException("Unhandled QuestCondition \"" + name + "\".");
}
 

Example 10

From project amber, under directory /oauth-2.0/common/src/main/java/org/apache/amber/oauth2/common/utils/.

Source file: OAuthUtils.java

  31 
vote

public static Object instantiateClassWithParameters(Class clazz,Class[] paramsTypes,Object[] paramValues) throws OAuthSystemException {
  try {
    if (paramsTypes != null && paramValues != null) {
      if (!(paramsTypes.length == paramValues.length)) {
        throw new IllegalArgumentException("Number of types and values must be equal");
      }
      if (paramsTypes.length == 0 && paramValues.length == 0) {
        return clazz.newInstance();
      }
      Constructor clazzConstructor=clazz.getConstructor(paramsTypes);
      return clazzConstructor.newInstance(paramValues);
    }
    return clazz.newInstance();
  }
 catch (  NoSuchMethodException e) {
    throw new OAuthSystemException(e);
  }
catch (  InstantiationException e) {
    throw new OAuthSystemException(e);
  }
catch (  IllegalAccessException e) {
    throw new OAuthSystemException(e);
  }
catch (  InvocationTargetException e) {
    throw new OAuthSystemException(e);
  }
}
 

Example 11

From project Android_1, under directory /org.eclipse.ecf.android/src/org/eclipse/ecf/android/.

Source file: SOManager.java

  31 
vote

@SuppressWarnings("unchecked") protected ISharedObject createSharedObjectInstance(final Class newClass,final Class[] argTypes,final Object[] args) throws Exception {
  Object newObject=null;
  try {
    newObject=AccessController.doPrivileged(new PrivilegedExceptionAction(){
      public Object run() throws Exception {
        Constructor aConstructor=newClass.getConstructor(argTypes);
        aConstructor.setAccessible(true);
        return aConstructor.newInstance(args);
      }
    }
);
  }
 catch (  java.security.PrivilegedActionException e) {
    throw e.getException();
  }
  return verifySharedObject(newObject);
}
 

Example 12

From project ant4eclipse, under directory /org.ant4eclipse.lib.core/src/org/ant4eclipse/lib/core/util/.

Source file: Utilities.java

  31 
vote

/** 
 * <p> The class must be loadable via Class.forName() and must have a constructor with a single String parameter. </p>
 * @param className The name of the class. Neither <code>null</code> nor empty.
 * @param arg The argument used to instantiate the class. Maybe <code>null</code>.
 * @return The newly instantiated type. Not <code>null</code>.
 */
@SuppressWarnings({"unchecked","rawtypes"}) public static final <T>T newInstance(String className,String arg){
  Assure.notNull("className",className);
  Class<?> clazz=null;
  try {
    clazz=Class.forName(className);
  }
 catch (  Exception ex) {
    throw new Ant4EclipseException(ex,CoreExceptionCode.COULD_NOT_LOAD_CLASS,className,ex.toString());
  }
  Constructor constructor=null;
  try {
    constructor=clazz.getConstructor(String.class);
  }
 catch (  NoSuchMethodException ex) {
    throw new Ant4EclipseException(ex,CoreExceptionCode.COULD_NOT_INSTANTIATE_CLASS,className,ex.toString());
  }
  T object=null;
  try {
    object=(T)constructor.newInstance(arg);
  }
 catch (  Exception ex) {
    throw new Ant4EclipseException(ex,CoreExceptionCode.COULD_NOT_INSTANTIATE_CLASS,className,ex.toString());
  }
  return object;
}
 

Example 13

From project any23, under directory /core/src/main/java/org/apache/any23/vocab/.

Source file: RDFSchemaUtils.java

  31 
vote

/** 
 * Serializes all the vocabularies to <i>NQuads</i> over the given output stream.
 * @param format output format for vocabularies.
 * @param ps output print stream.
 */
public static void serializeVocabularies(VocabularyFormat format,PrintStream ps){
  final Class vocabularyClass=Vocabulary.class;
  final List<Class> vocabularies=DiscoveryUtils.getClassesInPackage(vocabularyClass.getPackage().getName(),vocabularyClass);
  int currentIndex=0;
  for (  Class vocabClazz : vocabularies) {
    final Vocabulary instance;
    try {
      final Constructor constructor=vocabClazz.getDeclaredConstructor();
      constructor.setAccessible(true);
      instance=(Vocabulary)constructor.newInstance();
    }
 catch (    Exception e) {
      throw new RuntimeException("Error while instantiating vocabulary class " + vocabClazz,e);
    }
    try {
      serializeVocabulary(instance,format,currentIndex < vocabularies.size() - 2,ps);
    }
 catch (    RDFHandlerException rdfhe) {
      throw new RuntimeException("Error while serializing vocabulary.",rdfhe);
    }
  }
}
 

Example 14

From project avro, under directory /lang/java/avro/src/main/java/org/apache/avro/specific/.

Source file: SpecificData.java

  31 
vote

/** 
 * Create an instance of a class.  If the class implements  {@link SchemaConstructable}, call a constructor with a  {@link org.apache.avro.Schema} parameter, otherwise use a no-arg constructor. 
 */
@SuppressWarnings("unchecked") public static Object newInstance(Class c,Schema s){
  boolean useSchema=SchemaConstructable.class.isAssignableFrom(c);
  Object result;
  try {
    Constructor meth=(Constructor)CTOR_CACHE.get(c);
    if (meth == null) {
      meth=c.getDeclaredConstructor(useSchema ? SCHEMA_ARG : NO_ARG);
      meth.setAccessible(true);
      CTOR_CACHE.put(c,meth);
    }
    result=meth.newInstance(useSchema ? new Object[]{s} : (Object[])null);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  return result;
}
 

Example 15

From project BioMAV, under directory /Behavior/src/nl/ru/ai/projects/parrot/biomav/editor/.

Source file: BehaviorVertex.java

  31 
vote

@SuppressWarnings({"rawtypes","unchecked"}) public State initState(BehaviorArray behaviors){
  Class stateClass=FSM_STATES.get(selectedBehaviorState);
  try {
    Constructor c=stateClass.getConstructor(BehaviorArray.class);
    State result=(State)c.newInstance(behaviors);
    result.addStateListener(this);
    return result;
  }
 catch (  NoSuchMethodException e) {
    e.printStackTrace();
  }
catch (  SecurityException e) {
    e.printStackTrace();
  }
catch (  InstantiationException e) {
    e.printStackTrace();
  }
catch (  IllegalAccessException e) {
    e.printStackTrace();
  }
catch (  IllegalArgumentException e) {
    e.printStackTrace();
  }
catch (  InvocationTargetException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 16

From project blacktie, under directory /jatmibroker-xatmi/src/main/java/org/jboss/narayana/blacktie/jatmibroker/xatmi/impl/.

Source file: ConnectionImpl.java

  31 
vote

/** 
 * Allocate a new buffer
 * @param type The type of the buffer
 * @param subtype The subtype of the buffer
 * @return The new buffer
 * @throws ConnectionException If the buffer was unknown or invalid.
 * @throws ConfigurationException
 */
public Buffer tpalloc(String type,String subtype) throws ConnectionException, ConfigurationException {
  if (type == null) {
    throw new ConnectionException(ConnectionImpl.TPEINVAL,"No type provided");
  }
 else {
    log.debug("Initializing a new: " + type);
    try {
      Class clazz=Class.forName(getClass().getPackage().getName() + "." + type+ "_Impl");
      Constructor ctor=clazz.getConstructor(String.class);
      return (Buffer)ctor.newInstance(subtype);
    }
 catch (    InvocationTargetException t) {
      if (t.getCause() instanceof ConfigurationException) {
        throw ((ConfigurationException)t.getCause());
      }
      throw new ConnectionException(ConnectionImpl.TPENOENT,"Type was not known: " + type,t);
    }
catch (    Throwable t) {
      throw new ConnectionException(ConnectionImpl.TPENOENT,"Type was not known: " + type,t);
    }
  }
}
 

Example 17

From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.

Source file: AggregateConverter.java

  31 
vote

private Object createObject(String value,Class type) throws Exception {
  if (type.isInterface() || Modifier.isAbstract(type.getModifiers())) {
    throw new Exception("Unable to convert value " + value + " to type "+ type+ ". Type "+ type+ " is an interface or an abstract class");
  }
  Constructor constructor=null;
  try {
    constructor=type.getConstructor(String.class);
  }
 catch (  NoSuchMethodException e) {
    throw new RuntimeException("Unable to convert to " + type);
  }
  try {
    return ReflectionUtils.newInstance(blueprintContainer.getAccessControlContext(),constructor,value);
  }
 catch (  Exception e) {
    throw new Exception("Unable to convert ",getRealCause(e));
  }
}
 

Example 18

From project BMach, under directory /src/jsyntaxpane/actions/gui/.

Source file: MembersListRenderer.java

  31 
vote

@Override public Component getListCellRendererComponent(final JList list,Object value,final int index,final boolean isSelected,boolean cellHasFocus){
  Color back=(index % 2 == 1) ? list.getBackground() : evensColor;
  if (value instanceof Method) {
    final Method method=(Method)value;
    return new MethodCell(list,isSelected,back,method,dlg.getTheClass());
  }
 else   if (value instanceof Field) {
    Field field=(Field)value;
    return new FieldCell(list,isSelected,back,field,dlg.getTheClass());
  }
 else   if (value instanceof Constructor) {
    Constructor cons=(Constructor)value;
    return new ConstructorCell(list,isSelected,back,cons,dlg.getTheClass());
  }
 else {
    Component comp=super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
    comp.setBackground(back);
    return comp;
  }
}
 

Example 19

From project caseconductor-platform, under directory /utest-domain-services/src/main/java/com/utest/domain/service/impl/.

Source file: StaticDataServiceImpl.java

  31 
vote

@SuppressWarnings("unchecked") private Object createClass(final Class clazz_,final String description,final List<Integer> parentId) throws Exception {
  boolean found=false;
  boolean isParentDependable=false;
  for (  final Class intf : clazz_.getInterfaces()) {
    if (intf.equals(Descriptable.class)) {
      found=true;
    }
    if (intf.equals(ParentDependable.class)) {
      isParentDependable=true;
    }
  }
  if (!found) {
    throw new IllegalArgumentException("Class " + clazz_.getName() + " should implement "+ Descriptable.class.getName()+ " interface!");
  }
  if (isParentDependable && ((parentId == null) || parentId.isEmpty())) {
    throw new IllegalArgumentException("Class " + clazz_.getName() + " is parrent dependable and you should provide parent id!");
  }
  final Constructor constr=clazz_.getConstructor(new Class[]{});
  final Object created=constr.newInstance(new Object[]{});
  Method set=clazz_.getMethod("setDescription",String.class);
  set.invoke(created,description);
  set=clazz_.getMethod("setSortOrder",Integer.class);
  set.invoke(created,new Integer(0));
  if (isParentDependable) {
    ((ParentDependable)created).setParentId(parentId.get(0));
  }
  return created;
}
 

Example 20

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 21

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/.

Source file: Webserver.java

  29 
vote

protected Acceptor createAcceptor() throws IOException {
  String acceptorClass=(String)arguments.get(ARG_ACCEPTOR_CLASS);
  if (acceptorClass == null)   acceptorClass="nl.dannyarends.www.http.BasicAcceptor";
  try {
    acceptor=(Acceptor)Class.forName(acceptorClass).newInstance();
  }
 catch (  InstantiationException e) {
    log("Couldn't instantiate Acceptor, the Server is inoperable",e);
  }
catch (  IllegalAccessException e) {
    Constructor<?> c;
    try {
      c=Class.forName(acceptorClass).getDeclaredConstructor(Utils.EMPTY_CLASSES);
      c.setAccessible(true);
      acceptor=(Acceptor)c.newInstance(Utils.EMPTY_OBJECTS);
    }
 catch (    Exception e1) {
      log("Acceptor is not accessable or can't be instantiated, the Server is inoperable",e);
    }
  }
catch (  ClassNotFoundException e) {
    String fatal;
    log(fatal="Acceptor class not found, the Server is inoperable",e);
    Utils.console(fatal);
    System.exit(-2);
  }
  Map<String,Object> acceptorProperties=new HashMap<String,Object>();
  acceptor.init(arguments,acceptorProperties);
  hostName=(String)acceptorProperties.get(ARG_BINDADDRESS);
  Utils.log("Hostname:" + hostName,System.err);
  return acceptor;
}
 

Example 22

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 23

From project Aardvark, under directory /aardvark-core/src/main/java/gw/vark/typeloader/.

Source file: AntlibTypeInfo.java

  29 
vote

static IType makeListOfBlocksType(Class parameterType){
  try {
    Class<?> clazz=Class.forName("gw.internal.gosu.parser.expressions.BlockType");
    Constructor<?> ctor=clazz.getConstructor(IType.class,IType[].class,List.class,List.class);
    IType blkType=(IType)ctor.newInstance(JavaTypes.pVOID(),new IType[]{TypeSystem.get(parameterType)},Arrays.asList("arg"),Collections.<Object>emptyList());
    return JavaTypes.LIST().getGenericType().getParameterizedType(blkType);
  }
 catch (  Exception e) {
    throw GosuExceptionUtil.forceThrow(e);
  }
}
 

Example 24

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 25

From project AirReceiver, under directory /src/main/java/org/phlo/AirReceiver/.

Source file: AirTunesCrytography.java

  29 
vote

/** 
 * Creates a  {@link javax.crypto.Cipher} instance from a {@link javax.crypto.CipherSpi}.
 * @param cipherSpi the {@link javax.cyrpto.CipherSpi} instance
 * @param transformation the transformation cipherSpi was obtained for
 * @return a {@link javax.crypto.Cipher} instance
 * @throws Throwable in case of an error
 */
private static Cipher getCipher(final CipherSpi cipherSpi,final String transformation) throws Throwable {
  final Class<Cipher> cipherClass=Cipher.class;
  final Constructor<Cipher> cipherConstructor=cipherClass.getDeclaredConstructor(CipherSpi.class,String.class);
  cipherConstructor.setAccessible(true);
  try {
    return cipherConstructor.newInstance(cipherSpi,transformation);
  }
 catch (  final InvocationTargetException e) {
    throw e.getCause();
  }
}
 

Example 26

From project ALP, under directory /workspace/alp-flexpilot/src/main/java/com/lohika/alp/flexpilot/pagefactory/.

Source file: FlexPilotPageFactory.java

  29 
vote

/** 
 * Instantiate page.
 * @param driver the driver
 * @param pageClassToProxy the page class to proxy
 * @return the t
 */
private static <T>T instantiatePage(FlexPilotDriver driver,Class<T> pageClassToProxy){
  try {
    try {
      Constructor<T> constructor=pageClassToProxy.getConstructor(FlexPilotDriver.class);
      return constructor.newInstance(driver);
    }
 catch (    NoSuchMethodException e) {
      return pageClassToProxy.newInstance();
    }
  }
 catch (  InstantiationException e) {
    throw new RuntimeException(e);
  }
catch (  IllegalAccessException e) {
    throw new RuntimeException(e);
  }
catch (  InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 

Example 27

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 28

From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/bean/.

Source file: PureJavaReflectionProvider.java

  29 
vote

public Object newInstance(Class type){
  try {
    Constructor[] constructors=type.getDeclaredConstructors();
    for (int i=0; i < constructors.length; i++) {
      if (constructors[i].getParameterTypes().length == 0) {
        if (!Modifier.isPublic(constructors[i].getModifiers())) {
          constructors[i].setAccessible(true);
        }
        return constructors[i].newInstance(new Object[0]);
      }
    }
    if (Serializable.class.isAssignableFrom(type)) {
      return instantiateUsingSerialization(type);
    }
 else {
      throw new ObjectAccessException("Cannot construct " + type.getName() + " as it does not have a no-args constructor");
    }
  }
 catch (  InstantiationException e) {
    throw new ObjectAccessException("Cannot construct " + type.getName(),e);
  }
catch (  IllegalAccessException e) {
    throw new ObjectAccessException("Cannot construct " + type.getName(),e);
  }
catch (  InvocationTargetException e) {
    if (e.getTargetException() instanceof RuntimeException) {
      throw (RuntimeException)e.getTargetException();
    }
 else     if (e.getTargetException() instanceof Error) {
      throw (Error)e.getTargetException();
    }
 else {
      throw new ObjectAccessException("Constructor for " + type.getName() + " threw an exception",e.getTargetException());
    }
  }
}
 

Example 29

From project amplafi-sworddance, under directory /src/main/java/com/sworddance/beans/.

Source file: PropertyAdaptor.java

  29 
vote

/** 
 * Checks to see if this adaptor's property type has a public constructor that takes a single String argument.
 */
private Object instantiateViaStringConstructor(String value){
  try {
    Constructor<?> c=getReturnType().getConstructor(new Class[]{String.class});
    return c.newInstance(new Object[]{value});
  }
 catch (  Exception ex) {
    return null;
  }
}
 

Example 30

From project anadix, under directory /anadix-api/src/main/java/org/anadix/.

Source file: Anadix.java

  29 
vote

private Analyzer createAnalyzer(ConditionSet conditions,Parser parser) throws InstantiationException {
  if (conditions == null) {
    conditions=createConditionSet();
  }
  if (parser == null) {
    parser=createParser(conditions);
  }
  try {
    Constructor<?> constructor=analyzer.getConstructor(Parser.class,ConditionSet.class);
    Object instance=constructor.newInstance(parser,conditions);
    return Analyzer.class.cast(instance);
  }
 catch (  RuntimeException ex) {
    throw ex;
  }
catch (  Exception ex) {
    logger.error("Unable to instantiate AnalyzerImpl",ex);
    throw new RuntimeException("Unable to instantiate AnalyzerImpl",ex);
  }
}
 

Example 31

From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 32

From project android-client, under directory /xwiki-android-core/src/org/xwiki/android/context/.

Source file: XWikiApplicationContext.java

  29 
vote

public FileStoreManager getFileStoreManager(){
  FileStoreManager fsm=null;
  try {
    Constructor<FileStoreManagerImpl> con=FileStoreManagerImpl.class.getDeclaredConstructor(XWikiApplicationContext.class);
    con.setAccessible(true);
    fsm=con.newInstance(this);
  }
 catch (  SecurityException e) {
    e.printStackTrace();
  }
catch (  NoSuchMethodException e) {
    e.printStackTrace();
  }
catch (  IllegalArgumentException e) {
    e.printStackTrace();
  }
catch (  InstantiationException e) {
    e.printStackTrace();
  }
catch (  IllegalAccessException e) {
    e.printStackTrace();
  }
catch (  InvocationTargetException e) {
    e.printStackTrace();
  }
  return fsm;
}
 

Example 33

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/compat/.

Source file: CompatUtils.java

  29 
vote

public static Constructor<?> getConstructor(Class<?> targetClass,Class<?>... types){
  if (targetClass == null || types == null)   return null;
  try {
    return targetClass.getConstructor(types);
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
  return null;
}
 

Example 34

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.

Source file: BookStoreFactory.java

  29 
vote

private static void addStore(Context context,XmlResourceParser parser,AttributeSet attrs,HashMap<String,BooksStore> stores){
  TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.BookStore);
  final String name=a.getString(R.styleable.BookStore_name);
  if (TextUtils.isEmpty(name)) {
    throw new InflateException(parser.getPositionDescription() + ": A store must have a name");
  }
  final String label=a.getString(R.styleable.BookStore_label);
  if (TextUtils.isEmpty(label)) {
    throw new InflateException(parser.getPositionDescription() + ": A store must have a label");
  }
  final String storeClass=a.getString(R.styleable.BookStore_storeClass);
  if (TextUtils.isEmpty(name)) {
    throw new InflateException(parser.getPositionDescription() + ": A store must have a class");
  }
  a.recycle();
  try {
    Class<?> klass=Class.forName(storeClass);
    Constructor<?> constructor=klass.getDeclaredConstructor(String.class,String.class);
    constructor.setAccessible(true);
    BooksStore store=(BooksStore)constructor.newInstance(name,label);
    stores.put(name,store);
  }
 catch (  ClassNotFoundException e) {
  }
catch (  NoSuchMethodException e) {
    throw new InflateException(parser.getPositionDescription() + ": The book store " + storeClass+ " does not have a matching constructor");
  }
catch (  IllegalAccessException e) {
    throw new InflateException(parser.getPositionDescription() + ": Could not create the " + "book store",e);
  }
catch (  InvocationTargetException e) {
    throw new InflateException(parser.getPositionDescription() + ": Could not create the " + "book store",e);
  }
catch (  InstantiationException e) {
    throw new InflateException(parser.getPositionDescription() + ": Could not create the " + "book store",e);
  }
}
 

Example 35

From project androidquery, under directory /src/com/androidquery/.

Source file: AbstractAQuery.java

  29 
vote

protected T create(View view){
  T result=null;
  try {
    Constructor<T> c=getConstructor();
    result=(T)c.newInstance(view);
    result.act=act;
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return result;
}
 

Example 36

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T newInstance(String className,Class<?>[] constructorSignature,Object[] arguments){
  try {
    Class<?> clazz=mContext.getClassLoader().loadClass(className);
    Constructor<?> constructor=clazz.getConstructor(constructorSignature);
    return (T)constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    Log.w(LOG_TAG,"Cannot instantiate class: " + className,e);
  }
  return null;
}
 

Example 37

From project android_8, under directory /src/com/google/gson/.

Source file: DefaultConstructorAllocator.java

  29 
vote

private static final Constructor<Null> createNullConstructor(){
  try {
    return getNoArgsConstructor(Null.class);
  }
 catch (  Exception e) {
    return null;
  }
}
 

Example 38

From project android_packages_apps_Exchange, under directory /tests/src/com/android/exchange/adapter/.

Source file: SyncAdapterTestCase.java

  29 
vote

protected T getTestSyncAdapter(Class<T> klass){
  EasSyncService service=getTestService();
  Constructor<T> c;
  try {
    c=klass.getDeclaredConstructor(new Class[]{EasSyncService.class});
    return c.newInstance(service);
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
catch (  IllegalArgumentException e) {
  }
catch (  InstantiationException e) {
  }
catch (  IllegalAccessException e) {
  }
catch (  InvocationTargetException e) {
  }
  return null;
}
 

Example 39

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/compat/.

Source file: CompatUtils.java

  29 
vote

public static Constructor<?> getConstructor(Class<?> targetClass,Class<?>... types){
  if (targetClass == null || types == null)   return null;
  try {
    return targetClass.getConstructor(types);
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
  return null;
}
 

Example 40

From project ANNIS, under directory /annis-service/src/main/java/annis/ql/parser/.

Source file: ClauseAnalysis.java

  29 
vote

/** 
 * Automatically create a join from a node and a join class. This will automatically get the parent node, it's left and right hand node and will construct a new join specified by the type using reflection.
 * @node
 * @type
 */
private void join(PLingOp node,Class<? extends Join> type){
  QueryNode left=lhs(node);
  QueryNode right=rhs(node);
  Validate.notNull(left,errorLHS(type.getSimpleName()));
  Validate.notNull(right,errorRHS(type.getSimpleName()));
  try {
    Constructor<? extends Join> c=type.getConstructor(QueryNode.class);
    Join newJoin=c.newInstance(right);
    left.addJoin(newJoin);
  }
 catch (  Exception ex) {
    log.error(null,ex);
  }
}
 

Example 41

From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/utils/.

Source file: CompatUtils.java

  29 
vote

public static Constructor<?> getConstructor(Class<?> targetClass,Class<?>... types){
  if (targetClass == null || types == null)   return null;
  try {
    return targetClass.getConstructor(types);
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
  return null;
}
 

Example 42

From project apb, under directory /modules/apb-base/src/apb/.

Source file: ModuleHelper.java

  29 
vote

@Override void init(){
  super.init();
  Class<? extends TestModule> tmClass=getModule().test;
  if (tmClass != null) {
    try {
      Constructor<? extends TestModule> c=tmClass.getDeclaredConstructor();
      c.setAccessible(true);
      testModule=c.newInstance().getHelper();
      testModule.setModuleToTest(this);
    }
 catch (    InstantiationException e) {
      throw new BuildException(e);
    }
catch (    IllegalAccessException e) {
      throw new BuildException(e);
    }
catch (    NoSuchMethodException e) {
      throw new RuntimeException(e);
    }
catch (    InvocationTargetException e) {
      throw new RuntimeException(e.getCause());
    }
  }
}
 

Example 43

From project apollo, under directory /injector/src/main/java/com/bskyb/cg/environments/message/.

Source file: MessageFormatFactory.java

  29 
vote

private Object newInstance(String logFormat,Class<?>[] paramTypes,Object[] params){
  Object obj=null;
  String classname=logFormat;
  try {
    Class<?> cls=classes.get(classname);
    if (cls == null) {
      throw new RuntimeException("No class registered under " + logFormat);
    }
    Constructor<?> ctor=cls.getConstructor(paramTypes);
    obj=ctor.newInstance(params);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
  }
  return obj;
}
 

Example 44

From project Archimedes, under directory /br.org.archimedes.core/src/br/org/archimedes/factories/.

Source file: ElementFactory.java

  29 
vote

/** 
 * @param elementId Element's id
 * @param args The arguments (in the correct order) to create the element (the constructor with those arguments in this order MUST exist).
 * @return The element created
 * @throws ElementCreationException Thrown if there is some problem during the method invoke
 */
public Element createElement(String elementId,Object... args) throws ElementCreationException {
  ElementEPLoader loader=new ElementEPLoader();
  Element element=null;
  Class<? extends Element> elementClass=loader.getElementClass(elementId);
  if (elementClass != null) {
    try {
      Constructor<? extends Element> constructor=getMatchableConstructor(elementClass,args);
      element=constructor.newInstance(args);
    }
 catch (    IllegalArgumentException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_WrongNumberArguments,elementId),e);
    }
catch (    NoSuchMethodException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_WrongArgument,elementId),e);
    }
catch (    InstantiationException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_NonBuildableObject,elementId),e);
    }
catch (    SecurityException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_MissingPlugins,elementId),e);
    }
catch (    IllegalAccessException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_MissingPlugins,elementId),e);
    }
catch (    InvocationTargetException e) {
      throw new ElementCreationException(Messages.bind(Messages.ElementFactory_InvalidConstructor,elementId),e);
    }
  }
  return element;
}
 

Example 45

From project ardverk-dht, under directory /components/core/src/main/java/org/ardverk/dht/rsrc/.

Source file: ValueUtils.java

  29 
vote

public static <T extends Value>T valueOf(Class<T> clazz,InputStream in) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  try {
    StreamUtils.copy(in,baos);
  }
  finally {
    IoUtils.close(baos);
  }
  try {
    Constructor<T> constructor=clazz.getConstructor(byte[].class);
    return constructor.newInstance(baos.toByteArray());
  }
 catch (  SecurityException e) {
    throw new IOException("SecurityException",e);
  }
catch (  NoSuchMethodException e) {
    throw new IOException("NoSuchMethodException",e);
  }
catch (  IllegalArgumentException e) {
    throw new IOException("IllegalArgumentException",e);
  }
catch (  InstantiationException e) {
    throw new IOException("InstantiationException",e);
  }
catch (  IllegalAccessException e) {
    throw new IOException("IllegalAccessException",e);
  }
catch (  InvocationTargetException e) {
    throw new IOException("InvocationTargetException",e);
  }
}
 

Example 46

From project Arecibo, under directory /util/src/main/java/com/ning/arecibo/util/lifecycle/.

Source file: LifecycledProvider.java

  29 
vote

@SuppressWarnings("unchecked") public T get(){
  Class<? super T> classObject=(Class<? super T>)getRawType(type.getType());
  Constructor<?>[] constructors=classObject.getConstructors();
  for (  Constructor<?> constructor : constructors) {
    if (constructor.getAnnotation(Inject.class) != null) {
      Class<?>[] parameterTypes=constructor.getParameterTypes();
      Annotation[][] parameterAnnotations=constructor.getParameterAnnotations();
      if (parameterTypes.length != parameterAnnotations.length) {
        throw new RuntimeException("How is this possible?");
      }
      Object[] parameters=new Object[parameterTypes.length];
      for (int i=0; i < parameterTypes.length; ++i) {
        if (parameterAnnotations[i].length != 1) {
          parameters[i]=injector.getInstance(Key.get(parameterTypes[i]));
        }
 else {
          parameters[i]=injector.getInstance(Key.get(parameterTypes[i],parameterAnnotations[i][0]));
        }
      }
      try {
        return (T)constructor.newInstance(parameters);
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
  throw new RuntimeException(String.format("No @Inject annotations found on class[%s]",classObject.getName()));
}
 

Example 47

From project arkadiko, under directory /src/com/liferay/arkadiko/.

Source file: AKBeanPostProcessor.java

  29 
vote

/** 
 * Instantiate.
 * @param beanDefinition the bean definition
 * @param beanName the bean name
 * @param owner the owner
 * @param ctor the ctor
 * @param args the args
 * @return the object
 */
@Override public Object instantiate(RootBeanDefinition beanDefinition,String beanName,BeanFactory owner,Constructor<?> ctor,Object[] args){
  if (beanDefinition instanceof AKBeanDefinition) {
    AKBeanDefinition akBeanDefinition=(AKBeanDefinition)beanDefinition;
    return akBeanDefinition.getProxy();
  }
  return super.instantiate(beanDefinition,beanName,owner,ctor,args);
}
 

Example 48

From project arquillian-container-gae, under directory /gae-embedded/src/main/java/org/jboss/arquillian/container/appengine/embedded/hack/.

Source file: DevAppServerFactoryHack.java

  29 
vote

private static DevAppServer createDevAppServer(Object[] ctorArgs){
  ClassLoader loader=DevAppServerClassLoaderExposed.newClassLoader(DevAppServerFactory.class.getClassLoader());
  DevAppServer devAppServer;
  try {
    Class<?> devAppServerClass=Class.forName("com.google.appengine.tools.development.DevAppServerImpl",true,loader);
    Constructor<?> cons=devAppServerClass.getConstructor(DEV_APPSERVER_CTOR_ARG_TYPES);
    cons.setAccessible(true);
    devAppServer=(DevAppServer)cons.newInstance(ctorArgs);
  }
 catch (  Exception e) {
    Throwable t=e;
    if (e instanceof InvocationTargetException) {
      t=e.getCause();
    }
    throw new RuntimeException("Unable to create a DevAppServer",t);
  }
  System.setSecurityManager(new CustomSecurityManager(devAppServer));
  return devAppServer;
}
 

Example 49

From project arquillian-container-weld, under directory /weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: ServiceLoader.java

  29 
vote

private S prepareInstance(Class<? extends S> serviceClass){
  try {
    Constructor<? extends S> constructor=serviceClass.getDeclaredConstructor();
    constructor.setAccessible(true);
    return constructor.newInstance();
  }
 catch (  NoClassDefFoundError e) {
    log.log(WARNING,"Could not instantiate service class " + serviceClass.getName(),e);
    return null;
  }
catch (  InvocationTargetException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e.getCause());
  }
catch (  IllegalArgumentException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  InstantiationException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  IllegalAccessException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  SecurityException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  NoSuchMethodException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
}
 

Example 50

From project arquillian-core, under directory /container/impl-base/src/main/java/org/jboss/arquillian/container/impl/client/container/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Create a new instance by finding a constructor that matches the argumentTypes signature  using the arguments for instantiation.
 * @param className Full classname of class to create
 * @param argumentTypes The constructor argument types
 * @param arguments The constructor arguments
 * @return a new instance
 * @throws IllegalArgumentException if className, argumentTypes, or arguments are null
 * @throws RuntimeException if any exceptions during creation
 * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
 * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
 */
static <T>T newInstance(final Class<T> implClass,final Class<?>[] argumentTypes,final Object[] arguments){
  if (implClass == null) {
    throw new IllegalArgumentException("ImplClass must be specified");
  }
  if (argumentTypes == null) {
    throw new IllegalArgumentException("ArgumentTypes must be specified. Use empty array if no arguments");
  }
  if (arguments == null) {
    throw new IllegalArgumentException("Arguments must be specified. Use empty array if no arguments");
  }
  final T obj;
  try {
    Constructor<T> constructor=getConstructor(implClass,argumentTypes);
    if (!constructor.isAccessible()) {
      constructor.setAccessible(true);
    }
    obj=constructor.newInstance(arguments);
  }
 catch (  Exception e) {
    throw new RuntimeException("Could not create new instance of " + implClass,e);
  }
  return obj;
}
 

Example 51

From project arquillian-extension-android, under directory /android-configuration/src/main/java/org/jboss/arquillian/android/configuration/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 52

From project arquillian-extension-drone, under directory /drone-impl/src/main/java/org/jboss/arquillian/drone/impl/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 53

From project arquillian-extension-persistence, under directory /impl/src/main/java/org/jboss/arquillian/persistence/dbunit/configuration/.

Source file: ReflectionHelper.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 54

From project arquillian-extension-seam2, under directory /src/main/java/org/jboss/arquillian/seam2/.

Source file: ReflectionHelper.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 55

From project arquillian-extension-spring, under directory /arquillian-service-integration-spring-inject/src/main/java/org/jboss/arquillian/spring/integration/inject/container/.

Source file: XmlRemoteApplicationContextProducer.java

  29 
vote

/** 
 * <p>Creates new instance of  {@link org.springframework.context.ApplicationContext}.</p>
 * @param applicationContextClass the class of application context
 * @param locations               the locations from which load the configuration files
 * @return the created {@link org.springframework.context.ApplicationContext} instance
 */
private <T extends ApplicationContext>ApplicationContext createInstance(Class<T> applicationContextClass,String[] locations){
  try {
    Constructor<T> ctor=applicationContextClass.getConstructor(String[].class);
    return ctor.newInstance((Object)locations);
  }
 catch (  NoSuchMethodException e) {
    throw new RuntimeException("Could not create instance of " + applicationContextClass.getName() + ", no appropriate constructor found.",e);
  }
catch (  InvocationTargetException e) {
    throw new RuntimeException("Could not create instance of " + applicationContextClass.getName(),e);
  }
catch (  InstantiationException e) {
    throw new RuntimeException("Could not create instance of " + applicationContextClass.getName(),e);
  }
catch (  IllegalAccessException e) {
    throw new RuntimeException("Could not create instance of " + applicationContextClass.getName(),e);
  }
}
 

Example 56

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/test/.

Source file: SecurityActions.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 57

From project arquillian-graphene, under directory /graphene-webdriver/graphene-webdriver-impl/src/main/java/org/jboss/arquillian/graphene/enricher/.

Source file: ReflectionHelper.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 58

From project arquillian-rusheye, under directory /rusheye-api/src/main/java/org/jboss/rusheye/suite/.

Source file: Properties.java

  29 
vote

public <T>T getProperty(String propertyKey,Class<T> tClass){
  Object object=getProperty(propertyKey);
  if (object == null) {
    return null;
  }
  Constructor<T> constructor;
  try {
    constructor=tClass.getConstructor(String.class);
  }
 catch (  Exception e) {
    throw new IllegalStateException("can't automatically convert property '" + propertyKey + "', the constructor "+ tClass.getName()+ "(String) can't be access",e);
  }
  try {
    return constructor.newInstance(object.toString());
  }
 catch (  Exception e) {
    throw new IllegalStateException("can't automatically convert property, the call to " + tClass.getName() + "(\""+ propertyKey+ "\") failed",e);
  }
}
 

Example 59

From project arquillian-showcase, under directory /extensions/autodiscover/src/main/java/org/jboss/arquillian/showcase/extension/autodiscover/.

Source file: ReflectionHelper.java

  29 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 60

From project arquillian-weld-embedded-1.1, under directory /src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: ServiceLoader.java

  29 
vote

private S prepareInstance(Class<? extends S> serviceClass){
  try {
    Constructor<? extends S> constructor=serviceClass.getDeclaredConstructor();
    constructor.setAccessible(true);
    return constructor.newInstance();
  }
 catch (  NoClassDefFoundError e) {
    log.log(WARNING,"Could not instantiate service class " + serviceClass.getName(),e);
    return null;
  }
catch (  InvocationTargetException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e.getCause());
  }
catch (  IllegalArgumentException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  InstantiationException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  IllegalAccessException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  SecurityException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  NoSuchMethodException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
}
 

Example 61

From project arquillian_deprecated, under directory /containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: ServiceLoader.java

  29 
vote

private S prepareInstance(Class<? extends S> serviceClass){
  try {
    Constructor<? extends S> constructor=serviceClass.getDeclaredConstructor();
    constructor.setAccessible(true);
    return constructor.newInstance();
  }
 catch (  NoClassDefFoundError e) {
    log.log(WARNING,"Could not instantiate service class " + serviceClass.getName(),e);
    return null;
  }
catch (  InvocationTargetException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e.getCause());
  }
catch (  IllegalArgumentException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  InstantiationException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  IllegalAccessException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  SecurityException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
catch (  NoSuchMethodException e) {
    throw new RuntimeException("Error instantiating " + serviceClass,e);
  }
}
 

Example 62

From project asterisk-java, under directory /src/main/java/org/asteriskjava/fastagi/.

Source file: AbstractMappingStrategy.java

  29 
vote

/** 
 * Creates a new instance of an AGI script.
 * @param className Class name of the AGI script. The class must implement{@link AgiScript}.
 * @return the created instance of the AGI script class. If the instancecan't be created an error is logged and <code>null</code> is returned.
 */
@SuppressWarnings("unchecked") protected AgiScript createAgiScriptInstance(String className){
  Class<?> tmpClass;
  Class<AgiScript> agiScriptClass;
  Constructor<AgiScript> constructor;
  AgiScript agiScript;
  agiScript=null;
  try {
    tmpClass=getClassLoader().loadClass(className);
  }
 catch (  ClassNotFoundException e1) {
    logger.debug("Unable to create AgiScript instance of type " + className + ": Class not found, make sure the class exists and is available on the CLASSPATH");
    return null;
  }
  if (!AgiScript.class.isAssignableFrom(tmpClass)) {
    logger.warn("Unable to create AgiScript instance of type " + className + ": Class does not implement the AgiScript interface");
    return null;
  }
  agiScriptClass=(Class<AgiScript>)tmpClass;
  try {
    constructor=agiScriptClass.getConstructor();
    agiScript=constructor.newInstance();
  }
 catch (  Exception e) {
    logger.warn("Unable to create AgiScript instance of type " + className,e);
  }
  return agiScript;
}
 

Example 63

From project atlas, under directory /src/main/java/com/ning/atlas/.

Source file: Instantiator.java

  29 
vote

public static <T>T create(Class<T> type,Map<String,String> args) throws IllegalAccessException, InstantiationException {
  try {
    Constructor<?> c=type.getConstructor(Map.class);
    return type.cast(c.newInstance(args));
  }
 catch (  NoSuchMethodException e) {
  }
catch (  Exception e) {
    log.warn(e,"exception trying to use map constructor on " + type.getName());
  }
  return type.newInstance();
}
 

Example 64

From project AudioBox.fm-JavaLib, under directory /audiobox.fm-core/src/main/java/fm/audiobox/configurations/.

Source file: DefaultFactory.java

  29 
vote

@Override public IEntity getEntity(String tagName,IConfiguration configuration){
  IEntity entity=null;
  if (!this.containsEntity(tagName)) {
    log.warn("No IEntity found under key: " + tagName);
    return null;
  }
  Class<? extends IEntity> klass=getEntityByTag(tagName);
  try {
    Constructor<? extends IEntity> constructor=klass.getConstructor(IConfiguration.class);
    entity=constructor.newInstance(configuration);
  }
 catch (  SecurityException e) {
    log.error("SecurityException while instantiating IEntity under key: " + tagName,e);
  }
catch (  NoSuchMethodException e) {
    log.error("NoSuchMethodException while instantiating IEntity under key: " + tagName,e);
  }
catch (  IllegalArgumentException e) {
    log.error("IllegalArgumentException while instantiating IEntity under key: " + tagName,e);
  }
catch (  InstantiationException e) {
    log.error("InstantiationException while instantiating IEntity under key: " + tagName,e);
  }
catch (  IllegalAccessException e) {
    log.error("IllegalAccessException while instantiating IEntity under key: " + tagName,e);
  }
catch (  InvocationTargetException e) {
    log.error("InvocationTargetException while instantiating IEntity under key: " + tagName,e);
  }
  return entity;
}
 

Example 65

From project aviator, under directory /src/main/java/com/googlecode/aviator/asm/.

Source file: Type.java

  29 
vote

/** 
 * Returns the descriptor corresponding to the given constructor.
 * @param c a {@link Constructor Constructor} object.
 * @return the descriptor of the given constructor.
 */
public static String getConstructorDescriptor(final Constructor c){
  Class[] parameters=c.getParameterTypes();
  StringBuffer buf=new StringBuffer();
  buf.append('(');
  for (int i=0; i < parameters.length; ++i) {
    getDescriptor(buf,parameters[i]);
  }
  return buf.append(")V").toString();
}
 

Example 66

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/.

Source file: AWSClientFactory.java

  29 
vote

private <T extends AmazonWebServiceClient>T createClient(String endpoint,Class<T> clientClass){
  try {
    Constructor<T> constructor=clientClass.getConstructor(AWSCredentials.class,ClientConfiguration.class);
    AWSCredentials credentials=new BasicAWSCredentials(accountInfo.getAccessKey(),accountInfo.getSecretKey());
    ClientConfiguration config=createClientConfiguration(endpoint);
    T client=constructor.newInstance(credentials,config);
    client.setEndpoint(endpoint);
    return client;
  }
 catch (  Exception e) {
    throw new RuntimeException("Unable to create client: " + e.getMessage(),e);
  }
}
 

Example 67

From project azkaban, under directory /azkaban/src/java/azkaban/jobs/builtin/.

Source file: JavaJobRunnerMain.java

  29 
vote

private static Object getObject(String jobName,String className,Properties properties) throws Exception {
  Class<?> runningClass=JavaJobRunnerMain.class.getClassLoader().loadClass(className);
  if (runningClass == null) {
    throw new Exception("Class " + className + " was not found. Cannot run job.");
  }
  Class<?> propsClass=JavaJobRunnerMain.class.getClassLoader().loadClass(PROPS_CLASS);
  Object obj=null;
  if (propsClass != null && getConstructor(runningClass,String.class,propsClass) != null) {
    Constructor<?> con=getConstructor(propsClass,propsClass,Properties[].class);
    Object props=con.newInstance(null,new Properties[]{properties});
    obj=getConstructor(runningClass,String.class,propsClass).newInstance(jobName,props);
  }
 else   if (getConstructor(runningClass,String.class,Properties.class) != null) {
    obj=getConstructor(runningClass,String.class,Properties.class).newInstance(jobName,properties);
  }
 else   if (getConstructor(runningClass,String.class) != null) {
    obj=getConstructor(runningClass,String.class).newInstance(jobName);
  }
 else   if (getConstructor(runningClass) != null) {
    obj=getConstructor(runningClass).newInstance();
  }
  return obj;
}
 

Example 68

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/cache/.

Source file: CacheFactory.java

  29 
vote

/** 
 * Gets a cache specified by the given cache name.
 * @param cacheName the given cache name
 * @return a cache specified by the given cache name
 */
@SuppressWarnings("unchecked") public static synchronized Cache<String,? extends Serializable> getCache(final String cacheName){
  LOGGER.log(Level.INFO,"Constructing Cache[name={0}]....",cacheName);
  Cache<String,?> ret=CACHES.get(cacheName);
  try {
    if (null == ret) {
switch (Latkes.getRuntime("cache")) {
case LOCAL:
        final Class<Cache<String,?>> localLruCache=(Class<Cache<String,?>>)Class.forName("org.b3log.latke.cache.local.memory.LruMemoryCache");
      ret=localLruCache.newInstance();
    break;
case GAE:
  final Class<Cache<String,?>> gaeMemcache=(Class<Cache<String,?>>)Class.forName("org.b3log.latke.cache.gae.Memcache");
final Constructor<Cache<String,?>> gaeMemcacheConstructor=gaeMemcache.getConstructor(String.class);
ret=gaeMemcacheConstructor.newInstance(cacheName);
break;
case BAE:
final Class<Cache<String,?>> baeMemcache=(Class<Cache<String,?>>)Class.forName("org.b3log.latke.cache.NoCache");
final Constructor<Cache<String,?>> baeMemcacheConstructor=baeMemcache.getConstructor(String.class);
ret=baeMemcacheConstructor.newInstance(cacheName);
break;
default :
throw new RuntimeException("Latke runs in the hell.... Please set the enviornment correctly");
}
CACHES.put(cacheName,ret);
}
}
 catch (final Exception e) {
throw new RuntimeException("Can not get cache: " + e.getMessage(),e);
}
LOGGER.log(Level.INFO,"Constructed Cache[name={0}]",cacheName);
return (Cache<String,Serializable>)ret;
}
 

Example 69

From project bam, under directory /modules/activity-management/activity/src/main/java/org/overlord/bam/activity/model/.

Source file: ActivityUnit.java

  29 
vote

/** 
 * The copy constructor.
 * @param act The activity to copy.
 */
public ActivityUnit(ActivityUnit act){
  _id=act._id;
  if (act._origin != null) {
    _origin=new Origin(act._origin);
  }
  for (  ActivityType actType : _activityTypes) {
    try {
      Constructor<? extends ActivityType> con=actType.getClass().getConstructor(actType.getClass());
      if (con != null) {
        _activityTypes.add(con.newInstance(actType));
      }
 else {
        LOG.severe(MessageFormat.format(java.util.PropertyResourceBundle.getBundle("activity.Messages").getString("ACTIVITY-4"),actType.getClass().getName()));
      }
    }
 catch (    Exception e) {
      LOG.log(Level.SEVERE,java.util.PropertyResourceBundle.getBundle("activity.Messages").getString("ACTIVITY-5"),e);
    }
  }
}
 

Example 70

From project beanvalidation-tck, under directory /tests/src/main/java/org/hibernate/beanvalidation/tck/tests/bootstrap/.

Source file: ValidationProviderTest.java

  29 
vote

@Test @SpecAssertion(section="4.4.4.2",id="d") public void testValidationProviderContainsNoArgConstructor(){
  ValidationProvider<?> validationProviderUnderTest=TestUtil.getValidationProviderUnderTest();
  try {
    Constructor<?> constructor=validationProviderUnderTest.getClass().getConstructor();
    assertTrue(Modifier.isPublic(constructor.getModifiers()));
  }
 catch (  Exception e) {
    fail("The validation provider must have a public no arg constructor");
  }
}
 

Example 71

From project Binaural-Beats, under directory /src/com/jjoe64/graphview/compatible/.

Source file: ScaleGestureDetector.java

  29 
vote

/** 
 * @param context
 * @param simpleOnScaleGestureListener
 */
public ScaleGestureDetector(Context context,SimpleOnScaleGestureListener simpleOnScaleGestureListener){
  try {
    Class.forName("android.view.ScaleGestureDetector");
    Class<?> classRealScaleGestureDetector=Class.forName("com.jjoe64.graphview.compatible.RealScaleGestureDetector");
    method_getScaleFactor=classRealScaleGestureDetector.getMethod("getScaleFactor");
    method_isInProgress=classRealScaleGestureDetector.getMethod("isInProgress");
    method_onTouchEvent=classRealScaleGestureDetector.getMethod("onTouchEvent",MotionEvent.class);
    Constructor<?> constructor=classRealScaleGestureDetector.getConstructor(Context.class,getClass(),SimpleOnScaleGestureListener.class);
    realScaleGestureDetector=constructor.newInstance(context,this,simpleOnScaleGestureListener);
  }
 catch (  Exception e) {
    Log.w("com.jjoe64.graphview","*** WARNING *** No scaling available for graphs. Exception:");
    e.printStackTrace();
  }
}
 

Example 72

From project Bio-PEPA, under directory /uk.ac.ed.inf.biopepa.core/src/uk/ac/ed/inf/biopepa/core/sba/.

Source file: Parameters.java

  29 
vote

public void setValue(Parameter parameter,Object value){
  if (parameter.parameterClass.isInstance(value))   parameters.put(parameter,value);
 else   if (parameter.equals(Parameter.Components) && value instanceof String) {
    StringBuilder sb=new StringBuilder((String)value);
    ArrayList<String> al=new ArrayList<String>();
    int index, length;
    try {
      while (sb.length() > 0) {
        index=sb.indexOf(":");
        length=Integer.parseInt(sb.substring(0,index));
        sb.delete(0,index + 1);
        al.add(sb.substring(0,length));
        sb.delete(0,length);
      }
    }
 catch (    NumberFormatException e) {
      throw new IllegalArgumentException(parameter.descriptiveName + " requires a legal bencoded string.");
    }
    parameters.put(parameter,al.toArray(new String[]{}));
  }
 else   if (value instanceof String) {
    try {
      Constructor<?> constructor=parameter.parameterClass.getConstructor(String.class);
      Object o=constructor.newInstance(value);
      parameters.put(parameter,o);
    }
 catch (    Exception e) {
      throw new IllegalArgumentException("Value is not of type " + parameter.parameterClass.getName() + " and cannot be constructed using a String as a parameter.");
    }
  }
 else   throw new IllegalArgumentException("Value is not of type " + parameter.parameterClass.getName());
}
 

Example 73

From project Blueprint, under directory /blueprint-core/src/main/java/org/codemined/blueprint/.

Source file: Deserializer.java

  29 
vote

/** 
 * Attempts to deserialize an object using the String constructor. <p> The type is queried for a constructor that meets the following criteria: <ul> <li>is public;</li> <li>takes one String parameter.</li> </ul> If no such constructor is found, useConstructorDeserializer returns null. </p>
 * @param type Type to deserialize into.
 * @param value String to deserialize from.
 * @param < T > Type to deserialize into.
 * @return Deserialized instance or null if no adequate constructor is found.
 * @throws BlueprintException if an exception is thrown from inside the constructor.
 */
private <T>T useConstructorDeserializer(Class<T> type,String value){
  Constructor<T> ctor;
  try {
    ctor=type.getConstructor(String.class);
  }
 catch (  NoSuchMethodException e) {
    return null;
  }
  try {
    return ctor.newInstance(value);
  }
 catch (  Exception e) {
    throw new BlueprintException("Failed to deserialize configuration item" + " as an instance of " + type.getCanonicalName() + ", using constructor(String)"+ ", from value \""+ value+ "\"",e);
  }
}
 

Example 74

From project BookKeeperMetadataPlugin, under directory /src/main/java/org/apache/bookkeeper/metadata/plugin/.

Source file: PluginLoader.java

  29 
vote

public MetadataPlugin loadPlugin(String name) throws ClassNotFoundException, NoSuchMethodException, PluginLoaderException {
  ClassLoader classLoader=PluginLoader.class.getClassLoader();
  @SuppressWarnings("rawtypes") Class cls=classLoader.loadClass(name);
  @SuppressWarnings("unchecked") Constructor<MetadataPlugin> ct=cls.getConstructor();
  MetadataPlugin plugin;
  try {
    plugin=ct.newInstance();
  }
 catch (  Exception e) {
    throw new PluginLoaderException("Error invoking Plugin constructor",e);
  }
  return plugin;
}
 

Example 75

From project bpelunit, under directory /net.bpelunit.framework.control.deploy.activevos9/src/main/java/net/bpelunit/framework/model/bpel/.

Source file: BPELActivityFactory.java

  29 
vote

public BPELActivity createActivityFor(String localName,Element node,BPELProcess bpelProcess){
  Class<? extends BPELActivity> clazz=activities.get(localName);
  try {
    Constructor<? extends BPELActivity> c=clazz.getConstructor(Element.class,BPELProcess.class);
    return c.newInstance(node,bpelProcess);
  }
 catch (  Exception e) {
    return null;
  }
}
 

Example 76

From project capedwarf-blue, under directory /common/src/main/java/org/jboss/capedwarf/common/reflection/.

Source file: ReflectionUtils.java

  29 
vote

/** 
 * Create new instance.
 * @param clazz the class
 * @param types the ctor types
 * @param args  the ctor args
 * @return new instance
 */
public static <T>T newInstance(Class<T> clazz,Class[] types,Object[] args){
  if (clazz == null)   throw new IllegalArgumentException("Null class");
  try {
    Constructor<T> ctor=clazz.getDeclaredConstructor(types);
    ctor.setAccessible(true);
    return ctor.newInstance(args);
  }
 catch (  Throwable t) {
    throw new RuntimeException(t);
  }
}
 

Example 77

From project capedwarf-green, under directory /server-gae/src/main/java/org/jboss/capedwarf/server/gae/cache/.

Source file: OIDCacheEntryLookup.java

  29 
vote

protected Object toImplementationId(Class<?> entryType,Object id){
  if (oidClass == null) {
synchronized (this) {
      if (oidClass == null) {
        if (cache == null) {
          oidClass=Void.class;
          log.warning("Cache is null, forgot to set it?");
          return null;
        }
        try {
          oidClass=getClass().getClassLoader().loadClass(oidClassName);
        }
 catch (        ClassNotFoundException e) {
          log.warning("Cannot create OID: " + e);
          oidClass=Void.class;
        }
      }
    }
  }
  if (oidClass == Void.class)   return null;
  try {
    Constructor<?> ctor=oidClass.getConstructor(String.class,Object.class);
    return ctor.newInstance(entryType.getName(),id);
  }
 catch (  Exception e) {
    log.fine("Cannot create OID: " + e);
    return null;
  }
}