List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:velo.ejb.seam.action.HomeActionsBean.java
public void test() { //System.out.println("!!!!!!!!!!!" + dispatcher); //System.out.println("!!!!!!!!!!!" + dispatcher.getScheduler().getClass().getName()); try {//ww w . java2s . c o m InitialContext ic = new InitialContext(); org.quartz.impl.StdScheduler sched = (org.quartz.impl.StdScheduler) ic.lookup("Quartz"); System.out.println("!!!!!!!!!!!!!!!!!!NUUUUU: " + sched); } catch (NamingException e) { System.out.println("WAAAAAAAAAAAA: " + e.getMessage()); } }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.teiid.TeiidEmbeddedServer.java
public TeiidEmbeddedServer(EmbeddedConfiguration config, MemoryConfig memoryConfig, ServerConfig serverConfig, TransactionManagerConfiguration transactionManagerConfiguration) { // allow user to plugin their own customizable for teiid embedded server if ((serverConfig != null) && (serverConfig.getServerInit() != null)) serverConfig.getServerInit().init(this); // transaction manager is required for derived table if (config.getTransactionManager() == null) { boolean useMockTranscationManager = true; String transactionManagerLookup = null; if (serverConfig != null) transactionManagerLookup = serverConfig.getTransactionManagerJNDILookup(); if ((transactionManagerLookup != null) && (!transactionManagerLookup.trim().equals(""))) { try { InitialContext ic = new InitialContext(); Object utm = ic.lookup(transactionManagerLookup); if ((utm != null) && (utm instanceof TransactionManager)) { log.debug("Teiid Embedded Server: set transaction manager = " + transactionManagerLookup); config.setTransactionManager((TransactionManager) utm); useMockTranscationManager = false; }//from www . j a v a2 s . co m } catch (Exception ex) { log.debug( "Teiid Embedded Server: fail to set transaction manager = " + transactionManagerLookup, ex); } } if (useMockTranscationManager) { log.debug("Teiid Embedded Server: use simple transaction manager"); try { config.setTransactionManager(createTransactionManager(transactionManagerConfiguration)); } catch (Exception ex) { log.debug("Fail to initialize transaction manager for teiid engine", ex); } } if ((serverConfig != null) && (serverConfig.getXaTerminator() != null)) { setXaTerminator(serverConfig.getXaTerminator()); } } this.repo.odbcEnabled(); this.memoryConfig = memoryConfig; start(config); }
From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java
public LoaderStatusBeanLocal getLoaderStatusBean() throws I2B2Exception { InitialContext ctx; try {//from w w w .ja va2 s . c o m ctx = new InitialContext(); return (LoaderStatusBeanLocal) ctx.lookup("LoaderStatusBean/local"); } catch (NamingException e) { throw new I2B2Exception("Bean lookup error ", e); } }
From source file:org.meveo.service.job.JobInstanceService.java
public Job getJobByName(String jobName) { Job result = null;// w ww . j a v a2 s. c om try { InitialContext ic = new InitialContext(); result = (Job) ic .lookup("java:global/" + paramBean.getProperty("meveo.moduleName", "meveo") + "/" + jobName); } catch (NamingException e) { log.error("Failed to get job by name {}", jobName, e); } return result; }
From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java
public MissingTermReportBeanLocal getMissingTermReportBean() throws I2B2Exception { InitialContext ctx; try {/*from ww w.j av a 2 s .c om*/ ctx = new InitialContext(); return (MissingTermReportBeanLocal) ctx.lookup("MissingTermReportBean/local"); } catch (NamingException e) { throw new I2B2Exception("Bean lookup error ", e); } }
From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java
public DataMartLoaderAsyncBeanLocal getDataMartLoaderBean() throws I2B2Exception { InitialContext ctx; try {/*w ww . j a v a 2s . c om*/ ctx = new InitialContext(); return (DataMartLoaderAsyncBeanLocal) ctx.lookup("DataMartLoaderAsyncBean/local"); } catch (NamingException e) { throw new I2B2Exception("Bean lookup error ", e); } }
From source file:eu.uqasar.util.UQasarUtil.java
/** * Traverse the tree in postorder and update tree values * @param node/*from ww w . j a v a 2 s . c om*/ */ private static void postorder(TreeNode node) { if (node == null) { return; } logger.debug("------------postorder: " + node.getName() + "---------------"); // Iterate the node children for (Object o : node.getChildren()) { TreeNode nodeChild = (TreeNode) o; UQasarUtil.postorder(nodeChild); } logger.debug("Traversing project tree in postorder..." + node.toString()); // Update the value try { InitialContext ic = new InitialContext(); AdapterDataService adapterDataService = new AdapterDataService(); TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService"); if (node instanceof Metric) { Metric metric = (Metric) node; logger.debug("Recomputing the value of the Metric " + node); Float value = null; if (metric.getMetricSource() == MetricSource.Manual) { metric.updateQualityStatus(); } else { value = adapterDataService.getMetricValue(metric.getMetricSource(), metric.getMetricType(), metric.getProject()); metric.setValue(value); } metric.setLastUpdated(getLatestTreeUpdateDate()); metric.addHistoricValue(); // End Metric node treatment } else if (node instanceof QualityIndicator) { logger.info("Recomputing the value of the Quality Indicator " + node); QualityIndicator qi = (QualityIndicator) node; if (qi.getUseFormula()) { String formulaToEval = Formula.parseFormula(qi.getViewFormula()); if (formulaToEval != null && !formulaToEval.isEmpty()) { Float computedValue = Formula.evalFormula(formulaToEval); if (computedValue != null && !computedValue.isNaN()) { qi.setValue(computedValue); qi.setLastUpdated(getLatestTreeUpdateDate()); treeNodeService.update(qi); } } } else { float achieved = 0; float denominator = 0; for (final TreeNode me : qi.getChildren()) { float weight = ((Metric) me).getWeight(); if (me.getQualityStatus() == QualityStatus.Green) { achieved += weight; } denominator += weight; } if (denominator == 0) qi.getChildren().size(); qi.setValue(achieved * 100 / denominator); } qi.setLastUpdated(getLatestTreeUpdateDate()); qi.addHistoricValue(); // End Q.Indicator node treatment } else if (node instanceof QualityObjective) { logger.info("Recomputing the value of the Quality Objective " + node); QualityObjective qo = (QualityObjective) node; if (qo.getUseFormula()) { String formulaToEval = Formula.parseFormula(qo.getViewFormula()); if (formulaToEval != null && !formulaToEval.isEmpty()) { Float computedValue = Formula.evalFormula(formulaToEval); if (computedValue != null && !computedValue.isNaN()) { qo.setValue(computedValue); qo.setLastUpdated(getLatestTreeUpdateDate()); } } } else { float denominator = 0; float achieved = 0; for (final TreeNode qi : qo.getChildren()) { float weight = ((QualityIndicator) qi).getWeight(); if (qi.getQualityStatus() == QualityStatus.Green) { achieved += weight; } denominator += weight; } qo.setValue(achieved * 100 / denominator); } qo.setLastUpdated(getLatestTreeUpdateDate()); qo.addHistoricValue(); // End Quality Objective node treatment } else if (node instanceof Project) { logger.info("Recomputing the value of the Project " + node); Project prj = (Project) node; double qoValueSum = 0; double denominator = 0; for (Object o : node.getChildren()) { QualityObjective qo = (QualityObjective) o; if (qo.getWeight() == 0) { continue; } qoValueSum += qo.getValue() * (prj.isFormulaAverage() ? qo.getWeight() : 1); denominator += prj.isFormulaAverage() ? qo.getWeight() : 1; } // bad idea to divide something under 0 if (denominator == 0) { denominator = 1; } Double computedValue = qoValueSum / denominator; if (computedValue != null && !computedValue.isNaN() && !computedValue.isInfinite()) { prj.setValue(computedValue); } prj.setLastUpdated(getLatestTreeUpdateDate()); prj.addHistoricValue(); logger.debug(" [" + qoValueSum + "] denominator [" + denominator + "] " + computedValue); // End Project node treatment } // Get a (possible) suggestion for the tree node Multimap<?, ?> suggestions = getSuggestionForNode(node); //TODO: take all the suggestions into account Object[] types = suggestions.keys().toArray(); Object[] suggestionsValues = suggestions.values().toArray(); if (types.length > 0) { // for now use the first item as suggestion SuggestionType stype = (SuggestionType) types[0]; node.setSuggestionType(stype); if (suggestionsValues[0] != null && !suggestionsValues[0].equals("")) { node.setSuggestionValue((String) suggestionsValues[0]); } } treeNodeService.update(node); } catch (NamingException e) { e.printStackTrace(); } return; }
From source file:org.opentaps.notes.rest.NoteResource.java
/** * Handle POST requests: create a new note. * @param entity a <code>Representation</code> * @return a noteId as plain text and http.status SUCCESS_CREATED * @throws NamingException if the service cannot be found * @throws ServiceException if an error occur in the service *//* ww w . j a v a 2s . c o m*/ @Post public Representation createNote(Representation entity) throws NamingException, ServiceException { Messages messages = Messages.getInstance(getRequest()); String repString = getEmptyJSON(); String successMessage = ""; String errorMessage = ""; FacebookUser fbUser = null; NoteUser user = null; JSONUtil.setResponseHttpHeader(getResponse(), "Access-Control-Allow-Origin", "*"); Form form = new Form(entity); String userKey = form.getFirstValue("userKey"); if (!GenericValidator.isBlankOrNull(userKey)) { fbUser = userCache.getUser(userKey); if (fbUser != null) { user = new NoteUser(fbUser.getId(), fbUser.getUserIdType()); } } String noteText = form.getFirstValue(Note.Fields.noteText.getName()); InitialContext context = new InitialContext(); CreateNoteService createNoteService = (CreateNoteService) context .lookup("osgi:service/org.opentaps.notes.services.CreateNoteService"); if (createNoteService != null) { CreateNoteServiceInput createNoteServiceInput = new CreateNoteServiceInput(); createNoteServiceInput.setText(noteText); for (String param : form.getNames()) { if (param.startsWith(CUSTOM_FIELD_PREFIX)) { String fieldName = param.substring(CUSTOM_FIELD_PREFIX.length()); String value = form.getFirstValue(param); createNoteServiceInput.setAttribute(fieldName, value); } } createNoteServiceInput.setCreatedByUser(user); Reference ref = getRequest().getReferrerRef(); if (ref != null) { createNoteServiceInput.setClientDomain(ref.getHostDomain()); } String noteId = createNoteService.createNote(createNoteServiceInput).getNoteId(); if (!GenericValidator.isBlankOrNull(noteId)) { setStatus(Status.SUCCESS_CREATED); successMessage = messages.get("NoteCreatedSuccess"); Log.logDebug(successMessage); repString = getNoteIdJSON(noteId); if (fbUser != null) { String postOnMyWall = form.getFirstValue("postOnMyWall"); if ("Y".equalsIgnoreCase(postOnMyWall)) { postNoteOnUserWall(fbUser.getId(), fbUser.getAccessToken(), noteText); // post note on to opentaps wall postNoteOnUserWall(OPENTAPS_FACEBOOK_PAGE_ID, fbUser.getAccessToken(), noteText); } } } else { errorMessage = messages.get("CanNotCreateNote"); setStatus(Status.SERVER_ERROR_INTERNAL); Log.logError(errorMessage); } } else { errorMessage = messages.get("CreateNoteServiceUnavailable"); setStatus(Status.SERVER_ERROR_SERVICE_UNAVAILABLE); Log.logError(errorMessage); } return new StringRepresentation(JSONUtil.getJSONResult(repString, successMessage, errorMessage), MediaType.APPLICATION_JSON); }
From source file:eu.uqasar.util.UQasarUtil.java
/** * Traverse the tree in postorder and update tree values * @param node/*from www . ja v a 2 s.c o m*/ */ private static void postorderWithParticularNode(TreeNode node, TreeNode projectTreeNode) { if (node == null) { return; } if (projectTreeNode == null) { return; } logger.debug("------------postorder: " + projectTreeNode.getName() + "---------------"); logger.debug("Traversing project tree in postorder..." + projectTreeNode.toString()); // Update the value try { InitialContext ic = new InitialContext(); AdapterDataService adapterDataService = new AdapterDataService(); TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService"); if (projectTreeNode instanceof Metric) { Metric metric = (Metric) projectTreeNode; logger.debug("Recomputing the value of the Metric " + projectTreeNode); Float value = null; if (metric.getMetricSource() == MetricSource.Manual) { metric.updateQualityStatus(); } else { value = adapterDataService.getMetricValue(metric.getMetricSource(), metric.getMetricType(), metric.getProject()); metric.setValue(value); } metric.setLastUpdated(getLatestTreeUpdateDate()); metric.addHistoricValue(); // End Metric node treatment } else if (projectTreeNode instanceof QualityIndicator) { logger.info("Recomputing the value of the Quality Indicator " + projectTreeNode); QualityIndicator qi = (QualityIndicator) projectTreeNode; if (qi.getUseFormula()) { String formulaToEval = Formula.parseFormula(qi.getViewFormula()); if (formulaToEval != null && !formulaToEval.isEmpty()) { Float computedValue = Formula.evalFormula(formulaToEval); if (computedValue != null && !computedValue.isNaN()) { qi.setValue(computedValue); qi.setLastUpdated(getLatestTreeUpdateDate()); treeNodeService.update(qi); } } } else { float achieved = 0; float denominator = 0; for (final TreeNode me : qi.getChildren()) { float weight = ((Metric) me).getWeight(); if (me.getQualityStatus() == QualityStatus.Green) { achieved += weight; } denominator += weight; } if (denominator == 0) qi.getChildren().size(); qi.setValue(achieved * 100 / denominator); } qi.setLastUpdated(getLatestTreeUpdateDate()); qi.addHistoricValue(); // End Q.Indicator node treatment } else if (projectTreeNode instanceof QualityObjective) { logger.info("Recomputing the value of the Quality Objective " + projectTreeNode); QualityObjective qo = (QualityObjective) projectTreeNode; if (qo.getUseFormula()) { String formulaToEval = Formula.parseFormula(qo.getViewFormula()); if (formulaToEval != null && !formulaToEval.isEmpty()) { Float computedValue = Formula.evalFormula(formulaToEval); if (computedValue != null && !computedValue.isNaN()) { qo.setValue(computedValue); qo.setLastUpdated(getLatestTreeUpdateDate()); } } } else { float denominator = 0; float achieved = 0; for (final TreeNode qi : qo.getChildren()) { float weight = ((QualityIndicator) qi).getWeight(); if (qi.getQualityStatus() == QualityStatus.Green) { achieved += weight; } denominator += weight; } qo.setValue(achieved * 100 / denominator); } qo.setLastUpdated(getLatestTreeUpdateDate()); qo.addHistoricValue(); // End Quality Objective node treatment } else if (projectTreeNode instanceof Project) { logger.info("Recomputing the value of the Project " + projectTreeNode); Project prj = (Project) projectTreeNode; double qoValueSum = 0; double denominator = 0; for (Object o : projectTreeNode.getChildren()) { QualityObjective qo = (QualityObjective) o; if (qo.getWeight() == 0) { continue; } qoValueSum += qo.getValue() * (prj.isFormulaAverage() ? qo.getWeight() : 1); denominator += prj.isFormulaAverage() ? qo.getWeight() : 1; } // bad idea to divide something under 0 if (denominator == 0) { denominator = 1; } Double computedValue = qoValueSum / denominator; if (computedValue != null && !computedValue.isNaN() && !computedValue.isInfinite()) { prj.setValue(computedValue); } prj.setLastUpdated(getLatestTreeUpdateDate()); prj.addHistoricValue(); logger.debug(" [" + qoValueSum + "] denominator [" + denominator + "] " + computedValue); // End Project node treatment } // Get a (possible) suggestion for the tree node Multimap<?, ?> suggestions = getSuggestionForNode(projectTreeNode); //TODO: take all the suggestions into account Object[] types = suggestions.keys().toArray(); Object[] suggestionsValues = suggestions.values().toArray(); if (types.length > 0) { // for now use the first item as suggestion SuggestionType stype = (SuggestionType) types[0]; projectTreeNode.setSuggestionType(stype); if (suggestionsValues[0] != null && !suggestionsValues[0].equals("")) { projectTreeNode.setSuggestionValue((String) suggestionsValues[0]); } } treeNodeService.update(projectTreeNode); } catch (NamingException e) { e.printStackTrace(); } // Iterate the node children TreeNode nodeChild = projectTreeNode.getParent(); UQasarUtil.postorderWithParticularNode(projectTreeNode, nodeChild); return; }
From source file:org.nuxeo.ecm.platform.importer.base.TxHelper.java
protected UserTransaction createUT(Integer transactionTimeout) { InitialContext context = null; try {//from w w w . j a v a 2s. co m context = new InitialContext(); } catch (Exception e) { disabled = true; return null; } UserTransaction ut = null; try { ut = (UserTransaction) context.lookup(UT_NAME); } catch (NamingException ne) { try { ut = (UserTransaction) context.lookup(UT_NAME_ALT); } catch (NamingException ne2) { disabled = true; } } if (transactionTimeout != null && ut != null) { try { ut.setTransactionTimeout(transactionTimeout); } catch (SystemException e) { log.error("Error while setting transaction timeout to " + transactionTimeout, e); } } return ut; }