in eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java [87:269]
public boolean update()
{
this.denied.set(false);
boolean valid = true;
// First check, topic
final Object topicObj = reference.getProperty(EventConstants.EVENT_TOPIC);
if (topicObj instanceof String)
{
if ( topicObj.toString().equals("*") )
{
this.topics = null;
}
else
{
this.topics = new String[] {topicObj.toString()};
}
}
else if (topicObj instanceof String[])
{
// check if one value matches '*'
final String[] values = (String[])topicObj;
boolean matchAll = false;
for(int i=0;i<values.length;i++)
{
if ( "*".equals(values[i]) )
{
matchAll = true;
}
}
if ( matchAll )
{
this.topics = null;
}
else
{
this.topics = values;
}
}
else if (topicObj instanceof Collection)
{
@SuppressWarnings("unchecked")
final Collection<Object> col = (Collection<Object>)topicObj;
final String[] values = new String[col.size()];
int index = 0;
// check if one value matches '*'
final Iterator<Object> i = col.iterator();
boolean matchAll = false;
while ( i.hasNext() )
{
final String v = i.next().toString();
values[index] = v;
index++;
if ( "*".equals(v) )
{
matchAll = true;
}
}
if ( matchAll )
{
this.topics = null;
}
else
{
this.topics = values;
}
}
else if ( topicObj == null && !this.handlerContext.requireTopic )
{
this.topics = null;
}
else
{
final String reason;
if ( topicObj == null )
{
reason = "Missing";
}
else
{
reason = "Neither of type String nor String[] : " + topicObj.getClass().getName();
}
LogWrapper.getLogger().log(
this.reference,
LogWrapper.LOG_WARNING,
"Invalid EVENT_TOPICS : " + reason + " - Ignoring ServiceReference ["
+ this.reference + " | Bundle("
+ this.reference.getBundle() + ")]");
this.topics = null;
valid = false;
}
// Second check filter (but only if topics is valid)
Filter handlerFilter = null;
if ( valid )
{
final Object filterObj = reference.getProperty(EventConstants.EVENT_FILTER);
if (filterObj instanceof String)
{
try
{
handlerFilter = this.handlerContext.bundleContext.createFilter(filterObj.toString());
}
catch (final InvalidSyntaxException e)
{
valid = false;
LogWrapper.getLogger().log(
this.reference,
LogWrapper.LOG_WARNING,
"Invalid EVENT_FILTER - Ignoring ServiceReference ["
+ this.reference + " | Bundle("
+ this.reference.getBundle() + ")]", e);
}
}
else if ( filterObj != null )
{
valid = false;
LogWrapper.getLogger().log(
this.reference,
LogWrapper.LOG_WARNING,
"Invalid EVENT_FILTER - Ignoring ServiceReference ["
+ this.reference + " | Bundle("
+ this.reference.getBundle() + ")]");
}
}
this.filter = handlerFilter;
// new in 1.3 - deliver
this.asyncOrderedDelivery = true;
Object delivery = reference.getProperty(EventConstants.EVENT_DELIVERY);
if ( delivery instanceof Collection )
{
@SuppressWarnings("unchecked")
final Collection<String> col = (Collection<String>)delivery;
delivery = col.toArray(new String[col.size()]);
}
if ( delivery instanceof String )
{
this.asyncOrderedDelivery = !(EventConstants.DELIVERY_ASYNC_UNORDERED.equals(delivery.toString()));
}
else if ( delivery instanceof String[] )
{
final String[] deliveryArray = (String[])delivery;
boolean foundOrdered = false, foundUnordered = false;
for(int i=0; i<deliveryArray.length; i++)
{
final String value = deliveryArray[i];
if ( EventConstants.DELIVERY_ASYNC_UNORDERED.equals(value) )
{
foundUnordered = true;
}
else if ( EventConstants.DELIVERY_ASYNC_ORDERED.equals(value) )
{
foundOrdered = true;
}
else
{
LogWrapper.getLogger().log(
this.reference,
LogWrapper.LOG_WARNING,
"Invalid EVENT_DELIVERY - Ignoring invalid value for event delivery property " + value + " of ServiceReference ["
+ this.reference + " | Bundle("
+ this.reference.getBundle() + ")]");
}
}
if ( !foundOrdered && foundUnordered )
{
this.asyncOrderedDelivery = false;
}
}
else if ( delivery != null )
{
LogWrapper.getLogger().log(
this.reference,
LogWrapper.LOG_WARNING,
"Invalid EVENT_DELIVERY - Ignoring event delivery property " + delivery + " of ServiceReference ["
+ this.reference + " | Bundle("
+ this.reference.getBundle() + ")]");
}
// make sure to release the handler
this.release();
return valid;
}