From: <sf...@us...> - 2007-01-01 15:35:07
|
Revision: 3762 http://svn.sourceforge.net/smartfrog/?rev=3762&view=rev Author: sfpcg Date: 2007-01-01 07:35:03 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Context.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ContextImpl.java trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescription.java trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescriptionImpl.java trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/Prim.java trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/RemoteTags.java trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Tags.java Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Context.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Context.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Context.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -32,7 +32,7 @@ * * @see Copying */ -public interface Context extends PrettyPrinting, Copying, Serializable { +public interface Context extends Tags, PrettyPrinting, Copying, Serializable { /** * Returns true if the context contains value. * Deprecated: replaced by sfContainsValue() Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ContextImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ContextImpl.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/ContextImpl.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -20,14 +20,8 @@ package org.smartfrog.sfcore.common; -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.Vector; -import java.io.StringWriter; -import java.io.Writer; -import java.io.IOException; -import java.io.PrintWriter; +import java.util.*; +import java.io.*; /** @@ -39,9 +33,11 @@ * */ public class ContextImpl extends OrderedHashtable implements Context, - Serializable, PrettyPrinting { + Serializable, PrettyPrinting, Copying { - /** + Map attributeTags = new HashMap(); + + /** * Creates an empty context with default capacity. */ public ContextImpl() { @@ -158,7 +154,9 @@ } - /** + + + /** * Adds an attribute to this context under given name. * * @param name name of attribute @@ -259,9 +257,161 @@ } + /** + * Set the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @param tags a set of tags + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized void sfSetTags(Object name, Set tags) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for setting tags"); + Set s = Collections.synchronizedSet(new HashSet()); + s.addAll(tags); + attributeTags.put(name, s); + } + /** + * Get the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @return the set of tags + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized Set sfGetTags(Object name) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for getting tags"); + if (attributeTags.containsKey(name)) { // return a copy + Set s = new HashSet(); + s.addAll((Set)attributeTags.get(name)); + return s; + } else { //return an empty set as it has not been set yet + return new HashSet(); + } + } + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tag a tag to add to the set + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized void sfAddTag(Object name, String tag) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for adding tags"); + if (attributeTags.containsKey(name)) { // add it + Set s = (Set)attributeTags.get(name); + s.add(tag); + } else { //create a new set and add it + Set s = Collections.synchronizedSet(new HashSet()); + s.add(tag); + attributeTags.put(name, s); + } + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tag a tag to remove from the set + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized void sfRemoveTag(Object name, String tag) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for removing tags"); + if (attributeTags.containsKey(name)) { // remove it + Set s = (Set)attributeTags.get(name); + s.remove(tag); + if (s.size() == 0) attributeTags.remove(name); + } else { // do nothing as it isn't there! + } + } + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tags a set of tags to add to the set + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized void sfAddTags(Object name, Set tags) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for adding tags"); + if (attributeTags.containsKey(name)) { // add it + Set s = (Set)attributeTags.get(name); + s.addAll(tags); + } else { //create a new set and add it + Set s = Collections.synchronizedSet(new HashSet()); + s.addAll(tags); + attributeTags.put(name, s); + } + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tags a set of tags to remove from the set + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public synchronized void sfRemoveTags(Object name, Set tags) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for removing tags"); + if (attributeTags.containsKey(name)) { // remove it + Set s = (Set)attributeTags.get(name); + s.removeAll(tags); + if (s.size() == 0) attributeTags.remove(name); + } else { // do nothing as it isn't there! + } + } + /** + * Return an iterator over the tags for an attribute + * + * @param name the name of the attribute + * @return an iterator over the tags + * @throws SmartFrogContextException + * the attribute does not exist; + */ + public Iterator sfTags(Object name) throws SmartFrogContextException { + Iterator iter; + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for iterating over tags"); + if (attributeTags.containsKey(name)) { // return set iterator + Set s = (Set)attributeTags.get(name); + iter = s.iterator(); + } else { // return iterator on empty set + Set s = new HashSet(); + iter = s.iterator(); + } + return iter; + } + + /** + * Return whether or not a tag is in the list of tags for an attribute + * + * @param name the name of the attribute + * @param tag the tag to chack + * + * @return whether or not the attribute has that tag + * @throws SmartFrogContextException the attribute does not exist + */ + public boolean sfContainsTag(Object name, String tag) throws SmartFrogContextException { + if (!containsKey(name)) + throw new SmartFrogContextException("Attribute " + name + " does not exists for validating tag's existance"); + return ((Set)attributeTags.get(name)).contains(tag); + } + /** * Returns a string representation of the component. This will give a * description of the component which is parseable, and deployable @@ -325,6 +475,7 @@ Object key = keys.nextElement(); Object value = get(key); tabPad(ps, indent); + writeTagsOn(ps, indent, key); writeKeyOn(ps, indent, key); ps.write(' '); writeValueOn(ps, indent, value); @@ -341,6 +492,30 @@ * * @throws IOException failure while writing */ + protected void writeTagsOn(Writer ps, int indent, Object key) throws IOException { + if (attributeTags.containsKey(key)) { + try { + if (sfGetTags(key).size() > 0) { + ps.write("[ "); + for (Iterator i = sfTags(key); i.hasNext();) { + ps.write(i.next().toString() + " "); + } + ps.write("] "); + } + } catch (SmartFrogContextException e) { + // shouldn't happen... + } + } + } + /** + * Writes given attribute key on a writer. + * + * @param ps writer to write on + * @param indent indent level + * @param key key to stringify + * + * @throws IOException failure while writing + */ protected void writeKeyOn(Writer ps, int indent, Object key) throws IOException { ps.write(key.toString()); } @@ -449,4 +624,114 @@ ps.write(" "); } + + + // /////////////////////////////////////////////////////////////////////////////////// + // reimplementation of the hash table and oreder hash table methods to deal with the tags + // /////////////////////////////////////////////////////////////////////////////////// + + + + /** + * Clears the tags as well as the hashtable. + * Overwrites OrderedHashtable.clear(). + */ + public void clear() { + super.clear(); + attributeTags.clear(); + } + + /** + * Removes an entry from the hashtable. + * Overwrites OrderedHashtable.remove(). + * + * @param key key to remove + * + * @return removed object + */ + public Object remove(Object key) { + Object r = super.remove(key); + attributeTags.remove(key); + return r; + } + + + /** + * Removes the element at the specified position. + * Removes the key (and its corresponding value) from this hashtable. + * This method does nothing if the key is not in the hashtable. + * Overrides the method in OrderedHashtable + * + * @param index index to remove + * + * @return the value to which the index had been mapped in this hashtable, + * or null if the key did not have a mapping + */ + public Object remove(int index) { + Object key = orderedKeys.remove(index); + Object value = super.remove(index); + attributeTags.remove(key); + return value; + } + + + /** + * Renames an entry in the otable, leaving its position in the table + * unchanged. Overrides method in OrderedHashtable. + * + * @param key1 the initial key to be renamed + * @param key2 the new key name + * + * @return the initial key, or null if it wasn't in the table + */ + public Object rename(Object key1, Object key2) { + super.rename(key1, key2); + + if (attributeTags.containsKey(key1)) { + attributeTags.put(key2, attributeTags.get(key1)); + attributeTags.remove(key1); + } + + return key1; + } + + /** + * Does a shallow copy of the hashtable, the ordered keys and + * the attributeTags. + * + * @return shallow copy of this table + */ + + + public Object clone() { + Object ret = super.clone(); + Map m = new HashMap(); + for (Iterator i = attributeTags.keySet().iterator(); i.hasNext(); ) { + Object key = i.next(); + Set s = (Set) attributeTags.get(key); + Set sc = Collections.synchronizedSet(new HashSet()); + sc.addAll(s); + m.put(key, sc); + } + ((ContextImpl) ret).attributeTags = m; + return ret; + } + + /** + * Does a deep copy of the hashtable. Values in the hashtable which + * understand the Copying interface get copied properly. If the Values + * cannot be copied, the basic SF values (numbers, strings, booleans, are + * each properly dealt with. Other values are copied using serialize/deserialize + * if they implement serialization - note that because of this transient data will + * not be copied. It also copies the attributeTags. + * + * This overrides the one in OrderedHashtable. + * + * @return copy of hashtable + */ + public Object copy() { + // note that since the super method uses clone, + // this is already copying attributeTags + return super.copy(); + } } Added: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/RemoteTags.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/RemoteTags.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/RemoteTags.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -0,0 +1,89 @@ +package org.smartfrog.sfcore.common; + +import java.util.Set; +import java.util.Iterator; +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * Interface that defines the access to, and manipulation of, tags in + * contexts, component descriptions and (in its remote form) prims. + */ +public interface RemoteTags extends Remote { + // TAGS interface for a context + + /** + * Set the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @param tags a set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public void sfSetTags(Object name, Set tags) throws SmartFrogException, RemoteException; + + /** + * Get the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @return the set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public Set sfGetTags(Object name) throws SmartFrogException, RemoteException; + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tag a tag to add to the set + * + * @throws SmartFrogException the attribute does not exist; + */ + public void sfAddTag(Object name, String tag) throws SmartFrogException, RemoteException; + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tag a tag to remove from the set + * + * @throws SmartFrogException the attribute does not exist; + * + */ + public void sfRemoveTag(Object name, String tag) throws SmartFrogException, RemoteException; + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tags a set of tags to add to the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfAddTags(Object name, Set tags) throws SmartFrogException, RemoteException; + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tags a set of tags to remove from the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfRemoveTags(Object name, Set tags) throws SmartFrogException, RemoteException; + + /** + * Return whether or not a tag is in the list of tags for an attribute + * + * @param name the name of the attribute + * @param tag the tag to chack + * + * @return whether or not the attribute has that tag + * @throws SmartFrogException the attribute does not exist + */ + public boolean sfContainsTag(Object name, String tag) throws SmartFrogException, RemoteException; + +} Added: trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Tags.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Tags.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/common/Tags.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -0,0 +1,96 @@ +package org.smartfrog.sfcore.common; + +import java.util.Set; +import java.util.Iterator; + +/** + * Interface that defines the access to, and manipulation of, tags in + * contexts, component descriptions and (in its remote form) prims. + */ +public interface Tags { + // TAGS interface for a context + + /** + * Set the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @param tags a set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public void sfSetTags(Object name, Set tags) throws SmartFrogException; + + /** + * Get the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @return the set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public Set sfGetTags(Object name) throws SmartFrogException; + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tag a tag to add to the set + * + * @throws SmartFrogContextException the attribute does not exist; + */ + public void sfAddTag(Object name, String tag) throws SmartFrogException; + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tag a tag to remove from the set + * + * @throws SmartFrogException the attribute does not exist; + * + */ + public void sfRemoveTag(Object name, String tag) throws SmartFrogException; + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tags a set of tags to add to the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfAddTags(Object name, Set tags) throws SmartFrogException; + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tags a set of tags to remove from the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfRemoveTags(Object name, Set tags) throws SmartFrogException; + + /** + * Return an iterator over the tags for an attribute + * + * @param name the name of the attribute + * @return an iterator over the tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public Iterator sfTags(Object name) throws SmartFrogException; + + /** + * Return whether or not a tag is in the list of tags for an attribute + * + * @param name the name of the attribute + * @param tag the tag to chack + * + * @return whether or not the attribute has that tag + * @throws SmartFrogException the attribute does not exist + */ + public boolean sfContainsTag(Object name, String tag) throws SmartFrogException; +} Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescription.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescription.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescription.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -25,9 +25,6 @@ import java.util.Iterator; import java.util.Stack; -import org.smartfrog.sfcore.common.Context; -import org.smartfrog.sfcore.common.Copying; -import org.smartfrog.sfcore.common.PrettyPrinting; import org.smartfrog.sfcore.prim.Prim; import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.reference.ReferenceResolver; @@ -35,7 +32,7 @@ import org.smartfrog.sfcore.logging.LogSF; -import org.smartfrog.sfcore.common.SmartFrogRuntimeException; +import org.smartfrog.sfcore.common.*; /** * Defines the context interface used by Components. Context implementations @@ -43,7 +40,7 @@ * Components. * @see Copying */ -public interface ComponentDescription extends PrettyPrinting, Copying, ReferenceResolver, ReferenceResolverHelper { +public interface ComponentDescription extends Tags, PrettyPrinting, Copying, ReferenceResolver, ReferenceResolverHelper { /** * Add an attribute to the component description context. Values should be Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescriptionImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescriptionImpl.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescriptionImpl.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -24,11 +24,7 @@ import java.io.Serializable; import java.io.StringWriter; import java.io.Writer; -import java.util.Vector; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.Stack; -import java.util.Properties; +import java.util.*; import org.smartfrog.sfcore.common.Context; import org.smartfrog.sfcore.common.PrettyPrinting; @@ -1195,4 +1191,106 @@ } return cd; } + + // implementation of the TAGS interface + + + /** + * Set the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @param tags a set of tags + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfSetTags(Object name, Set tags) throws SmartFrogException { + sfContext.sfSetTags(name, tags); + } + + /** + * Get the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @return the set of tags + * @throws SmartFrogException + * the attribute does not exist; + */ + public Set sfGetTags(Object name) throws SmartFrogException { + return sfContext.sfGetTags(name); + } + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tag a tag to add to the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfAddTag(Object name, String tag) throws SmartFrogException { + sfContext.sfAddTag(name, tag); + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tag a tag to remove from the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfRemoveTag(Object name, String tag) throws SmartFrogException { + sfContext.sfRemoveTag(name, tag); + } + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tags a set of tags to add to the set + * @throws SmartFrogException + * the attribute does not exist; + */ +public void sfAddTags(Object name, Set tags) throws SmartFrogException { + sfContext.sfAddTags(name, tags); + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tags a set of tags to remove from the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfRemoveTags(Object name, Set tags) throws SmartFrogException { + sfContext.sfRemoveTags(name, tags); + } + + /** + * Return an iterator over the tags for an attribute + * + * @param name the name of the attribute + * @return an iterator over the tags + * @throws SmartFrogException + * the attribute does not exist; + */ + public Iterator sfTags(Object name) throws SmartFrogException { + return sfContext.sfTags(name); + } + + /** + * Return whether or not a tag is in the list of tags for an attribute + * + * @param name the name of the attribute + * @param tag the tag to chack + * @return whether or not the attribute has that tag + * @throws SmartFrogException + * the attribute does not exist + */ + public boolean sfContainsTag(Object name, String tag) throws SmartFrogException { + return sfContext.sfContainsTag(name, tag); + } } Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/languages/sf/sfcomponentdescription/SFComponentDescriptionImpl.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -25,6 +25,8 @@ import java.io.Writer; import java.util.Enumeration; import java.util.Vector; +import java.util.Set; +import java.util.HashSet; import org.smartfrog.sfcore.common.*; @@ -221,7 +223,14 @@ for (Enumeration e = sfContext.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = sfContext.get(key); + Set tags = null; try { + tags = sfContext.sfGetTags(key); + } catch (SmartFrogException e1) { + //shouldn't happen + } + + try { // Get attribute and if key a reference try to place it in the // right component. Don't resolve value since it ain't mine if (key instanceof Reference) { @@ -230,7 +239,7 @@ removals = new Vector(5); } - if (place( (Reference) key, value, resState)) { + if (place( (Reference) key, value, tags, resState)) { removals.addElement(key); } } else if (value instanceof ComponentResolver) { @@ -270,7 +279,7 @@ *@param value attribute value *@param resState resolution state */ - protected boolean place(Reference key, Object value, ResolutionState resState) { + protected boolean place(Reference key, Object value, Set tags, ResolutionState resState) { Object nam = ((HereReferencePart) key.lastElement()).getValue(); ComponentDescription destDescription = null; @@ -292,6 +301,11 @@ // place value under simple name in destination destDescription.sfContext().put(nam, value); + try { + if (tags != null) destDescription.sfContext().sfAddTags(nam, tags); + } catch (SmartFrogException e) { + // shouldn't happen + } // Set new parent if value is component if (value instanceof ComponentDescription) { @@ -415,12 +429,12 @@ Context sContext = (Context) superType.sfContext().copy(); Object key; Object value; + Set tags; // re-parent any descriptions in super sfContext for (Enumeration e = sContext.keys(); e.hasMoreElements(); ) { key = e.nextElement(); value = sContext.get(key); - if (value instanceof SFComponentDescription) { ((SFComponentDescription) value).setParent(this); } @@ -431,6 +445,12 @@ key = e.nextElement(); value = sfContext.get(key); sContext.put(key, value); + try { + tags = sfContext.sfGetTags(key); + sContext.sfAddTags(key, tags); + } catch (SmartFrogException e1) { + //shouldn't happen + } } // set sfContext @@ -603,19 +623,28 @@ for (Enumeration e = sfContext.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); Object value = sfContext.get(key); + Set tags = null; - if (value instanceof SFTempValue) { + if (value instanceof SFTempValue) { //nothing - attribute is to be removed... } else if (value instanceof Phases) { value = ((Phases) value).sfAsComponentDescription(); ((ComponentDescription) value).setParent(res); newContext.put(key, value); - } else if (value instanceof ReferencePhases) { + } else if (value instanceof ReferencePhases) { value = ((ReferencePhases) value).sfAsReference(); newContext.put(key, value); - } else + } else newContext.put(key, copyValue(value)); + + try { + tags = sfContext.sfGetTags(key); + newContext.sfAddTags(key, tags); + } catch (SmartFrogException e1) { + //shouldn't happen + } } + return res; } Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/Prim.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/Prim.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/Prim.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -20,9 +20,7 @@ package org.smartfrog.sfcore.prim; -import org.smartfrog.sfcore.common.Context; -import org.smartfrog.sfcore.common.SmartFrogException; -import org.smartfrog.sfcore.common.SmartFrogRuntimeException; +import org.smartfrog.sfcore.common.*; import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.reference.RemoteReferenceResolver; import org.smartfrog.sfcore.reference.RemoteReferenceResolverHelper; @@ -38,7 +36,7 @@ * component knows how to react to termination, liveness, etc. * */ -public interface Prim extends Update, Liveness, RemoteReferenceResolver, RemoteReferenceResolverHelper, Diagnostics, Remote { +public interface Prim extends Update, Liveness, RemoteReferenceResolver, RemoteReferenceResolverHelper, RemoteTags, Diagnostics, Remote { /** * Add an attribute to the component's context. Values should be * marshallable types if they are to be referenced remotely at run-time. Modified: trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java 2006-12-22 12:14:41 UTC (rev 3761) +++ trunk/core/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java 2007-01-01 15:35:03 UTC (rev 3762) @@ -27,11 +27,11 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.Vector; +import java.util.Set; import org.smartfrog.sfcore.common.Diagnostics; import org.smartfrog.sfcore.common.Context; import org.smartfrog.sfcore.common.ContextImpl; -import org.smartfrog.sfcore.common.Diagnostics; import org.smartfrog.sfcore.common.Logger; import org.smartfrog.sfcore.common.MessageKeys; import org.smartfrog.sfcore.common.MessageUtil; @@ -177,7 +177,7 @@ try { // if sfLog() is called then a new log is created and an upcall is triggered if ((sfLog!=null) && sfLog().isTraceEnabled()) { - sfLog().trace("sfResolved HERE '"+name.toString()+"' to '"+ result.toString()+"'"); sfLog().trace("sfResolved HERE '"+name.toString()+"' to '"+ result.toString()+"'"); + sfLog().trace("sfResolved HERE '"+name.toString()+"' to '"+ result.toString()+"'"); } } catch (Throwable thr) {thr.printStackTrace();} //ignore @@ -1649,4 +1649,111 @@ } } } + + + + + + // implementation of the RemoteTags interface + + /** + * Set the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @param tags a set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public void sfSetTags(Object name, Set tags) throws SmartFrogException, RemoteException { + sfContext.sfSetTags(name, tags); + } + + /** + * Get the TAGS for an attribute. TAGS are simply uninterpreted strings associated + * with each attribute. + * + * @param name attribute key for tags + * @return the set of tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public Set sfGetTags(Object name) throws SmartFrogException, RemoteException { + return sfContext.sfGetTags(name); + } + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tag a tag to add to the set + * + * @throws SmartFrogException the attribute does not exist; + */ + public void sfAddTag(Object name, String tag) throws SmartFrogException, RemoteException { + sfContext.sfAddTag(name,tag); + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tag a tag to remove from the set + * + * @throws SmartFrogException the attribute does not exist; + * + */ + public void sfRemoveTag(Object name, String tag) throws SmartFrogException, RemoteException { + sfContext.sfRemoveTag(name, tag); + } + + /** + * add a tag to the tag set of an attribute + * + * @param name attribute key for tags + * @param tags a set of tags to add to the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfAddTags(Object name, Set tags) throws SmartFrogException, RemoteException { + sfContext.sfAddTags(name, tags); + } + + /** + * remove a tag from the tag set of an attribute if it exists + * + * @param name attribute key for tags + * @param tags a set of tags to remove from the set + * @throws SmartFrogException + * the attribute does not exist; + */ + public void sfRemoveTags(Object name, Set tags) throws SmartFrogException, RemoteException { + sfContext.sfRemoveTags(name, tags); + } + + /** + * Return an iterator over the tags for an attribute - not part of RemoteTags, but is part of Tags + * + * @param name the name of the attribute + * @return an iterator over the tags + * + * @throws SmartFrogException the attribute does not exist; + */ + public Iterator sfTags(Object name) throws SmartFrogException { + return sfContext.sfTags(name); + } + + /** + * Return whether or not a tag is in the list of tags for an attribute + * + * @param name the name of the attribute + * @param tag the tag to chack + * + * @return whether or not the attribute has that tag + * @throws SmartFrogException the attribute does not exist + */ + public boolean sfContainsTag(Object name, String tag) throws SmartFrogException, RemoteException { + return sfContext.sfContainsTag(name, tag); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |