List of usage examples for java.lang InstantiationException toString
public String toString()
From source file:org.lsc.beans.LscBean.java
/** * Set a bean from an LDAP entry//from www .ja v a2 s . co m * * @param entry * the LDAP entry * @param baseDn * the base Dn used to set the right Dn * @param c * class to instantiate * @return the bean * @throws NamingException * thrown if a directory exception is encountered while looking * at the entry */ public static LscBean getInstance(final SearchResult entry, final String baseDn, final Class<?> c) throws NamingException { try { if (entry != null) { LscBean ab = (LscBean) c.newInstance(); String dn = entry.getName(); if ((dn.length() > 0) && (dn.charAt(0) == '"') && (dn.charAt(dn.length() - 1) == '"')) { dn = dn.substring(1, dn.length() - 1); } if (dn.startsWith("ldap://")) { ab.setDistinguishName(entry.getNameInNamespace()); } else { // Manually concat baseDn because getNameInNamespace returns // a differently escaped DN, causing LSC to detect a MODRDN if ((baseDn != null) && (baseDn.length() > 0)) { if (dn.length() > 0) { ab.setDistinguishName(dn + "," + baseDn); } else { ab.setDistinguishName(baseDn); } } else { ab.setDistinguishName(dn); } } NamingEnumeration<?> ne = entry.getAttributes().getAll(); while (ne.hasMore()) { ab.setAttribute((Attribute) ne.next()); } return ab; } else { return null; } } catch (InstantiationException ie) { LOGGER.error(ie.toString()); LOGGER.debug(ie.toString(), ie); } catch (IllegalAccessException iae) { LOGGER.error(iae.toString()); LOGGER.debug(iae.toString(), iae); } return null; }
From source file:run.ace.Utils.java
public static Object invokeConstructorWithBestParameterMatch(Class c, Object[] args) { Constructor[] constructors = c.getConstructors(); int numArgs = args.length; // Look at all constructors for (Constructor constructor : constructors) { Class<?>[] parameterTypes = constructor.getParameterTypes(); // Does it have the right number of parameters? if (parameterTypes.length == numArgs) { // Are all the parameters types that will work? Object[] matchingArgs = tryToMakeArgsMatch(args, parameterTypes, false); if (matchingArgs != null) { try { return constructor.newInstance(matchingArgs); } catch (InstantiationException ex) { throw new RuntimeException( "Error instantiating " + c.getSimpleName() + ": " + ex.toString()); } catch (IllegalAccessException ex) { throw new RuntimeException(c.getSimpleName() + "'s matching constructor is inaccessible"); } catch (InvocationTargetException ex) { throw new RuntimeException("Error in " + c.getSimpleName() + "'s constructor: " + ex.getTargetException().toString()); }//from www. java 2 s . c o m } } } throw new RuntimeException( c + " does not have a public constructor with " + numArgs + " matching parameter type(s)."); }
From source file:org.wso2.carbon.apimgt.keymgt.util.APIKeyMgtDataHolder.java
public static void initData() { try {//from ww w.j av a 2 s . co m APIKeyMgtDataHolder.isKeyCacheEnabledKeyMgt = getInitValues(APIConstants.KEY_MANAGER_TOKEN_CACHE); APIKeyMgtDataHolder.isThriftServerEnabled = getInitValues( APIConstants.API_KEY_VALIDATOR_ENABLE_THRIFT_SERVER); APIManagerConfiguration configuration = org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder .getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration(); if (configuration == null) { log.error("API Manager configuration is not initialized"); } else { applicationTokenScope = configuration.getFirstProperty(APIConstants.APPLICATION_TOKEN_SCOPE); jwtGenerationEnabled = Boolean .parseBoolean(configuration.getFirstProperty(APIConstants.ENABLE_JWT_GENERATION)); if (log.isDebugEnabled()) { log.debug("JWTGeneration enabled : " + jwtGenerationEnabled); } if (jwtGenerationEnabled) { String clazz = configuration.getFirstProperty(APIConstants.TOKEN_GENERATOR_IMPL); if (clazz == null) { tokenGenerator = new JWTGenerator(); } else { try { tokenGenerator = (TokenGenerator) APIUtil.getClassForName(clazz).newInstance(); } catch (InstantiationException e) { log.error("Error while instantiating class " + clazz, e); } catch (IllegalAccessException e) { log.error(e); } catch (ClassNotFoundException e) { log.error("Cannot find the class " + clazz + e); } } } } } catch (Exception e) { log.error("Error occur while initializing API KeyMgt Data Holder.Default configuration will be used." + e.toString()); } }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
private static Script loadCompiledScript(Context cx, String path, Object securityDomain) { final byte[] data = (byte[]) readFileOrUrl(path, false); if (data == null) { exitCode = EXITCODE_FILE_NOT_FOUND; return null; }// www . jav a2s.c o m // XXX: For now extract class name of compiled Script from path // instead of parsing class bytes int nameStart = path.lastIndexOf('/'); if (nameStart < 0) { nameStart = 0; } else { ++nameStart; } int nameEnd = path.lastIndexOf('.'); if (nameEnd < nameStart) { // '.' does not exist in path (nameEnd < 0) // or it comes before nameStart nameEnd = path.length(); } final String name = path.substring(nameStart, nameEnd); try { final GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain); final Class clazz = loader.defineClass(name, data); loader.linkClass(clazz); if (!Script.class.isAssignableFrom(clazz)) { throw Context.reportRuntimeError("msg.must.implement.Script"); } return (Script) clazz.newInstance(); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (IllegalAccessException iaex) { exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(iaex.toString()); } catch (InstantiationException inex) { exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(inex.toString()); } return null; }
From source file:rapture.structured.StructuredFactory.java
private static StructuredStore getStructuredStore(String className, String instance, Map<String, String> config, String authority) {//from w ww .j a v a 2 s. c o m try { Class<?> repoClass = Class.forName(className); Object fStore; fStore = repoClass.newInstance(); if (fStore instanceof StructuredStore) { StructuredStore ret = (StructuredStore) fStore; ret.setInstance(instance); ret.setConfig(config, authority); return ret; } else { String message = (className + " is not a repo, cannot instantiate"); throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, message); } } catch (InstantiationException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "InstantiationException. Error creating structured store of type " + className, e); } catch (IllegalAccessException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "IllegalAccessException. Error creating structured store of type " + className, e); } catch (ClassNotFoundException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "ClassNotFoundException. Error creating structured store of type " + className + ": " + e.toString()); } }
From source file:ProxyFactory.java
/** * Returns an instance of a proxy class for this factory's interfaces that * dispatches method invocations to the specified invocation handler. * <tt>ProxyFactory.newInstance</tt> throws <tt>IllegalArgumentException</tt> * for the same reasons that <tt>Proxy.getProxyClass</tt> does. * * @param handler//from ww w . j ava 2 s. com * the invocation handler to dispatch method invocations to * @return * a proxy instance with the specified invocation handler of a proxy * class that implements this factory's specified interfaces * * @throws IllegalArgumentException * if any of the restrictions on the parameters that may be passed to * <tt>getProxyClass</tt> are violated * @throws NullPointerException * if the invocation handler is null */ public Object newInstance(InvocationHandler handler) { if (handler == null) throw new NullPointerException(); try { return getConstructor().newInstance(new Object[] { handler }); } catch (InstantiationException e) { throw new InternalError(e.toString()); } catch (IllegalAccessException e) { throw new InternalError(e.toString()); } catch (InvocationTargetException e) { throw new InternalError(e.toString()); } }
From source file:cn.jarlen.richcommon.mvp.view.BaseMvpActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); preBindView();// ww w.j a v a 2s.c o m setContentView(getLayoutId()); try { presenter = getPresenter().newInstance(); presenter.setIntent(getIntent()); presenter.setActivity(this); presenter.setProxyView(getProxyView()); onBindView(savedInstanceState); presenter.onBindView(savedInstanceState); } catch (InstantiationException e) { LogUtils.e("mvp", e.toString()); } catch (IllegalAccessException e) { LogUtils.e("mvp", e.toString()); } catch (Exception e) { LogUtils.e("mvp", e.toString()); } }
From source file:cn.jarlen.richcommon.mvp.view.BaseMvpFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try {//ww w. ja v a2 s .com presenter = getPresenter().newInstance(); presenter.setActivity(getActivity()); presenter.setProxyView(getProxyView()); presenter.setArguments(getArguments()); presenter.onCreated(); onBindView(savedInstanceState); presenter.onBindView(savedInstanceState); } catch (java.lang.InstantiationException e) { LogUtils.e("mvp", e.toString()); } catch (IllegalAccessException e) { LogUtils.e("mvp", e.toString()); } catch (Exception e) { LogUtils.e("mvp", e.toString()); } }
From source file:com.massivedisaster.activitymanager.FragmentTransaction.java
/** * FragmentTransaction constructor, created to be used by an activity. * * @param activity The activity to be used to add the new fragment. * @param fragmentClass The Fragment to be injected in the activityClass. *//*from w w w . java 2 s. c o m*/ @SuppressLint("CommitTransaction") FragmentTransaction(AbstractFragmentActivity activity, Class<? extends Fragment> fragmentClass) { mActivity = activity; mFrgTransaction = mActivity.getSupportFragmentManager().beginTransaction(); try { mFragment = fragmentClass.newInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mFragment.setSharedElementEnterTransition( TransitionInflater.from(mActivity).inflateTransition(android.R.transition.move)); mFragment.setSharedElementReturnTransition( TransitionInflater.from(mActivity).inflateTransition(android.R.transition.move)); } } catch (InstantiationException e) { Log.e(ActivityFragmentManager.class.getCanonicalName(), e.toString()); } catch (IllegalAccessException e) { Log.e(ActivityFragmentManager.class.getCanonicalName(), e.toString()); } }
From source file:volumesculptor.shell.Main.java
private static Script loadCompiledScript(Context cx, String path, byte[] data, Object securityDomain) throws FileNotFoundException { if (data == null) { throw new FileNotFoundException(path); }/*from ww w .j a va 2 s . co m*/ // XXX: For now extract class name of compiled Script from path // instead of parsing class bytes int nameStart = path.lastIndexOf('/'); if (nameStart < 0) { nameStart = 0; } else { ++nameStart; } int nameEnd = path.lastIndexOf('.'); if (nameEnd < nameStart) { // '.' does not exist in path (nameEnd < 0) // or it comes before nameStart nameEnd = path.length(); } String name = path.substring(nameStart, nameEnd); try { GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain); Class<?> clazz = loader.defineClass(name, data); loader.linkClass(clazz); if (!Script.class.isAssignableFrom(clazz)) { throw Context.reportRuntimeError("msg.must.implement.Script"); } return (Script) clazz.newInstance(); } catch (IllegalAccessException iaex) { Context.reportError(iaex.toString()); throw new RuntimeException(iaex); } catch (InstantiationException inex) { Context.reportError(inex.toString()); throw new RuntimeException(inex); } }