use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.
the class AggregateObjectFactory method getObjectReferences.
@Override
public <T> List<IPentahoObjectReference<T>> getObjectReferences(Class<T> interfaceClass, IPentahoSession curSession, Map<String, String> properties) throws ObjectFactoryException {
// Use a set to avoid duplicates
Set<IPentahoObjectReference<T>> referenceSet = new HashSet<IPentahoObjectReference<T>>();
readLock.lock();
try {
for (IPentahoObjectFactory fact : factories) {
if (fact.objectDefined(interfaceClass)) {
List<IPentahoObjectReference<T>> found = fact.getObjectReferences(interfaceClass, curSession, properties);
if (found != null) {
referenceSet.addAll(found);
}
}
}
} finally {
readLock.unlock();
}
// transform to a list to sort
List<IPentahoObjectReference<T>> referenceList = new ArrayList<IPentahoObjectReference<T>>();
referenceList.addAll(referenceSet);
Collections.sort(referenceList, referencePriorityComparitor);
return referenceList;
}
use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.
the class AggregateObjectFactory method getAll.
@Override
public <T> List<T> getAll(Class<T> interfaceClass, IPentahoSession curSession, Map<String, String> properties) throws ObjectFactoryException {
List<IPentahoObjectReference<T>> referenceList = new ArrayList<IPentahoObjectReference<T>>();
readLock.lock();
try {
for (IPentahoObjectFactory fact : factories) {
if (fact.objectDefined(interfaceClass)) {
List<IPentahoObjectReference<T>> refs = fact.getObjectReferences(interfaceClass, curSession, properties);
if (refs != null) {
referenceList.addAll(refs);
}
}
}
} finally {
readLock.unlock();
}
Collections.sort(referenceList, referencePriorityComparitor);
// create final list of impls
List<T> entryList = new ArrayList<T>();
for (IPentahoObjectReference<T> ref : referenceList) {
if (!entryList.contains(ref.getObject())) {
entryList.add(ref.getObject());
}
}
return entryList;
}
use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.
the class AggregateObjectFactory method getObjectReference.
@Override
public <T> IPentahoObjectReference<T> getObjectReference(Class<T> clazz, IPentahoSession curSession) throws ObjectFactoryException {
Set<IPentahoObjectReference<T>> references = new HashSet<IPentahoObjectReference<T>>();
readLock.lock();
try {
for (IPentahoObjectFactory fact : factories) {
if (fact.objectDefined(clazz)) {
IPentahoObjectReference<T> found = fact.getObjectReference(clazz, curSession);
if (found != null) {
references.add(found);
}
}
}
} finally {
readLock.unlock();
}
IPentahoObjectReference<T> highestRef = null;
int highestRefPriority = -1;
for (IPentahoObjectReference<T> ref : references) {
int pri = computePriority(ref);
if (pri > highestRefPriority) {
highestRef = ref;
highestRefPriority = pri;
}
}
return highestRef;
}
use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.
the class OSGIObjectFactory method getAll.
@Override
public <T> List<T> getAll(Class<T> interfaceClass, IPentahoSession session, Map<String, String> properties) throws ObjectFactoryException {
if (isBundleContextValid() == false) {
return null;
}
List<T> returnList = new ArrayList<T>();
// make sure we check by reference first
if (properties == null || !properties.containsKey(REFERENCE_CLASS)) {
Map<String, String> props = new HashMap<String, String>();
if (properties != null) {
props.putAll(properties);
}
props.put(REFERENCE_CLASS, interfaceClass.getName());
List<IPentahoObjectReference> all = getAll(IPentahoObjectReference.class, session, props);
if (all != null) {
for (IPentahoObjectReference iPentahoObjectReference : all) {
returnList.add((T) iPentahoObjectReference.getObject());
}
}
}
String filter = OSGIUtils.createFilter(properties);
try {
Collection<ServiceReference<T>> refs = context.getServiceReferences(interfaceClass, filter);
if (refs == null || refs.size() == 0) {
log.info("\n\nOSGI: did not find object: " + interfaceClass.getName());
return returnList;
}
for (ServiceReference ref : refs) {
T obj = (T) context.getService(ref);
if (obj instanceof IPentahoInitializer) {
((IPentahoInitializer) obj).init(session);
}
returnList.add(obj);
}
return returnList;
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
return returnList;
}
use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.
the class OSGIRuntimeObjectFactory method registerReference.
public <T> IPentahoObjectRegistration registerReference(final IPentahoObjectReference<?> reference, OSGIPentahoObjectRegistration existingRegistration, Class<?>... classes) {
if (this.bundleContext == null) {
ObjectRegistration runtimeRegistration = (ObjectRegistration) super.registerReference(reference, classes);
OSGIPentahoObjectRegistration osgiPentahoObjectRegistration = new OSGIPentahoObjectRegistration(runtimeRegistration);
synchronized (deferredRegistrations) {
deferredRegistrations.add(osgiPentahoObjectRegistration);
}
return osgiPentahoObjectRegistration;
}
Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
hashtable.putAll(reference.getAttributes());
List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
for (Class<?> aClass : classes) {
try {
// references unless the IPentahoObjectReference is a Singleton scope
if (reference instanceof SingletonPentahoObjectReference || reference instanceof SpringPentahoObjectReference && (hashtable.get("scope").equals("singleton"))) {
ServiceFactory<Object> factory = new ServiceFactory<Object>() {
@Override
public Object getService(Bundle bundle, ServiceRegistration<Object> serviceRegistration) {
return reference.getObject();
}
@Override
public void ungetService(Bundle bundle, ServiceRegistration<Object> serviceRegistration, Object o) {
}
};
if (hashtable.containsKey("priority")) {
hashtable.put(Constants.SERVICE_RANKING, hashtable.get("priority"));
}
ServiceRegistration<?> serviceRegistration = bundleContext.registerService(aClass.getName(), factory, hashtable);
registrations.add(serviceRegistration);
} else {
// Publish it as an IPentahoObjectReference instead
Hashtable<String, Object> referenceHashTable = new Hashtable<>(hashtable);
referenceHashTable.put(REFERENCE_CLASS, aClass.getName());
ServiceRegistration<?> serviceRegistration = bundleContext.registerService(IPentahoObjectReference.class.getName(), reference, referenceHashTable);
registrations.add(serviceRegistration);
}
} catch (ClassCastException e) {
logger.error("Error Retriving object from OSGI, Class is not as expected", e);
}
}
if (existingRegistration != null) {
existingRegistration.setRegistrations(registrations);
return existingRegistration;
} else {
return new OSGIPentahoObjectRegistration(registrations);
}
}
Aggregations