You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@depot.apache.org by aj...@apache.org on 2004/07/20 21:32:51 UTC
svn commit: rev 23103 - in incubator/depot/trunk/update/src/java/org/apache/depot/update: protocols protocols/select util/chainprocess util/compare
Author: ajack
Date: Tue Jul 20 14:32:50 2004
New Revision: 23103
Removed:
incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/select/
incubator/depot/trunk/update/src/java/org/apache/depot/update/util/chainprocess/
Modified:
incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java
incubator/depot/trunk/update/src/java/org/apache/depot/update/util/compare/ComparatorSequence.java
Log:
Whittle
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java Tue Jul 20 14:32:50 2004
@@ -29,69 +29,127 @@
import org.apache.depot.common.util.debug.Dumpable;
import org.apache.depot.update.UpdateException;
import org.apache.depot.update.impl.ArtifactUpdaterContext;
-import org.apache.depot.update.protocols.select.DestinationProtocolProviderSelector;
-import org.apache.depot.update.protocols.select.SourceDestinationProtocolProviderSelector;
-import org.apache.depot.update.protocols.select.SourceProtocolProviderSelector;
-import org.apache.depot.update.util.UpdateConstants;
-import org.apache.depot.update.util.chainprocess.HandlerManager;
import org.apache.depot.update.util.net.VirtualResourceLocator;
import org.apache.depot.update.util.select.ISelector;
-import org.apache.depot.update.util.select.SelectorHandlerChain;
+import org.apache.depot.update.util.select.SelectionHelper;
/**
* @author ajack
*/
-public class ProtocolOperationsManager
- extends HandlerManager
- implements Dumpable {
+public class ProtocolOperationsManager implements Dumpable {
private ArtifactUpdaterContext m_context = null;
private List m_providers = new ArrayList();
private Map m_sourceProtocolMap = new HashMap();
private Map m_destinationProtocolMap = new HashMap();
- ProtocolOperationsManager(ArtifactUpdaterContext context) {
- m_context = context;
- configureSelectors();
+ private class SourceProtocolProviderSelector implements ISelector {
+
+ String m_sourceProtocol;
+
+ public SourceProtocolProviderSelector(String protocol) {
+ m_sourceProtocol = protocol;
+ }
+
+ public boolean select(Object protocolProvider) {
+
+ List listOfSourceProtocols = ((IProtocolOperationsProvider) protocolProvider).getSupportedSourceProtocols();
+
+ for (Iterator protocolIterator = listOfSourceProtocols.iterator(); protocolIterator.hasNext();) {
+ String protocol = (String) protocolIterator.next();
+ if (protocol.equals(m_sourceProtocol)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ private class DestinationProtocolProviderSelector implements ISelector {
+
+ String m_destinationProtocol;
+
+ public DestinationProtocolProviderSelector(String protocol) {
+ m_destinationProtocol = protocol;
+ }
+
+ public boolean select(Object protocolProvider) {
+
+ List listOfDestinationProtocols = ((IProtocolOperationsProvider) protocolProvider).getSupportedDestinationProtocols();
+
+ for (Iterator protocolIterator = listOfDestinationProtocols.iterator(); protocolIterator.hasNext();) {
+ String protocol = (String) protocolIterator.next();
+ if (protocol.equals(m_destinationProtocol)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
- private void configureSelectors() {
+ private class SourceDestinationProtocolProviderSelector
+ implements
+ ISelector {
+
+ String m_sourceProtocol;
+ String m_destinationProtocol;
+
+ public SourceDestinationProtocolProviderSelector(String srcProtocol,
+ String destProtocol) {
+ m_sourceProtocol = srcProtocol;
+ m_destinationProtocol = destProtocol;
+ }
+
+ public boolean select(Object protocolProvider) {
+
+ List listOfSourceProtocols = ((IProtocolOperationsProvider) protocolProvider).getSupportedSourceProtocols();
+
+ // check the src protocol
+ for (Iterator srcProtocolIterator = listOfSourceProtocols.iterator(); srcProtocolIterator.hasNext();) {
+ String protocol = (String) srcProtocolIterator.next();
+ if (protocol.equals(m_sourceProtocol)) {
+ // if src protocol matches, check the destination protocol
+ List listOfDestinationProtocols = ((IProtocolOperationsProvider) protocolProvider).getSupportedDestinationProtocols();
+
+ for (Iterator protocolIterator = listOfDestinationProtocols.iterator(); protocolIterator.hasNext();) {
+ String destProtocol = (String) protocolIterator.next();
+ if (destProtocol.equals(m_destinationProtocol)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ }
- // create the selector handler chain and
- // add it to the list of handler chains
- SelectorHandlerChain selectors =
- new SelectorHandlerChain(UpdateConstants.SELECTOR);
- // add the selectors chain to the handler manager
- this.addHandlerChain(selectors);
+ ProtocolOperationsManager(ArtifactUpdaterContext context) {
+ m_context = context;
}
public void registerProvider(IProtocolOperationsProvider p)
- throws Exception {
+ throws Exception {
m_providers.add(p);
p.init(m_context);
- registerIntoMap(
- m_sourceProtocolMap,
- p,
- p.getSupportedSourceProtocols().iterator());
-
- registerIntoMap(
- m_destinationProtocolMap,
- p,
- p.getSupportedDestinationProtocols().iterator());
+ registerIntoMap(m_sourceProtocolMap, p,
+ p.getSupportedSourceProtocols().iterator());
+
+ registerIntoMap(m_destinationProtocolMap, p,
+ p.getSupportedDestinationProtocols().iterator());
}
public Set getSupportedSourceProtocols() {
return m_sourceProtocolMap.keySet();
}
+
public Set getSupportedDestinationProtocols() {
return m_destinationProtocolMap.keySet();
}
- private void registerIntoMap(
- Map map,
- IProtocolOperationsProvider p,
- Iterator i) {
+ private void registerIntoMap(Map map, IProtocolOperationsProvider p,
+ Iterator i) {
for (; i.hasNext();) {
addProvider(map, (String) i.next(), p);
}
@@ -108,21 +166,14 @@
* @param to
* @throws Exception
*/
- public List performList(
- VirtualResourceLocator container,
- ISelector selector)
- throws Exception {
- return performList(
- container,
- determineProviderFor(container),
- selector);
+ public List performList(VirtualResourceLocator container, ISelector selector)
+ throws Exception {
+ return performList(container, determineProviderFor(container), selector);
}
- public List performList(
- VirtualResourceLocator container,
- IProtocolOperationsProvider provider,
- ISelector selector)
- throws Exception {
+ public List performList(VirtualResourceLocator container,
+ IProtocolOperationsProvider provider, ISelector selector)
+ throws Exception {
Logger.getLogger().debug("Perform LIST: " + container);
return provider.list(container, selector);
}
@@ -135,7 +186,7 @@
* @throws Exception
*/
public boolean checkExists(VirtualResourceLocator container)
- throws Exception {
+ throws Exception {
Logger.getLogger().debug("Check EXISTS: " + container);
boolean exists = determineProviderFor(container).exists(container);
return exists;
@@ -148,11 +199,8 @@
* @param to
* @throws Exception
*/
- public void performCopy(
- VirtualResourceLocator from,
- VirtualResourceLocator to,
- ISelector selector)
- throws Exception {
+ public void performCopy(VirtualResourceLocator from,
+ VirtualResourceLocator to, ISelector selector) throws Exception {
Logger.getLogger().info("Perform COPY " + from + " -> " + to);
determineProviderFor(from, to).copy(from, to, selector);
}
@@ -164,35 +212,27 @@
* @param to
* @throws Exception
*/
- public void performDelete(
- VirtualResourceLocator locator,
- ISelector selector)
- throws Exception {
+ public void performDelete(VirtualResourceLocator locator, ISelector selector)
+ throws Exception {
Logger.getLogger().info("Perform DELETE " + locator);
determineProviderFor(locator).delete(locator, selector);
}
IProtocolOperationsProvider determineProviderFor(
- VirtualResourceLocator source,
- VirtualResourceLocator destination)
- throws UpdateException {
+ VirtualResourceLocator source, VirtualResourceLocator destination)
+ throws UpdateException {
// Locate a Provider that handles both address
// types (e.g. protocols)
- List providers =
- determineSourceDestinationProviders(
- source.getProtocol(),
- destination.getProtocol());
+ List providers = determineSourceDestinationProviders(
+ source.getProtocol(), destination.getProtocol());
if (0 == providers.size())
- throw new UpdateException(
- "No providers for protocols : "
- + source.getProtocol()
- + " and "
+ throw new UpdateException("No providers for protocols : "
+ + source.getProtocol() + " and "
+ destination.getProtocol());
- IProtocolOperationsProvider provider =
- (IProtocolOperationsProvider) providers.get(0);
+ IProtocolOperationsProvider provider = (IProtocolOperationsProvider) providers.get(0);
//
// :TODO: Maybe filter/select by capabilities.
@@ -201,18 +241,17 @@
return provider;
}
- IProtocolOperationsProvider determineProviderFor(VirtualResourceLocator source)
- throws UpdateException {
+ IProtocolOperationsProvider determineProviderFor(
+ VirtualResourceLocator source) throws UpdateException {
// Locate a Provider that handles both address
// types (e.g. protocols)
List providers = determineSourceProviders(source.getProtocol());
if (null == providers)
- throw new UpdateException(
- "No providers for protocol : " + source.getProtocol());
+ throw new UpdateException("No providers for protocol : "
+ + source.getProtocol());
- IProtocolOperationsProvider provider =
- (IProtocolOperationsProvider) providers.get(0);
+ IProtocolOperationsProvider provider = (IProtocolOperationsProvider) providers.get(0);
//
// :TODO: Maybe filter/select by capabilities.
@@ -222,53 +261,25 @@
}
private List determineSourceProviders(String protocol)
- throws UpdateException {
- // set the selector and then pass the providers through the process chain
- SourceProtocolProviderSelector sourceProtocolSelector =
- new SourceProtocolProviderSelector(protocol);
-
- return processProviderList(sourceProtocolSelector);
+ throws UpdateException {
+ return SelectionHelper.select(m_providers, new SourceProtocolProviderSelector(
+ protocol));
}
private List determineDestinationProviders(String protocol)
- throws UpdateException {
- // set the selector and then pass the providers through the process chain
- DestinationProtocolProviderSelector destinationProtocolSelector =
- new DestinationProtocolProviderSelector(protocol);
-
- return processProviderList(destinationProtocolSelector);
- }
-
- private List determineSourceDestinationProviders(
- String srcProtocol,
- String destProtocol)
- throws UpdateException {
- // set the selector and then pass the providers through the process chain
- SourceDestinationProtocolProviderSelector srcDestProtocolSelector =
- new SourceDestinationProtocolProviderSelector(
- srcProtocol,
- destProtocol);
-
- return processProviderList(srcDestProtocolSelector);
+ throws UpdateException {
+ return SelectionHelper.select(m_providers, new DestinationProtocolProviderSelector(
+ protocol));
}
- private List processProviderList(ISelector selector)
- throws UpdateException {
-
- List listOfProviders = null;
- List selectorList = new ArrayList();
- selectorList.add(selector);
-
- setHandlers(UpdateConstants.SELECTOR, selectorList);
-
- listOfProviders = process(m_providers);
- return listOfProviders;
+ private List determineSourceDestinationProviders(String srcProtocol,
+ String destProtocol) throws UpdateException {
+ return SelectionHelper.select(m_providers, new SourceDestinationProtocolProviderSelector(
+ srcProtocol, destProtocol));
}
- private void addProvider(
- Map map,
- String protocol,
- IProtocolOperationsProvider p) {
+ private void addProvider(Map map, String protocol,
+ IProtocolOperationsProvider p) {
List providers = (List) map.get(protocol);
if (null == providers) {
providers = new ArrayList();
@@ -277,37 +288,21 @@
providers.add(p);
}
- /*private List join(List list1, List list2) {
- List join = new ArrayList();
-
- for (Iterator i = list1.iterator(); i.hasNext();) {
- Object entity = i.next();
-
- if (list2.contains(entity))
- join.add(entity);
- }
-
- return join;
- }*/
-
+ /**
+ * Show the contents of this ProtocolManager
+ */
public void dump(PrintWriter out, int depth, boolean verbose) {
//String indent = DebugUtils.getIndent(depth);
String indent1 = DebugUtils.getIndent(depth + 1);
dumpRegistry(out, indent1, "Source Protocols", m_sourceProtocolMap);
- dumpRegistry(
- out,
- indent1,
- "Destination Protocols",
- m_destinationProtocolMap);
+ dumpRegistry(out, indent1, "Destination Protocols",
+ m_destinationProtocolMap);
}
- private void dumpRegistry(
- PrintWriter out,
- String indent,
- String title,
- Map map) {
+ private void dumpRegistry(PrintWriter out, String indent, String title,
+ Map map) {
out.print(indent);
out.println("Registry: " + title);
@@ -317,12 +312,11 @@
List providers = (List) map.get(key);
for (Iterator ii = providers.iterator(); ii.hasNext();) {
- IProtocolOperationsProvider p =
- (IProtocolOperationsProvider) ii.next();
+ IProtocolOperationsProvider p = (IProtocolOperationsProvider) ii.next();
out.print(indent);
out.print("Key: \'" + key + "\' -> ");
out.println("Provider: " + p);
}
}
}
-}
+}
\ No newline at end of file
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/util/compare/ComparatorSequence.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/util/compare/ComparatorSequence.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/util/compare/ComparatorSequence.java Tue Jul 20 14:32:50 2004
@@ -26,9 +26,7 @@
*/
public class ComparatorSequence extends ArrayList implements Comparator {
- //
// An set of all
- //
public ComparatorSequence(List comparators) {
super(comparators);
}
@@ -44,13 +42,15 @@
add(c);
}
- //
- // Compare in list order.
- //
+ /**
+ * Compare using sub comparators, in order, until
+ * a difference is found, or not.
+ */
public int compare(Object o1, Object o2) {
int comparison = 0;
- for (Iterator i = iterator(); i.hasNext() && (0 == comparison);) {
+ for (Iterator i = iterator();
+ i.hasNext() && (0 == comparison);) {
Comparator comparator = ((Comparator) i.next());
comparison = comparator.compare(o1, o2);