List of usage examples for java.lang InstantiationException toString
public String toString()
From source file:org.wso2.carbon.apimgt.keymgt.service.APIKeyValidationService.java
public APIKeyValidationService() { try {// w w w. jav a2 s . c om if (keyValidationHandler == null) { KeyValidationHandler validationHandler = (KeyValidationHandler) APIUtil .getClassForName(ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration() .getFirstProperty(APIConstants.API_KEY_MANGER_VALIDATIONHANDLER_CLASS_NAME)) .newInstance(); log.info("Initialised KeyValidationHandler instance successfully"); if (keyValidationHandler == null) { synchronized (this) { keyValidationHandler = validationHandler; } } } } catch (InstantiationException e) { log.error("Error while instantiating class" + e.toString()); } catch (IllegalAccessException e) { log.error("Error while accessing class" + e.toString()); } catch (ClassNotFoundException e) { log.error("Error while creating keyManager instance" + e.toString()); } }
From source file:org.onecmdb.core.internal.job.workflow.CiToJavaObject.java
public Object toBeanObject(ICi ci) { String alias;// w w w .j av a 2s . c o m if (ci.isBlueprint()) { alias = ci.getAlias(); } else { ICi parent = ci.getDerivedFrom(); alias = parent.getAlias(); } Class cl = getClassForAlias(alias); if (cl == null) { log.warn("No class with alias " + alias + " found!"); return (null); /* throw new IllegalArgumentException("No class found for alias <" + alias + ">"); */ } Object instance = null; try { instance = cl.newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException("alias <" + alias + "> " + e.toString(), e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("alias <" + alias + "> " + e.toString(), e); } HashMap<String, Object> map = buildAttributeMap(ci); Method[] methods = instance.getClass().getMethods(); HashMap<String, Method> methodMap = new HashMap<String, Method>(); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName().toLowerCase(); methodMap.put(name, methods[i]); } for (String methodName : map.keySet()) { Object o = map.get(methodName); String setMethodName = "set" + methodName; String setMethodNameLowerCase = setMethodName.toLowerCase(); Method m = methodMap.get(setMethodNameLowerCase); if (m == null) { log.warn("No method " + setMethodName + " found in class " + cl.getName() + " with alias " + alias + " found!"); // For now we skip the set method... continue; /* throw new IllegalArgumentException( "No method in " + cl.getName() + "." + setMethodName + "(" + o + ")"); */ } try { m.invoke(instance, new Object[] { o }); } catch (Exception e) { throw new IllegalArgumentException( "Error:" + cl.getName() + "." + m.getName() + "(" + o + ") : " + e.toString(), e); } } return (instance); }
From source file:org.projectforge.excel.ExcelImport.java
/** * convert the contents of the table into an array. * /*from w ww . j a va 2 s .c o m*/ * @param clazz the target class * @return an array with the object values. */ @SuppressWarnings("unchecked") public T[] convertToRows(final Class<T> clazz) { if (clazzFactory == null) { setRowClass(clazz); } final HSSFSheet sheet = work.getSheetAt(activeSheet); final int numberOfRows = sheet.getLastRowNum(); final List<T> list = new ArrayList<T>(numberOfRows); final HSSFRow columnNames = sheet.getRow(columnNameRow); for (int i = startAtRow; i <= numberOfRows; i++) { try { T line; line = convertToBean(sheet.getRow(i), columnNames, i + 1); if (line == null) { continue; } if (clazz.isInstance(line) == false) { throw new IllegalStateException("returned type " + line.getClass() + " is not assignable to " + clazz + " in sheet='" + sheet.getSheetName() + "', row=" + i); } list.add(line); } catch (final InstantiationException ex) { throw new IllegalArgumentException("Can't create bean " + ex.toString() + " in sheet='" + sheet.getSheetName() + "', row=" + i); } catch (final IllegalAccessException ex) { throw new IllegalArgumentException("Getter is not visible " + ex.toString() + " in sheet='" + sheet.getSheetName() + "', row=" + i); } catch (final InvocationTargetException ex) { log.error(ex.getMessage(), ex); throw new IllegalArgumentException("Getter threw an exception " + ex.toString() + " in sheet='" + sheet.getSheetName() + "', row=" + i); } catch (final NoSuchMethodException ex) { throw new IllegalArgumentException("Getter is not existant " + ex.toString() + " in sheet='" + sheet.getSheetName() + "', row=" + i); } } return list.toArray((T[]) Array.newInstance(clazz, 0)); }
From source file:org.lsc.service.AbstractJdbcService.java
/** * Override default AbstractJdbcSrcService to get a SimpleBean * @throws LscServiceException //from w w w .jav a 2 s.c o m */ @SuppressWarnings("unchecked") @Override public IBean getBean(String id, LscDatasets attributes, boolean fromSameService) throws LscServiceException { IBean srcBean = null; try { srcBean = beanClass.newInstance(); List<?> records = sqlMapper.queryForList(getRequestNameForObjectOrClean(fromSameService), getAttributesMap(attributes)); if (records.size() > 1) { throw new LscServiceException("Only a single record can be returned from a getObject request ! " + "For id=" + id + ", there are " + records.size() + " records !"); } else if (records.size() == 0) { return null; } Map<String, Object> record = (Map<String, Object>) records.get(0); for (Entry<String, Object> entry : record.entrySet()) { if (entry.getValue() != null) { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue()))); } else { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey()))); } } srcBean.setMainIdentifier(id); return srcBean; } catch (InstantiationException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (IllegalAccessException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (SQLException e) { LOGGER.warn("Error while looking for a specific entry with id={} ({})", id, e); LOGGER.debug(e.toString(), e); // TODO This SQLException may mean we lost the connection to the DB // This is a dirty hack to make sure we stop everything, and don't risk deleting everything... throw new LscServiceException(new CommunicationException(e.getMessage())); } catch (NamingException e) { LOGGER.error("Unable to get handle cast: " + e.toString()); LOGGER.debug(e.toString(), e); } return null; }
From source file:net.oauth.j2me.OAuthMessage.java
public void createSignature(String signatureMethod, String consumerSecret) { this.signatureMethod = signatureMethod; String signatureClassName = ""; if ("PLAINTEXT".equals(signatureMethod)) { signatureClassName = "net.oauth.j2me.signature.PLAINTEXTSignature"; } else if ("HMAC-SHA1".equals(signatureMethod)) { signatureClassName = "net.oauth.j2me.signature.HMACSHA1Signature"; }//from www . j a va2 s.com System.out.println("sig mthod=" + signatureMethod + ", sig class name=" + signatureClassName); if (!"".equals(signatureClassName)) { try { createSignature((OAuthSignature) Class.forName(signatureClassName).newInstance(), consumerSecret); } catch (java.lang.InstantiationException e) { System.out.println(e.toString()); } catch (java.lang.ClassNotFoundException e) { System.out.println(e.toString()); ; } catch (Exception e) { System.out.println(e.toString()); ; } } }
From source file:com.t2.androidspineexample.AndroidSpineExampleActivity.java
/** Called when the activity is first created. */ @Override//w w w .j av a 2 s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, this.getClass().getSimpleName() + ".onCreate()"); mInstance = this; setContentView(R.layout.main); // Set up member variables to UI Elements mTextViewDataMindset = (TextView) findViewById(R.id.textViewData); mTextViewDataShimmerEcg = (TextView) findViewById(R.id.textViewDataShimmerEcg); mTextViewDataShimmerGsr = (TextView) findViewById(R.id.textViewDataShimmerGsr); mTextViewDataShimmerEmg = (TextView) findViewById(R.id.textViewDataShimmerEmg); // ---------------------------------------------------- // Initialize SPINE by passing the fileName with the configuration properties // ---------------------------------------------------- Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); try { mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, "Exception creating SPINE manager: " + e.toString()); Log.e(TAG, "Check to see that valid defaults.properties, and SpineTestApp.properties files exist in the Assets folder!"); e.printStackTrace(); } // ... then we need to register a SPINEListener implementation to the SPINE manager instance // to receive sensor node data from the Spine server // (I register myself since I'm a SPINEListener implementation!) mSpineManager.addListener(this); // Create a broadcast receiver. Note that this is used ONLY for command messages from the service // All data from the service goes through the mail SPINE mechanism (received(Data data)). // See public void received(Data data) this.mCommandReceiver = new SpineReceiver(this); // Set up filter intents so we can receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction("com.t2.biofeedback.service.status.BROADCAST"); this.registerReceiver(this.mCommandReceiver, filter); try { mCurrentMindsetData = new MindsetData(this); } catch (Exception e1) { Log.e(TAG, "Exception creating MindsetData: " + e1.toString()); } // Since Mindset is a static node we have to manually put it in the active node list // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor Node MindsetNode = null; MindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET)); mSpineManager.getActiveNodes().add(MindsetNode); // Since Shimmer is a static node we have to manually put it in the active node list mShimmerNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_SHIMMER)); mSpineManager.getActiveNodes().add(mShimmerNode); // Set up graph(s) mSeries = new XYSeries("parameter"); generateChart(); }
From source file:com.t2.compassionMeditation.DeviceManagerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInstance = this; sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); //this.sendBroadcast(new Intent(BioFeedbackService.ACTION_SERVICE_START)); this.setContentView(R.layout.device_manager_activity_layout); this.findViewById(R.id.bluetoothSettingsButton).setOnClickListener(this); Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); try {//from ww w.ja v a2 s . c om mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, this.getClass().getSimpleName() + " Exception creating SPINE manager: " + e.toString()); e.printStackTrace(); } // ... then we need to register a SPINEListener implementation to the SPINE manager instance // to receive sensor node data from the Spine server // (I register myself since I'm a SPINEListener implementation!) mSpineManager.addListener(this); // Create a broadcast receiver. Note that this is used ONLY for command messages from the service // All data from the service goes through the mail SPINE mechanism (received(Data data)). // See public void received(Data data) this.mCommandReceiver = new SpineReceiver(this); // Set up filter intents so we can receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction("com.t2.biofeedback.service.status.BROADCAST"); filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BioFeedbackService.ACTION_STATUS_BROADCAST); this.registerReceiver(this.mCommandReceiver, filter); // Tell the bluetooth service to send us a list of bluetooth devices and system status // Response comes in public void onStatusReceived(BioFeedbackStatus bfs) STATUS_PAIRED_DEVICES mSpineManager.pollBluetoothDevices(); // this.deviceManager = DeviceManager.getInstance(this.getBaseContext(), null); this.deviceList = (ListView) this.findViewById(R.id.list); this.deviceListAdapter = new ManagerItemAdapter(this, R.layout.manager_item); this.deviceList.setAdapter(this.deviceListAdapter); this.bluetoothDisabledDialog = new AlertDialog.Builder(this).setMessage("Bluetooth is not enabled.") .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }).setPositiveButton("Setup Bluetooth", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startBluetoothSettings(); } }).create(); try { PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); mVersionName = info.versionName; Log.i(TAG, this.getClass().getSimpleName() + " Spine server Test Application Version " + mVersionName); } catch (NameNotFoundException e) { Log.e(TAG, this.getClass().getSimpleName() + e.toString()); } }
From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java
/** * Factory method that returns a new instance of the given Class. This is called at the start of * the bean creation process and may be overridden to provide custom behavior like returning a * cached bean instance./*from w w w . j a v a 2 s. c o m*/ * * @param <T> The type of object to create * @param c The Class to create an object from. * @return A newly created object of the Class. * @throws SQLException if creation failed. */ private <T> T newInstance(Class<T> c) throws SQLException { try { return c.newInstance(); } catch (InstantiationException e) { throw new SQLException("Cannot create " + c.getName() + ": " + e.toString(), e); } catch (IllegalAccessException e) { throw new SQLException("Cannot create " + c.getName() + ": " + e.toString(), e); } }
From source file:org.apache.jmeter.junit.JMeterTest.java
public static Collection<Object> getObjects(Class<?> extendsClass) throws Exception { String exName = extendsClass.getName(); Object myThis = ""; Iterator<String> classes = ClassFinder .findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { extendsClass }).iterator(); List<Object> objects = new LinkedList<>(); String n = ""; boolean caughtError = true; Throwable caught = null;//from w w w . j a va2s . c om try { while (classes.hasNext()) { n = classes.next(); // TODO - improve this check if (n.endsWith("RemoteJMeterEngineImpl")) { continue; // Don't try to instantiate remote server } Class<?> c = null; try { c = Class.forName(n); try { // Try with a parameter-less constructor first objects.add(c.newInstance()); } catch (InstantiationException e) { caught = e; try { // Events often have this constructor objects.add(c.getConstructor(new Class[] { Object.class }) .newInstance(new Object[] { myThis })); } catch (NoSuchMethodException f) { // no luck. Ignore this class System.out.println( "o.a.j.junit.JMeterTest WARN: " + exName + ": NoSuchMethodException " + n + ", missing empty Constructor or Constructor with Object parameter"); } } } catch (NoClassDefFoundError e) { // no luck. Ignore this class System.out.println("o.a.j.junit.JMeterTest WARN: " + exName + ": NoClassDefFoundError " + n + ":" + e.getMessage()); e.printStackTrace(System.out); } catch (IllegalAccessException e) { caught = e; System.out.println("o.a.j.junit.JMeterTest WARN: " + exName + ": IllegalAccessException " + n + ":" + e.getMessage()); e.printStackTrace(System.out); // We won't test restricted-access classes. } catch (HeadlessException | ExceptionInInitializerError e) {// EIIE can be caused by Headless caught = e; System.out.println("o.a.j.junit.JMeterTest Error creating " + n + " " + e.toString()); } catch (Exception e) { caught = e; if (e instanceof RemoteException) { // not thrown, so need to check here System.out.println( "o.a.j.junit.JMeterTest WARN: " + "Error creating " + n + " " + e.toString()); } else { throw new Exception("Error creating " + n, e); } } } caughtError = false; } finally { if (caughtError) { System.out.println("Last class=" + n); System.out.println("objects.size=" + objects.size()); System.out.println("Last error=" + caught); } } if (objects.isEmpty()) { System.out.println("No classes found that extend " + exName + ". Check the following:"); System.out.println("Search paths are:"); String ss[] = JMeterUtils.getSearchPaths(); for (String s : ss) { System.out.println(s); } if (!classPathShown) {// Only dump it once System.out.println("Class path is:"); String cp = System.getProperty("java.class.path"); String classPathElements[] = JOrphanUtils.split(cp, java.io.File.pathSeparator); for (String classPathElement : classPathElements) { System.out.println(classPathElement); } classPathShown = true; } } return objects; }
From source file:org.mitre.mat.engineclient.MATCgiClient.java
protected MATDocumentInterface doFileOperation(MATDocumentInterface doc, String task, String workflow, String op, String opKey, String opVal, HashMap<String, String> data) throws MATEngineClientException { ArrayList pArray = new ArrayList(); MATJSONEncoding e = new MATJSONEncoding(); pArray.add(new NameValuePair("task", task)); pArray.add(new NameValuePair("workflow", workflow)); pArray.add(new NameValuePair("operation", op)); pArray.add(new NameValuePair(opKey, opVal)); pArray.add(new NameValuePair("file_type", "mat-json")); pArray.add(new NameValuePair("input", e.toEncodedString(doc))); JsonNode jsonValues = this.postHTTP(pArray, data); // Here's the output format. It's a hash of three elements: error (None if // there's no error), errorStep (None if there's no error), and // a list of success hashes, which have a val and steps. // See MATCGI_tpl.py. An error always terminates the processing, // so on the client, you process the successes and then the error. // The steps should be in order of execution, and so should the // successes. It's not EXACTLY enforced. HashMap stepMap = new HashMap(); if (!jsonValues.isObject()) { throw new MATEngineClientException("CGI response isn't Javascript object"); }/*ww w. j a va 2s. c o m*/ JsonNode errNode = jsonValues.path("error"); if ((!errNode.isMissingNode()) && (!errNode.isNull())) { // It's an error. String stepName = jsonValues.path("errorStep").getTextValue(); String stepMsg = errNode.getTextValue(); throw new MATEngineClientException("Step " + stepName + " failed: " + stepMsg); } JsonNode successes = jsonValues.path("successes"); if (successes.isMissingNode() || (!successes.isArray()) || (successes.size() == 0)) { // I doubt that this will ever happen. throw new MATEngineClientException("No error, but no successful document either"); } // Get the last one. JsonNode success = successes.get(successes.size() - 1); JsonNode val = success.path("val"); MATDocumentInterface newDoc; try { newDoc = doc.getClass().newInstance(); } catch (InstantiationException ex) { Logger.getLogger(MATCgiClient.class.getName()).log(Level.SEVERE, null, ex); throw new MATEngineClientException("Couldn't create a response document"); } catch (IllegalAccessException ex) { Logger.getLogger(MATCgiClient.class.getName()).log(Level.SEVERE, null, ex); throw new MATEngineClientException("Couldn't create a response document"); } try { e.fromJsonNode(newDoc, val); } catch (MATDocumentException ex) { throw new MATEngineClientException("Error during JSON decode: " + ex.toString()); } catch (AnnotationException ex) { throw new MATEngineClientException("Error during JSON decode: " + ex.toString()); } return newDoc; }