/** * Construct an implementation using a constructor whose parameters match * that of the provided objects. * * @param intf the interface to construct an instance of * @param <T> the type of the class * @return an implementation of provided interface * @throws IllegalArgumentException thrown if the implementation can not be * constructed * @throws IllegalArgumentException thrown if the provided class is not an * interface */ public <T extends ICDKObject> T ofClass(Class<T> intf, Object... objects) { try { if (!intf.isInterface()) throw new IllegalArgumentException("expected interface, got " + intf.getClass()); Creator<T> constructor = get(new ObjectBasedKey(intf, objects)); return constructor.create(objects); } catch (InstantiationException e) { throw new IllegalArgumentException("unable to instantiate chem object: ", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("constructor is not accessible: ", e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("invocation target exception: ", e); } }
/** * Construct an implementation using a constructor whose parameters match * that of the provided objects. * * @param intf the interface to construct an instance of * @param <T> the type of the class * @return an implementation of provided interface * @throws IllegalArgumentException thrown if the implementation can not be * constructed * @throws IllegalArgumentException thrown if the provided class is not an * interface */ public <T extends ICDKObject> T ofClass(Class<T> intf, Object... objects) { try { if (!intf.isInterface()) throw new IllegalArgumentException("expected interface, got " + intf.getClass()); Creator<T> constructor = get(new ObjectBasedKey(intf, objects)); return constructor.create(objects); } catch (InstantiationException e) { throw new IllegalArgumentException("unable to instantiate chem object: ", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("constructor is not accessible: ", e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("invocation target exception: ", e); } }
/** * Construct an implementation using the default constructor. This provides * some speed boost over invoking {@link #ofClass(Class, Object...)}. * * @param intf the interface to construct an instance of * @param <T> the type of the class * @return an implementation of provided interface constructed using the * default constructor. * @throws IllegalArgumentException thrown if the implementation can not be * constructed * @throws IllegalArgumentException thrown if the provided class is not an * interface */ public <T extends ICDKObject> T ofClass(Class<T> intf) { try { if (!intf.isInterface()) throw new IllegalArgumentException("expected interface, got " + intf.getClass()); Creator<T> creator = get(new ClassBasedKey(intf, EMPTY_CLASS_ARRAY)); return creator.create(null); // throws an exception if no impl was found } catch (InstantiationException e) { throw new IllegalArgumentException("unable to instantiate chem object: ", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("constructor is not accessible: ", e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("invocation target exception: ", e); } }
/** * Construct an implementation using the default constructor. This provides * some speed boost over invoking {@link #ofClass(Class, Object...)}. * * @param intf the interface to construct an instance of * @param <T> the type of the class * @return an implementation of provided interface constructed using the * default constructor. * @throws IllegalArgumentException thrown if the implementation can not be * constructed * @throws IllegalArgumentException thrown if the provided class is not an * interface */ public <T extends ICDKObject> T ofClass(Class<T> intf) { try { if (!intf.isInterface()) throw new IllegalArgumentException("expected interface, got " + intf.getClass()); Creator<T> creator = get(new ClassBasedKey(intf, EMPTY_CLASS_ARRAY)); return creator.create(null); // throws an exception if no impl was found } catch (InstantiationException e) { throw new IllegalArgumentException("unable to instantiate chem object: ", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("constructor is not accessible: ", e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("invocation target exception: ", e); } }
/** *{@inheritDoc} */ @Override public T create(Object[] objects) throws InvocationTargetException, IllegalAccessException, InstantiationException { T instance = parent.create(objects); modifier.modify(instance); return instance; }
/** *{@inheritDoc} */ @Override public T create(Object[] objects) throws InvocationTargetException, IllegalAccessException, InstantiationException { return parent.create(new Object[]{objects}); }
/** *{@inheritDoc} */ @Override public T create(Object[] objects) throws InvocationTargetException, IllegalAccessException, InstantiationException { return parent.create(new Object[]{objects}); }
/** *{@inheritDoc} */ @Override public T create(Object[] objects) throws InvocationTargetException, IllegalAccessException, InstantiationException { T instance = parent.create(objects); modifier.modify(instance); return instance; }