@Override public void markAsDirtyRecursive() { markAsDirty(); for (ClientConnector connector : getAllChildrenIterable(this)) { connector.markAsDirtyRecursive(); } }
/** * {@inheritDoc} * * <p>The {@link #getSession()} and {@link #getUI()} methods might return <code>null</code> after * this method is called. */ @Override public void detach() { for (ClientConnector connector : getAllChildrenIterable(this)) { connector.detach(); } fireEvent(new DetachEvent(this)); getUI().getConnectorTracker().unregisterConnector(this); }
/** * Finds a UI ancestor of this connector. <code>null</code> is returned if no UI ancestor is found * (typically because the connector is not attached to a proper hierarchy). * * @return the UI ancestor of this connector, or <code>null</code> if none is found. */ @Override public UI getUI() { ClientConnector connector = this; while (connector != null) { if (connector instanceof UI) { return (UI) connector; } connector = connector.getParent(); } return null; }
@Override public void attach() { markAsDirty(); getUI().getConnectorTracker().registerConnector(this); fireEvent(new AttachEvent(this)); for (ClientConnector connector : getAllChildrenIterable(this)) { connector.attach(); } }
/** * Method for finding the error handler for the given connector. Uses connector hierarchy to find * a connector with an error handler. Falls back to the VaadinSession error handler if no * connector has specified an error handler. * * <p>Returns a {@link DefaultErrorHandler} if no error handler was found * * @param connector The target connector * @return An ErrorHandler for the connector */ public static ErrorHandler findErrorHandler(ClientConnector connector) { if (connector != null) { ErrorHandler errorHandler = connector.getErrorHandler(); if (errorHandler != null) { return errorHandler; } ClientConnector parent = connector.getParent(); if (parent != null) { return findErrorHandler(parent); } /* * Reached UI and found no error handler. Try session which * typically has one. */ UI ui = connector.getUI(); if (ui != null) { errorHandler = findErrorHandler(ui.getSession()); if (errorHandler != null) { return errorHandler; } } } /* * No connector known or the connector is not attached to a session. Try * the current session */ if (VaadinSession.getCurrent() != null) { ErrorHandler errorHandler = VaadinSession.getCurrent().getErrorHandler(); if (errorHandler != null) { return errorHandler; } } /* * We should never really get here as at least the session should have * an error handler. If for some reason it does not we use the default * error handler. */ return new DefaultErrorHandler(); }
/** * Get an Iterable for iterating over all child connectors, including both extensions and child * components. * * @param connector the connector to get children for * @return an Iterable giving all child connectors. */ public static Iterable<? extends ClientConnector> getAllChildrenIterable( final ClientConnector connector) { Collection<Extension> extensions = connector.getExtensions(); boolean hasComponents = connector instanceof HasComponents; boolean hasExtensions = extensions.size() > 0; if (!hasComponents && !hasExtensions) { // If has neither component nor extensions, return immutable empty // list as iterable. return Collections.emptyList(); } if (hasComponents && !hasExtensions) { // only components return (HasComponents) connector; } if (!hasComponents && hasExtensions) { // only extensions return extensions; } // combine the iterators of extensions and components to a new iterable. final Iterator<Component> componentsIterator = ((HasComponents) connector).iterator(); final Iterator<Extension> extensionsIterator = extensions.iterator(); Iterable<? extends ClientConnector> combinedIterable = new Iterable<ClientConnector>() { @Override public Iterator<ClientConnector> iterator() { return new Iterator<ClientConnector>() { @Override public boolean hasNext() { return componentsIterator.hasNext() || extensionsIterator.hasNext(); } @Override public ClientConnector next() { if (componentsIterator.hasNext()) { return componentsIterator.next(); } if (extensionsIterator.hasNext()) { return extensionsIterator.next(); } throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; return combinedIterable; }
@Override public void run() { try { echoSocket = new Socket(succursaleIPAdresse, portNumber); messageSender = new ObjectOutputStream(echoSocket.getOutputStream()); messageReader = new ObjectInputStream(echoSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("Hote inconnu: " + succursaleIPAdresse); System.exit(1); } catch (IOException e) { System.err.println("Ne pas se connecter au serveur: " + succursaleIPAdresse); System.exit(1); } try { messageSender.writeObject(new ClientDispatchRequest()); } catch (IOException e) { e.printStackTrace(); } System.out.println("Le client vient de se connecter"); try { Message messageReceived = (Message) messageReader.readObject(); System.out.println("message de type " + messageReceived); if (ClientDispatchAnswer.class.isInstance(messageReceived)) { ClientDispatchAnswer msg = (ClientDispatchAnswer) messageReceived; ServerConnectionThread connector = new ServerConnectionThread(msg.getServerAvailaible()); new Thread(connector).start(); ClientConnector.getInstance().setServerConnectedTo(connector); } } catch (SocketException e) { connectionDestroyed = true; System.out.println("erreur dans la connection"); try { messageSender.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); System.out.println("erreur dans l'objet"); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
/** * Gets a global URI for a resource if it's registered with this handler. * * @param connector the connector for which the uri should be generated. * @param resource the resource for which the uri should be generated. * @return an URI string, or <code>null</code> if the resource is not registered. */ public String getUri(ClientConnector connector, ConnectorResource resource) { // app://APP/global/[ui]/[type]/[id] String uri = legacyResourceKeys.get(resource); if (uri != null && !uri.isEmpty()) { return ApplicationConstants.APP_PROTOCOL_PREFIX + ApplicationConstants.APP_PATH + '/' + RESOURCE_REQUEST_PATH + connector.getUI().getUIId() + '/' + uri; } else { return null; } }