This commit is contained in:
Manuele Simi 2009-10-13 23:03:22 +00:00
parent 55350ea099
commit 5a50b1ba0a
7 changed files with 390 additions and 518 deletions

View File

@ -7,10 +7,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.contexts.GCUBEServiceContext;
@ -19,7 +16,6 @@ import org.gcube.common.core.porttypes.GCUBEPortType;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.events.GCUBEEvent;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.FactoryContext;
@ -37,21 +33,16 @@ import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
import org.gcube.informationsystem.registry.stubs.RemoveScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.ResourceNotAcceptedFault;
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
import org.gcube.informationsystem.registry.stubs.StartRegistration;
import org.gcube.informationsystem.registry.stubs.StartRegistrationResponse;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
import static org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ResourceType;
/**
* Implementation of the <em>Registry Factory</em> portType
*
* @author Andrea Manzi, Manuele Simi (ISTI-CNR)
* @author Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*/
public class RegistryFactory extends GCUBEPortType {
@ -70,15 +61,8 @@ public class RegistryFactory extends GCUBEPortType {
/** Object logger */
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
enum OperationType {
create, update, destroy
};
/**
* Map of registration to Notification
*/
public static final List<GCUBEWSResourceKey> notificationMap = Collections
.synchronizedList(new ArrayList<GCUBEWSResourceKey>());
enum OperationType {create, update, destroy};
/** the key used to label the Factory Resource */
public static final String NOTIFICATOR_RESOURCE_KEY = "RegistryResource";
@ -88,36 +72,10 @@ public class RegistryFactory extends GCUBEPortType {
*/
@Override
protected void onInitialisation() throws Exception {
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext()
.getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = "
+ temporaryResourceLifetimeInMs);
}
/**
* Use to Load from Disk persistence profiles and registers it into the
* IS-IC ( in case the IS-IC is empty)
*
*
* @param start
* same as void
* @return void
* @throws RemoteException
* Exception
*/
public StartRegistrationResponse startRegistration(StartRegistration start)
throws GCUBEFault {
// start registration to broker and new profiles registration
logger.debug("Starting profile registration from disk");
try {
// loadProfiles();
} catch (Exception e) {
logger.error("Error Loading profiles");
throw new GCUBEFault(e.getMessage());
}
return new StartRegistrationResponse();
temporaryResourceLifetimeInMs = (Long) ServiceContext.getContext().getProperty(LIFETIME_JNDI_NAME);
logger.info("Temporary resources lifetime = " + temporaryResourceLifetimeInMs);
}
/**
*
@ -133,108 +91,108 @@ public class RegistryFactory extends GCUBEPortType {
public String createResource(CreateResourceMessage mess) throws SchemaValidationFault, RemoteException,
ProfileAlreadyRegisteredFault, ResourceNotAcceptedFault {
GCUBEResource resource = null;
logger.info("CreateResource operation invoked");
// logSecurityInfo("createResource");
String profile = mess.getProfile();
if (profile == null || profile.compareTo("") == 0) {
String msg = "Profile file is empty";
logger.debug(msg);
throw new RemoteException(msg);
}
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(profile.getBytes("UTF-8")), "UTF-8")));
// the parse Profile class allows to extract from profiles
// information about type/SCOPE/UniqueID
// in order to distinguish among different Resource Type
// Adding scopes to Profile
String[] scopes = mess.getScopes();
if (scopes != null) {
for (String scope : scopes) {
logger.debug(resource.getID()
+ " Adding Scopes to Profile " + scope);
resource.addScope(GCUBEScope.getScope(scope));
GCUBEResource resource = null;
logger.info("CreateResource operation invoked");
// logSecurityInfo("createResource");
String profile = mess.getProfile();
if (profile == null || profile.compareTo("") == 0) {
String msg = "Profile file is empty";
logger.debug(msg);
throw new RemoteException(msg);
}
}
// check ID
if (resource.getID() == null || resource.getID().compareTo("") == 0) {
resource.setID(uuidgen.nextUUID());
}
} catch (Exception ex) {
logger.error("Error trying to load profile", ex);
throw new SchemaValidationFault();
}
// apply resource filter
try {
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault();
}
logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource "
+ resource.getID() + " CANNOT be filtered ");
}
// check if the Resource already exists
if (isResourceCreated(resource.getID())) {
// update the existing resource
logger.warn("A Resource with ID " + resource.getID()
+ " is already registered");
UpdateResourceMessage upmess = new UpdateResourceMessage();
upmess.setUniqueID(resource.getID());
upmess.setXmlProfile(mess.getProfile());
upmess.setType(mess.getType());
this.updateResource(upmess);
// throw new ProfileAlreadyRegisteredFault();
} else {
// try to create resource
try {
logger.debug(resource.getID() + " Creating the stateful resource for " + resource.getID());
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext()
.makeKey(resource.getID()), resource);
presource.store();
// Deleting the WSResource created if != from GHN
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
this.scheduleForLazyDeletion(presource);
} catch (Exception ex) {
String msg = "Error creating Resource " + resource.getID();
logger.error(msg, ex);
throw new RemoteException(msg);
}
try {
updateCounterInfo(resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.CREATE, event);
} catch (Exception e) {
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
}
}
StringWriter writer = new StringWriter();
try {
logger.debug("Persisting the stateful resource for "
+ resource.getID());
resource.store(writer);
} catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e);
}
logger.info("Profile " + resource.getID() + " created ");
return writer.toString();
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(profile.getBytes("UTF-8")), "UTF-8")));
// the parse Profile class allows to extract from profiles
// information about type/SCOPE/UniqueID
// in order to distinguish among different Resource Type
// Adding scopes to Profile
String[] scopes = mess.getScopes();
if (scopes != null) {
for (String scope : scopes) {
logger.debug(resource.getID()
+ " Adding Scopes to Profile " + scope);
resource.addScope(GCUBEScope.getScope(scope));
}
}
// check ID
if (resource.getID() == null || resource.getID().compareTo("") == 0) {
resource.setID(uuidgen.nextUUID());
}
} catch (Exception ex) {
logger.error("Error trying to load profile", ex);
throw new SchemaValidationFault();
}
// apply resource filter
try {
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault();
}
logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource "
+ resource.getID() + " CANNOT be filtered ");
}
// check if the Resource already exists
if (isResourceCreated(resource.getID())) {
// update the existing resource
logger.warn("A Resource with ID " + resource.getID()
+ " is already registered");
UpdateResourceMessage upmess = new UpdateResourceMessage();
upmess.setUniqueID(resource.getID());
upmess.setXmlProfile(mess.getProfile());
upmess.setType(mess.getType());
this.updateResource(upmess);
// throw new ProfileAlreadyRegisteredFault();
} else {
// try to create resource
try {
logger.debug(resource.getID() + " Creating the stateful resource for " + resource.getID());
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext()
.makeKey(resource.getID()), resource);
presource.store();
// Deleting the WSResource created if != from GHN
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
this.scheduleForLazyDeletion(presource);
} catch (Exception ex) {
String msg = "Error creating Resource " + resource.getID();
logger.error(msg, ex);
throw new RemoteException(msg);
}
try {
updateCounterInfo(resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.CREATE, event);
} catch (Exception e) {
logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e);
}
}
StringWriter writer = new StringWriter();
try {
logger.debug("Persisting the stateful resource for "
+ resource.getID());
resource.store(writer);
} catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e);
}
logger.info("Profile " + resource.getID() + " created ");
return writer.toString();
}
/**
@ -275,72 +233,66 @@ public class RegistryFactory extends GCUBEPortType {
*/
@SuppressWarnings("unchecked")
public UpdateResourceResponse updateResource(UpdateResourceMessage mess)
throws RemoteException, SchemaValidationFault,
ResourceNotAcceptedFault, GCUBEFault {
// logSecurityInfo("updateResource");
logger.info("UpdateResource operation invoked");
String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile();
GCUBEResource resource = null;
CreateResourceMessage input = null;
// validating input parameters
if (ID == null || ID.compareTo("") == 0) {
logger.debug(" ID missing ");
throw new RemoteException("Error, ID missing");
}
if (xmlProfile == null || xmlProfile.compareTo("") == 0) {
logger.debug("Profile missing");
throw new RemoteException("Error, profile missing");
}
// check if the profile exist
if (!isResourceCreated(ID)) {
input = new CreateResourceMessage();
input.setProfile(xmlProfile);
input.setType(mess.getType());
this.createResource(input);
return new UpdateResourceResponse();
}
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile));
// apply resource filter
try {
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault();
throws RemoteException, SchemaValidationFault, ResourceNotAcceptedFault, GCUBEFault {
logger.info("UpdateResource operation invoked");
String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile();
GCUBEResource resource = null;
CreateResourceMessage input = null;
// validating input parameters
if (ID == null || ID.compareTo("") == 0) {
logger.debug(" ID missing ");
throw new RemoteException("Error, ID missing");
}
logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource " + resource.getID() + " CANNOT be filtered ");
}
ProfileResource presource = getProfileResource(ID);
presource.updateResource(resource);
// Deleting the WSResource created
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
this.scheduleForLazyDeletion(presource);
} catch (Exception e) {
logger.error("Error updating profile for ID " + e);
throw new RemoteException(e.toString());
}
try {
updateCounterInfo(ID, ResourceType.valueOf(mess.getType()),
OperationType.update, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(
ServiceContext.RegistryTopic.UPDATE, event);
} catch (Exception e) {
logger.warn("Error updating counting info for resource with ID "
+ resource.getID(), e);
}
logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse();
if (xmlProfile == null || xmlProfile.compareTo("") == 0) {
logger.debug("Profile missing");
throw new RemoteException("Error, profile missing");
}
// check if the profile exist
if (!isResourceCreated(ID)) {
input = new CreateResourceMessage();
input.setProfile(xmlProfile);
input.setType(mess.getType());
this.createResource(input);
return new UpdateResourceResponse();
}
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile));
// apply resource filter
try {
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
logger.warn("Resource " + resource.getID() + " NOT accepted ");
throw new ResourceNotAcceptedFault();
}
logger.trace("Resource " + resource.getID() + " accepted ");
} catch (InvalidFilterException e) {
logger.warn("Invalid filter selected, the resource " + resource.getID() + " CANNOT be filtered ");
}
ProfileResource presource = getProfileResource(ID);
presource.updateResource(resource);
// Deleting the WSResource created
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) != 0)
this.scheduleForLazyDeletion(presource);
} catch (Exception e) {
logger.error("Error updating profile for ID " + e);
throw new RemoteException(e.toString());
}
try {
this.updateCounterInfo(ID, ResourceType.valueOf(mess.getType()), OperationType.update, Calendar.getInstance());
GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource> event = new GCUBEEvent<ServiceContext.RegistryTopic, GCUBEResource>();
event.setPayload(resource);
ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.UPDATE, event);
} catch (Exception e) {
logger.warn("Error while updating the counting info for resource with ID " + resource.getID(), e);
}
logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse();
}
/**
@ -481,63 +433,27 @@ public class RegistryFactory extends GCUBEPortType {
*
* @return NotifierResource resource
* @throws RemoteException
* Exception
*
*/
private RegistryFactoryResource getResource() throws RemoteException {
Object resource = null;
try {
resource = FactoryContext.getContext().getWSHome().find(
FactoryContext.getContext().makeKey(
NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) {
logger.error(" Unable to access resource", e);
}
RegistryFactoryResource factoryResource = (RegistryFactoryResource) resource;
return factoryResource;
Object resource = null;
try {
resource = FactoryContext.getContext().getWSHome().find(
FactoryContext.getContext().makeKey(NOTIFICATOR_RESOURCE_KEY));
} catch (Exception e) {
logger.error(" Unable to access resource", e);
}
RegistryFactoryResource factoryResource = (RegistryFactoryResource) resource;
return factoryResource;
}
/**
*
* @param message
* UpdateScopeInProfileMessage
* @return String
* @throws GCUBEFault
* -
/**
* {@inheritDoc}
*/
public String updateScopeInProfile(UpdateScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/**
*
* @param message
* RemoveScopeInProfileMessage
* @return String
* @throws GCUBEFault
* -
*/
public String removeScopeInProfile(RemoveScopeInProfileMessage message)
throws GCUBEFault {
return null;
}
/**
*
* @param message
* UpdateStateMessage
* @return
* @throws GCUBEFault
* -
*/
public String updateState(UpdateStateMessage message) throws GCUBEFault {
return null;
}
@Override
protected GCUBEServiceContext getServiceContext() {
return ServiceContext.getContext();
return ServiceContext.getContext();
}
}

View File

@ -16,7 +16,7 @@ import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
*/
public class EliminatePoolingThread extends Thread {
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");;
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
@ -24,49 +24,57 @@ public class EliminatePoolingThread extends Thread {
public void run() {
boolean noErrors = true;
while (noErrors) {
while (true) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
try {
long timestamp = System.currentTimeMillis();
try {
synchronized (stack) {
int numRes = stack.size();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
if (timestamp >= c.lifetime) {
try {
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} catch (Exception e) {
logger.error(e);
tmpStack.offer(c);// re-insert the resource in the list
}
} else {
tmpStack.offer(c); // re-insert the resource in the list
}
}
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
stack.addAll(tmpStack);
LinkedList<Pair> undeletedResources = this.checkResources();
logger.debug("cannot destroy " + undeletedResources.size() + " resources, retrying later");
logger.debug("destroyed " + (numRes - undeletedResources.size()) + " resources ");
stack.addAll(undeletedResources);
} // end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
noErrors = false;
break;
}
}
}
public synchronized List<Pair> getStack() {
return this.stack;
}
/**
* Checks and deletes expired temporary resources
* @return the list of still living resources
*/
private LinkedList<Pair> checkResources() {
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
long timestamp = System.currentTimeMillis();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
if (timestamp >= c.lifetime) {
try {
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} catch (Exception e) {
logger.error(e);
tmpStack.offer(c);// re-insert the resource in the list
}
} else {
tmpStack.offer(c); // re-insert the resource in the list
}
}
return tmpStack;
}
}

View File

@ -0,0 +1,84 @@
package org.gcube.informationsystem.registry.impl.resources;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
/**
* A to-be-registered {@link GCUBEResource} passed to the ISRegistry
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class GCUBERegisteredResource {
protected GCUBEResource resource;
Document dom = null;
public GCUBERegisteredResource (GCUBEResource resource) throws Exception {
this.resource = resource;
this.parse();
}
public String getID() {
return this.resource.getID();
}
/**
* States if the resource is a temporary resource, i.e. must be destroyed after its registration
* @return
*/
public boolean isTemporary() {
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
return false;
else
return true;
}
private void parse() throws Exception {
StringWriter writer = new StringWriter();
try {
resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>") + 2, writer.toString().length()));
InputSource source = new InputSource(reader);
this.dom = builder.parse(source);
} catch (Exception e1) {
throw new Exception("Unable to parse the resource");
}
}
/**
* @return the XML Document representation of the resouce
*/
public Document getAsDOM() {
return this.dom;
}
/**
* @return the source resource
*/
public GCUBEResource getSource() {
return this.resource;
}
}

View File

@ -1,253 +1,117 @@
package org.gcube.informationsystem.registry.impl.state;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.resources.GCUBERegisteredResource;
import org.globus.wsrf.ResourceException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* Stateful resource wrapping a {@link GCUBEResource}
* Profile Stateful resource
*
* @author Andrea Manzi, Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*/
public class ProfileResource extends GCUBEWSResource {
private static GCUBELog logger = new GCUBELog(ProfileResource.class
.getName());
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName());
protected GCUBEResource gCubeResource;
protected GCUBEResource gCubeResource;
protected static final String ProfileRP = "Profile";
protected static final String ProfileRP = "Profile";
@Override
protected String[] getPropertyNames() {
return new String[] { ProfileRP };
}
/**
* Constructor
*
* @throws Exception
* Exception
*/
public ProfileResource() throws Exception {
};
/**
* initialize the resource
*
* @param params
* Object
* @throws ResourceException
* if resource is missing
*/
@Override
public void initialise(Object... params) throws ResourceException {
GCUBEResource resource = (GCUBEResource) params[0];
logger.debug("initializing resource " + resource.getID());
Document dom = null;
StringWriter writer = new StringWriter();
try {
resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(
writer.toString().indexOf("?>") + 2,
writer.toString().length()));
InputSource source = new InputSource(reader);
dom = builder.parse(source);
} catch (Exception e1) {
throw new ResourceException(e1);
/**
* Constructor
*
*/
public ProfileResource() {};
/**
* {@inheritDoc}
*/
@Override
protected String[] getPropertyNames() {
return new String[] { ProfileRP };
}
this.setProfile(dom);
// this.setNotificationProfile(dom);
this.setGCubeResource(resource);
if (hasToLive(resource))
this.setTerminationTime(null);
/*
* if (hasToLive(resource)) { //registration of Topic To IS-Notifier
/**
* Initializes the resource
*
* listQname.add(new SimpleTopic(this.generateQName()));
* synchronized(RegistryFactory.notificationMap) { if
* (!(RegistryFactory.notificationMap.contains(this.getID()))) { try {
* notifier = GHNContext.getImplementation(ISNotifier.class);
* notifier.registerISNotification(this.getEPR(), listQname,
* ServiceContext.getContext());
*
* } catch (Exception e){ e.printStackTrace(); throw new
* ResourceException(e); }
*
* RegistryFactory.notificationMap.add(this.getID()); } } }
* @param params
* Object
* @throws ResourceException
* if resource is missing
*/
}
@Override
public void initialise(Object... params) throws ResourceException {
GCUBERegisteredResource resource;
try {
resource = new GCUBERegisteredResource((GCUBEResource) params[0]);
} catch (Exception e) {
throw new ResourceException("Invalid GCUBEResource");
}
logger.debug("initializing resource " + resource.getID());
this.setProfile(resource.getAsDOM());
// this.setNotificationProfile(dom);
this.setGCubeResource(resource.getSource());
/**
* set notification Profile
*
* @param profile
* Document
*/
/*
* public void setNotificationProfile(Document profile) {
* this.getResourcePropertySet().get(NotificationProfileRP).clear();
* this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
* //this.getPersistenceDelegate().store(this); }
*/
if (resource.isTemporary())
this.setTerminationTime(null);
}
/**
* get notification Profile
*
* @return Document profile
*/
/*
* public Document getNotificationProfile() { return
* (Document)this.getResourcePropertySet
* ().get(NotificationProfileRP).get(0); }
*/
/**
* set Profile
*
* @param profile
* Document
*/
public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear();
this.getResourcePropertySet().get(ProfileRP).add(profile);
}
/**
* get Profile
*
* @return Document profile
*/
public Document getProfile() {
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
}
/**
* Checks if the profile has to live or not
*
* @param resource the resource
* @return true/false
*/
private boolean hasToLive(GCUBEResource resource) {
if (resource.getType().compareTo(GCUBEHostingNode.TYPE) == 0)
return true;
else
return false;
}
/**
* Gets the Resource QName
*
* @return the Resource QName
*/
// private QName generateQName() {
// return new QName(ProfileContext.getContext().getNamespace(),
// NotificationProfileRP+this.getID().getValue());
// }
/**
* Returns the Resource
*
* @return the resource
*/
public GCUBEResource getGCubeResource() {
return this.gCubeResource;
}
/**
* Sets the resource
*
* @param resource the resource
*/
public void setGCubeResource(GCUBEResource resource) {
this.gCubeResource = resource;
}
// /** {@inheritDoc}*/
// @Override
// public void onRemove() throws ResourceException{
// super.onRemove();
// logger.info("Resource " + this.getID()+ " is going to be removed.");
//
// try {
// publisher = GHNContext.getImplementation(ISPublisher.class);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// /*
// if (RegistryFactory.notificationMap.contains(this.getID()))
// {
// try {
// notifier = GHNContext.getImplementation(ISNotifier.class);
// notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
// } catch (ISPublisherException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// synchronized(RegistryFactory.notificationMap) {
// RegistryFactory.notificationMap.remove(this.getID());
// }
// }*/
//
// try {
// publisher.removeWSResource(this,ServiceContext.getContext().getScope());
// //System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
// } catch (ISPublisherException e) {
// e.printStackTrace();
// }
//
// }
/**
* Updates the resource
*
* @param resource the resource to update
* @throws Exception if something goes wrong
*/
public void updateResource(GCUBEResource resource) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
StringWriter writer = new StringWriter();
resource.store(writer);
StringReader reader = new StringReader(writer.toString());
InputSource source = new InputSource(reader);
Document dom = builder.parse(source);
this.setProfile(dom);
this.setGCubeResource(resource);
// updates the notification profile too
/*
* if (this.hasToLive(resource)) this.setNotificationProfile(dom);
/**
* Sets Profile
*
* @param profile the profile
*/
this.store();
}
public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear();
this.getResourcePropertySet().get(ProfileRP).add(profile);
}
/**
* Gets Profile
*
* @return the profile
*/
public Document getProfile() {
return (Document) this.getResourcePropertySet().get(ProfileRP).get(0);
}
/**
* Returns the source {@link GCUBEResource}
*
* @return the resource
*/
public GCUBEResource getGCubeResource() {
return this.gCubeResource;
}
/**
* Sets the source {@link GCUBEResource}
*
* @param resource the resource
*/
public void setGCubeResource(GCUBEResource resource) {
this.gCubeResource = resource;
}
/**
* Updates the resource
*
* @param resource
* the resource to update
* @throws Exception
* if something goes wrong
*/
public void updateResource(GCUBEResource resource) throws Exception {
GCUBERegisteredResource regResource = new GCUBERegisteredResource(resource);
this.setProfile(regResource.getAsDOM());
this.setGCubeResource(resource);
this.store();
}
}