?? message.java
字號(hào):
Iterator allLineage = getMessageLineage(); while( allLineage.hasNext() ) { toString.append( allLineage.next().toString() ); if( allLineage.hasNext() ) { toString.append( ',' ); } } toString.append( '}' ); if( GLOBAL_TRACKING_ELEMENT ) { toString.append( "[" ); Iterator eachUUID = getMessageElements( "jxta", "Tracking UUID" ); while( eachUUID.hasNext() ) { toString.append( "[" ); toString.append( eachUUID.next().toString() ); toString.append( "]" ); if( eachUUID.hasNext() ) { toString.append( ',' ); } } toString.append( "]" ); } return toString.toString(); } /** * Read this Object in for Java Serialization * * @param s The stream from which the Object will be read. * @throws IOException for errors reading from the input stream. * @throws ClassNotFoundException if the serialized representation contains * references to classes which cannot be found. **/ private void readObject( ObjectInputStream s ) throws IOException, ClassNotFoundException { // reads defaultNamespace, modifiable flag s.defaultReadObject(); MimeMediaType readType = new MimeMediaType( s.readUTF() ); // XXX bondolo 20040307 Should do something with encoding here. Message readMessage = WireFormatMessageFactory.fromWire( s, readType, null ); namespaces = readMessage.namespaces; elements = readMessage.elements; if( elements.contains( defaultNamespace ) ) { throw new IOException( "Corrupted Object--does not contain required namespace." ); } properties = new HashMap(); lineage = new ArrayList(); lineage.add( new Integer( getNextMessageNumber() ) ); if ( LOG_MODIFICATIONS ) { modHistory = new ArrayList(); incMessageModCount(); } } /** * Write this Object out for Java Serialization * * @param s The stream to which the Object will be written. * @throws IOException for errors writing to the output stream. **/ private void writeObject( ObjectOutputStream s ) throws IOException { s.defaultWriteObject(); MimeMediaType writeType = WireFormatMessageFactory.DEFAULT_WIRE_MIME; s.writeUTF( writeType.toString() ); // XXX bondolo 20040307 Should do something with encoding here. WireFormatMessage serialed = WireFormatMessageFactory.toWire( this, writeType, null ); serialed.sendToStream( s ); } /** * Return the default Namespace of this message. * * @return The default namespace for this message. **/ protected String getDefaultNamespace() { return defaultNamespace; } /** * Add a MessageElement into the message. The MessageElement is stored in * the default namespace. * * @param add the Element to add to the message. **/ public void addMessageElement( MessageElement add ) { addMessageElement( null, add ); } /** * Add a MessageElement into the message using the specified namespace. * * @param namespace contains the namespace of the element to add. You can * specify null as a shorthand for the default namespace. * @param add the MessageElement to add to the message. **/ public void addMessageElement( String namespace, MessageElement add ) { if( null == namespace ) { namespace = getDefaultNamespace(); } if( null == add ) { throw new IllegalArgumentException( "Message Element must be non-null" ); } elements.add( new element( namespace, add ) ); List namespaceElements = (List) namespaces.get( namespace ); if( null == namespaceElements ) { namespaceElements = new ArrayList(); namespaces.put( namespace, namespaceElements ); } namespaceElements.add( add ); incMessageModCount(); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Added " + namespace + "::" + add.getElementName() + "/" + add.getClass().getName() + "@" + add.hashCode() + " to " + this ); } } /** * Replace a {@link net.jxta.endpoint.MessageElement} in the message. This method will remove * all MessageElement instances in the default namespace which match the * specified name (if any) and then insert the replacement element. The * existing version of the element is returned, if more than one matching * element was removed, a random matching element is returned. * * <p/>For greatest control over element replacement, use the * {@link java.util.ListIterator#set(java.lang.Object)} method as returned * by {@link #getMessageElements()}, * {@link #getMessageElements(java.lang.String)} or * {@link #getMessageElementsOfNamespace(java.lang.String)} * * @param replacement the Element to be inserted into to the message. * @return One of the elements which was replaced or null if no existing * matching item was located. **/ public MessageElement replaceMessageElement( MessageElement replacement ) { return replaceMessageElement( null, replacement ); } /** * Replace a {@link net.jxta.endpoint.MessageElement} in the message using the specified * namespace. This method will remove all MessageElement instances which * match the specified name (if any) and then insert the replacement * element. The existing version of the element is returned, if more than * one matching element was removed, a random matching element is returned. * * <p/>For greatest control over element replacement, use the * {@link java.util.ListIterator#set(java.lang.Object)} method as returned * by {@link #getMessageElements()}, * {@link #getMessageElements(java.lang.String)} or * {@link #getMessageElementsOfNamespace(java.lang.String)} * * @param namespace contains the namespace of the element to be replaced. * You can specify null as a shorthand for the default namespace. * @param replacement the Element to be inserted into to the message. * @return One of the elements which was replaced or null if no existing * matching item was located. **/ public MessageElement replaceMessageElement( String namespace, MessageElement replacement ) { if( null == namespace ) { namespace = getDefaultNamespace(); } if( null == replacement ) { throw new IllegalArgumentException( "Message Element must be non-null" ); } MessageElement removed = null; Iterator allMatching = getMessageElements( namespace, replacement.getElementName() ); while( allMatching.hasNext() ) { MessageElement anElement = (MessageElement) allMatching.next(); allMatching.remove(); removed = anElement; } addMessageElement( namespace, replacement ); // updates mod count return removed; } /** * Returns an iterator of the namespaces present in this message. All of the * elements will be Strings. * * @return iterator of strings of the namespaces of this message. **/ public Iterator getMessageNamespaces( ) { return Collections.unmodifiableMap(namespaces).keySet().iterator(); } /** * Retrieve a element by name from the message without regard to * namespace. If there is more than one element with this name, a random * element will be returned. * * @param name The name of the element to attept to retrieve. * @return Element the element or null if no matching element could be * found. */ public MessageElement getMessageElement( String name ) { Iterator eachElement = elements.listIterator(); while( eachElement.hasNext() ) { element anElement = (element) eachElement.next(); if( name.equals( anElement.element.getElementName() ) ) { return anElement.element; } } return null; } /** * Retrieve a element by name in the specified namespace from the message. * If there is more than one element with this name, a random * element will be returned. * * @param namespace contains the namespace of the element to get. You can * specify null as a shorthand for the default namespace. * @param name contains the name of the element to get * @return Element the element. **/ public MessageElement getMessageElement( String namespace, String name ) { if( null == namespace ) { namespace = getDefaultNamespace(); } List namespaceElements = (List) namespaces.get( namespace ); // no namespace means no element. if( null == namespaceElements ) { return null; } Iterator eachElement = namespaceElements.listIterator(); while( eachElement.hasNext() ) { MessageElement anElement = (MessageElement) eachElement.next(); if( name.equals( anElement.getElementName() ) ) { return anElement; } } return null; } /** * Returns a list iterator of all of the elements contained in this message. * Elements from all namespaces are returned. * * <p/>The iterator returned is not synchronized with the message and will * throw {@link java.util.ConcurrentModificationException} if the * message is modified. * * @return Enumeration of Elements. * **/ public ElementIterator getMessageElements( ) { Vector theMsgElements = new Vector( elements ); return new ElementIterator( theMsgElements.listIterator() ); } /** * Returns a list iterator of all of the elements contained in this * message who's name matches the specified name. Elements from all * namespaces are returned. Message Elements are iterated in the order in * which they were added to the Message. * * <p/>The iterator returned is not synchronized with the message and will * throw {@link java.util.ConcurrentModificationException} if the * message is modified. * * @param name the name of the elements to match against * @return iterator of the elements matching the specified name, if any. */ public ElementIterator getMessageElements( String name ) { List theMsgElements = new ArrayList( elements.size() ); Iterator eachElement = elements.iterator(); while ( eachElement.hasNext() ) { element anElement = (element) eachElement.next(); if( name.equals(anElement.element.getElementName()) ) { theMsgElements.add( anElement ); } } return new ElementIterator( theMsgElements.listIterator() ); } /** * Returns an list iterator of all of the elements contained in this message * which match the specified namespace. Message Elements are iterated in * the order in which they were added to the Message. * * <p/>This ListIterator returned is not synchronized with the message. If * you modify the state of the Message, the iterator will throw * ConcurrentModificationException when <code>next()</code> or * <code>previous()</code> is called. * * <p/>The iterator returned is not synchronized with the message and will * throw {@link java.util.ConcurrentModificationException} if the * message is modified. * * @param namespace contains the namespace which must be matched in the * elements returned. You can specify null as a shorthand for the default * namespace. * @return Enumeration of Elements. **/ public ElementIterator getMessageElementsOfNamespace( String namespace ) { List theMsgElements = new ArrayList( elements.size() ); if( null == namespace ) { namespace = getDefaultNamespace(); } Iterator eachElement = elements.iterator(); while ( eachElement.hasNext() ) { element anElement = (element) eachElement.next(); if( namespace.equals(anElement.namespace) ) { theMsgElements.add( anElement ); } } return new ElementIterator( theMsgElements.listIterator() ); } /** * Returns a list iterator of all of the elements contained in the * specified namespace who's name matches the specified name in the order
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -