List of usage examples for com.vaadin.ui ConnectorTracker getConnector
public ClientConnector getConnector(String connectorId)
From source file:org.semanticsoft.vaaclipse.app.servlet.VaaclipseServerRpcHandler.java
License:Open Source License
private MethodInvocation parseInvocation(JSONArray invocationJson, MethodInvocation previousInvocation, ConnectorTracker connectorTracker, long lastSyncIdSeenByClient) throws JSONException { String connectorId = invocationJson.getString(0); String interfaceName = invocationJson.getString(1); String methodName = invocationJson.getString(2); if (connectorTracker.getConnector(connectorId) == null && !connectorId.equals(ApplicationConstants.DRAG_AND_DROP_CONNECTOR_ID)) { if (!connectorTracker.connectorWasPresentAsRequestWasSent(connectorId, lastSyncIdSeenByClient)) { getLogger().log(Level.WARNING, "RPC call to " + interfaceName + "." + methodName + " received for connector " + connectorId + " but no such connector could be found. Resynchronizing client."); // This is likely an out of sync issue (client tries to update a // connector which is not present). Force resync. connectorTracker.markAllConnectorsDirty(); }/*from w w w .j a v a2s. co m*/ return null; } JSONArray parametersJson = invocationJson.getJSONArray(3); if (LegacyChangeVariablesInvocation.isLegacyVariableChange(interfaceName, methodName)) { if (!(previousInvocation instanceof LegacyChangeVariablesInvocation)) { previousInvocation = null; } return parseLegacyChangeVariablesInvocation(connectorId, interfaceName, methodName, (LegacyChangeVariablesInvocation) previousInvocation, parametersJson, connectorTracker); } else { return parseServerRpcInvocation(connectorId, interfaceName, methodName, parametersJson, connectorTracker); } }
From source file:org.semanticsoft.vaaclipse.app.servlet.VaaclipseServerRpcHandler.java
License:Open Source License
private ServerRpcMethodInvocation parseServerRpcInvocation(String connectorId, String interfaceName, String methodName, JSONArray parametersJson, ConnectorTracker connectorTracker) throws JSONException { ClientConnector connector = connectorTracker.getConnector(connectorId); ServerRpcManager<?> rpcManager = connector.getRpcManager(interfaceName); if (rpcManager == null) { /*// ww w . ja v a2 s . co m * Security: Don't even decode the json parameters if no RpcManager * corresponding to the received method invocation has been * registered. */ getLogger().warning("Ignoring RPC call to " + interfaceName + "." + methodName + " in connector " + connector.getClass().getName() + "(" + connectorId + ") as no RPC implementation is registered"); return null; } // Use interface from RpcManager instead of loading the class based on // the string name to avoid problems with OSGi Class<? extends ServerRpc> rpcInterface = rpcManager.getRpcInterface(); ServerRpcMethodInvocation invocation = new ServerRpcMethodInvocation(connectorId, rpcInterface, methodName, parametersJson.length()); Object[] parameters = new Object[parametersJson.length()]; Type[] declaredRpcMethodParameterTypes = invocation.getMethod().getGenericParameterTypes(); for (int j = 0; j < parametersJson.length(); ++j) { Object parameterValue = parametersJson.get(j); Type parameterType = declaredRpcMethodParameterTypes[j]; parameters[j] = JsonCodec.decodeInternalOrCustomType(parameterType, parameterValue, connectorTracker); } invocation.setParameters(parameters); return invocation; }
From source file:org.semanticsoft.vaaclipse.app.servlet.VaaclipseServerRpcHandler.java
License:Open Source License
private void handleInvocations(UI uI, int lastSyncIdSeenByClient, JSONArray invocationsData) { // TODO PUSH Refactor so that this is not needed LegacyCommunicationManager manager = uI.getSession().getCommunicationManager(); try {/*from ww w . j av a2s. c om*/ ConnectorTracker connectorTracker = uI.getConnectorTracker(); Set<Connector> enabledConnectors = new HashSet<Connector>(); List<MethodInvocation> invocations = parseInvocations(uI.getConnectorTracker(), invocationsData, lastSyncIdSeenByClient); for (MethodInvocation invocation : invocations) { final ClientConnector connector = connectorTracker.getConnector(invocation.getConnectorId()); if (connector != null && connector.isConnectorEnabled()) { enabledConnectors.add(connector); } } for (int i = 0; i < invocations.size(); i++) { MethodInvocation invocation = invocations.get(i); final ClientConnector connector = connectorTracker.getConnector(invocation.getConnectorId()); if (connector == null) { getLogger().log(Level.WARNING, "Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})", new Object[] { invocation.getConnectorId(), invocation.getInterfaceName(), invocation.getMethodName() }); continue; } if (!enabledConnectors.contains(connector)) { if (invocation instanceof LegacyChangeVariablesInvocation) { LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation; // TODO convert window close to a separate RPC call and // handle above - not a variable change // Handle special case where window-close is called // after the window has been removed from the // application or the application has closed Map<String, Object> changes = legacyInvocation.getVariableChanges(); if (changes.size() == 1 && changes.containsKey("close") && Boolean.TRUE.equals(changes.get("close"))) { // Silently ignore this continue; } } // Connector is disabled, log a warning and move to the next getLogger().warning(getIgnoredDisabledError("RPC call", connector)); continue; } // DragAndDropService has null UI if (connector.getUI() != null && connector.getUI().isClosing()) { String msg = "Ignoring RPC call for connector " + connector.getClass().getName(); if (connector instanceof Component) { String caption = ((Component) connector).getCaption(); if (caption != null) { msg += ", caption=" + caption; } } msg += " in closed UI"; getLogger().warning(msg); continue; } if (invocation instanceof ServerRpcMethodInvocation) { try { ServerRpcManager.applyInvocation(connector, (ServerRpcMethodInvocation) invocation); } catch (RpcInvocationException e) { manager.handleConnectorRelatedException(connector, e); } } else { // All code below is for legacy variable changes LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation; Map<String, Object> changes = legacyInvocation.getVariableChanges(); try { if (connector instanceof VariableOwner) { // The source parameter is never used anywhere changeVariables(null, (VariableOwner) connector, changes); executorService.exec(); } else { throw new IllegalStateException("Received legacy variable change for " + connector.getClass().getName() + " (" + connector.getConnectorId() + ") which is not a VariableOwner. The client-side connector sent these legacy varaibles: " + changes.keySet()); } } catch (Exception e) { manager.handleConnectorRelatedException(connector, e); } } } } catch (JSONException e) { getLogger().warning("Unable to parse RPC call from the client: " + e.getMessage()); throw new RuntimeException(e); } }