From f36d6d6d5a0fd6599e9bdb4d1b7c0ea1bf416d6c Mon Sep 17 00:00:00 2001 From: rescobar Date: Mon, 23 Aug 2010 19:52:49 +0000 Subject: Updated class dependencies to reflect direct cache dependency instead of depending on the cache service object which brings in unnecessary dependencies. Updated DataTranslationService registration to use dependency tracker --- .../framework/core/message/internal/Activator.java | 98 ++-------------------- .../internal/DataTranslationServiceFactory.java | 30 ++----- .../internal/DataTranslationServiceRegHandler.java | 67 +++++++++++++++ ...AttributeTypeCacheUpdateResponseTranslator.java | 13 ++- .../TransactionCacheUpdateResponseTranslator.java | 13 ++- .../translation/TransactionRecordTranslator.java | 12 ++- 6 files changed, 99 insertions(+), 134 deletions(-) create mode 100644 plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceRegHandler.java (limited to 'plugins/org.eclipse.osee.framework.core.message/src') diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/Activator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/Activator.java index cc1f1e8902f..d2edeeaaa6e 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/Activator.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/Activator.java @@ -10,109 +10,25 @@ *******************************************************************************/ package org.eclipse.osee.framework.core.message.internal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.osee.framework.core.enums.OseeServiceTrackerId; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.BranchFactory; -import org.eclipse.osee.framework.core.model.OseeModelFactoryService; -import org.eclipse.osee.framework.core.model.TransactionRecordFactory; -import org.eclipse.osee.framework.core.model.type.ArtifactTypeFactory; -import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; -import org.eclipse.osee.framework.core.model.type.OseeEnumTypeFactory; -import org.eclipse.osee.framework.core.model.type.RelationTypeFactory; -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.core.services.IOseeCachingServiceProvider; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryServiceProvider; -import org.eclipse.osee.framework.core.translation.IDataTranslationService; +import org.eclipse.osee.framework.core.util.ServiceDependencyTracker; +import org.eclipse.osee.framework.jdk.core.util.Lib; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.osgi.util.tracker.ServiceTracker; -public class Activator implements BundleActivator, IOseeCachingServiceProvider, IOseeModelFactoryServiceProvider { +public class Activator implements BundleActivator { public static final String PLUGIN_ID = "org.eclipse.osee.framework.core.model"; - private static Activator instance = null; - private BundleContext bundleContext; - private final List services; - private final Map mappedTrackers; - - public Activator() { - services = new ArrayList(); - mappedTrackers = new HashMap(); - } + private ServiceDependencyTracker dependencyTracker; @Override public void start(BundleContext context) throws Exception { - instance = this; - instance.bundleContext = context; - - IOseeModelFactoryService factories = createFactoryService(); - IDataTranslationService service = new DataTranslationServiceFactory().createService(this, this); - - createService(context, IOseeModelFactoryService.class, factories); - createService(context, IDataTranslationService.class, service); - - createServiceTracker(context, IOseeCachingService.class, OseeServiceTrackerId.OSEE_CACHING_SERVICE); - createServiceTracker(context, IOseeModelFactoryService.class, OseeServiceTrackerId.OSEE_MODEL_FACTORY); - } - - private IOseeModelFactoryService createFactoryService() { - return new OseeModelFactoryService(new BranchFactory(), new TransactionRecordFactory(), - new ArtifactTypeFactory(), new AttributeTypeFactory(), new RelationTypeFactory(), new OseeEnumTypeFactory()); + dependencyTracker = new ServiceDependencyTracker(context, new DataTranslationServiceRegHandler()); + dependencyTracker.open(); } @Override public void stop(BundleContext context) throws Exception { - for (ServiceRegistration service : services) { - service.unregister(); - } - - for (ServiceTracker tracker : mappedTrackers.values()) { - tracker.close(); - } - services.clear(); - mappedTrackers.clear(); - - instance.bundleContext = null; - instance = null; - } - - public static BundleContext getBundleContext() { - return instance.bundleContext; - } - - private void createService(BundleContext context, Class serviceInterface, Object serviceImplementation) { - services.add(context.registerService(serviceInterface.getName(), serviceImplementation, null)); - } - - private void createServiceTracker(BundleContext context, Class clazz, OseeServiceTrackerId trackerId) { - ServiceTracker tracker = new ServiceTracker(context, clazz.getName(), null); - tracker.open(); - mappedTrackers.put(trackerId, tracker); - } - - @Override - public IOseeCachingService getOseeCachingService() { - return getTracker(OseeServiceTrackerId.OSEE_CACHING_SERVICE, IOseeCachingService.class); + Lib.close(dependencyTracker); } - private T getTracker(OseeServiceTrackerId trackerId, Class clazz) { - ServiceTracker tracker = mappedTrackers.get(trackerId); - Object service = tracker.getService(); - return clazz.cast(service); - } - - @Override - public IOseeModelFactoryService getOseeFactoryService() throws OseeCoreException { - return getTracker(OseeServiceTrackerId.OSEE_MODEL_FACTORY, IOseeModelFactoryService.class); - } - - public static Activator getInstance() { - return instance; - } } diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java index 920e272b50d..c8157d3c083 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java @@ -37,8 +37,9 @@ import org.eclipse.osee.framework.core.message.internal.translation.RelationType import org.eclipse.osee.framework.core.message.internal.translation.TableDataTranslator; import org.eclipse.osee.framework.core.message.internal.translation.TransactionCacheUpdateResponseTranslator; import org.eclipse.osee.framework.core.message.internal.translation.TransactionRecordTranslator; -import org.eclipse.osee.framework.core.services.IOseeCachingServiceProvider; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryServiceProvider; +import org.eclipse.osee.framework.core.model.TransactionRecordFactory; +import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; +import org.eclipse.osee.framework.core.services.IOseeCachingService; import org.eclipse.osee.framework.core.translation.IDataTranslationService; /** @@ -48,28 +49,13 @@ import org.eclipse.osee.framework.core.translation.IDataTranslationService; public class DataTranslationServiceFactory { public DataTranslationServiceFactory() { + // } - public IDataTranslationService createService(IOseeCachingServiceProvider cachingService, IOseeModelFactoryServiceProvider factoryProvider) throws OseeCoreException { + public IDataTranslationService createService(IOseeCachingService cachingService, TransactionRecordFactory txRecordFactory, AttributeTypeFactory attributeTypeFactory) throws OseeCoreException { IDataTranslationService service = new DataTranslationService(); - // service.addTranslator(new BasicArtifactTranslator(), - // CoreTranslatorId.ARTIFACT_METADATA); - // service.addTranslator(new BranchTranslator(service, factoryProvider), - // CoreTranslatorId.BRANCH); - - // service.addTranslator(new ArtifactTypeTranslator(service, - // factoryProvider), CoreTranslatorId.ARTIFACT_TYPE); - // service.addTranslator(new AttributeTypeTranslator(service, - // factoryProvider), CoreTranslatorId.ATTRIBUTE_TYPE); - // service.addTranslator(new RelationTypeTranslator(service, - // factoryProvider), CoreTranslatorId.RELATION_TYPE); - // service.addTranslator(new OseeEnumEntryTranslator(factoryProvider), - // CoreTranslatorId.OSEE_ENUM_ENTRY); - // service.addTranslator(new OseeEnumTypeTranslator(service, - // factoryProvider), CoreTranslatorId.OSEE_ENUM_TYPE); - - service.addTranslator(new TransactionRecordTranslator(factoryProvider), CoreTranslatorId.TRANSACTION_RECORD); + service.addTranslator(new TransactionRecordTranslator(txRecordFactory), CoreTranslatorId.TRANSACTION_RECORD); service.addTranslator(new BranchCreationRequestTranslator(), CoreTranslatorId.BRANCH_CREATION_REQUEST); service.addTranslator(new BranchCreationResponseTranslator(), CoreTranslatorId.BRANCH_CREATION_RESPONSE); @@ -92,13 +78,13 @@ public class DataTranslationServiceFactory { service.addTranslator(new BranchCacheUpdateResponseTranslator(), CoreTranslatorId.BRANCH_CACHE_UPDATE_RESPONSE); service.addTranslator(new BranchCacheStoreRequestTranslator(), CoreTranslatorId.BRANCH_CACHE_STORE_REQUEST); - service.addTranslator(new TransactionCacheUpdateResponseTranslator(factoryProvider), + service.addTranslator(new TransactionCacheUpdateResponseTranslator(txRecordFactory), CoreTranslatorId.TX_CACHE_UPDATE_RESPONSE); service.addTranslator(new ArtifactTypeCacheUpdateResponseTranslator(), CoreTranslatorId.ARTIFACT_TYPE_CACHE_UPDATE_RESPONSE); - service.addTranslator(new AttributeTypeCacheUpdateResponseTranslator(factoryProvider), + service.addTranslator(new AttributeTypeCacheUpdateResponseTranslator(attributeTypeFactory), CoreTranslatorId.ATTRIBUTE_TYPE_CACHE_UPDATE_RESPONSE); service.addTranslator(new RelationTypeCacheUpdateResponseTranslator(), diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceRegHandler.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceRegHandler.java new file mode 100644 index 00000000000..b5a40ecca61 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceRegHandler.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.message.internal; + +import java.util.Map; +import java.util.logging.Level; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.TransactionRecordFactory; +import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; +import org.eclipse.osee.framework.core.translation.IDataTranslationService; +import org.eclipse.osee.framework.core.util.AbstractTrackingHandler; +import org.eclipse.osee.framework.logging.OseeLog; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +/** + * @author Roberto E. Escobar + */ +public class DataTranslationServiceRegHandler extends AbstractTrackingHandler { + + private static final Class[] DEPENDENCIES = new Class[] {// + IOseeCachingService.class, // + IOseeModelFactoryService.class // + }; + + private ServiceRegistration registration; + + @Override + public Class[] getDependencies() { + return DEPENDENCIES; + } + + @Override + public void onActivate(BundleContext context, Map, Object> services) { + IOseeCachingService cachingService = getService(IOseeCachingService.class, services); + IOseeModelFactoryService factoryService = getService(IOseeModelFactoryService.class, services); + + TransactionRecordFactory txFactory = factoryService.getTransactionFactory(); + AttributeTypeFactory attributeTypeFactory = factoryService.getAttributeTypeFactory(); + + DataTranslationServiceFactory factory = new DataTranslationServiceFactory(); + try { + IDataTranslationService service = factory.createService(cachingService, txFactory, attributeTypeFactory); + registration = context.registerService(IDataTranslationService.class.getName(), service, null); + } catch (OseeCoreException ex) { + OseeLog.log(Activator.class, Level.SEVERE, ex); + } + } + + @Override + public void onDeActivate() { + if (registration != null) { + registration.unregister(); + } + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/AttributeTypeCacheUpdateResponseTranslator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/AttributeTypeCacheUpdateResponseTranslator.java index e71057fc5d4..f3b6cd55889 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/AttributeTypeCacheUpdateResponseTranslator.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/AttributeTypeCacheUpdateResponseTranslator.java @@ -20,7 +20,6 @@ import org.eclipse.osee.framework.core.message.AttributeTypeCacheUpdateResponse; import org.eclipse.osee.framework.core.message.TranslationUtil; import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryServiceProvider; import org.eclipse.osee.framework.core.translation.ITranslator; import org.eclipse.osee.framework.jdk.core.type.PropertyStore; @@ -35,14 +34,14 @@ public class AttributeTypeCacheUpdateResponseTranslator implements ITranslator rows = object.getAttrTypeRows(); for (int index = 0; index < rows.size(); index++) { diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionCacheUpdateResponseTranslator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionCacheUpdateResponseTranslator.java index 68a614fa0fb..89883fe1db1 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionCacheUpdateResponseTranslator.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionCacheUpdateResponseTranslator.java @@ -18,7 +18,6 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.message.TransactionCacheUpdateResponse; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.TransactionRecordFactory; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryServiceProvider; import org.eclipse.osee.framework.core.translation.ITranslator; import org.eclipse.osee.framework.jdk.core.type.PropertyStore; @@ -34,14 +33,14 @@ public class TransactionCacheUpdateResponseTranslator implements ITranslator rows = object.getTxRows(); for (int index = 0; index < rows.size(); index++) { diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionRecordTranslator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionRecordTranslator.java index e54132f7f31..77b34050624 100644 --- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionRecordTranslator.java +++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/TransactionRecordTranslator.java @@ -16,7 +16,6 @@ import org.eclipse.osee.framework.core.enums.TransactionDetailsType; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.TransactionRecordFactory; -import org.eclipse.osee.framework.core.services.IOseeModelFactoryServiceProvider; import org.eclipse.osee.framework.core.translation.ITranslator; import org.eclipse.osee.framework.jdk.core.type.PropertyStore; @@ -35,10 +34,10 @@ public final class TransactionRecordTranslator implements ITranslator