From: <bh...@us...> - 2006-07-28 02:40:35
|
Revision: 100 Author: bh2 Date: 2006-07-26 10:34:38 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/cishell/?rev=100&view=rev Log Message: ----------- * some more code clean up and small refactorings Modified Paths: -------------- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmFactoryRegistry.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmRegistry.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AttributeDefinitionRegistry.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/CIShellFramework.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/DataModelRegistry.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/MetaTypeProviderRegistry.java trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/ObjectClassDefinitionRegistry.java trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerAdapter.java trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerListener.java trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerService.java trunk/core/org.cishell.framework/src/org/cishell/service/conversion/Converter.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/modelmanager/ModelManagerServiceImpl.java trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmFactoryRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmFactoryRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmFactoryRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -20,7 +20,6 @@ public interface AlgorithmFactoryRegistry { public static String SERVICE_NAME = "AlgorithmFactoryRegistry"; - public static String SERVICE_METHODS = "createParameters createAlgorithm"; public String createParameters(String servicePID, Vector dataModelIDs); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AlgorithmRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -18,7 +18,6 @@ public interface AlgorithmRegistry { public static String SERVICE_NAME = "AlgorithmRegistry"; - public static String SERVICE_METHODS = "execute unregisterAlgorithm"; public void execute(String sessionID, String algorithmID); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AttributeDefinitionRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AttributeDefinitionRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/AttributeDefinitionRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -19,7 +19,6 @@ public interface AttributeDefinitionRegistry { public static String SERVICE_NAME = "AttributeDefinitionRegistry"; - public static String SERVICE_METHODS = "*"; public int getCardinality(String attrID); public Vector getDefaultValue(String attrID); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/CIShellFramework.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/CIShellFramework.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/CIShellFramework.java 2006-07-26 17:34:38 UTC (rev 100) @@ -18,7 +18,6 @@ public interface CIShellFramework { public static String SERVICE_NAME = "CIShellFramework"; - public static String SERVICE_METHODS = "createSession getLifeCycleEvents getAlgorithmFactories"; public String createSession(String clientURL); public void closeSession(String sessionID); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/DataModelRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/DataModelRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/DataModelRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -20,7 +20,6 @@ public interface DataModelRegistry { public static String SERVICE_NAME = "DataModelRegistry"; - public static String SERVICE_METHODS = "*"; public Hashtable getProperties(String dataModelID); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/MetaTypeProviderRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/MetaTypeProviderRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/MetaTypeProviderRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -19,7 +19,6 @@ public interface MetaTypeProviderRegistry { public static String SERVICE_NAME = "MetaTypeProviderRegistry"; - public static String SERVICE_METHODS = "*"; public Vector getLocales(String providerID); public String getObjectClassDefinition(String providerID, String id, String locale); Modified: trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/ObjectClassDefinitionRegistry.java =================================================================== --- trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/ObjectClassDefinitionRegistry.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/clients/remoting/org.cishell.remoting/src/org/cishell/remoting/service/framework/ObjectClassDefinitionRegistry.java 2006-07-26 17:34:38 UTC (rev 100) @@ -19,7 +19,6 @@ public interface ObjectClassDefinitionRegistry { public static String SERVICE_NAME = "ObjectClassDefinitionRegistry"; - public static String SERVICE_METHODS = "*"; public String getID(String ocdID); public String getName(String ocdID); Modified: trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerAdapter.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerAdapter.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerAdapter.java 2006-07-26 17:34:38 UTC (rev 100) @@ -22,12 +22,12 @@ * * @author Bruce Herr (bh...@bh...) */ -public abstract class ModelManagerAdapter implements ModelManagerListener { +public class ModelManagerAdapter implements ModelManagerListener { /** - * @see org.cishell.app.service.modelmanager.ModelManagerListener#modelAdded(org.cishell.framework.datamodel.DataModel) + * @see org.cishell.app.service.modelmanager.ModelManagerListener#modelAdded(org.cishell.framework.datamodel.DataModel, java.lang.String) */ - public void modelAdded(DataModel dm) {} - + public void modelAdded(DataModel dm, String label) {} + /** * @see org.cishell.app.service.modelmanager.ModelManagerListener#modelRemoved(org.cishell.framework.datamodel.DataModel) */ @@ -37,4 +37,9 @@ * @see org.cishell.app.service.modelmanager.ModelManagerListener#modelsSelected(org.cishell.framework.datamodel.DataModel[]) */ public void modelsSelected(DataModel[] dm) {} + + /** + * @see org.cishell.app.service.modelmanager.ModelManagerListener#modelLabelChanged(org.cishell.framework.datamodel.DataModel, java.lang.String) + */ + public void modelLabelChanged(DataModel dm, String label) {} } Modified: trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerListener.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerListener.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerListener.java 2006-07-26 17:34:38 UTC (rev 100) @@ -27,11 +27,20 @@ * Notifies that a model has been added to the associated * {@link ModelManagerService} * - * @param dm The added {@link DataModel} + * @param dm The added {@link DataModel} + * @param label The label assigned to the datamodel */ - public void modelAdded(DataModel dm); + public void modelAdded(DataModel dm, String label); /** + * Notifies that a model has had its label changed + * + * @param dm The DataModel + * @param label The new label + */ + public void modelLabelChanged(DataModel dm, String label); + + /** * Notifies that a model has been removed from the associated * {@link ModelManagerService} * Modified: trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerService.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerService.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/modelmanager/ModelManagerService.java 2006-07-26 17:34:38 UTC (rev 100) @@ -80,4 +80,8 @@ * @param listener The listener to be removed */ public void removeModelManagerListener(ModelManagerListener listener); + + //TODO: Documentation + public String getLabel(DataModel dm); + public void setLabel(DataModel dm, String label); } Modified: trunk/core/org.cishell.framework/src/org/cishell/service/conversion/Converter.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/service/conversion/Converter.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.framework/src/org/cishell/service/conversion/Converter.java 2006-07-26 17:34:38 UTC (rev 100) @@ -16,6 +16,7 @@ import java.util.Dictionary; import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.datamodel.DataModel; import org.osgi.framework.ServiceReference; /** @@ -25,4 +26,6 @@ public ServiceReference[] getConverterChain(); public AlgorithmFactory getAlgorithmFactory(); public Dictionary getProperties(); + + public DataModel convert(DataModel dm); } Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/modelmanager/ModelManagerServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/modelmanager/ModelManagerServiceImpl.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/modelmanager/ModelManagerServiceImpl.java 2006-07-26 17:34:38 UTC (rev 100) @@ -75,8 +75,8 @@ className = className.substring(0,className.lastIndexOf("Algorithm")); } - if (className.endsWith("Plugin")) { - className = className.substring(0,className.lastIndexOf("Plugin")); + if (className.endsWith("Factory")) { + className = className.substring(0,className.lastIndexOf("Factory")); } } label = className; @@ -90,7 +90,7 @@ addModel(model, label); for (Iterator iter=listeners.iterator(); iter.hasNext();) { - ((ModelManagerListener) iter.next()).modelAdded(model); + ((ModelManagerListener) iter.next()).modelAdded(model, label); } } @@ -145,7 +145,7 @@ public void removeModel(DataModel model) { - String label = getLabelForModel(model); + String label = getLabel(model); labelToModelMap.remove(label); modelToLabelMap.remove(model); @@ -176,9 +176,20 @@ return (DataModel)labelToModelMap.get(label); } - private String getLabelForModel(DataModel model){ + public String getLabel(DataModel model){ return (String)modelToLabelMap.get(model); } + + public synchronized void setLabel(DataModel model, String label) { + label = findUniqueLabel(label); + + modelToLabelMap.put(model, label); + labelToModelMap.put(label, model); + + for (Iterator iter=listeners.iterator(); iter.hasNext();) { + ((ModelManagerListener) iter.next()).modelLabelChanged(model, label); + } + } public DataModel[] getAllModels() { return (DataModel[]) models.toArray(new DataModel[]{}); Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2006-07-26 17:34:38 UTC (rev 100) @@ -14,15 +14,18 @@ package org.cishell.reference.service.conversion; import java.util.Dictionary; +import java.util.Enumeration; import java.util.Hashtable; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.datamodel.BasicDataModel; import org.cishell.framework.datamodel.DataModel; import org.cishell.service.conversion.Converter; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.service.metatype.MetaTypeProvider; @@ -34,9 +37,11 @@ private ServiceReference[] refs; private BundleContext bContext; private Dictionary props; + private CIShellContext ciContext; - public ConverterImpl(BundleContext bContext, ServiceReference[] refs) { + public ConverterImpl(BundleContext bContext, CIShellContext ciContext, ServiceReference[] refs) { this.bContext = bContext; + this.ciContext = ciContext; this.refs = refs; props = new Hashtable(); @@ -56,6 +61,39 @@ } /** + * @see org.cishell.service.conversion.Converter#convert(org.cishell.framework.datamodel.DataModel) + */ + public DataModel convert(DataModel inDM) { + DataModel[] dm = new DataModel[]{inDM}; + + AlgorithmFactory factory = getAlgorithmFactory(); + Algorithm alg = factory.createAlgorithm(dm, new Hashtable(), ciContext); + + dm = alg.execute(); + + Object outData = null; + if (dm != null && dm.length > 0) { + outData = dm[0].getData(); + } + + if (outData != null) { + Dictionary props = inDM.getMetaData(); + Dictionary newProps = new Hashtable(); + + for (Enumeration e=props.keys(); e.hasMoreElements();) { + Object key = e.nextElement(); + newProps.put(key, props.get(key)); + } + + String outFormat = (String)getProperties().get(AlgorithmProperty.OUT_DATA); + return new BasicDataModel(newProps, outData, outFormat); + } else { + return null; + } + } + + + /** * @see org.cishell.service.conversion.Converter#getAlgorithmFactory() */ public AlgorithmFactory getAlgorithmFactory() { @@ -106,7 +144,7 @@ dm = alg.execute(); } else { throw new RuntimeException("Missing subconverter: " - + refs[i].getProperty(AlgorithmProperty.LABEL)); + + refs[i].getProperty(Constants.SERVICE_PID)); } } Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java 2006-07-24 22:32:30 UTC (rev 99) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java 2006-07-26 17:34:38 UTC (rev 100) @@ -16,23 +16,17 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; import java.util.List; import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; -import org.cishell.framework.datamodel.BasicDataModel; import org.cishell.framework.datamodel.DataModel; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; import org.osgi.framework.BundleContext; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; public class DataConversionServiceImpl implements DataConversionService, AlgorithmProperty { private BundleContext bContext; @@ -51,7 +45,8 @@ public Converter[] findConverters(String inFormat, String outFormat) { try { String filter = "(&("+IN_DATA+"="+inFormat+") " + - "("+OUT_DATA+"="+outFormat+"))"; + "("+OUT_DATA+"="+outFormat+")" + + "(!("+REMOTEABLE+"=*)))"; ServiceReference[] refs = bContext.getServiceReferences( AlgorithmFactory.class.getName(), filter); @@ -59,7 +54,7 @@ if (refs != null && refs.length > 0) { Converter[] converters = new Converter[refs.length]; for (int i=0; i < converters.length; i++) { - converters[i] = new ConverterImpl(bContext, new ServiceReference[]{refs[i]}); + converters[i] = new ConverterImpl(bContext, ciContext, new ServiceReference[]{refs[i]}); } return converters; @@ -67,7 +62,6 @@ return new Converter[0]; } } catch (InvalidSyntaxException e) { - getLog().log(LogService.LOG_ERROR, "Incorrect Syntax", e); throw new RuntimeException(e); } } @@ -80,63 +74,9 @@ return findConverters(inFormat, outFormat); } - public DataModel convert(DataModel inDM, String outFormat) { - String inFormat = inDM.getFormat(); - - Converter[] converters = new Converter[0]; - if (inFormat != null) { - if (inFormat.equals(outFormat)) return inDM; - - converters = findConverters(inFormat, outFormat); - } else if (inDM.getData() != null) { - //try to find a converter that will convert the java object to - //the correct outFormat - - inFormat = inDM.getData().getClass().getName(); - if (inFormat.equals(outFormat)) return inDM; - converters = findConverters(inFormat, outFormat); - - Class[] classes = inDM.getData().getClass().getClasses(); - - for (int i=0; i < classes.length && converters.length == 0; i++) { - inFormat = classes[i].getName(); - - if (inFormat.equals(outFormat)) return inDM; - - converters = findConverters(inFormat, outFormat); - } - } - - Object outData = null; - - if (converters.length > 0) { - DataModel[] dm = new DataModel[]{inDM}; - - AlgorithmFactory factory = converters[0].getAlgorithmFactory(); - Algorithm alg = factory.createAlgorithm(dm, new Hashtable(), ciContext); - - dm = alg.execute(); - - if (dm != null && dm.length > 0) { - outData = dm[0].getData(); - } - } - - if (outData != null) { - Dictionary props = inDM.getMetaData(); - Dictionary newProps = new Hashtable(); - - for (Enumeration e=props.keys(); e.hasMoreElements();) { - Object key = e.nextElement(); - newProps.put(key, props.get(key)); - } - - return new BasicDataModel(newProps, outData, outFormat); - } else { - return null; - } - } - + /** + * @see org.cishell.service.conversion.DataConversionService#findConverters(org.cishell.framework.datamodel.DataModel, java.lang.String) + */ public Converter[] findConverters(DataModel dm, String outFormat) { String format = dm.getFormat(); @@ -162,7 +102,21 @@ return (Converter[]) list.toArray(new Converter[0]); } - private LogService getLog() { - return (LogService)ciContext.getService(LogService.class.getName()); + /** + * @see org.cishell.service.conversion.DataConversionService#convert(org.cishell.framework.datamodel.DataModel, java.lang.String) + */ + public DataModel convert(DataModel inDM, String outFormat) { + String inFormat = inDM.getFormat(); + + if (inFormat != null && inFormat.equals(outFormat)) { + return inDM; + } + + Converter[] converters = findConverters(inDM, outFormat); + if (converters.length > 0) { + inDM = converters[0].convert(inDM); + } + + return inDM; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |