@Override protected IStatus runStatus(IProgressMonitor monitor) { IPingService pingService = SERVICES.getService(IPingService.class); try { // side-effect of every service call (whether ping or any other) is to get // client notifications pingService.ping("GetClientNotifications"); } catch (Throwable t) { if (LOG.isInfoEnabled()) { LOG.info("polling", t); } } if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } else { // re-schedule long netLatency = 0L; IPerformanceAnalyzerService perf = SERVICES.getService(IPerformanceAnalyzerService.class); if (perf != null) { netLatency = perf.getNetworkLatency(); } long sleepInterval = m_analyzeNetworkLatency ? Math.max(m_pollInterval, 10 * netLatency) : m_pollInterval; schedule(sleepInterval); return Status.OK_STATUS; } }
/** * sets permission collection that is associated with the current subject * * @param p permission collection */ public void setPermissionsOfCurrentSubject(Permissions p) { String userId = SERVICES.getService(IAccessControlService.class).getUserIdOfCurrentSubject(); if (userId == null) { throw new SecurityException("userId is null"); } setPermissions(userId, p); }
/** @return the permission collection that is associated with the current subject */ public Permissions getPermissionsOfCurrentSubject() { String userId = SERVICES.getService(IAccessControlService.class).getUserIdOfCurrentSubject(); if (userId == null) { return null; } return getPermissions(userId); }
@Override protected void execAction() throws ProcessingException { for (ITableRow row : getSelectedRows()) { File file = (File) row.getKeyValues().get(0); SERVICES.getService(IShellService.class).shellOpen(file.getPath()); } }
@Override protected void initConfig() { m_uiFacade = new P_UIFacade(); Class<? extends IGroupBoxBodyGrid> bodyGridClazz = getConfiguredBodyGrid(); if (bodyGridClazz != null) { IGroupBoxBodyGrid bodyGrid; try { bodyGrid = bodyGridClazz.newInstance(); setBodyGrid(bodyGrid); } catch (Exception e) { SERVICES .getService(IExceptionHandlerService.class) .handleException( new ProcessingException( "error creating instance of class '" + bodyGridClazz.getName() + "'.", e)); } } m_customProcessButtonGrid = new GroupBoxProcessButtonGrid(this, true, false); m_systemProcessButtonGrid = new GroupBoxProcessButtonGrid(this, false, true); super.initConfig(); categorizeFields(); setExpandable(getConfiguredExpandable()); setExpanded(getConfiguredExpanded()); setBorderVisible(getConfiguredBorderVisible()); setBorderDecoration(getConfiguredBorderDecoration()); setGridColumnCountHint(getConfiguredGridColumnCount()); setBackgroundImageName(getConfiguredBackgroundImageName()); setBackgroundImageHorizontalAlignment(getConfiguredBackgroundImageHorizontalAlignment()); setBackgroundImageVerticalAlignment(getConfiguredBackgroundImageVerticalAlignment()); setScrollable(getConfiguredScrollable()); }
/** * Applies move descriptors registered on {@link IExtensionRegistry#registerMove(Class, double)} * to all objects of the given list. * * <p><b>Important</b>: The given {@link Iterable} is not sorted by this method. */ public static void moveModelObjects(Iterable<? extends IOrdered> modelObjects) { IInternalExtensionRegistry extensionRegistry = SERVICES.getService(IInternalExtensionRegistry.class); for (IOrdered m : modelObjects) { MoveDescriptor<IOrdered> moveDesc = extensionRegistry.createModelMoveDescriptorFor(m, null); if (moveDesc != null && moveDesc.getNewOrder() != null) { m.setOrder(moveDesc.getNewOrder()); } } }
@Override public File getRemoteFile(String dir, String simpleName, Locale locale, boolean checkCache) throws ProcessingException { RemoteFile spec = null; File f = null; if (locale != null && simpleName != null && simpleName.lastIndexOf(".") != -1) { String filename = simpleName; String language = locale.toString().replaceAll("__", "_"); String prefix = filename.substring(0, filename.lastIndexOf(".")) + "_"; String suffix = filename.substring(filename.lastIndexOf(".")); filename = prefix + language + suffix; File test = getFileLocation(dir, filename, false); while (!test.exists()) { if (language.indexOf("_") == -1) { filename = simpleName; break; } language = language.substring(0, language.lastIndexOf("_")); filename = prefix + language + suffix; test = getFileLocation(dir, filename, false); } f = getFileLocation(dir, filename, false); spec = new RemoteFile(dir, filename, locale, 0L); } else { f = getFileLocation(dir, simpleName, false); spec = new RemoteFile(dir, simpleName, locale, 0L); } if (f.exists()) { spec.setLastModified(f.lastModified()); } // if (checkCache && OfflineState.isOnlineInCurrentThread()) { IRemoteFileService svc = SERVICES.getService(IRemoteFileService.class); spec = svc.getRemoteFile(spec); try { if (spec.getName() != null && !spec.getName().equalsIgnoreCase(f.getName())) { if (locale != null && f.getName().length() > spec.getName().length()) { // if local file has longer name (including locale), this means that // this file was deleted on the server f.delete(); } f = getFileLocation(spec.getDirectory(), spec.getName(), false); } if (spec.exists() && spec.hasContent()) { spec.writeData(new FileOutputStream(f)); f.setLastModified(spec.getLastModified()); } else if (!spec.exists()) { f.delete(); } } catch (IOException e) { throw new ProcessingException("error writing remote file in local store", e); } } return f; }
@Override public List<ILookupRow<T>> getDataByText(ILookupCall<T> call) throws ProcessingException { // change wildcards * in text to db specific wildcards if (call.getText() != null) { String s = call.getText(); String sqlWildcard = SERVICES.getService(ISqlService.class).getSqlStyle().getLikeWildcard(); call.setText(s.replaceAll("[*]", sqlWildcard)); } String sql = getConfiguredSqlSelect(); return execLoadLookupRows(sql, filterSqlByText(sql), call); }
@Override protected void execInitField() throws ProcessingException { // Table already is scrollable, it's not necessary to make the form scrollable too IDeviceTransformationService service = SERVICES.getService(IDeviceTransformationService.class); if (service != null && service.getDeviceTransformer() != null) { service .getDeviceTransformer() .getDeviceTransformationConfig() .excludeFieldTransformation(this, MobileDeviceTransformation.MAKE_MAINBOX_SCROLLABLE); } }
@Override protected List<ILookupRow<String>> execCreateLookupRows() throws ProcessingException { TreeMap<String, ILookupRow<String>> sortMap = new TreeMap<String, ILookupRow<String>>(); ISpellCheckerService sc = SERVICES.getService(ISpellCheckerService.class); if (sc != null) { for (String lang : sc.getAvailableLanguages()) { Locale loc = NlsUtility.parseLocale(lang); sortMap.put( lang, new LookupRow<String>( lang, loc.getDisplayLanguage() + " (" + loc.getDisplayCountry() + ")")); } } return new ArrayList<ILookupRow<String>>(sortMap.values()); }
protected void setStatusImpl(long userId, int status) throws ProcessingException { int oldStatus = 0; synchronized (m_usersLock) { oldStatus = IUserActivityStateService.STATUS_OFFLINE; Integer oldStatInt = m_users.get(userId); if (oldStatInt != null) { oldStatus = m_users.get(userId); } m_users.put(userId, status); if (oldStatus != status) { UserStatusMap map = getUserStatusMap(); SERVICES .getService(IClientNotificationService.class) .putNotification(new UserActivityClientNotification(map), new AllUserFilter(120000L)); } } }
@Override protected void initConfig() { m_uiFacade = new P_UIFacade(); super.initConfig(); setImageTransform(new AffineTransformSpec()); setAutoFit(getConfiguredAutoFit()); setImageId(getConfiguredImageId()); setPanDelta(getConfiguredPanDelta()); setRotateDelta(getConfiguredRotateDelta()); setZoomDelta(getConfiguredZoomDelta()); setDragType(getConfiguredDragType()); setDropType(getConfiguredDropType()); setScrollBarEnabled(getConfiguredScrollBarEnabled()); // menus List<Class<? extends IMenu>> declaredMenus = getDeclaredMenus(); List<IMenu> contributedMenus = m_contributionHolder.getContributionsByClass(IMenu.class); OrderedCollection<IMenu> menus = new OrderedCollection<IMenu>(); for (Class<? extends IMenu> menuClazz : declaredMenus) { try { menus.addOrdered(ConfigurationUtility.newInnerInstance(this, menuClazz)); } catch (Exception e) { SERVICES .getService(IExceptionHandlerService.class) .handleException( new ProcessingException( "error creating instance of class '" + menuClazz.getName() + "'.", e)); } } menus.addAllOrdered(contributedMenus); try { injectMenusInternal(menus); } catch (Exception e) { LOG.error("error occured while dynamically contributing menus.", e); } new MoveActionNodesHandler<IMenu>(menus).moveModelObjects(); m_contextMenu = new FormFieldContextMenu<IImageField>(this, menus.getOrderedList()); m_contextMenu.setContainerInternal(this); }
protected void load() { if (m_session == null || ClientSessionThreadLocal.get() == m_session) { m_env = SERVICES.getService(IUserPreferencesStorageService.class).loadPreferences(); } else { ClientAsyncJob job = new ClientAsyncJob("Load user preferences", m_session) { @Override protected void runVoid(IProgressMonitor monitor) throws Throwable { m_env = SERVICES.getService(IUserPreferencesStorageService.class).loadPreferences(); } }; job.schedule(); try { job.join(); } catch (InterruptedException e) { // nop } } if (m_env == null) { throw new IllegalStateException("Could not load preferences in client job"); } }
@Override protected List<Part> createPartsList(LookupCall call) { return SERVICES.getService(IMinifigDataStoreService.class).getAvailableTorsos(); }
@Override public Object invoke(final Packet packet, final Method method, final Object... aobj) throws InvocationTargetException, IllegalAccessException { final T portType = ScoutInstanceResolver.this.resolve(packet); if (portType == null) { throw new WebServiceException("No port type found"); } Subject subject = null; try { subject = Subject.getSubject(AccessController.getContext()); } catch (Exception e) { LOG.error("Failed to get subject of calling access context", e); } if (subject == null) { throw new WebServiceException( "Webservice request was NOT dispatched due to security reasons: request must run on behalf of a subject context."); } IServerSession session = getSession(m_context.getMessageContext()); if (session == null) { LOG.warn( "Webservice request is not run in a session context as no server session is configured."); return method.invoke(portType, aobj); } try { final ObjectHolder resultHolder = new ObjectHolder(); final Holder<InvocationTargetException> invocationTargetExceptionHolder = new Holder<InvocationTargetException>(InvocationTargetException.class); final Holder<IllegalAccessException> illegalAccessExceptionHolder = new Holder<IllegalAccessException>(IllegalAccessException.class); final Holder<RuntimeException> runtimeExceptionHolder = new Holder<RuntimeException>(RuntimeException.class); // run server job final IServerJobFactory jobFactory = SERVICES.getService(IServerJobService.class).createJobFactory(session, subject); ServerJob serverJob = jobFactory.create( "Tx", new ITransactionRunnable() { @Override public IStatus run(IProgressMonitor monitor) throws ProcessingException { try { resultHolder.setValue(method.invoke(portType, aobj)); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); ThreadContext.getTransaction().addFailure(cause); // rollback transaction if (cause instanceof RuntimeException) { LOG.warn( "Webservice processing exception occured. Please handle faults by respective checked SOAP faults.", cause); invocationTargetExceptionHolder.setValue( new InvocationTargetException( new WebServiceException("Internal Server Error"))); } else { // business exception (SOAP faults are checked exceptions) LOG.info("Webservice processing exception occured.", cause); invocationTargetExceptionHolder.setValue(e); } } catch (IllegalAccessException e) { ThreadContext.getTransaction().addFailure(e); // rollback transaction LOG.error( "Illegal access exception occured while dispatching webservice request. This might be caused because of Java security settings.", e); illegalAccessExceptionHolder.setValue(e); } catch (RuntimeException e) { ThreadContext.getTransaction().addFailure(e); // rollback transaction LOG.error( "Unexpected error occured while dispatching webservice request.", e); runtimeExceptionHolder.setValue(e); } return Status.OK_STATUS; } }); serverJob.setSystem(true); serverJob.runNow(new NullProgressMonitor()); if (invocationTargetExceptionHolder.getValue() != null) { throw invocationTargetExceptionHolder.getValue(); } if (illegalAccessExceptionHolder.getValue() != null) { throw illegalAccessExceptionHolder.getValue(); } if (runtimeExceptionHolder.getValue() != null) { throw runtimeExceptionHolder.getValue(); } return resultHolder.getValue(); } finally { postInvoke(packet, portType); } }
private void syncRemoteFilesInternal( String serverFolderPath, FilenameFilter filter, boolean useServerFolderStructureOnClient) throws ProcessingException { IRemoteFileService svc = SERVICES.getService(IRemoteFileService.class); String[][] realFiles = getFiles(serverFolderPath, filter, useServerFolderStructureOnClient); RemoteFile[] existingFileInfoOnClient = new RemoteFile[realFiles.length]; for (int i = 0; i < realFiles.length; i++) { RemoteFile rf = new RemoteFile(realFiles[i][0], realFiles[i][1], 0); String dir = m_rootPath == null ? realFiles[i][0] : ""; File f = getFileLocation(dir, realFiles[i][1], false); if (f.exists()) { rf.setLastModified(f.lastModified()); } existingFileInfoOnClient[i] = rf; } existingFileInfoOnClient = svc.getRemoteFiles(serverFolderPath, filter, existingFileInfoOnClient); for (RemoteFile spec : existingFileInfoOnClient) { String fileDirectory = useServerFolderStructureOnClient ? spec.getDirectory() : null; File f = getFileLocation(fileDirectory, spec.getName(), false); if (spec.exists() && spec.hasContent()) { try { if (spec.hasMoreParts()) { // file is splitted - get all parts int counter = 0; long fileDate = spec.getLastModified(); File part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false); spec.writeData(new FileOutputStream(part)); part.setLastModified(fileDate); RemoteFile specPart = spec; while (specPart.hasMoreParts()) { counter++; part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false); if (!part.exists() || fileDate != part.lastModified()) { specPart = svc.getRemoteFilePart(spec, counter); specPart.writeData(new FileOutputStream(part)); part.setLastModified(fileDate); } else { // resuming canceled part: nothing to do } } // put together counter = 0; f = getFileLocation(fileDirectory, spec.getName(), false); OutputStream out = new FileOutputStream(f); part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false); while (part.exists()) { InputStream in = new FileInputStream(part); byte[] buf = new byte[102400]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); in.close(); part.delete(); counter++; part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false); } out.close(); f.setLastModified(fileDate); } else { // normal files spec.writeData(new FileOutputStream(f)); f.setLastModified(spec.getLastModified()); } } catch (IOException e) { throw new ProcessingException("error writing remote file in local store", e); } } else if (!spec.exists()) { f.delete(); } } }