@Override public Object clone(){ return new VersionProperty(myName, myNumber); } }
public static <Conf,Param> SingleServiceListener<ConfigurationWriter<Conf,Param>> createWriterServiceListener(BundleContext context, Class<Conf> configClass, Class<Param> paramClass, VersionProperty configFormat, String serviceFilter){ Properties props = new Properties(); props.put(Constants.CONFIG_FORMAT_VERSION, configFormat.toString()); props.put(Constants.CONFIG_CLASS, configClass.getName()); props.put(Constants.CONFIG_PARAM_CLASS, paramClass.getName()); String writerFilter = OSGiUtils.createServiceFilter(props); if(serviceFilter != null && !serviceFilter.isEmpty()){ writerFilter = "(&"+writerFilter+"("+serviceFilter+"))"; } return new SingleServiceListener( ConfigurationWriter.class, context, serviceFilter); } }
/** * Set the version name * @param name new version name */ public void setName(String name){ if(name == null){ throw new NullPointerException(); } String old = myName; myName = name; firePropertyChange(PROP_NAME, old, myName); }
"Unable to find ServiceFactories matching version: " + "{0}, class: {1}.", new Object[]{serviceVersion.display(), serviceClass.getName()}); return null; "Unable to find ServiceLoader matching configFormat: " + "{0}, config class: {1}, param class: {2}.", new Object[]{configFormat.display(), configClass.getName(), paramClass.getName()});
private static OSGiComponent launchJointGroupConfig( BundleContext context, File file, String paramId){ Properties props = new Properties(); props.put(Constants.CONFIG_PARAM_ID, paramId); props.put(Constants.CONFIG_FORMAT_VERSION, RobotJointGroupConfigXMLReader.VERSION.toString()); ServiceLifecycleProvider lifecycle = new SimpleLifecycle(file, File.class, props); OSGiComponent paramComp = new OSGiComponent(context, lifecycle); paramComp.start(); return paramComp; }
/** * Set the version number * @param num new version number */ public void setNumber(String num){ if(num == null){ throw new NullPointerException(); } String old = myNumber; myNumber = num; firePropertyChange(PROP_NUMBER, old, myNumber); }
public static ServiceRegistration registerAddOnDriver( BundleContext context, ServiceAddOnDriver driver, Properties props){ Dictionary<String, Object> propTable = new Hashtable<String, Object>(); if(context == null || driver == null){ throw new NullPointerException(); } if(props != null){ for(Object prop: props.keySet()) { propTable.put(prop.toString(), props.get(prop)); } } propTable.put(Constants.SERVICE_VERSION, driver.getServiceVersion().toString()); propTable.put(Constants.CONFIG_FORMAT_VERSION, driver.getConfigurationFormat().toString()); ServiceRegistration reg = context.registerService( ServiceAddOnDriver.class.getName(), driver, propTable); if(reg == null){ theLogger.log(Level.WARNING, "Unknown error occured while registering " + "ServiceConfigurationWriter."); }else{ theLogger.log(Level.INFO, "ServiceAddOnDriver registered successfully."); } return reg; }
/** * Returns a XML node for the given VersionProperty. * @param version VersionProperty to write * @param type type attribute for the VersionProperty * @return XML node for the given VersionProperty */ public static ConfigurationNode writeVersion(VersionProperty version, String type){ ConfigurationNode node = node(XML_VERSION); node.addAttribute(node(XML_VERSION_TYPE, type)); node.addChild(node(XML_VERSION_NAME, version.getName())); node.addChild(node(XML_VERSION_NUMBER, version.getNumber())); return node; }
private static VersionProperty getVersion(Property p) throws IllegalAccessException, InvocationTargetException{ if(p == null){ return new VersionProperty("", ""); } Object val = p.getValue(); if(val instanceof VersionProperty){ return (VersionProperty)val; } return new VersionProperty("", ""); } }
private static OSGiComponent launchRobotConfig( BundleContext context, File file, String paramId){ Properties props = new Properties(); props.put(Constants.CONFIG_PARAM_ID, paramId); props.put(Constants.CONFIG_FORMAT_VERSION, RobotConfigXMLReader.VERSION.toString()); ServiceLifecycleProvider lifecycle = new SimpleLifecycle(file, File.class, props); OSGiComponent paramComp = new OSGiComponent(context, lifecycle); paramComp.start(); return paramComp; } }
/** * Writes a VersionProperty to XML. * @param xs XmlSerializer to write VersionProperty * @param p VersionProperty to write * @param type VersionProperty type attribute value * @throws IOException */ public static void writeVersionProperty(XmlSerializer xs, VersionProperty p, String type) throws IOException{ String namespace = VERSION_NAMESPACE; xs.startTag(namespace, XML_VERSION); xs.attribute(namespace, XML_VERSION_TYPE, type); xs.startTag(namespace, XML_VERSION_NAME); xs.text(p.getName()); xs.endTag(namespace, XML_VERSION_NAME); xs.startTag(namespace, XML_VERSION_NUMBER); xs.text(p.getNumber()); xs.endTag(namespace, XML_VERSION_NUMBER); xs.endTag(namespace, XML_VERSION); } }
/** * * @return */ public VersionProperty getVersion(){ String name = myVersionNameTxtBox.getText(); String number = myVersionNumberTxtBox.getText(); VersionProperty version = new VersionProperty(name, number); return version; } /** This method is called from within the constructor to
+ "and class={1}", new Object[]{ serviceVersion.toString(), serviceClass.getName()}); return null;
/** * Reads a VersionProperty from a XML node. * @param config XML node of the VersionProperty * @return VersionProperty from a XML node */ public static VersionProperty readVersion(HierarchicalConfiguration config){ String name = config.getString(XML_VERSION_NAME); String num = config.getString(XML_VERSION_NUMBER); return new VersionProperty(name, num); }
+ "formatVersion={0}, configClass={1} " + "and paramClass={2}", new Object[]{configFormat.toString(), configClass.getName(), paramClass.getName()}); return null;
+ "formatVersion={0}, configClass={1} " + "and paramClass={2}", new Object[]{configFormat.toString(), configClass.getName(), paramClass.getName()}); return null;
private static <Param> OSGiComponent launchJointGroupConfig( BundleContext context, Param jointGroupConfigParam, Class<Param> paramClass, String configParamId, Configuration<String> jgSvcConf){ Properties props = new Properties(); props.put(Constants.CONFIG_PARAM_ID, configParamId); props.put(Constants.CONFIG_FORMAT_VERSION, get(VersionProperty.class, jgSvcConf, CONF_CONFIG_READER_VERSION).toString()); ServiceLifecycleProvider lifecycle = new SimpleLifecycle( jointGroupConfigParam, paramClass, props); OSGiComponent paramComp = new OSGiComponent(context, lifecycle); paramComp.start(); startedJointGroupConfigs.add(paramComp); return paramComp; }
private DependencyDescriptor buildFactoryDescriptor(Class<T> serviceClass, Class<C> configClass, VersionProperty serviceVersion){ DescriptorBuilder descs = new DescriptorBuilder(theServiceFactory, ServiceFactory.class) .with(Constants.SERVICE_CLASS, serviceClass.getName()) .with(Constants.SERVICE_VERSION, serviceVersion.toString()); if(configClass != null){ descs.with(Constants.CONFIG_CLASS, configClass.getName()); } return descs.getDescriptor(); }