List of usage examples for org.apache.commons.lang.mutable MutableObject setValue
public void setValue(Object value)
From source file:mitm.application.djigzo.james.mailets.SenderDKIMSign.java
protected void onHandleUserEvent(User user, MutableObject pemKeyPairHolder) throws MessagingException { try {/*from w w w . j a v a 2s . com*/ pemKeyPairHolder.setValue(user.getUserPreferences().getProperties().getProperty(keyProperty, false)); } catch (HierarchicalPropertiesException e) { throw new MessagingException("Error reading DKIM key pair.", e); } }
From source file:fr.inria.eventcloud.pubsub.PublishSubscribeUtils.java
/** * Rewrites the specified {@code subscription} (written by using a SPARQL * Select query) to a new one where all the result vars have been removed * except for the graph variable.//from ww w . j a va 2 s. c o m * * @param subscription * the subscription to rewrite. * * @return new subscription where all the result vars have been removed * except for the graph variable. */ public static final String removeResultVarsExceptGraphVar(String subscription) { Query query = QueryFactory.create(subscription); final MutableObject graphNode = new MutableObject(); ElementWalker.walk(query.getQueryPattern(), new ElementVisitorBase() { @Override public void visit(ElementNamedGraph el) { if (!el.getGraphNameNode().isVariable()) { throw new IllegalArgumentException( "The specified subscription does not have a graph variable: " + el.getGraphNameNode()); } graphNode.setValue(el.getGraphNameNode()); } }); Op op = Transformer.transform(new TransformBase() { @Override public Op transform(OpProject opProject, Op subOp) { return new OpProject(subOp, Lists.newArrayList((Var) graphNode.getValue())); } }, Algebra.compile(query)); return OpAsQuery.asQuery(op).toString(); }
From source file:mitm.djigzo.web.components.QuarantineManager.java
public Link getViewMIMELink() { final MutableObject mutableLink = new MutableObject(); ComponentEventCallback<Link> callback = new ComponentEventCallback<Link>() { @Override// w w w .j a v a 2s. c o m public boolean handleResult(Link link) { mutableLink.setValue(link); return true; } }; resources.triggerEvent(VIEW_MIME_CLICKED_EVENT, new Object[] { mailRepositoryItem.getId() }, callback); return (Link) mutableLink.getValue(); }
From source file:mitm.application.djigzo.james.mailets.BlackberrySMIMEAdapter.java
private Part findAttachment(MimeMessage containerMessage) throws MessagingException, IOException, PartException { final MutableObject smimePart = new MutableObject(); final MutableObject octetPart = new MutableObject(); PartListener partListener = new PartScanner.PartListener() { @Override/*from ww w . jav a 2s . c o m*/ public boolean onPart(Part parent, Part part, Object context) throws PartException { try { if (ArrayUtils.contains(part.getHeader(DjigzoHeader.MARKER), DjigzoHeader.ATTACHMENT_MARKER_VALUE)) { smimePart.setValue(part); /* * we found the part with the marker so we can stop scanning */ return false; } /* * Fallback scanning for octet-stream in case the template does not contain a DjigzoHeader.MARKER */ if (part.isMimeType("application/octet-stream")) { octetPart.setValue(part); } return true; } catch (MessagingException e) { throw new PartException(e); } } }; PartScanner partScanner = new PartScanner(partListener, MAX_DEPTH); partScanner.scanPart(containerMessage); Part result = (Part) smimePart.getValue(); if (result == null) { result = (Part) octetPart.getValue(); if (result != null) { logger.debug("Marker not found. Using octet-stream instead."); } else { throw new MessagingException("Unable to find the attachment part in the template."); } } return result; }
From source file:com.ms.commons.test.tool.ExportDatabaseData.java
private static String getSqlTableName(String sql, final Map<String, Integer> tableMap, final MutableObject refTableName) { CCJSqlParserManager sqlPaerserManager = new CCJSqlParserManager(); try {//from ww w . java 2s . co m Statement statement = sqlPaerserManager.parse(new StringReader(sql)); final MutableObject refTable = new MutableObject(null); statement.accept(new StatementVisitor() { public void visit(CreateTable createTable) { throw new MessageException("Cannot parser sql for: " + createTable.getClass().getSimpleName()); } public void visit(Truncate truncate) { throw new MessageException("Cannot parser sql for: " + truncate.getClass().getSimpleName()); } public void visit(Drop drop) { throw new MessageException("Cannot parser sql for: " + drop.getClass().getSimpleName()); } public void visit(Replace replace) { throw new MessageException("Cannot parser sql for: " + replace.getClass().getSimpleName()); } public void visit(Insert insert) { throw new MessageException("Cannot parser sql for: " + insert.getClass().getSimpleName()); } public void visit(Update update) { throw new MessageException("Cannot parser sql for: " + update.getClass().getSimpleName()); } public void visit(Delete delete) { throw new MessageException("Cannot parser sql for: " + delete.getClass().getSimpleName()); } public void visit(Select select) { select.getSelectBody().accept(new SelectVisitor() { public void visit(Union union) { refTable.setValue("table_" + GLOBAL_COUNT.getAndIncrement()); } public void visit(PlainSelect plainSelect) { plainSelect.getFromItem().accept(new FromItemVisitor() { public void visit(SubJoin subjoin) { refTable.setValue("table_" + GLOBAL_COUNT.getAndIncrement()); } public void visit(SubSelect subSelect) { refTable.setValue("table_" + GLOBAL_COUNT.getAndIncrement()); } public void visit(Table tableName) { String tn = tableName.getName().trim().toLowerCase(); refTableName.setValue(tn); Integer tnCount = tableMap.get(tn); if (tnCount == null) { tableMap.put(tn, Integer.valueOf(1)); refTable.setValue(tn); } else { tnCount = Integer.valueOf(tnCount.intValue() + 1); tableMap.put(tn, tnCount); refTable.setValue(tn + "_" + tnCount.intValue()); } } }); } }); } }); if (refTable.getValue() == null) { throw new MessageException("Canot parser sql and get table name."); } return (String) refTable.getValue(); } catch (Exception e) { throw ExceptionUtil.wrapToRuntimeException(e); } }
From source file:com.cognifide.actions.core.internal.ActionEventHandler.java
@Override public boolean process(Event job) { final String path = (String) job.getProperty(SlingConstants.PROPERTY_PATH); Boolean result = true;//from w w w. j a v a 2s . co m final MutableObject actionNameObject = new MutableObject(); try { executor.execute(new JcrCommand() { @Override public void run(Session session, ResourceResolver resolver) throws Exception { PageManager pm = resolver.adaptTo(PageManager.class); Page page = pm.getPage(path); String actionType = null; if (page != null && page.getContentResource() != null) { actionType = page.getContentResource().getResourceType(); } if (actionType != null) { LOG.debug("Incoming action: " + actionType); Action action = actionRegistry.getAction(actionType); if (action != null) { LOG.debug("Performing action: " + actionType); actionNameObject.setValue(actionType); action.perform(page); LOG.debug("Action " + actionType + " finished"); } else { LOG.info("No action found for: " + actionType); } } } }); } catch (Exception ex) { result = false; LOG.error(ex.getMessage(), ex); } if (actionNameObject.getValue() != null) { LOG.info(String.format("Action %s succeeded", actionNameObject.getValue())); } return result; }
From source file:com.ritesh.idea.plugin.state.SettingsPage.java
private void testConnection() { final MutableObject connException = new MutableObject(); if (StringUtils.isEmpty(loginPanel.getUrl()) || StringUtils.isEmpty(loginPanel.getUsername()) || StringUtils.isEmpty(loginPanel.getPassword())) { Messages.showErrorDialog(project, "Connection information provided is invalid.", "Invalid Settings"); return;/* www. j av a 2s. c o m*/ } TaskUtil.queueTask(project, PluginBundle.message(PluginBundle.CONNECTION_TEST_TITLE), true, new ThrowableFunction<ProgressIndicator, Void>() { @Override public Void throwableCall(ProgressIndicator params) throws Exception { try { params.setIndeterminate(true); ReviewDataProvider.getInstance(project).testConnection(loginPanel.getUrl(), loginPanel.getUsername(), loginPanel.getPassword()); // The task was not cancelled and is successful connException.setValue(Boolean.TRUE); } catch (InvalidConfigurationException a) { } catch (final Exception exception) { connException.setValue(exception); } return null; } }, null, null); if (connException.getValue() == Boolean.TRUE) { Messages.showInfoMessage(project, PluginBundle.message(PluginBundle.LOGIN_SUCCESS_MESSAGE), PluginBundle.message(PluginBundle.CONNECTION_STATUS_TITLE)); } else if (connException.getValue() instanceof Exception) { final ExceptionHandler.Message message = ExceptionHandler .getMessage((Exception) connException.getValue()); Messages.showErrorDialog(message.message, PluginBundle.message(PluginBundle.CONNECTION_STATUS_TITLE)); } }
From source file:mitm.application.djigzo.james.mailets.Relay.java
private void handleMessageAction(Session session, Mail sourceMail, MimeMessage relayMessage) throws DatabaseException { final MutableObject userInfoContainer = new MutableObject(); RelayUserInfoProvider infoProvider = new RelayUserInfoProvider() { @Override/*w w w.j av a 2 s . c o m*/ public RelayUserInfo getRelayUserInfo(MimeMessage message) throws MessagingException, RelayException { RelayUserInfo userInfo = null; InternetAddress originator = messageOriginatorIdentifier.getOriginator(message); if (originator != null) { String userEmail = originator.getAddress(); logger.debug("Getting relay info for " + userEmail); userEmail = EmailAddressUtils.canonicalizeAndValidate(userEmail, false); try { User user = userWorkflow.getUser(userEmail, UserWorkflow.GetUserMode.CREATE_IF_NOT_EXIST); userInfo = createRelayUserInfo(user); /* * Save the userInfo because we need it later on */ userInfoContainer.setValue(userInfo); } catch (HierarchicalPropertiesException e) { throw new RelayException(e); } } return userInfo; } }; RelayHandler handler = new RelayHandler(pKISecurityServices, infoProvider); if (preventReplay) { handler.setAdditionalRelayValidator(relayValidator); } try { MimeMessage messageToRelay = handler.handleRelayMessage(relayMessage); if (messageToRelay != null) { sendRelayMessage(sourceMail, messageToRelay, handler.getRecipients()); /* * ghost the source mail if not passThrough */ if (!passThrough) { sourceMail.setState(Mail.GHOST); } } } catch (RelayException e) { handleBlackBerryRelayException(e, (RelayUserInfo) userInfoContainer.getValue(), sourceMail); } catch (MessagingException e) { throw new DatabaseException(e); } catch (IOException e) { throw new DatabaseException(e); } }
From source file:nl.strohalm.cyclos.services.elements.MessageServiceImpl.java
/** * This methods runs a new transaction for handling the sms status, charging, etc... Then, the log is always persisted in another transaction * (with a {@link TransactionEndListener}). So, even if the sending fails, the log is persisted */// w w w. j ava2s . co m @Override public SmsLog sendSms(final SendSmsDTO params) { final MutableObject result = new MutableObject(); transactionHelper.runInNewTransaction(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { // The returned log is transient... SmsLog log; try { log = doSendSms(params); } catch (LockingException e) { throw e; } catch (Exception e) { LOG.error("Unknown error sending sms", e); log = newSmsLog(params, ErrorType.SEND_ERROR, false); } if (log.getErrorType() != null) { status.setRollbackOnly(); } // ... we can only actually persist it after this transaction ends, because we don't know if it will be committed final SmsLog toSave = log; CurrentTransactionData.addTransactionEndListener(new TransactionEndListener() { @Override protected void onTransactionEnd(final boolean commit) { transactionHelper.runInCurrentThread(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { result.setValue(smsLogService.save(toSave)); } }); } }); } }); return (SmsLog) result.getValue(); }
From source file:nl.strohalm.cyclos.utils.ParallelTask.java
/** * Runs all the given tasks. If any exception occurs, throws it and interrupts other any tasks *///from w ww . ja va 2 s.c om public void run(final Collection<T> tasks) { final CountDownLatch latch = new CountDownLatch(tasks.size()); final MutableObject exception = new MutableObject(); // Use a WorkerThreads to actually run everything final WorkerThreads<T> threads = new WorkerThreads<T>(name, maxParallelThreads, false) { @Override protected void process(final T object) { try { // When some task has already failed, simply skip if (exception.getValue() == null) { ParallelTask.this.process(object); } } catch (final Exception e) { exception.setValue(e); } finally { latch.countDown(); } } }; // Dispatch the tasks threads.enqueueAll(tasks); // Await for all tasks to complete try { latch.await(); } catch (final InterruptedException e) { throw new IllegalStateException(e); } finally { // Interrupt all threads threads.interrupt(); } // Throw the exception, if any final Exception e = (Exception) exception.getValue(); if (e != null) { throw (e instanceof RuntimeException) ? (RuntimeException) e : new IllegalStateException(e); } }