From: <hu...@us...> - 2007-07-02 16:12:01
|
Revision: 411 http://svn.sourceforge.net/cishell/?rev=411&view=rev Author: huangb Date: 2007-07-02 09:11:58 -0700 (Mon, 02 Jul 2007) Log Message: ----------- a small update, adjust log message layout in the console window Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2007-07-02 16:11:22 UTC (rev 410) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2007-07-02 16:11:58 UTC (rev 411) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Menu Manager Plug-in Bundle-SymbolicName: org.cishell.reference.gui.menumanager;singleton:=true -Bundle-Version: 0.5.0 +Bundle-Version: 0.6.0 Bundle-Activator: org.cishell.reference.gui.menumanager.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-07-02 16:11:22 UTC (rev 410) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-07-02 16:11:58 UTC (rev 411) @@ -116,7 +116,7 @@ String label = (String)ref.getProperty("label"); if (label != null){ acknowledgement.append("..........\n"+ - label+" was selected.\n\n"); + label+" was selected.\n"); } String authors = (String)ref.getProperty("authors"); if (authors != null) @@ -136,8 +136,9 @@ acknowledgement.append("Reference: "+reference+"\n"); String docu = (String)ref.getProperty("docu"); if (docu != null) - acknowledgement.append("Docu: "+docu); - logger.log(LogService.LOG_INFO, acknowledgement.toString()); + acknowledgement.append("Docu: "+docu+"\n"); + if(acknowledgement.length()>1) + logger.log(LogService.LOG_INFO, acknowledgement.toString()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2008-03-25 15:34:47
|
Revision: 697 http://cishell.svn.sourceforge.net/cishell/?rev=697&view=rev Author: bh2 Date: 2008-03-25 08:33:54 -0700 (Tue, 25 Mar 2008) Log Message: ----------- did simple updates to menumanager, but still needs to deal w/ parameters, better exception handling, and in/out data extension Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-25 15:25:26 UTC (rev 696) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-25 15:33:54 UTC (rev 697) @@ -2,19 +2,19 @@ Bundle-ManifestVersion: 2 Bundle-Name: Menu Manager Plug-in Bundle-SymbolicName: org.cishell.reference.gui.menumanager;singleton:=true -Bundle-Version: 0.6.0 +Bundle-Version: 1.0.0 Bundle-Activator: org.cishell.reference.gui.menumanager.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Eclipse-LazyStart: true -Import-Package: org.cishell.app.service.datamanager, - org.cishell.app.service.scheduler, - org.cishell.framework, - org.cishell.framework.algorithm, - org.cishell.framework.data, +Import-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.scheduler;version="1.0.0", + org.cishell.framework;version="1.0.0", + org.cishell.framework.algorithm;version="1.0.0", + org.cishell.framework.data;version="1.0.0", org.cishell.reference.gui.workspace, - org.cishell.service.conversion, - org.cishell.service.guibuilder, + org.cishell.service.conversion;version="1.0.0", + org.cishell.service.guibuilder;version="1.0.0", org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0" Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-25 15:25:26 UTC (rev 696) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-25 15:33:54 UTC (rev 697) @@ -29,11 +29,6 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; public class AlgorithmAction extends Action implements AlgorithmProperty, DataManagerListener { @@ -113,7 +108,7 @@ //adjust to log the whole acknowledgement in one block LogService logger = (LogService) ciContext.getService(LogService.class.getName()); StringBuffer acknowledgement = new StringBuffer(); - String label = (String)ref.getProperty("label"); + String label = (String)ref.getProperty(LABEL); if (label != null){ acknowledgement.append("..........\n"+ label+" was selected.\n"); @@ -121,22 +116,22 @@ String authors = (String)ref.getProperty("authors"); if (authors != null) acknowledgement.append("Author(s): "+authors+"\n"); - String implementers = (String)ref.getProperty("implementers"); + String implementers = (String)ref.getProperty(IMPLEMENTERS); if (implementers != null) acknowledgement.append("Implementer(s): "+implementers+"\n"); - String integrators = (String)ref.getProperty("integrators"); + String integrators = (String)ref.getProperty(INTEGRATORS); if (integrators != null) acknowledgement.append("Integrator(s): "+integrators+"\n"); - String reference = (String)ref.getProperty("reference"); - String reference_url = (String)ref.getProperty("reference_url"); + String reference = (String)ref.getProperty(REFERENCE); + String reference_url = (String)ref.getProperty(REFERENCE_URL); if (reference != null && reference_url != null ) acknowledgement.append("Reference: "+reference+ " ("+reference_url+")\n"); else if (reference != null && reference_url == null ) acknowledgement.append("Reference: "+reference+"\n"); - String docu = (String)ref.getProperty("docu"); + String docu = (String)ref.getProperty(DOCUMENTATION_URL); if (docu != null) - acknowledgement.append("Docu: "+docu+"\n"); + acknowledgement.append("Documentation: "+docu+"\n"); if(acknowledgement.length()>1) logger.log(LogService.LOG_INFO, acknowledgement.toString()); Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-25 15:25:26 UTC (rev 696) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-25 15:33:54 UTC (rev 697) @@ -110,7 +110,9 @@ } } - this.provider = factory.createParameters(data); + //FIXME: + //this.provider = factory.createParameters(data); + this.provider = null; String pid = (String)ref.getProperty(Constants.SERVICE_PID); this.parameters = new Hashtable(); @@ -218,12 +220,12 @@ && originalData.length == data.length) { for (int i=0; i < outData.length; i++) { if (outData[i] != null) { - Object parent = outData[i].getMetaData().get(DataProperty.PARENT); + Object parent = outData[i].getMetadata().get(DataProperty.PARENT); if (parent != null) { for (int j=0; j < data.length; i++) { if (parent == data[j]) { - outData[i].getMetaData().put(DataProperty.PARENT, + outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); break; } @@ -243,8 +245,8 @@ for (int i=0; i < outData.length; i++) { //if they don't have a parent set already then we set one if (outData[i] != null && - outData[i].getMetaData().get(DataProperty.PARENT) == null) { - outData[i].getMetaData().put(DataProperty.PARENT, originalData[0]); + outData[i].getMetadata().get(DataProperty.PARENT) == null) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2008-03-25 16:24:06
|
Revision: 701 http://cishell.svn.sourceforge.net/cishell/?rev=701&view=rev Author: bh2 Date: 2008-03-25 09:23:43 -0700 (Tue, 25 Mar 2008) Log Message: ----------- 'properly' handling new metatype id stuff and parameter mutators. Still need to add in support for in/out data exceptions and other badly needed refactorings. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-25 15:53:46 UTC (rev 700) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-25 16:23:43 UTC (rev 701) @@ -14,6 +14,7 @@ org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", org.cishell.reference.gui.workspace, + org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", org.osgi.service.log;version="1.3.0", Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-25 15:53:46 UTC (rev 700) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-25 16:23:43 UTC (rev 701) @@ -12,6 +12,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; /** * The activator class controls the plug-in life cycle @@ -24,6 +25,8 @@ // The shared instance private static Activator plugin; + private static BundleContext context; + MenuAdapter menuAdapter; /** @@ -39,6 +42,8 @@ public void start(BundleContext context) throws Exception { super.start(context); + this.context = context; + while (getWorkbench() == null) { Thread.sleep(500); } @@ -77,6 +82,16 @@ super.stop(context); } + + public static Object getService(String service_pid) { + ServiceReference ref = context.getServiceReference(service_pid); + + if (ref != null) { + return context.getService(ref); + } else { + return null; + } + } /** * Returns the shared instance Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-25 15:53:46 UTC (rev 700) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-25 16:23:43 UTC (rev 701) @@ -27,10 +27,13 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.DataValidator; +import org.cishell.framework.algorithm.ParameterMutator; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; +import org.cishell.reference.gui.menumanager.Activator; +import org.cishell.reference.service.metatype.BasicMetaTypeProvider; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; @@ -39,6 +42,7 @@ import org.osgi.service.log.LogService; import org.osgi.service.metatype.AttributeDefinition; import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; @@ -110,11 +114,34 @@ } } - //FIXME: - //this.provider = factory.createParameters(data); - this.provider = null; String pid = (String)ref.getProperty(Constants.SERVICE_PID); + String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); + if (metatype_pid == null) { + metatype_pid = pid; + } + + this.provider = null; + + MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + if (metaTypeService != null) { + provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + } + + if (factory instanceof ParameterMutator && provider != null) { + try { + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); + + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + + if (ocd != null) { + provider = new BasicMetaTypeProvider(ocd); + } + } catch (IllegalArgumentException e) { + log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + } + } + this.parameters = new Hashtable(); if (provider != null) { this.parameters = builder.createGUIandWait(pid, provider); @@ -167,6 +194,15 @@ } } + protected void log(int logLevel, String message) { + LogService log = (LogService) Activator.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message); + } else { + System.out.println(message); + } + } + protected void printParameters() { LogService logger = getLogService(); setupIdToLabelMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-04-02 18:12:36
|
Revision: 757 http://cishell.svn.sourceforge.net/cishell/?rev=757&view=rev Author: mwlinnem Date: 2008-04-02 11:12:33 -0700 (Wed, 02 Apr 2008) Log Message: ----------- Added user prefs stuff to main branch (includes major refactoring). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-04-02 18:12:33 UTC (rev 757) @@ -12,9 +12,11 @@ org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", + org.cishell.framework.userprefs;version="1.0.0", org.cishell.reference.gui.workspace, org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", + org.osgi.service.cm;version="1.2.0", org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0" Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-04-02 18:12:33 UTC (rev 757) @@ -28,6 +28,7 @@ import org.eclipse.jface.action.Action; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.log.LogService; @@ -39,10 +40,14 @@ protected Data[] originalData; protected Converter[][] converters; - public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { + protected ConfigurationAdmin ca; + + //ConfigurationAdmin can be null + public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, ConfigurationAdmin ca) { this.ref = ref; this.ciContext = ciContext; this.bContext = bContext; + this.ca = ca; setText((String)ref.getProperty(LABEL)); setToolTipText((String)ref.getProperty(AlgorithmProperty.DESCRIPTION)); @@ -92,7 +97,7 @@ printAlgorithmInformation(); - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters), ref); + scheduler.schedule(new AlgorithmWrapper(ref, ciContext, bContext, originalData, data, converters, ca), ref); } catch (Throwable e) { e.printStackTrace(); } @@ -150,7 +155,7 @@ Data datum = (Data) dataSet.get(j); if (datum != null) { - if (isAsignableFrom(inData[i], datum)) { + if (isAssignableFrom(inData[i], datum)) { dataSet.remove(j); data[i] = datum; converters[i] = null; @@ -185,7 +190,7 @@ setEnabled(data != null); //&& isValid()); } - private boolean isAsignableFrom(String type, Data datum) { + private boolean isAssignableFrom(String type, Data datum) { Object data = datum.getData(); boolean assignable = false; Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-04-02 18:12:33 UTC (rev 757) @@ -13,6 +13,7 @@ * ***************************************************************************/ package org.cishell.reference.gui.menumanager.menu; +import java.io.IOException; import java.util.ArrayList; import java.util.Dictionary; import java.util.Enumeration; @@ -24,7 +25,6 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.DataValidator; @@ -33,302 +33,359 @@ import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; +import org.cishell.framework.userprefs.UserPrefsProperty; import org.cishell.reference.gui.menumanager.Activator; +import org.cishell.reference.gui.menumanager.menu.metatypewrapper.ParamMetaTypeProvider; import org.cishell.reference.service.metatype.BasicMetaTypeProvider; -import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.log.LogService; import org.osgi.service.metatype.AttributeDefinition; import org.osgi.service.metatype.MetaTypeProvider; import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; - public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { - protected ServiceReference ref; - protected BundleContext bContext; - protected CIShellContext ciContext; - protected Data[] originalData; - protected Data[] data; - protected Converter[][] converters; - protected Dictionary parameters; - protected Map idToLabelMap; - protected MetaTypeProvider provider; - protected ProgressMonitor progressMonitor; - protected Algorithm algorithm; - - public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, - CIShellContext ciContext, Data[] originalData, Data[] data, - Converter[][] converters) { - this.ref = ref; - this.bContext = bContext; - this.ciContext = ciContext; - this.originalData = originalData; - this.data = data; - this.converters = converters; + protected ServiceReference algFactoryRef; + protected BundleContext bContext; + protected CIShellContext ciContext; + protected Data[] originalData; + protected Data[] convertableData; + protected Converter[][] converters; + protected ProgressMonitor progressMonitor; - this.idToLabelMap = new HashMap(); - this.progressMonitor = null; - } + protected ConfigurationAdmin ca; + protected GUIBuilderService builder; + protected DataManagerService dataManager; - /** - * @see org.cishell.framework.algorithm.Algorithm#execute() - */ - public Data[] execute() { - for (int i=0; i < data.length; i++) { - if (converters[i] != null) { - try { - data[i] = converters[i][0].convert(data[i]); - } catch (ConversionException e) { - log(LogService.LOG_ERROR,"The conversion of data to give" + - " the algorithm failed for this reason: "+e.getMessage(), e); - return null; - } + // ConfigurationAdmin may be null + public AlgorithmWrapper(ServiceReference ref, CIShellContext ciContext, BundleContext bContext, + Data[] originalData, Data[] data, Converter[][] converters, ConfigurationAdmin ca) { + this.algFactoryRef = ref; + this.bContext = bContext; + this.ciContext = ciContext; + this.originalData = originalData; + this.convertableData = data; + this.converters = converters; - if (data[i] == null && i < (data.length - 1)) { - log(LogService.LOG_ERROR, "The converter: " + - converters[i].getClass().getName() + - " returned a null result where data was expected when" + - " converting the data to give the algorithm."); - return null; - } - converters[i] = null; - } - } - - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - - AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); - - if (factory instanceof DataValidator) { - String validation = ((DataValidator) factory).validate(data); - - if (validation != null && validation.length() > 0) { - String label = (String) ref.getProperty(LABEL); - if (label == null) { - label = "Algorithm"; - } - - log(LogService.LOG_ERROR,"INVALID DATA: The data given to \""+label+"\" is incompatible for this reason: "+validation); - return null; - } - } - - String pid = (String)ref.getProperty(Constants.SERVICE_PID); - - String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); - if (metatype_pid == null) { - metatype_pid = pid; - } + this.ca = ca; + this.progressMonitor = null; + this.builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + this.dataManager = (DataManagerService) bContext.getService(bContext + .getServiceReference(DataManagerService.class.getName())); + } - this.provider = null; - - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); - if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); - } + /** + * @see org.cishell.framework.algorithm.Algorithm#execute() + */ + public Data[] execute() { + try { + // prepare to run the algorithm + Data[] data = convertDataToRequiredFormat(this.convertableData, this.converters); + AlgorithmFactory algFactory = (AlgorithmFactory) bContext.getService(algFactoryRef); + boolean inputIsValid = testDataValidityIfPossible(algFactory, data); + if (!inputIsValid) return null; - if (factory instanceof ParameterMutator && provider != null) { - try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); - - ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); - - if (ocd != null) { - provider = new BasicMetaTypeProvider(ocd); - } - } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); - } - } - - this.parameters = new Hashtable(); - if (provider != null) { - this.parameters = builder.createGUIandWait(metatype_pid, provider); - } - - //check to see if the user cancelled the operation - if(this.parameters == null) { - return null; - } - - algorithm = factory.createAlgorithm(data, parameters, ciContext); - - printParameters(); - - if (progressMonitor != null && algorithm instanceof ProgressTrackable) { - ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); - } - - Data[] outData = null; - try { - outData = algorithm.execute(); - } catch (AlgorithmExecutionException e) { - log(LogService.LOG_ERROR, - "The Algorithm: \""+ref.getProperty(AlgorithmProperty.LABEL)+ - "\" had an error while executing: "+e.getMessage()); - } catch (RuntimeException e) { - builder.showError("Error!", "An unexpected exception occurred while " - +"executing \""+ref.getProperty(AlgorithmProperty.LABEL)+".\"", e); - } - - if (outData != null) { - DataManagerService dataManager = (DataManagerService) - bContext.getService(bContext.getServiceReference( - DataManagerService.class.getName())); - - doParentage(outData); - - List goodData = new ArrayList(); - for (int i=0; i < outData.length; i++) { - if (outData[i] != null) { - goodData.add(outData[i]); - } - } - - outData = (Data[]) goodData.toArray(new Data[0]); - - if (outData.length != 0) { - dataManager.setSelectedData(outData); - } - } - - return outData; - } - - protected void log(int logLevel, String message) { - LogService log = (LogService) Activator.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message); - } else { - System.out.println(message); - } - } + // create algorithm parameters - protected void log(int logLevel, String message, Throwable exception) { - LogService log = (LogService) Activator.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message, exception); - } else { - System.out.println(message); - exception.printStackTrace(); - } - } - - protected void printParameters() { - LogService logger = getLogService(); - setupIdToLabelMap(); - - if (logger != null) { - if (!this.parameters.isEmpty()) { - //adjust to log all input parameters in one block - StringBuffer inputParams = new StringBuffer("\n"+"Input Parameters:"); - - for (Enumeration e = this.parameters.keys(); e - .hasMoreElements();) { - String key = (String) e.nextElement(); - Object value = this.parameters.get(key); - - key = (String) idToLabelMap.get(key); - inputParams.append("\n"+key+": "+value); - - } - logger.log(LogService.LOG_INFO, inputParams.toString()); - } - } - } - - protected void setupIdToLabelMap() { - if (provider != null) { - ObjectClassDefinition ocd = null; - try { - String pid = (String) ref.getProperty(Constants.SERVICE_PID); - ocd = provider.getObjectClassDefinition(pid, null); - - if (ocd != null) { - AttributeDefinition[] attr = - ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - - for (int i=0; i < attr.length; i++) { - String id = attr[i].getID(); - String label = attr[i].getName(); - - idToLabelMap.put(id, label); - } - } - } catch (IllegalArgumentException e) {} - } - } - - //only does anything if parentage=default so far... - protected void doParentage(Data[] outData) { - //make sure the parent set is the original Data and not the - //converted data... - if (outData != null && data != null && originalData != null - && originalData.length == data.length) { - for (int i=0; i < outData.length; i++) { - if (outData[i] != null) { - Object parent = outData[i].getMetadata().get(DataProperty.PARENT); - - if (parent != null) { - for (int j=0; j < data.length; i++) { - if (parent == data[j]) { - outData[i].getMetadata().put(DataProperty.PARENT, - originalData[j]); - break; - } - } - } - } - } - } - - //check and act on parentage settings - String parentage = (String)ref.getProperty("parentage"); - if (parentage != null) { - parentage = parentage.trim(); - if (parentage.equalsIgnoreCase("default")) { - if (originalData != null && originalData.length > 0 && originalData[0] != null) { - - for (int i=0; i < outData.length; i++) { - //if they don't have a parent set already then we set one - if (outData[i] != null && - outData[i].getMetadata().get(DataProperty.PARENT) == null) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); - } - } - } - } - } - } - - private LogService getLogService() { + MetaTypeProvider parameterSetupInfo = obtainParameterSetupInfo(algFactory, data); + Dictionary parameters = createParameters(parameterSetupInfo); + printParameters(parameters, parameterSetupInfo); + + // create the algorithm + + Algorithm algorithm = algFactory.createAlgorithm(data, parameters, ciContext); + trackAlgorithmProgressIfPossible(algorithm); + + // execute the algorithm + + Data[] rawOutData = algorithm.execute(); + + // return the algorithm's output + + Data[] processedOutData = processOutData(rawOutData); + return processedOutData; + + } catch (Throwable e) { + // show any errors to the user + + showGenericExecutionError(e); + return new Data[0]; + } + } + + // should return null if algorithm is not progress trackable + public ProgressMonitor getProgressMonitor() { + return progressMonitor; + } + + public void setProgressMonitor(ProgressMonitor monitor) { + progressMonitor = monitor; + } + + protected Data[] convertDataToRequiredFormat(Data[] data, Converter[][] converters) throws Exception { + // convert data into the in_data format of the algorithm we are trying to run + for (int i = 0; i < data.length; i++) { + if (converters[i] != null) { + // WARNING: arbitrarily chooses first converter out of a list of possible converters + data[i] = converters[i][0].convert(data[i]); + if (data[i] == null && i < (data.length - 1)) { + Exception e = new Exception("The converter " + converters[i].getClass().getName() + + " returned a null result where data was expected."); + throw e; + } + converters[i] = null; + } + } + + return data; + } + + protected boolean testDataValidityIfPossible(AlgorithmFactory algFactory, Data[] dataInQuestion) { + if (algFactory instanceof DataValidator) { + String validation = ((DataValidator) algFactory).validate(dataInQuestion); + + if (validation != null && validation.length() > 0) { + String label = (String) algFactoryRef.getProperty(LABEL); + if (label == null) { + label = "Algorithm"; + } + + builder.showError("Invalid Data", "The data given to \"" + label + "\" is incompatible for this reason: " + + validation, (String) null); + return false; + } + return true; + } else { + //counts as valid if there is no validator available. + return true; + } + } + + protected MetaTypeProvider obtainParameterSetupInfo(AlgorithmFactory algFactory, Data[] data) { + + MetaTypeProvider provider = null; + + // first, get the standard parameter setup info for the algorithm factory. + + MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + if (metaTypeService != null) { + provider = metaTypeService.getMetaTypeInformation(algFactoryRef.getBundle()); + } + + // if the algorithm factory wants to mutate the parameter setup info, allow it to. + if (algFactory instanceof ParameterMutator && provider != null) { + String parameterPID = determineParameterPID(algFactoryRef, provider); + try { + ObjectClassDefinition ocd = provider.getObjectClassDefinition(parameterPID, null); + + ocd = ((ParameterMutator) algFactory).mutateParameters(data, ocd); + + if (ocd != null) { + provider = new BasicMetaTypeProvider(ocd); + } + } catch (IllegalArgumentException e) { + LogService logger = getLogService(); + logger.log(LogService.LOG_DEBUG, algFactoryRef.getProperty(Constants.SERVICE_PID) + + " has an invalid metatype parameter id: " + parameterPID); + } + } + + // wrap the parameter setup info so that default parameter values + // specified in the user preference service are filled in. + + if (provider != null) { + provider = wrapProvider(this.algFactoryRef, provider); + } + + return provider; + } + + protected Dictionary createParameters(MetaTypeProvider parameterSetupInfo) { + // ask the user to specify the values for algorithm's parameters + String parameterPID = determineParameterPID(algFactoryRef, parameterSetupInfo); + Dictionary parameters = new Hashtable(); + if (parameterSetupInfo != null) { + parameters = builder.createGUIandWait(parameterPID, parameterSetupInfo); + } + return parameters; + } + + protected void printParameters(Dictionary parameters, MetaTypeProvider parameterSetupInfo) { + LogService logger = getLogService(); + Map idToLabelMap = createIdToLabelMap(parameterSetupInfo); + + if (logger != null) { + if (parameters.isEmpty()) { + // adjust to log all input parameters in one block + StringBuffer inputParams = new StringBuffer("\n" + "Input Parameters:"); + + for (Enumeration e = parameters.keys(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + Object value = parameters.get(key); + + key = (String) idToLabelMap.get(key); + inputParams.append("\n" + key + ": " + value); + + } + logger.log(LogService.LOG_INFO, inputParams.toString()); + } + } + } + + protected void trackAlgorithmProgressIfPossible(Algorithm algorithm) { + if (algorithm instanceof ProgressTrackable) { + ((ProgressTrackable) algorithm).setProgressMonitor(progressMonitor); + } + } + + protected Data[] processOutData(Data[] rawOutData) { + if (rawOutData != null) { + doParentage(rawOutData); + List goodData = new ArrayList(); + for (int i = 0; i < rawOutData.length; i++) { + if (rawOutData[i] != null) { + goodData.add(rawOutData[i]); + } + } + + Data[] processedOutData = (Data[]) goodData.toArray(new Data[goodData.size()]); + if (rawOutData.length != 0) { + dataManager.setSelectedData(rawOutData); + } + + return processedOutData; + } else { + return null; + } + } + + // wrap the provider to provide special functionality, such as overriding default values of attributes through + // preferences. + protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { + if (ca != null && hasParamDefaultPreferences(algRef)) { + String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); + String paramOverrideConfPID = standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; + try { + Configuration defaultParamValueOverrider = ca.getConfiguration(paramOverrideConfPID, null); + Dictionary defaultParamOverriderDict = defaultParamValueOverrider.getProperties(); + MetaTypeProvider wrappedProvider = new ParamMetaTypeProvider(unwrappedProvider, + defaultParamOverriderDict); + return wrappedProvider; + } catch (IOException e) { + return unwrappedProvider; + } + } else { + } + + return unwrappedProvider; + } + + protected String determineParameterPID(ServiceReference ref, MetaTypeProvider provider) { + String overridePID = (String) ref.getProperty(AlgorithmProperty.PARAMETERS_PID); + if (overridePID != null) { + return overridePID; + } else { + return (String) ref.getProperty(Constants.SERVICE_PID); + } + } + + protected Map createIdToLabelMap(MetaTypeProvider parameterSetupInfo) { + Map idToLabelMap = new HashMap(); + if (parameterSetupInfo != null) { + ObjectClassDefinition ocd = null; + try { + String parameterPID = determineParameterPID(algFactoryRef, parameterSetupInfo); + ocd = parameterSetupInfo.getObjectClassDefinition(parameterPID, null); + + if (ocd != null) { + AttributeDefinition[] attr = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + + for (int i = 0; i < attr.length; i++) { + String id = attr[i].getID(); + String label = attr[i].getName(); + + idToLabelMap.put(id, label); + } + } + } catch (IllegalArgumentException e) { + } + } + + return idToLabelMap; + } + + // only does anything if parentage=default so far... + protected void doParentage(Data[] outData) { + // make sure the parent set is the original Data and not the + // converted data... + if (outData != null && convertableData != null && originalData != null + && originalData.length == convertableData.length) { + for (int i = 0; i < outData.length; i++) { + if (outData[i] != null) { + Object parent = outData[i].getMetadata().get(DataProperty.PARENT); + + if (parent != null) { + for (int j = 0; j < convertableData.length; i++) { + if (parent == convertableData[j]) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); + break; + } + } + } + } + } + } + + // check and act on parentage settings + String parentage = (String) algFactoryRef.getProperty("parentage"); + if (parentage != null) { + parentage = parentage.trim(); + if (parentage.equalsIgnoreCase("default")) { + if (originalData != null && originalData.length > 0 && originalData[0] != null) { + + for (int i = 0; i < outData.length; i++) { + // if they don't have a parent set already then we set one + if (outData[i] != null && outData[i].getMetadata().get(DataProperty.PARENT) == null) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); + } + } + } + } + } + } + + protected LogService getLogService() { ServiceReference serviceReference = bContext.getServiceReference(DataManagerService.class.getName()); LogService log = null; - + if (serviceReference != null) { - log = (LogService) bContext.getService( - bContext.getServiceReference(LogService.class.getName())); + log = (LogService) bContext.getService(bContext.getServiceReference(LogService.class.getName())); } - + return log; } - public ProgressMonitor getProgressMonitor() { - if (algorithm instanceof ProgressTrackable) { - return progressMonitor; + protected boolean hasParamDefaultPreferences(ServiceReference algRef) { + String prefsToPublish = (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); + if (prefsToPublish == null) { + return true; } - else { - return null; + + if (prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE)) { + return true; + } else { + return false; } } - public void setProgressMonitor(ProgressMonitor monitor) { - progressMonitor = monitor; + protected void showGenericExecutionError(Throwable e) { + builder.showError("Error!", "The Algorithm: \"" + algFactoryRef.getProperty(AlgorithmProperty.LABEL) + + "\" had an error while executing.", e); } } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-04-02 18:12:33 UTC (rev 757) @@ -42,6 +42,7 @@ import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.log.LogService; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -60,6 +61,8 @@ private Map itemToParentMap; private ContextListener listener; private IWorkbenchWindow window; + + private ConfigurationAdmin ca; /* * This map holds a pid as a key and the corresponding * ServiceReference as a value. @@ -113,8 +116,24 @@ } catch (InvalidSyntaxException e) { getLog().log(LogService.LOG_DEBUG, "Invalid Syntax", e); } + + attemptToObtainConfigurationAdmin(bContext); } + private void attemptToObtainConfigurationAdmin(BundleContext bContext) { + if (ca == null) { + try { + ServiceReference caRef = bContext.getServiceReference(ConfigurationAdmin.class.getName()); + if (caRef != null) { + ConfigurationAdmin ca = (ConfigurationAdmin) bContext.getService(caRef); + this.ca = ca; //may or may not be null, but if it is null, its the same as if we never tried to set it (that is to say, ok) + } + } catch (NoClassDefFoundError e) { + //do nothing + } + } + } + /* * This method scans all service bundles. If a bundle specifies * menu_path, get service.pid of this bundle (key), let the service @@ -259,7 +278,8 @@ ServiceReference ref = (ServiceReference) pidToServiceReferenceMapCopy. get(pid.toLowerCase().trim()); pidToServiceReferenceMap.remove(pid.toLowerCase().trim()); - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); + attemptToObtainConfigurationAdmin(bContext); + AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca); action.setId(getItemID(ref)); action.setText(menuName); parentMenuBar.add(action); @@ -345,7 +365,8 @@ String[] items = (path == null) ? null : path.split("/"); IMenuManager menu = null; if (items != null && items.length > 1) { - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); + attemptToObtainConfigurationAdmin(bContext); + AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca); action.setId(getItemID(ref)); IMenuManager targetMenu = menuBar; Copied: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper (from rev 756, branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper) Deleted: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java 2008-04-02 18:12:33 UTC (rev 757) @@ -1,62 +0,0 @@ -package org.cishell.reference.gui.menumanager.menu.metatypewrapper; - -import org.osgi.service.log.LogService; -import org.osgi.service.metatype.AttributeDefinition; - -public class ParamAD implements AttributeDefinition { - - private LogService log; - - private AttributeDefinition realAD; - - private String[] defaultValueOverride; - - public ParamAD(LogService log, AttributeDefinition realAD, String[] defaultValueOverride) { - this.log = log; - - this.realAD = realAD; - - this.defaultValueOverride = defaultValueOverride; - } - - public int getCardinality() { - return this.realAD.getCardinality(); - } - - public String[] getDefaultValue() { - if (defaultValueOverride != null) { - return defaultValueOverride; - } else { - return realAD.getDefaultValue(); - } - } - - public String getDescription() { - return this.realAD.getDescription(); - } - - public String getID() { - return this.realAD.getID(); - } - - public String getName() { - return this.realAD.getName(); - } - - public String[] getOptionLabels() { - return this.realAD.getOptionLabels(); - } - - public String[] getOptionValues() { - return this.realAD.getOptionValues(); - } - - public int getType() { - return this.realAD.getType(); - } - - public String validate(String value) { - return this.realAD.validate(value); - } - -} Copied: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java (from rev 756, branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java 2008-04-02 18:12:33 UTC (rev 757) @@ -0,0 +1,62 @@ +package org.cishell.reference.gui.menumanager.menu.metatypewrapper; + +import org.osgi.service.log.LogService; +import org.osgi.service.metatype.AttributeDefinition; + +public class ParamAD implements AttributeDefinition { + + private LogService log; + + private AttributeDefinition realAD; + + private String[] defaultValueOverride; + + public ParamAD(LogService log, AttributeDefinition realAD, String[] defaultValueOverride) { + this.log = log; + + this.realAD = realAD; + + this.defaultValueOverride = defaultValueOverride; + } + + public int getCardinality() { + return this.realAD.getCardinality(); + } + + public String[] getDefaultValue() { + if (defaultValueOverride != null) { + return defaultValueOverride; + } else { + return realAD.getDefaultValue(); + } + } + + public String getDescription() { + return this.realAD.getDescription(); + } + + public String getID() { + return this.realAD.getID(); + } + + public String getName() { + return this.realAD.getName(); + } + + public String[] getOptionLabels() { + return this.realAD.getOptionLabels(); + } + + public String[] getOptionValues() { + return this.realAD.getOptionValues(); + } + + public int getType() { + return this.realAD.getType(); + } + + public String validate(String value) { + return this.realAD.validate(value); + } + +} Deleted: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java 2008-04-02 18:12:33 UTC (rev 757) @@ -1,33 +0,0 @@ -package org.cishell.reference.gui.menumanager.menu.metatypewrapper; - -import java.util.Dictionary; - -import org.osgi.service.metatype.MetaTypeProvider; -import org.osgi.service.metatype.ObjectClassDefinition; - -public class ParamMetaTypeProvider implements MetaTypeProvider { - - private MetaTypeProvider realMTP; - - private Dictionary defaultOverrider; - - public ParamMetaTypeProvider(MetaTypeProvider realMTP, Dictionary defaultOverrider) { - this.realMTP = realMTP; - this.defaultOverrider = defaultOverrider; - } - - public String[] getLocales() { - return this.realMTP.getLocales(); - } - - public ObjectClassDefinition getObjectClassDefinition(String id, - String locale) { - ObjectClassDefinition ocd = realMTP.getObjectClassDefinition(id, locale); - if (ocd != null) { - return new ParamOCD(realMTP.getObjectClassDefinition(id, locale), defaultOverrider); - } else { - return null; - } - } - -} Copied: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java (from rev 756, branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamMetaTypeProvider.java 2008-04-02 18:12:33 UTC (rev 757) @@ -0,0 +1,33 @@ +package org.cishell.reference.gui.menumanager.menu.metatypewrapper; + +import java.util.Dictionary; + +import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.ObjectClassDefinition; + +public class ParamMetaTypeProvider implements MetaTypeProvider { + + private MetaTypeProvider realMTP; + + private Dictionary defaultOverrider; + + public ParamMetaTypeProvider(MetaTypeProvider realMTP, Dictionary defaultOverrider) { + this.realMTP = realMTP; + this.defaultOverrider = defaultOverrider; + } + + public String[] getLocales() { + return this.realMTP.getLocales(); + } + + public ObjectClassDefinition getObjectClassDefinition(String id, + String locale) { + ObjectClassDefinition ocd = realMTP.getObjectClassDefinition(id, locale); + if (ocd != null) { + return new ParamOCD(realMTP.getObjectClassDefinition(id, locale), defaultOverrider); + } else { + return null; + } + } + +} Deleted: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java 2008-04-02 18:06:52 UTC (rev 756) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java 2008-04-02 18:12:33 UTC (rev 757) @@ -1,77 +0,0 @@ -package org.cishell.reference.gui.menumanager.menu.metatypewrapper; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Dictionary; - -import org.osgi.service.log.LogService; -import org.osgi.service.metatype.AttributeDefinition; -import org.osgi.service.metatype.ObjectClassDefinition; - -public class ParamOCD implements ObjectClassDefinition { - - private ObjectClassDefinition realOCD; - private ParamAD[] wrappedADs; - - private LogService log; - - private Dictionary defaultOverrider; - - public ParamOCD(ObjectClassDefinition realOCD, Dictionary defaultOverrider) { - this.realOCD = realOCD; - this.defaultOverrider = defaultOverrider; - - //TODO: don't always return all attributeDefinitions, regardless of filter - this.wrappedADs = wrapAttributeDefinitions(realOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)); - } - - private ParamAD[] wrapAttributeDefinitions(AttributeDefinition[] realAttributeDefinitions) { - ParamAD[] wrappedADs = new ParamAD[realAttributeDefinitions.length]; - - for (int i = 0; i < realAttributeDefinitions.length; i++) { - AttributeDefinition realAD = realAttributeDefinitions[i]; - - String[] defaultOverrideValue = getDefaultOverrideValue(realAD.getID(), defaultOverrider); - - ParamAD wrappedAD = new ParamAD(this.log, realAD, defaultOverrideValue); - - wrappedADs[i] = wrappedAD; - } - - return wrappedADs; - } - - private String[] getDefaultOverrideValue(String overrideKey, Dictionary defaultOverrider) { - if (defaultOverrider != null) { - String defaultOverrideValue = (String) defaultOverrider.get(overrideKey); - if (defaultOverrideValue != null) { - return new String[]{defaultOverrideValue}; - } else { - return null; - } - } else { - return null; - } - } - - public AttributeDefinition[] getAttributeDefinitions(int filter) { - return wrappedADs; - } - - public String getDescription() { - return this.realOCD.getDescription(); - } - - public String getID() { - return this.realOCD.getID(); - } - - public InputStream getIcon(int size) throws IOException { - return this.realOCD.getIcon(size); - } - - public String getName() { - return this.realOCD.getName(); - } - -} Copied: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java (from rev 756, branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamOCD.java 2008-04-02 18:12:33 UTC (rev 757) @@ -0,0 +1,77 @@ +package org.cishell.reference.gui.menumanager.menu.metatypewrapper; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Dictionary; + +import org.osgi.service.log.LogService; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.ObjectClassDefinition; + +public class ParamOCD implements ObjectClassDefinition { + + private ObjectClassDefinition realOCD; + private ParamAD[] wrappedADs; + + private LogService log; + + private Dictionary defaultOverrider; + + public ParamOCD(ObjectClassDefinition realOCD, Dictionary defaultOverrider) { + this.realOCD = realOCD; + this.defaultOverrider = defaultOverrider; + + //TODO: don't always return all attributeDefinitions, regardless of filter + this.wrappedADs = wrapAttributeDefinitions(realOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)); + } + + private ParamAD[] wrapAttributeDefinitions(AttributeDefinition[] realAttributeDefinitions) { + ParamAD[] wrappedADs = new ParamAD[realAttributeDefinitions.length]; + + for (int i = 0; i < realAttributeDefinitions.length; i++) { + AttributeDefinition realAD = realAttributeDefinitions[i]; + + String[] defaultOverrideValue = getDefaultOverrideValue(realAD.getID(), defaultOverrider); + + ParamAD wrappedAD = new ParamAD(this.log, realAD, defaultOverrideValue); + + wrappedADs[i] = wrappedAD; + } + + return wrappedADs; + } + + private String[] getDefaultOverrideValue(String overrideKey, Dictionary defaultOverrider) { + if (defaultOverrider != null) { + String defaultOverrideValue = (String) defaultOverrider.get(overrideKey); + if (defaultOverrideValue != null) { + return new String[]{defaultOverrideValue}; + } else { + return null; + } + } else { + return null; + } + } + + public AttributeDefinition[] getAttributeDefinitions(int filter) { + return wrappedADs; + } + + public String getDescription() { + return this.realOCD.getDescription(); + } + + public String getID() { + return this.realOCD.getID(); + } + + public InputStream getIcon(int size) throws IOException { + return this.realOCD.getIcon(size); + } + + public String getName() { + return this.realOCD.getName(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |