COR•REC Service

package com.corgroup.bmp.osgi.service;

import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;

import org.osgi.framework.BundleContext;

    /**
     * Hold default values for CorrecService_I concrete classes
     *
     */
    public abstract class CorrecService implements CorrecService_I{
      private String name;
      private BundleContext context;
      private boolean service_complete = false;
      private HashSet consumers;

    /**
     *
     * @param name - properties file key with value a human readable service title
     * @param context - plugin context creating and registering this service
     */
    public CorrecService(String name, BundleContext context) {
      this.name = name;
      this.context = context;
    }

    /**
     * BundleContext supplied at instantiation
     */
     @Override
     public BundleContext getBundleContext() {
      return context;
    }
    /**
     * This is not required.
     * Extended feature for plugins that have obtained
     * access to the COR•REC Platform ObjectGraph.
     */
     @Override
     public boolean isOGcompatible() {
      return false;
     }
    /**
     * String supplied at instantiation
     */
    public String getName() {
      return name;
     }
    /**
     * prevent or allow continued access during this session
     */
    public boolean isServiceCompleted() {
      return service_complete;
    }
    public void setServiceComplete(boolean b) {
    service_complete = b;
    }
    public Boolean isAvailable(){
      return true;//default is true - meaning the service is not restricted - override otherwise
    }
    /**
     * Default is all plugin modules may request access
     * to this service. Otherwise it should contain the
     * fully qualified names plugins that may request access.
     */
    public String[] getTargets() {
      return new String[] {CorrecServiceRegistry.ANY};
    }
    /**
     * A convenience method when a service needs to
     * keep track of the consumers it is servicing
     */
     @Override
    public void registerConsumer(Object consumer) {
      if(consumers == null) consumers = new HashSet();
      consumers.add(consumer);
    }
     @Override
    public void disposeConsumer(Object consumer) {
      if(consumers != null)
      consumers.remove(consumer);
    }
     @Override
    public int compareTo(CorrecService_I o) {
      return name.compareTo(o.getName());
    }
    /**
     * Utility method - create empty Map[String, Object]
     *
     * if key given than add to return map HashMap[key, value]
     *
     * @param key - used to initialize the map - may be null
     * @param value - - used to initialize map - may be null
     * @return
     */
    public static Map<String, Object>
    newCollaborateMap(String key, Object value){
       Map<String, Object> map = new HashMap();
       if(key != null) {
         map.put(key, value);
       }
       return map;
     }
    }
© CORGROUP® LLC 2025 All rights reserved