/** * Get the CarbonRuntime service. This is the bind method that gets called for CarbonRuntime * service registration that satisfy the policy. * * @param carbonRuntime the CarbonRuntime service that is registered as a service. */ @Reference( name = "carbon.runtime.service", service = CarbonRuntime.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unregisterCarbonRuntime") protected void registerCarbonRuntime(CarbonRuntime carbonRuntime) { DataHolder.getInstance().setCarbonRuntime(carbonRuntime); }
@Test public void load() throws Exception { PgmLoader pgmLoader = new PgmLoader(testFileFolder + file); DataHolder dataHolder = pgmLoader.loadFile(); assertEquals(pgmLoader.getHeaderValue("MagicNumber"), "P5"); assertEquals(pgmLoader.getHeaderValue("Width"), "1024"); assertEquals(pgmLoader.getHeaderValue("Height"), "1024"); assertEquals(pgmLoader.getHeaderValue("Maxval"), "65535"); Dataset data = dataHolder.getDataset("Portable Grey Map"); // Check the first data point assertEquals(data.getDouble(0, 0), 0.0, 0.0); // Check the middle data point assertEquals(data.getDouble(512, 511), 15104.0, 0.0); // Check the last data point assertEquals(data.getDouble(1023, 1023), 0.0, 0.0); }
private void promptOperation() { String stockSymbol = getInput("Please enter the stock symbol : "); DataHolder dataHolder = DataHolder.getInstance(); Stock stock = null; if (stockSymbol != null) { stock = dataHolder.getStock(stockSymbol.toUpperCase()); } if (stock != null) { System.out.println(stock); promptMarketPrice(stock); } else { System.out.println("Invalid stock symbol! "); promptOperation(); } fetchStockPerformance(stock); }
/** * Doing the start, stop, reload and lazy unload of webapps inside all hosts respectively when * getting request. * * @param nameOfOperation the operation to be performed in oder to hot update the host * @throws CarbonException if errors occurs when hot update the host */ private void handleHotUpdateToHost(String nameOfOperation) throws CarbonException { if (DataHolder.getHotUpdateService() != null) { List<String> mappings = URLMappingHolder.getInstance().getUrlMappingsPerApplication(this.context.getName()); Engine engine = DataHolder.getCarbonTomcatService().getTomcat().getEngine(); Context hostContext; Host host; for (String hostName : mappings) { host = (Host) engine.findChild(hostName); if (host != null) { hostContext = (Context) host.findChild("/"); if (hostContext != null) { if (nameOfOperation.equalsIgnoreCase("start")) { start(hostContext); } else if (nameOfOperation.equalsIgnoreCase("stop")) { stop(hostContext); } else if (nameOfOperation.equalsIgnoreCase("reload")) { reload(hostContext); } else if (nameOfOperation.equalsIgnoreCase("lazyunload")) { lazyUnload(hostContext); DataHolder.getHotUpdateService().removeHost(hostName); } else if (nameOfOperation.equalsIgnoreCase("delete")) { DataHolder.getHotUpdateService().deleteHost(hostName); } } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DataHolder.InitDataHolder(getApplicationContext()); nextButton = (Button) findViewById(R.id.nextButton); editTeamsButton = (Button) findViewById(R.id.toEditTeam); mTeamSpinner = (Spinner) (findViewById(R.id.teamSelectSpinnerId)); Hashtable teamsHashtable = DataHolder.getInstance().getTeams(); ArrayList<String> initTeams = new ArrayList<String>(teamsHashtable.size()); Enumeration<String> keys = teamsHashtable.keys(); String tempString; while (keys.hasMoreElements()) { tempString = keys.nextElement(); initTeams.add(tempString); } mSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, initTeams); mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mTeamSpinner.setAdapter(mSpinnerAdapter); mPlayerListView = (ListView) findViewById(R.id.listViewPlayers); Team jaredTeam = (Team) teamsHashtable.get("Jared"); Hashtable playersHashtable = jaredTeam.getmPlayers(); ArrayList<Player> tempList = makePlayerArrayList(playersHashtable); mListViewAdapter = new PlayerListAdapter(this, tempList); mPlayerListView.setAdapter(mListViewAdapter); mTeamSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String teamName = (String) mTeamSpinner.getSelectedItem(); Team currentTeam = (Team) DataHolder.getInstance().getTeams().get(teamName); Hashtable currentPlayers = currentTeam.getmPlayers(); ListView teamList = (ListView) findViewById(R.id.listViewPlayers); PlayerListAdapter tempAdp = (PlayerListAdapter) teamList.getAdapter(); ArrayList<Player> tempList = makePlayerArrayList(currentPlayers); tempAdp.clear(); tempAdp.addAll(tempList); tempAdp.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); }
@Test public void testTruncatedFile() { try { DataHolder dh = new TIFFImageLoader("testfiles/images/test-trunc.tiff").loadFile(); System.err.println(dh.size()); Assert.fail("Should have thrown an exception"); } catch (ScanFileHolderException e) { // e.printStackTrace(); } }
@Override public void bindView(View view, Context context, Cursor cursor) { final DataHolder contactData = (DataHolder) view.getTag(R.id.contact_info_tag); final ViewHolder holder = (ViewHolder) view.getTag(R.id.holder_tag); if (holder == null) { Log.w(TAG, "ViewHolder was null. This should not happen."); return; } if (contactData == null) { Log.w(TAG, "DataHolder was null. This should not happen."); return; } if (ID_COLUMN < 0) { populateColumnIndices(cursor); } contactData.type = cursor.getInt(TYPE_COLUMN); contactData.name = cursor.getString(NAME_COLUMN); contactData.number = cursor.getString(NUMBER_COLUMN); contactData.numberType = cursor.getInt(NUMBER_TYPE_COLUMN); contactData.id = cursor.getLong(ID_COLUMN); if (contactData.type != ContactsDatabase.PUSH_TYPE) { holder.name.setTextColor(drawables.getColor(1, 0xff000000)); holder.number.setTextColor(drawables.getColor(1, 0xff000000)); } else { holder.name.setTextColor(drawables.getColor(0, 0xa0000000)); holder.number.setTextColor(drawables.getColor(0, 0xa0000000)); } if (selectedContacts.containsKey(contactData.id)) { holder.checkBox.setChecked(true); } else { holder.checkBox.setChecked(false); } holder.name.setText(contactData.name); if (contactData.number == null || contactData.number.isEmpty()) { holder.name.setEnabled(false); holder.number.setText(""); } else if (contactData.type == ContactsDatabase.PUSH_TYPE) { holder.number.setText(contactData.number); } else { final CharSequence label = ContactsContract.CommonDataKinds.Phone.getTypeLabel( context.getResources(), contactData.numberType, ""); final CharSequence numberWithLabel = contactData.number + " " + label; final Spannable numberLabelSpan = new SpannableString(numberWithLabel); numberLabelSpan.setSpan( new ForegroundColorSpan(drawables.getColor(2, 0xff444444)), contactData.number.length(), numberWithLabel.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); holder.number.setText(numberLabelSpan); } holder.contactPhoto.setImageBitmap(defaultCroppedPhoto); loadBitmap(contactData.number, holder.contactPhoto); }
/** * Return a File object representing the "application root" directory for our associated Host. * * @return The AppBase //TODO - when webapp exploding is supported for stratos, this should return * the tenant's webapp dir */ protected File getAppBase() { File appBase = null; File file = new File(DataHolder.getCarbonTomcatService().getTomcat().getHost().getAppBase()); /*if (!file.isAbsolute()) { file = new File(System.getProperty("catalina.base"), host.getAppBase()); }*/ try { appBase = file.getCanonicalFile(); } catch (IOException e) { appBase = file; } return appBase; }
@Test public void testSaveFile() throws ScanFileHolderException { Dataset a = DatasetFactory.createRange(128 * 128, Dataset.FLOAT32).reshape(128, 128); DataHolder d = new DataHolder(); a.idivide(10000); d.addDataset("a", a); String oname = testScratchDirectoryName + "a.tif"; TIFFImageSaver s; DataHolder in; s = new TIFFImageSaver(oname, true); s.saveFile(d); in = new TIFFImageLoader(oname).loadFile(); checkDataset(a, in.getDataset(0)); s = new TIFFImageSaver(oname); s.saveFile(d); in = new TIFFImageLoader(oname).loadFile(); checkDataset(a.cast(Dataset.INT32), in.getDataset(0)); }
/* (non-Javadoc) * @see org.wso2.carbon.identity.application.authentication.framework.AbstractApplicationAuthenticator#initiateAuthenticationRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) */ @Override protected void initiateAuthenticationRequest( HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException { String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL(); String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId( context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier()); try { String retryParam = ""; if (context.isRetrying()) { retryParam = "&authFailure=true&authFailureMsg=login.fail.message"; } else { // Insert entry to DB only if this is not a retry DBUtils.insertUserResponse( context.getContextIdentifier(), String.valueOf(MSSAuthenticator.UserResponse.PENDING)); } // MSISDN will be saved in the context in the MSISDNAuthenticator String msisdn = (String) context.getProperty("msisdn"); MSSRequest mssRequest = new MSSRequest(); mssRequest.setMsisdnNo("+" + msisdn); mssRequest.setSendString( DataHolder.getInstance().getMobileConnectConfig().getMSS().getMssText()); String contextIdentifier = context.getContextIdentifier(); MSSRestClient mssRestClient = new MSSRestClient(contextIdentifier, mssRequest); mssRestClient.start(); response.sendRedirect( response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&authenticators=" + getName() + ":" + "LOCAL" + retryParam); } catch (IOException e) { throw new AuthenticationFailedException(e.getMessage(), e); } catch (AuthenticatorException e) { throw new AuthenticationFailedException(e.getMessage(), e); } }
@Override protected void onCreate(Bundle savedInstanceState) { // Probe.deploy(this, new OvermeasureInterceptor(R.id.root_layout)); super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); setContentView(R.layout.activity_main_draw); // for layoutmodule i.e. second module which demonstrates onLayout pass // setContentView(R.layout.activity_main_layoutmodule); ButterKnife.bind(this); int[] screnDimen = DataHolder.getScreenDimension(); Timber.d("screenWidth , screenHeight = %d , %d", screnDimen[0], screnDimen[1]); int[] locationInWindow = new int[2]; int[] locationInScreen = new int[2]; customView.getLocationInWindow(locationInWindow); customView.getLocationOnScreen(locationInScreen); Timber.d("Custom view locationin window %d:%d", locationInWindow[0], locationInWindow[1]); Timber.d("Custom view location on screen %d:%d", locationInScreen[0], locationInScreen[1]); }
private void lazyUnload(Context context) throws CarbonException { Host host = DataHolder.getCarbonTomcatService().getTomcat().getHost(); try { if (context.getAvailable()) { // If the following is not done, the Realm will throw a LifecycleException, because // Realm.stop is called for each context. context.setRealm(null); context.stop(); context.destroy(); host.removeChild(context); log.info("Unloaded webapp: " + context); } // if the webapp is stopped above context.getAvailable() becomes false. // So to unload stopped webapps this is done. else if (LifecycleState.STOPPED.equals(context.getState())) { context.setRealm(null); context.destroy(); host.removeChild(context); log.info("Unloaded webapp: " + context); } } catch (Exception e) { throw new CarbonException("Cannot lazy unload webapp " + this.context, e); } }
protected void setConfigurationContext(ConfigurationContextService configCtx) { this.configCtx = configCtx.getServerConfigContext(); DataHolder.setServerConfigContext(configCtx.getServerConfigContext()); }
@Override public void onBindViewHolder(DataHolder viewHolder, int i) { viewHolder.bindTo(users.get(i)); }
public static Object toObject(DataHolder dataHolder) { return toObject(dataHolder.toData()); }
/** * This is the unbind method for the above reference that gets called for CarbonRuntime instance * un-registrations. * * @param carbonRuntime the CarbonRuntime service that get unregistered. */ protected void unregisterCarbonRuntime(CarbonRuntime carbonRuntime) { DataHolder.getInstance().setCarbonRuntime(null); }
@SuppressWarnings("unchecked") public DataHolder loadFile(boolean loadData) { DataHolder dataHolder = new DataHolder(); NexusFile file; try { file = new NexusFile(fileName, NexusFile.NXACC_READ); if (loadMetadata) { metadata = new Metadata(); metadata.setFilePath(fileName); } // file.opengroup("entry1", "NXentry"); // Look for an NXentry... Enumeration<String> topKeys = file.groupdir().keys(); while (topKeys.hasMoreElements()) { String topName = topKeys.nextElement(); String topClass = (String) file.groupdir().get(topName); if (topClass.compareTo("NXentry") == 0) { // Specify class explicitly to make sure we are opening the correct one. Otherwise it will // throw an // exception. file.opengroup(topName, "NXentry"); Enumeration<String> keys = file.groupdir().keys(); while (keys.hasMoreElements()) { String name = keys.nextElement(); String className = (String) file.groupdir().get(name); if (className.compareTo("NXdata") == 0) { file.opengroup(name, "NXdata"); // Now lets get a list of the data items Enumeration<String> dataKeys = file.groupdir().keys(); while (dataKeys.hasMoreElements()) { // Hashtable h = file.attrdir(); // Enumeration e = h.keys(); // while (e.hasMoreElements()) { // String attname = (String)e.nextElement(); // AttributeEntry atten = (AttributeEntry)h.get(attname); // JythonServerFacade.getInstance().print("Found SDS attribute: " + attname + // " type: "+ atten.type + " ,length: " + atten.length); // // } String dataName = dataKeys.nextElement(); file.opendata(dataName); int[] iDim = new int[20]; int[] iStart = new int[2]; file.getinfo(iDim, iStart); // JythonServerFacade.getInstance().print( // "Found " + dataName + " with: rank = " + iStart[0] + " type = " + iStart[1] // + " dims = " + iDim[0] + ", " + iDim[1]); // h = file.attrdir(); // e = h.keys(); // while (e.hasMoreElements()) { // String attname = (String)e.nextElement(); // AttributeEntry atten = (AttributeEntry)h.get(attname); // JythonServerFacade.getInstance().print("Found SDS attribute: " + attname + // " type: "+ atten.type + " ,length: " + atten.length); // // } // Now lets create an array of the dimensions for creating the dataset. final int rank = iStart[0]; int[] shape = Arrays.copyOf(iDim, rank); if (loadData) { final int dtype = Nexus.getDType(iStart[1]); Dataset ds = DatasetFactory.zeros(shape, dtype); file.getdata(ds.getBuffer()); ds.setName(dataName); dataHolder.addDataset(dataName, ds); } if (loadMetadata) { metadata.addDataInfo(dataName, shape); } file.closedata(); } // Close NXdata file.closegroup(); } } // Close the NXentry file.closegroup(); } } // for (Iterator iterator = file.groupdir().values().iterator(); iterator.hasNext();) { // String type = (String) iterator.next(); // JythonServerFacade.getInstance().print(type); // } file.close(); if (loadMetadata) { dataHolder.setMetadata(metadata); } return dataHolder; } catch (NexusException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // TODO Empty clause } return null; }
/** * Formats Acceleration, Compass, KeyPress, Keyboard, Orientation, Gps and Touch logs for * displaying on JSP page. * * @param session the wanted session * @return a DataHolder with data formatted for displaying. */ @Override public DataHolder formatForJsp(Sessionlog session) { DataHolder data = new DataHolder(session); if (session != null) { List<Acceleration> accLogs = pullFromDb(Acceleration.class, data); List<Compass> comLogs = pullFromDb(Compass.class, data); List<KeyPress> keyPresses = pullFromDb(KeyPress.class, data); List<Keyboard> keyboards = pullFromDb(Keyboard.class, data); List<Orientation> gyroLogs = pullFromDb(Orientation.class, data); List<Gps> gpsLogs = pullFromDb(Gps.class, data); List<Touch> touchLogs = pullFromDb(Touch.class, data); int accI = 0; int comI = 0; int pressI = 0; int keybI = 0; int gyroI = 0; int gpsI = 0; int touchI = 0; for (Long time : data.getTimestamps()) { if (accLogs != null && accLogs.size() > accI && (accLogs.get(accI).getTimestamp() / 10) * 10 <= time) { while ((accLogs.get(accI).getTimestamp() / 10) * 10 <= time) { if ((accLogs.get(accI).getTimestamp() / 10) * 10 == time) { data.addToColumn("Acc X", accLogs.get(accI).getAccX().toString()); data.addToColumn("Acc Y", accLogs.get(accI).getAccY().toString()); data.addToColumn("Acc Z", accLogs.get(accI).getAccZ().toString()); } else { data.addToColumn("Acc X", ""); data.addToColumn("Acc Y", ""); data.addToColumn("Acc Z", ""); } accI++; if (accLogs.size() >= accI) break; } } else { data.addToColumn("Acc X", ""); data.addToColumn("Acc Y", ""); data.addToColumn("Acc Z", ""); } if (comLogs != null && comLogs.size() > comI && (comLogs.get(comI).getTimestamp() / 10) * 10 <= time) { while ((comLogs.get(comI).getTimestamp() / 10) * 10 <= time) { if ((comLogs.get(comI).getTimestamp() / 10) * 10 == time) { data.addToColumn("Heading, true", comLogs.get(comI).getTrueHeading().toString()); data.addToColumn( "Heading, magnetic", comLogs.get(comI).getMagneticHeading().toString()); } else { data.addToColumn("Heading, true", ""); data.addToColumn("Heading, magnetic", ""); } comI++; if (comLogs.size() >= comI) break; } } else { data.addToColumn("Heading, true", ""); data.addToColumn("Heading, magnetic", ""); } if (keyPresses != null && keyPresses.size() > pressI && (keyPresses.get(pressI).getTimestamp() / 10) * 10 <= time) { while ((keyPresses.get(pressI).getTimestamp() / 10) * 10 <= time) { if ((keyPresses.get(pressI).getTimestamp() / 10) * 10 == time) { data.addToColumn("Key pressed", keyPresses.get(pressI).getKeyPressed()); } else { data.addToColumn("Key pressed", ""); } pressI++; if (keyPresses.size() >= pressI) break; } } else { data.addToColumn("Key pressed", ""); } if (keyboards != null && keyboards.size() > keybI && (keyboards.get(keybI).getTimestamp() / 10) * 10 <= time) { while ((keyboards.get(keybI).getTimestamp() / 10) * 10 <= time) { if ((keyboards.get(keybI).getTimestamp() / 10) * 10 == time) { data.addToColumn("Keyboard status", keyboards.get(keybI).getKeyboardFocus()); } else { data.addToColumn("Keyboard status", ""); } keybI++; if (keyboards.size() >= keybI) break; } } else { data.addToColumn("Keyboard status", ""); } if (gyroLogs != null && gyroLogs.size() > gyroI && (gyroLogs.get(gyroI).getTimestamp() / 10) * 10 <= time) { while ((gyroLogs.get(gyroI).getTimestamp() / 10) * 10 <= time) { if ((gyroLogs.get(gyroI).getTimestamp() / 10) * 10 == time) { data.addToColumn("Gyro X", gyroLogs.get(gyroI).getCurrentRotationRateX().toString()); data.addToColumn("Gyro Y", gyroLogs.get(gyroI).getCurrentRotationRateY().toString()); data.addToColumn("Gyro Z", gyroLogs.get(gyroI).getCurrentRotationRateZ().toString()); } else { data.addToColumn("Gyro X", ""); data.addToColumn("Gyro Y", ""); data.addToColumn("Gyro Z", ""); } gyroI++; if (gyroLogs.size() >= gyroI) break; } } else { data.addToColumn("Gyro X", ""); data.addToColumn("Gyro Y", ""); data.addToColumn("Gyro Z", ""); } if (gpsLogs != null && gpsLogs.size() > gpsI && (gpsLogs.get(gpsI).getTimestamp() / 10) * 10 <= time) { while ((gpsLogs.get(gpsI).getTimestamp() / 10) * 10 <= time) { if ((gpsLogs.get(gpsI).getTimestamp() / 10) * 10 == time) { data.addToColumn("gps Latitude", gpsLogs.get(gpsI).getLat().toString()); data.addToColumn("gps Longitude", gpsLogs.get(gpsI).getLon().toString()); data.addToColumn("gps Altitude", gpsLogs.get(gpsI).getAlt().toString()); } else { data.addToColumn("gps Latitude", ""); data.addToColumn("gps Longitude", ""); data.addToColumn("gps Altitude", ""); } gpsI++; if (gpsLogs.size() >= gpsI) break; } } else { data.addToColumn("gps Latitude", ""); data.addToColumn("gps Longitude", ""); data.addToColumn("gps Altitude", ""); } if (touchLogs != null && touchLogs.size() > touchI && (touchLogs.get(touchI).getTimestamp() / 10) * 10 <= time) { while ((touchLogs.get(touchI).getTimestamp() / 10) * 10 <= time) { if ((touchLogs.get(touchI).getTimestamp() / 10) * 10 == time) { data.addToColumn("touch x", "" + touchLogs.get(touchI).getXcoord()); data.addToColumn("touch y", "" + touchLogs.get(touchI).getYcoord()); data.addToColumn("touch action", touchLogs.get(touchI).getAction()); } else { data.addToColumn("touch x", ""); data.addToColumn("touch y", ""); data.addToColumn("touch action", ""); } touchI++; if (touchLogs.size() >= touchI) break; } } else { data.addToColumn("touch x", ""); data.addToColumn("touch y", ""); data.addToColumn("touch action", ""); } } } return data; }
private <T extends Abstractlog> List<T> pullFromDb(Class<T> cls, DataHolder data) { return logService.getAllBySessionId(cls, data.getSession()); }