package org.gcube.informationsystem.registry.impl.core; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import javax.xml.namespace.QName; import org.gcube.common.core.state.GCUBEWSResource; import org.gcube.informationsystem.registry.impl.util.RegistrationThread; import org.gcube.informationsystem.registry.stubs.RegistryProperty; import org.globus.wsrf.ResourceException; /** * * The RegistryFactoryResource has the role to maintain WS-Topics used to notify changes each time * a GCUBEResource profile is created/removed/updated. A single instance of this class is created within * each instance of the IS-Registry service. * * @author Andrea Manzi, Manuele Simi (CNR) * */ public class RegistryFactoryResource extends GCUBEWSResource { protected static final String ExternalRunningInstanceRP="ExternalRunningInstance"; protected static final String ServiceRP="Service"; protected static final String CollectionRP="Collection"; protected static final String CSRP="CS"; protected static final String CSInstanceRP="CSInstance"; protected static final String GHNRP="GHN"; protected static final String gLiteSERP="gLiteSE"; protected static final String gLiteCERP="gLiteCE"; protected static final String gLiteSiteRP="gLiteSite"; protected static final String gLiteServiceRP="gLiteService"; protected static final String VRERP="VRE"; protected static final String GenericRP="Generic"; protected static final String TransformationProgramRP="TransformationProgram"; protected static final String MetadataCollectionRP="MetadataCollection"; protected static final String RunningInstanceRP="RunningInstance"; protected static String[] RPNames = { RunningInstanceRP, ExternalRunningInstanceRP, ServiceRP, CollectionRP, CSRP, CSInstanceRP, GHNRP, gLiteSERP, gLiteCERP, gLiteSiteRP, gLiteServiceRP, VRERP, GenericRP, TransformationProgramRP, MetadataCollectionRP }; @Override protected String[] getTopicNames() { return RPNames; } @Override protected String[] getPropertyNames() { return RPNames; } /** * */ private ArrayList listQname; /** * * Initializes Resource Properties. * @throws Exception Exception */ protected void initialise(Object... o) throws ResourceException { logger.debug("Initialising the RegistryFactoryresource..."); /* Initialize the RP's */ this.initialiseRPs(); logger.debug("RegistryFactoryResource RPs initialised"); try { //Topic List creation for registration to IS-Notifier listQname = new ArrayList(); for (String rpName : RPNames) listQname.add(new QName(this.getPorttypeContext().getNamespace(),rpName)); try { RegistrationThread thread = new RegistrationThread(listQname); Thread t = new Thread(thread); t.start(); }catch (Exception e) { e.printStackTrace(); logger.error("Error on Registration Thread",e); } //GHNContext.getImplementation(ISPublisher.class).registerWSResource(this,GHNContext.getContext().getDefaultScope()); } catch (Exception e) { logger.error("Error on Initialization of Resource",e); throw new ResourceException("Failed to initialise the RPs and related topics"); } } /** * Default Setter for the RP runningInstanceRP * * @param property The RI property * */ @SuppressWarnings("unchecked") public void setRunningInstance (RegistryProperty property) { this.getResourcePropertySet().get(RunningInstanceRP).clear(); this.getResourcePropertySet().get(RunningInstanceRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP runningInstanceRP * * @return The RegistryProperty */ public RegistryProperty getRunningInstance () { return (RegistryProperty) this.getResourcePropertySet().get(RunningInstanceRP).get(0); } /** * Default Setter for the RP ExternalRunningInstanceRP * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setExternalRunningInstance (RegistryProperty property) { this.getResourcePropertySet().get(ExternalRunningInstanceRP).clear(); this.getResourcePropertySet().get(ExternalRunningInstanceRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP ExternalRunningInstanceRP * * @return The RegistryProperty * */ public RegistryProperty getExternalRunningInstance () { return (RegistryProperty) this.getResourcePropertySet().get(ExternalRunningInstanceRP).get(0); } /** * Default Setter for the RP Service * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setService (RegistryProperty property) { this.getResourcePropertySet().get(ServiceRP).clear(); this.getResourcePropertySet().get(ServiceRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP Service * * @return The RegistryProperty * */ public RegistryProperty getService () { return (RegistryProperty) this.getResourcePropertySet().get(ServiceRP).get(0); } /** * Default Setter for the RP Collection * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setCollection (RegistryProperty property) { this.getResourcePropertySet().get(CollectionRP).clear(); this.getResourcePropertySet().get(CollectionRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP Collection * @return The RegistryProperty * */ public RegistryProperty getCollection () { return (RegistryProperty) this.getResourcePropertySet().get(CollectionRP).get(0); } /** * Default Setter for the RP CS * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setCS (RegistryProperty property) { this.getResourcePropertySet().get(CSRP).clear(); this.getResourcePropertySet().get(CSRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP CS * * @return The RegistryProperty * */ public RegistryProperty getCS () { return (RegistryProperty) this.getResourcePropertySet().get(CSRP).get(0); } /** * Default Setter for the RP CSInstance * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setCSInstance (RegistryProperty property) { this.getResourcePropertySet().get(CSInstanceRP).clear(); this.getResourcePropertySet().get(CSInstanceRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP CSInstance * * @return The RegistryProperty * */ public RegistryProperty getCSInstance () { return (RegistryProperty) this.getResourcePropertySet().get(CSInstanceRP).get(0); } /** * Default Setter for the RP ghn * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGHN (RegistryProperty property) { this.getResourcePropertySet().get(GHNRP).clear(); this.getResourcePropertySet().get(GHNRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP ghn * * @return The RegistryProperty */ public RegistryProperty getGHN () { return (RegistryProperty) this.getResourcePropertySet().get(GHNRP).get(0); } /** * Default Setter for the RP gLiteSE * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGLiteSE (RegistryProperty property) { this.getResourcePropertySet().get(gLiteSERP).clear(); this.getResourcePropertySet().get(gLiteSERP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP gLiteSE * * @return The RegistryProperty * */ public RegistryProperty getGLiteSE () { return (RegistryProperty) this.getResourcePropertySet().get(gLiteSERP).get(0); } /** * Default Setter for the RP gLiteCE * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGLiteCE (RegistryProperty property) { this.getResourcePropertySet().get(gLiteCERP).clear(); this.getResourcePropertySet().get(gLiteCERP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP gLiteCE * @return The RegistryProperty * */ public RegistryProperty getGLiteCE () { return (RegistryProperty) this.getResourcePropertySet().get(gLiteCERP).get(0); } /** * Default Setter for the RP gLiteSite * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGLiteSite (RegistryProperty property) { this.getResourcePropertySet().get(gLiteSiteRP).clear(); this.getResourcePropertySet().get(gLiteSiteRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP gLiteSite * * @return The RegistryProperty * */ public RegistryProperty getGLiteSite () { return (RegistryProperty) this.getResourcePropertySet().get(gLiteSiteRP).get(0); } /** * Default Setter for the RP gLiteSite * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGLiteService (RegistryProperty property) { this.getResourcePropertySet().get(gLiteServiceRP).clear(); this.getResourcePropertySet().get(gLiteServiceRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP gLiteSite * @return The RegistryProperty * */ public RegistryProperty getGLiteService () { return (RegistryProperty) this.getResourcePropertySet().get(gLiteServiceRP).get(0); } /** * Default Setter for the RP VRE * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setVRE (RegistryProperty property) { this.getResourcePropertySet().get(VRERP).clear(); this.getResourcePropertySet().get(VRERP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP VRE * @return The RegistryProperty * */ public RegistryProperty getVRE () { return (RegistryProperty) this.getResourcePropertySet().get(gLiteServiceRP).get(0); } /** * Default Setter for the RP MetadataColletion * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setMetaColl (RegistryProperty property) { this.getResourcePropertySet().get(MetadataCollectionRP).clear(); this.getResourcePropertySet().get(MetadataCollectionRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP MetadataColletion * * @return The RegistryProperty * */ public RegistryProperty getMetaColl () { return (RegistryProperty) this.getResourcePropertySet().get(MetadataCollectionRP).get(0); } /** * Default Setter for the RP TransRule * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setTransProgram (RegistryProperty property) { this.getResourcePropertySet().get(TransformationProgramRP).clear(); this.getResourcePropertySet().get(TransformationProgramRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP TransRule * * @return The RegistryProperty * */ public RegistryProperty getTransProgram () { return (RegistryProperty) this.getResourcePropertySet().get(TransformationProgramRP).get(0); } /** * Default Setter for the RP Generic * * @param property The RegistryProperty * */ @SuppressWarnings("unchecked") public void setGenericResource (RegistryProperty property) { this.getResourcePropertySet().get(GenericRP).clear(); this.getResourcePropertySet().get(GenericRP).add(property); //this.getPersistenceDelegate().store(this); } /** * Default getter for the RP Generic * * @return The RegistryProperty * */ public RegistryProperty getGenericResource () { return (RegistryProperty) this.getResourcePropertySet().get(GenericRP).get(0); } private void initialiseRPs() { RegistryProperty property = new RegistryProperty(); /*for (Method method :this.getClass().getDeclaredMethods()) { if (method.getName().contains("set")) { try { method.invoke(this,property); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } break; } }*/ this.getResourcePropertySet().get(RunningInstanceRP).clear(); this.getResourcePropertySet().get(RunningInstanceRP).add(property); this.getResourcePropertySet().get(ExternalRunningInstanceRP).clear(); this.getResourcePropertySet().get(ExternalRunningInstanceRP).add(property); this.getResourcePropertySet().get(ServiceRP).clear(); this.getResourcePropertySet().get(ServiceRP).add(property); this.getResourcePropertySet().get(CollectionRP).clear(); this.getResourcePropertySet().get(CollectionRP).add(property); this.getResourcePropertySet().get(CSRP).clear(); this.getResourcePropertySet().get(CSRP).add(property); this.getResourcePropertySet().get(CSInstanceRP).clear(); this.getResourcePropertySet().get(CSInstanceRP).add(property); this.getResourcePropertySet().get(GHNRP).clear(); this.getResourcePropertySet().get(GHNRP).add(property); this.getResourcePropertySet().get(gLiteCERP).clear(); this.getResourcePropertySet().get(gLiteCERP).add(property); this.getResourcePropertySet().get(gLiteSERP).clear(); this.getResourcePropertySet().get(gLiteSERP).add(property); this.getResourcePropertySet().get(gLiteServiceRP).clear(); this.getResourcePropertySet().get(gLiteServiceRP).add(property); this.getResourcePropertySet().get(gLiteSiteRP).clear(); this.getResourcePropertySet().get(gLiteSiteRP).add(property); this.getResourcePropertySet().get(VRERP).clear(); this.getResourcePropertySet().get(VRERP).add(property); this.getResourcePropertySet().get(MetadataCollectionRP).clear(); this.getResourcePropertySet().get(MetadataCollectionRP).add(property); this.getResourcePropertySet().get(GenericRP).clear(); this.getResourcePropertySet().get(GenericRP).add(property); this.getResourcePropertySet().get(TransformationProgramRP).clear(); this.getResourcePropertySet().get(TransformationProgramRP).add(property); } }