List of usage examples for java.lang InstantiationException printStackTrace
public void printStackTrace()
From source file:com.mysql.stresstool.StressTool.java
/** * createAll/*from w w w . ja v a 2 s . c om*/ */ private void createThreads() { float maxInsert = poolNumber; float maxSelect = poolNumber; float maxDelete = poolNumber; maxSelect = (maxSelect * (pctSelect / 100)); maxInsert = (maxInsert * (pctInsert / 100)); maxDelete = (maxDelete * (pctDelete / 100)); int aInsert = new Float(maxInsert).intValue(); int aSelect = new Float(maxSelect).intValue(); int aDelete = new Float(maxDelete).intValue(); threadInfoInsertMap = new HashMap((aInsert > 0 ? aInsert - 1 : 0)); threadInfoSelectMap = new HashMap((aSelect > 0 ? aSelect - 1 : 0)); threadInfoDeleteMap = new HashMap((aDelete > 0 ? aDelete - 1 : 0)); HashMap connMapcoordinates = new HashMap(); connMapcoordinates.put("jdbcUrl", connUrl); connMapcoordinates.put("dbType", dbType); connMapcoordinates.put("connectstring", connectString); connMapcoordinates.put("database", databaseDefault); if (this.ignoreBinlog) { if (!validatePermission(connMapcoordinates)) { System.out.println("============ ERROR ============"); System.out.println( "You ask for skipping mysql Binlog Insert but you don't have the permission to do it"); System.out.println( "Change the flag for parameter \" ignorebinlog \" from true to false, OR remove it"); } } System.out.println("Thread to run for Insert:" + maxInsert); System.out.println("Thread to run for Select:" + maxSelect); System.out.println("Thread to run for Delete:" + maxDelete); System.out.println("Class handling Insert :" + this.insertDefaultClass); System.out.println("Class handling Select :" + this.selectDefaultClass); System.out.println("Class handling Delete :" + this.deleteDefaultClass); if (aInsert >= 1) insertThread = new HashMap(poolNumber); if (aSelect >= 1) selectThread = new HashMap(poolNumber); if (aDelete >= 1) deleteThread = new HashMap(poolNumber); for (int i = 0; i < poolNumber; i++) { if (aInsert > i) { System.out.println("Starting Insert: " + i); RunnableQueryInsertInterface qth = null; try { qth = (RunnableQueryInsertInterface) Class.forName(insertDefaultClass).newInstance(); } catch (InstantiationException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (IllegalAccessException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } qth.setID(i + INSERT_ID_CONST); qth.setJdbcUrl(connMapcoordinates); qth.setSleepFor(sleepWrite); qth.setRepeatNumber(repeatNumber); qth.setDoLog(dolog); qth.setOperationShort(operationShort); qth.setDbType(dbType); qth.setDoDelete(doDelete); qth.setIgnoreBinlog(ignoreBinlog); qth.setEngine(tableEngine); qth.setIBatchInsert(iBatchInsert); qth.setUseBatchInsert(doBatch); qth.setDoSimplePk(doSimplePk); qth.setOnDuplicateKey(this.getOnDuplicateKey()); if (stressSettings.get("actionClass") != null) { qth.setClassConfiguration(stressSettings.get("actionClass")); } if (this.doReport) qth.setMySQLStatistics(mySQLStatistics); Thread th = new Thread((Runnable) qth); th.start(); insertThread.put(i, qth); } if (aSelect > i) { System.out.println("Starting Select: " + i); RunnableSelectQueryInterface qths = null; try { qths = (RunnableSelectQueryInterface) Class.forName(selectDefaultClass).newInstance(); } catch (InstantiationException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (IllegalAccessException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } qths.setID(i + SELECT_ID_CONST); qths.setJdbcUrl(connMapcoordinates); qths.setSleepFor(sleepRead); qths.setRepeatNumber(repeatNumber); qths.setDoLog(dolog); qths.setDbType(dbType); qths.setEngine(tableEngine); qths.setIBatchSelect(iBatchSelect); qths.setSqlQuery(sqlString); qths.setDoSimplePk(doSimplePk); if (stressSettings.get("actionClass") != null) { qths.setClassConfiguration(stressSettings.get("actionClass")); } if (this.doReport) qths.setMySQLStatistics(mySQLStatistics); Thread ths = new Thread((Runnable) qths); ths.start(); selectThread.put(i, qths); } if (doDelete) { if (aDelete > i) { System.out.println("Starting Delete: " + i); RunnableQueryDeleteInterface qthd = null; try { qthd = (RunnableQueryDeleteInterface) Class.forName(deleteDefaultClass).newInstance(); } catch (InstantiationException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (IllegalAccessException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println( "ERROR === CLASS defined in configuration invalid or not correctly loaded \n CLASS = " + insertDefaultClass); e.printStackTrace(); } qthd.setID(i + DELETE_ID_CONST); qthd.setJdbcUrlMap(connMapcoordinates); qthd.setSleepFor(sleepDelete); qthd.setRepeatNumber(repeatNumber); qthd.setDoLog(dolog); qthd.setOperationShort(operationShort); qthd.setDbType(dbType); qthd.setDoDelete(doDelete); qthd.setEngine(tableEngine); qthd.setUseBatchInsert(doBatch); qthd.setDoSimplePk(doSimplePk); if (stressSettings.get("actionClass") != null) { qthd.setClassConfiguration(stressSettings.get("actionClass")); } if (this.doReport) qthd.setMySQLStatistics(mySQLStatistics); Thread th = new Thread((Runnable) qthd); th.start(); deleteThread.put(i, qthd); } } } }
From source file:org.evergreen.web.utils.beanutils.PropertyUtilsBean.java
/** * Return the value of the specified simple property of the specified * bean, with no type conversions.//from w w w . jav a2 s.c o m * * @param bean Bean whose property is to be extracted * @param name Name of the property to be extracted * @return The property value * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception IllegalArgumentException if <code>bean</code> or * <code>name</code> is null * @exception IllegalArgumentException if the property name * is nested or indexed * @exception InvocationTargetException if the property accessor method * throws an exception * @exception NoSuchMethodException if an accessor method for this * propety cannot be found */ public Object getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } // Validate the syntax of the property name if (resolver.hasNested(name)) { throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } else if (resolver.isIndexed(name)) { throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } else if (resolver.isMapped(name)) { throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } // Handle DynaBean instances specially if (bean instanceof DynaBean) { DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new NoSuchMethodException( "Unknown property '" + name + "' on dynaclass '" + ((DynaBean) bean).getDynaClass() + "'"); } return (((DynaBean) bean).get(name)); } // Retrieve the property getter method for the specified property PropertyDescriptor descriptor = getPropertyDescriptor(bean, name); if (descriptor == null) { throw new NoSuchMethodException("Unknown property '" + name + "' on class '" + bean.getClass() + "'"); } Method readMethod = getReadMethod(bean.getClass(), descriptor); if (readMethod == null) { throw new NoSuchMethodException( "Property '" + name + "' has no getter method in class '" + bean.getClass() + "'"); } // Call the property getter and return the value Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY); //??,?,? if (value == null) { try { //getternullsetter Object instance = readMethod.getReturnType().newInstance(); Method writeMethod = getWriteMethod(bean.getClass(), descriptor); if (writeMethod == null) { throw new NoSuchMethodException( "Property '" + name + "' has no setter method in class '" + bean.getClass() + "'"); } invokeMethod(writeMethod, bean, new Object[] { instance }); value = instance; } catch (InstantiationException e) { e.printStackTrace(); } } return (value); }
From source file:com.testmax.framework.BasePage.java
protected PerformerBase getRequestObject(String action) { PerformerBase httprequest = null;//from w w w . j a va 2 s.co m String httpclient = this.urlConfig.getUrlElement().attributeValue("httpclient"); if (httpclient == null || httpclient.equals("")) { httpclient = "com.testmax.uri.HttpRestWithXmlBody"; } try { synchronized (state) { httprequest = (PerformerBase) Class.forName(httpclient).newInstance(); httprequest.setup(this, action); } } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return (httprequest); }
From source file:com.rockstor.tools.RockStorFsFormat.java
protected void createDB() { System.out.println("---- Start creating db----------"); try {/*from w w w . jav a2 s .com*/ // create table TableSplitInterface tsi = null; String splitClazzName = conf.get("rockstor.db.splits.class"); System.out.println("rockstor.db.split.class: " + splitClazzName); try { tsi = (TableSplitInterface) Class.forName(splitClazzName).newInstance(); } catch (InstantiationException e) { ExceptionLogger.log(LOG, "get table split instance failed", e); throw new IOException(e); } catch (IllegalAccessException e) { ExceptionLogger.log(LOG, "get table split instance failed", e); throw new IOException(e); } catch (ClassNotFoundException e) { ExceptionLogger.log(LOG, "get table split instance failed", e); throw new IOException(e); } Map<String, byte[][]> tbSplitMap = tsi.generateSplits(oldTables); HTableGenInterface htgi = null; String hTableGenClazzName = conf.get("rockstor.db.descriptor.generator"); System.out.println("rockstor.db.descriptor.generator: " + hTableGenClazzName); try { htgi = (HTableGenInterface) Class.forName(hTableGenClazzName).newInstance(); } catch (InstantiationException e) { ExceptionLogger.log(LOG, "get table generator instance failed", e); throw new IOException(e); } catch (IllegalAccessException e) { ExceptionLogger.log(LOG, "get table generator instance failed", e); throw new IOException(e); } catch (ClassNotFoundException e) { ExceptionLogger.log(LOG, "get table generator instance failed", e); throw new IOException(e); } Map<String, HTableDescriptor> tbDesMap = htgi.initTableDescriptor(); String tbName = null; for (Map.Entry<String, HTableDescriptor> entry : tbDesMap.entrySet()) { tbName = entry.getKey(); ha.createTable(entry.getValue(), tbSplitMap.get(tbName)); LOG.info("created table " + tbName); ha.enableTable(tbName); LOG.info("enabled table " + tbName); } } catch (MasterNotRunningException e) { e.printStackTrace(); } catch (ZooKeeperConnectionException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } LOG.info("create rockstor db ok!"); }
From source file:com.t2.compassionMeditation.MeditationActivity.java
/** Called when the activity is first created. */ @Override//from w w w . j av a 2 s . co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()"); mInstance = this; mRateOfChange = new RateOfChange(mRateOfChangeSize); mIntroFade = 255; // We don't want the screen to timeout in this activity getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView setContentView(R.layout.buddah_activity_layout); sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); currentMindsetData = new MindsetData(this); mSaveRawWave = SharedPref.getBoolean(this, BioZenConstants.PREF_SAVE_RAW_WAVE, BioZenConstants.PREF_SAVE_RAW_WAVE_DEFAULT); mShowAGain = SharedPref.getBoolean(this, BioZenConstants.PREF_SHOW_A_GAIN, BioZenConstants.PREF_SHOW_A_GAIN_DEFAULT); mAllowComments = SharedPref.getBoolean(this, BioZenConstants.PREF_COMMENTS, BioZenConstants.PREF_COMMENTS_DEFAULT); mShowForeground = SharedPref.getBoolean(this, "show_lotus", true); mShowToast = SharedPref.getBoolean(this, "show_toast", true); mAudioTrackResourceName = SharedPref.getString(this, "audio_track", "None"); mBaseImageResourceName = SharedPref.getString(this, "background_images", "Sunset"); mBioHarnessParameters = getResources().getStringArray(R.array.bioharness_parameters_array); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); String s = SharedPref.getString(this, BioZenConstants.PREF_SESSION_LENGTH, "10"); mSecondsRemaining = Integer.parseInt(s) * 60; mSecondsTotal = mSecondsRemaining; s = SharedPref.getString(this, BioZenConstants.PREF_ALPHA_GAIN, "5"); mAlphaGain = Float.parseFloat(s); mMovingAverage = new TMovingAverageFilter(mMovingAverageSize); mMovingAverageROC = new TMovingAverageFilter(mMovingAverageSizeROC); View v1 = findViewById(R.id.buddahView); v1.setOnTouchListener(this); Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); // Set up member variables to UI Elements mTextInfoView = (TextView) findViewById(R.id.textViewInfo); mTextBioHarnessView = (TextView) findViewById(R.id.textViewBioHarness); mCountdownTextView = (TextView) findViewById(R.id.countdownTextView); mCountdownImageView = (ImageView) findViewById(R.id.imageViewCountdown); mPauseButton = (ImageButton) findViewById(R.id.buttonPause); mSignalImage = (ImageView) findViewById(R.id.imageView1); mTextViewInstructions = (TextView) findViewById(R.id.textViewInstructions); // Note that the seek bar is a debug thing - used only to set the // alpha of the buddah image manually for visual testing mSeekBar = (SeekBar) findViewById(R.id.seekBar1); mSeekBar.setOnSeekBarChangeListener(this); // Scale such that values to the right of center are scaled 1 - 10 // and values to the left of center are scaled 0 = .99999 if (mAlphaGain > 1.0) { mSeekBar.setProgress(50 + (int) (mAlphaGain * 5)); } else { int i = (int) (mAlphaGain * 50); mSeekBar.setProgress(i); } // mSeekBar.setProgress((int) mAlphaGain * 10); // Controls start as invisible, need to touch screen to activate them mCountdownTextView.setVisibility(View.INVISIBLE); mCountdownImageView.setVisibility(View.INVISIBLE); mTextInfoView.setVisibility(View.INVISIBLE); mTextBioHarnessView.setVisibility(View.INVISIBLE); mPauseButton.setVisibility(View.INVISIBLE); mPauseButton.setVisibility(View.VISIBLE); mSeekBar.setVisibility(View.INVISIBLE); mBackgroundImage = (ImageView) findViewById(R.id.buddahView); mForegroundImage = (ImageView) findViewById(R.id.lotusView); mBaseImage = (ImageView) findViewById(R.id.backgroundView); if (!mShowForeground) { mForegroundImage.setVisibility(View.INVISIBLE); } int resource = 0; if (mBaseImageResourceName.equalsIgnoreCase("Buddah")) { mBackgroundImage.setImageResource(R.drawable.buddha); mForegroundImage.setImageResource(R.drawable.lotus_flower); mBaseImage.setImageResource(R.drawable.none_bg); } else if (mBaseImageResourceName.equalsIgnoreCase("Bob")) { mBackgroundImage.setImageResource(R.drawable.bigbob); mForegroundImage.setImageResource(R.drawable.red_nose); mBaseImage.setImageResource(R.drawable.none_bg); } else if (mBaseImageResourceName.equalsIgnoreCase("Sunset")) { mBackgroundImage.setImageResource(R.drawable.eeg_layer); mForegroundImage.setImageResource(R.drawable.breathing_rate); mBaseImage.setImageResource(R.drawable.meditation_bg); } // Initialize SPINE by passing the fileName with the configuration properties try { mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, "Exception creating SPINE manager: " + e.toString()); e.printStackTrace(); } // 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)); mManager.getActiveNodes().add(mindsetNode); Node zepherNode = null; zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR)); mManager.getActiveNodes().add(zepherNode); // The arduino node is programmed to look like a static Spine node // Note that currently we don't have to turn it on or off - it's always streaming // Since Spine (in this case) is a static node we have to manually put it in the active node list // Since the final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001 mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE)); mManager.getActiveNodes().add(mSpineNode); // 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); try { PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); mApplicationVersion = info.versionName; Log.i(TAG, "BioZen Application Version: " + mApplicationVersion + ", Activity Version: " + mActivityVersion); } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } // First create GraphBioParameters for each of the ECG static params (ie mindset) int itemId = 0; eegPos = itemId; // eeg always comes first mBioParameters.clear(); for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true); param.isShimmer = false; mBioParameters.add(param); } // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, HR, Skin Temp, Resp Rate String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names); for (String paramName : paramNamesStringArray) { if (paramName.equalsIgnoreCase("not assigned")) continue; if (paramName.equalsIgnoreCase("EEG")) continue; GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true); if (paramName.equalsIgnoreCase("gsr")) { gsrPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("emg")) { emgPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("ecg")) { ecgPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("heart rate")) { heartRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("resp rate")) { respRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("skin temp")) { skinTempPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Airflow")) { eHealthAirFlowPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Temp")) { eHealthTempPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth SpO2")) { eHealthSpO2Pos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Heartrate")) { eHealthHeartRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth GSR")) { eHealthGSRPos = itemId; param.isShimmer = false; } itemId++; mBioParameters.add(param); } // The session start time will be used as session id // Note this also sets session start time // **** This session ID will be prepended to all JSON data stored // in the external database until it's changed (by the start // of a new session. Calendar cal = Calendar.getInstance(); SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US); String sessionDate = sdf.format(new Date()); long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0); mUserId = SharedPref.getString(this, "SelectedUser", ""); // Now get the database object associated with this user try { mBioUserDao = getHelper().getBioUserDao(); mBioSessionDao = getHelper().getBioSessionDao(); QueryBuilder<BioUser, Integer> builder = mBioUserDao.queryBuilder(); builder.where().eq(BioUser.NAME_FIELD_NAME, mUserId); builder.limit(1); // builder.orderBy(ClickCount.DATE_FIELD_NAME, false).limit(30); List<BioUser> list = mBioUserDao.query(builder.prepare()); if (list.size() == 1) { mCurrentBioUser = list.get(0); } else if (list.size() == 0) { try { mCurrentBioUser = new BioUser(mUserId, System.currentTimeMillis()); mBioUserDao.create(mCurrentBioUser); } catch (SQLException e1) { Log.e(TAG, "Error creating user " + mUserId, e1); } } else { Log.e(TAG, "General Database error" + mUserId); } } catch (SQLException e) { Log.e(TAG, "Can't find user: " + mUserId, e); } mSignalImage.setImageResource(R.drawable.signal_bars0); // Check to see of there a device configured for EEG, if so then show the skin conductance meter String tmp = SharedPref.getString(this, "EEG", null); if (tmp != null) { mSignalImage.setVisibility(View.VISIBLE); mTextViewInstructions.setVisibility(View.VISIBLE); } else { mSignalImage.setVisibility(View.INVISIBLE); mTextViewInstructions.setVisibility(View.INVISIBLE); } mDataOutHandler = new DataOutHandler(this, mUserId, sessionDate, mAppId, DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId); if (mDatabaseEnabled) { TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); String myNumber = telephonyManager.getLine1Number(); String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name", getString(R.string.database_uri)); // remoteDatabaseUri += myNumber; Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove try { mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName, remoteDatabaseUri); } catch (DataOutHandlerException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } mDataOutHandler.setRequiresAuthentication(false); } mBioDataProcessor.initialize(mDataOutHandler); mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true); mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false); mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false); mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false); if (mAntHrmEnabled) { mHeartRateSource = HEARTRATE_ANT; } else { mHeartRateSource = HEARTRATE_ZEPHYR; } if (mLoggingEnabled) { mDataOutHandler.enableLogging(this); } if (mLogCatEnabled) { mDataOutHandler.enableLogCat(); } // Log the version try { PackageManager packageManager = getPackageManager(); PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0); mApplicationVersion = info.versionName; String versionString = mAppId + " application version: " + mApplicationVersion; DataOutPacket packet = new DataOutPacket(); packet.add(DataOutHandlerTags.version, versionString); try { mDataOutHandler.handleDataOut(packet); } catch (DataOutHandlerException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } if (mInternalSensorMonitoring) { // IntentSender Launches our service scheduled with with the alarm manager mBigBrotherService = PendingIntent.getService(MeditationActivity.this, 0, new Intent(MeditationActivity.this, BigBrotherService.class), 0); long firstTime = SystemClock.elapsedRealtime(); // Schedule the alarm! AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000, mBigBrotherService); // Tell the user about what we did. Toast.makeText(MeditationActivity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show(); } }
From source file:org.pmedv.core.provider.ApplicationMenuBarProviderImpl.java
@SuppressWarnings("unused") public ApplicationMenuBarProviderImpl() { populateKeyTable();//from www . j ava 2s .c o m menubar = new JMenuBar(); try { JAXBContext c = JAXBContext.newInstance(ApplicationMenubar.class); Unmarshaller u = c.createUnmarshaller(); ApplicationMenubar appMenuBar = (ApplicationMenubar) u .unmarshal(getClass().getClassLoader().getResourceAsStream("menus.xml")); for (ApplicationMenu currentMenu : appMenuBar.getMenus()) { JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(currentMenu.getName())); menu.setMnemonic(resources.getResourceByKey(currentMenu.getName()).charAt(0)); for (ApplicationMenuItem currentItem : currentMenu.getItems()) { try { if (currentItem.getActionClass() != null) { if (currentItem.getActionClass().equals("separator")) { menu.addSeparator(); continue; } log.info("Mapping action class : " + currentItem.getActionClass()); try { AbstractCommand command = null; Class<?> clazz = Class.forName(currentItem.getActionClass()); if (currentItem.isBean()) { command = (AbstractCommand) ctx.getBean(clazz); } else { command = (AbstractCommand) clazz.newInstance(); } ImageIcon icon = null; String mnemonic = null; String toolTipText = null; if (currentItem.getImageIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(currentItem.getImageIcon()); if (is == null) { is = getClass().getClassLoader() .getResourceAsStream("icons/noresource_16x16.png"); } icon = new ImageIcon(ImageIO.read(is)); } if (currentItem.getMnemonic() != null) { mnemonic = currentItem.getMnemonic(); } if (currentItem.getToolTipText() != null) { toolTipText = currentItem.getToolTipText(); } if (currentItem.getType() != null && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) { CmdJCheckBoxMenuItem cmdItem = new CmdJCheckBoxMenuItem(currentItem.getName(), icon, command, mnemonic, toolTipText, null); if (mnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } else { JMenuItem cmdItem = new JMenuItem(command); if (mnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } } catch (InstantiationException e) { log.info("could not instanciate menuitem, skipping."); } catch (IllegalAccessException e) { log.info("could not access menuitem, skipping."); } } } catch (ClassNotFoundException e) { log.info("could not find action class " + currentItem.getActionClass()); } } if (currentMenu.getType() != null && currentMenu.getType().equalsIgnoreCase("file")) { JMenu openRecentMenu = new JMenu(resources.getResourceByKey("menu.recentfiles")); RecentFileList fileList = null; try { String inputDir = System.getProperty("user.home") + "/." + AppContext.getName() + "/"; String inputFileName = "recentFiles.xml"; File inputFile = new File(inputDir + inputFileName); if (inputFile.exists()) { Unmarshaller u1 = JAXBContext.newInstance(RecentFileList.class).createUnmarshaller(); fileList = (RecentFileList) u1.unmarshal(inputFile); } if (fileList == null) fileList = new RecentFileList(); ArrayList<String> recent = fileList.getRecentFiles(); Collections.reverse(recent); for (String recentFile : fileList.getRecentFiles()) { File file = new File(recentFile); AbstractCommand openBoardAction = new OpenBoardCommand(file.getName(), file); JMenuItem item = new JMenuItem(openBoardAction); openRecentMenu.add(item); } } catch (JAXBException e) { e.printStackTrace(); } menu.addSeparator(); menu.add(openRecentMenu); JMenu openSamplesMenu = createSamplesMenu(); menu.add(openSamplesMenu); } menu.setId("common"); if (currentMenu.getType() != null && !currentMenu.getType().equalsIgnoreCase("help")) menubar.add(menu); else helpMenus.add(menu); menubar.setFont(new Font("SansSerif", Font.PLAIN, 12)); } ApplicationPerspectiveProvider perspectiveProvider = ctx.getBean(ApplicationPerspectiveProvider.class); ArrayList<ApplicationPerspective> perspectives = perspectiveProvider.getPerspectives(); JMenuWithId perspectivesMenu = new JMenuWithId("Perspectives"); perspectivesMenu.setId("common"); perspectivesMenu.setMnemonic('P'); for (ApplicationPerspective perspective : perspectives) { ImageIcon icon = null; String mnemonic = null; String toolTipText = null; if (perspective.getPerspectiveIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(perspective.getPerspectiveIcon()); if (is != null) { icon = new ImageIcon(ImageIO.read(is)); } else { is = getClass().getClassLoader().getResourceAsStream("icons/noresource_16x16.png"); if (is != null) icon = new ImageIcon(ImageIO.read(is)); } } if (perspective.getMnemonic() != null) { mnemonic = perspective.getMnemonic(); } if (perspective.getToolTipText() != null) { toolTipText = perspective.getToolTipText(); } log.info("mapping perspective class " + perspective.getPerspectiveClass()); OpenPerspectiveCommand command = new OpenPerspectiveCommand(perspective.getId()); JMenuItem item = new JMenuItem(command); if (mnemonic != null && perspective.getModifier() != null) { if (perspective.getModifier().equalsIgnoreCase("ctrl")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (perspective.getModifier().equalsIgnoreCase("alt")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (perspective.getModifier().equalsIgnoreCase("shift")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } perspectivesMenu.add(item); for (ApplicationMenu pMenu : perspective.getMenubarContributions()) { JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(pMenu.getName())); // if (pMenu.getMnemonic() != null && pMenu.getMnemonic().length() > 0) menu.setMnemonic(resources.getResourceByKey(pMenu.getName()).charAt(0)); for (ApplicationMenuItem currentItem : pMenu.getItems()) { try { if (currentItem.getActionClass() != null) { if (currentItem.getActionClass().equals("separator")) { menu.addSeparator(); continue; } log.info("Mapping action class : " + currentItem.getActionClass()); try { AbstractCommand pCommand = null; Class<?> clazz = Class.forName(currentItem.getActionClass()); if (currentItem.isBean()) { pCommand = (AbstractCommand) ctx.getBean(clazz); } else { pCommand = (AbstractCommand) clazz.newInstance(); } ImageIcon pIcon = null; String pMnemonic = null; String pToolTipText = null; if (currentItem.getImageIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(currentItem.getImageIcon()); pIcon = new ImageIcon(ImageIO.read(is)); } if (currentItem.getMnemonic() != null) { pMnemonic = currentItem.getMnemonic(); } if (currentItem.getToolTipText() != null) { pToolTipText = currentItem.getToolTipText(); } if (currentItem.getType() != null && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) { log.info( "Creating menu checkbox for class " + currentItem.getActionClass()); JCheckBoxMenuItem cmdItem = new JCheckBoxMenuItem(pCommand); if (pMnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); cmdItem.setSelected(true); } else { log.info("Creating menu entry for class " + currentItem.getActionClass()); JMenuItem cmdItem = new JMenuItem(pCommand); if (pMnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } } catch (InstantiationException e) { log.info("could not instanciate menuitem, skipping."); } catch (IllegalAccessException e) { log.info("could not access menuitem, skipping."); } } } catch (ClassNotFoundException e) { log.info("could not find action class " + currentItem.getActionClass()); } } menu.setId(perspective.getId()); menu.setVisible(false); menubar.add(menu); } } if (perspectiveProvider.getPerspectives().size() > 1) { menubar.add(perspectivesMenu); } for (JMenuWithId helpmenu : helpMenus) { menubar.add(helpmenu); } menubar.setFont(new Font("SansSerif", Font.PLAIN, 12)); } catch (JAXBException e) { log.info("could not deserialize menus."); throw new RuntimeException("could not deserialize menus."); } catch (IOException e) { log.info("could not load menus."); throw new RuntimeException("could not load menus."); } }
From source file:gr.abiss.calipso.CalipsoServiceImpl.java
/** * @param history//from ww w .j a v a 2s .c om * @param item */ public void runStateChangePlugins(History history, Item item, Integer state) { // assets to create based on Item info? AbstractItem abstractItem = history != null ? history : item; logger.info("RUNNING PLUGINS (" + state + "), item state: " + abstractItem.getSpace().getMetadata().getStatusValue(abstractItem.getStatus())); // run plugins Map<Integer, String> pluginsMap = abstractItem.getSpace().getMetadata().getStatesPluginMap(); if (abstractItem.getStatus() != null && MapUtils.isNotEmpty(pluginsMap)) { String pluginClassNames = pluginsMap.get(abstractItem.getStatus()); logger.info("pluginClassNames:" + pluginClassNames + ", status: " + (abstractItem != null ? abstractItem.getStatus() : null)); logger.info("Running plugins for status: " + abstractItem.getStatus() + ", plugins: " + pluginsMap.get(abstractItem.getStatus())); if (pluginClassNames != null && pluginClassNames.length() > 0) { String[] pluginNames = pluginClassNames.split(" "); for (int i = 0; i < pluginNames.length; i++) { String pluginClassName = pluginNames[i]; if (StringUtils.isNotBlank(pluginClassName)) { logger.debug("Loading plugin class: " + pluginClassName); // "clazz" is the class name to load Class clazz = null; try { clazz = Class.forName(pluginClassName); AbstractStatePlugin plugin = (AbstractStatePlugin) clazz.newInstance(); if (state.equals(AbstractStatePlugin.PRE_STATE_CHANGE)) { plugin.executePreStateChange(this, item); } else if (state.equals(AbstractStatePlugin.PRE_HISTORY_SAVE)) { plugin.executePreHistoryChange(this, history); } else if (state.equals(AbstractStatePlugin.POST_STATE_CHANGE)) { plugin.executePostStateChange(this, history); } } catch (ClassNotFoundException e) { logger.error("Cannot load State Plugin class: " + pluginClassName, e); e.printStackTrace(); } catch (InstantiationException ie) { logger.error("Cannot instantiate State Plugin class: " + pluginClassName, ie); ie.printStackTrace(); } catch (IllegalAccessException iae) { logger.error("Cannot load State Plugin class: " + pluginClassName, iae); iae.printStackTrace(); } } } } } }
From source file:com.idega.builder.business.BuilderLogic.java
/** * Gets a copy of a UIComponent by its instanceId (component.getId()) if it is found in the current pages ibxml * @param component/*from w w w . java 2s .co m*/ * @return A reset copy of the component from ibxml */ public UIComponent getCopyOfUIComponentFromIBXML(UIComponent component) { String instanceId = getInstanceId(component); UIComponent newComponent = null; try { newComponent = component.getClass().newInstance(); newComponent.setId(instanceId); PropertyCache.getInstance().setAllCachedPropertiesOnInstance(instanceId, newComponent); List<UIComponent> childrenList = component.getChildren(); for (UIComponent childComponent : childrenList) { UIComponent newChildComponent = getCopyOfUIComponentFromIBXML(childComponent); if (newChildComponent != null) { newComponent.getChildren().add(newChildComponent); } } } catch (InstantiationException ex) { ex.printStackTrace(); return null; } catch (IllegalAccessException ex) { ex.printStackTrace(); return null; } return newComponent; }