* @param resource
* @return
*/
private Subscription regStorageToSubscription(Resource resource)
throws RegistryException, XMLStreamException {
Subscription subscription = new Subscription();
SubscriptionData subscriptionData = new SubscriptionData();
String eprContent = new String((byte[]) resource.getContent());
OMElement payload = AXIOMUtil.stringToOM(eprContent);
if (payload.getFirstElement() != null) {
OMElement element = payload.getFirstElement();
try {
if (element.getFirstElement() == null) {
handleException("EPR creation failure");
}
String url = element.getFirstElement().getAttributeValue(new QName(URI));
subscription.setEndpointUrl(url);
subscription.setAddressUrl(url);
} catch (Exception e) {
handleException("EPR creation failure", e);
}
}
Properties property = resource.getProperties();
if (property != null) {
if (!property.isEmpty()) {
for (Enumeration e = property.propertyNames() ; e.hasMoreElements() ;) {
String propName = (String)e.nextElement();
if (propName.equals(EXPIRES)) {
if (resource.getProperty(EXPIRES).equals("*")) {
subscription.setExpires(null); // never expire subscription
} else {
subscription.setExpires(ConverterUtil.convertToDateTime(
resource.getProperty(EXPIRES)));
}
} else if (propName.equals(SUB_MANAGER_URI)) {
subscription
.setSubManUrl(resource.getProperty(SUB_MANAGER_URI));
} else if (propName.equals(FILTER_VALUE)) {
subscription.setFilterValue(resource.getProperty(FILTER_VALUE));
} else if (propName.equals(FILTER_DIALECT)) {
subscription.setFilterDialect(resource.getProperty(FILTER_DIALECT));
} else {
subscriptionData.setProperty(propName, resource.getProperty(propName));
}
}
}
}
subscription.setSubscriptionData(subscriptionData);
return subscription;
}