/** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.eclipse.datatools.connectivity.oda.openmrs.ui.impl; import java.util.Properties; import org.eclipse.datatools.connectivity.oda.design.DataSetDesign; /** * This class is to hold the public properties for the different data set pages. * The basic idea was taken from the publicly available XML ODA. This data * structure allows properties to be shared between the different data set pages * within the same user session. */ public class InformationHolder { private static final String QUERY = "QUERY"; private static final String DATASTYLE = "DATASTYLE"; private static final String FILTER = "FILTER"; private static final String TOKENS = "TOKENS"; private static final String TOKENTAG = "TOKENTAG"; private static Properties prop; /** * Gets all of the properties. * * @return the properties */ public static Properties getProperties() { return prop; } /** * Gets the property value. * * @param key the key * * @return the property value */ public static String getPropertyValue(String key) { if (prop == null) return null; String val = prop.getProperty(key); return val; } /** * Sets the property value. * * @param key the key * @param value the value */ public static void setPropertyValue(String key, String value) { if (prop == null) { prop = new Properties(); ; } if (value != null) { prop.setProperty(key, value); } } /** * Initializes the InformationHolder. A DataSetDesign so that any existing * public properties can be extracted from the design. * * @param dataSetDesign the data set design */ public static void start(DataSetDesign dataSetDesign) { if (dataSetDesign == null) { return; } String queryText = dataSetDesign.getQueryText(); if (queryText != null && queryText.trim().length() > 0) { setPropertyValue(QUERY, queryText); } if (dataSetDesign.getPublicProperties() != null) { String selectedTag = dataSetDesign.getPublicProperties() .getProperty(TOKENTAG); String tokens = dataSetDesign.getPublicProperties().getProperty( TOKENS); String filter = dataSetDesign.getPublicProperties().getProperty( FILTER); String dataStyle = dataSetDesign.getPublicProperties().getProperty( DATASTYLE); setPropertyValue(TOKENTAG, selectedTag); setPropertyValue(TOKENS, tokens); setPropertyValue(FILTER, filter); setPropertyValue(DATASTYLE, dataStyle); } } /** * destroy the holder class. */ public static void destroy() { prop = null; } /** * Checks if destroyed to know whether or not start(DataSetDesign) needs to * be called. * * @return true, if destroyed */ public static boolean hasDestroyed() { return prop == null; } }