All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.datasource.Domain Maven / Gradle / Ivy

The newest version!
package at.spardat.xma.datasource;
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: Domain.java 7293 2011-02-25 17:15:33Z aku $


import java.util.ArrayList;
import java.util.List;

import at.spardat.xma.plugins.PluginManagerServer;
import at.spardat.xma.session.XMASession;
import at.spardat.xma.session.XMASessionServer;

/**
 * A utility class to access a XMA-domain-table (see {@link ITabularDomData}).
 * This class can be used to get long or short values of domain keys or to retrieved the complete domain.
 * Usually this is not needed, as the domain handling is done by widget models.
 * All domain values can be retrieved by this class or one domain row identfied by its key.
 * Domain rows are returned as IDomRow objects.
 * This class itself does not store any domain specific values beside the specTable given by getInstance() identifying a domain.
 * 

* * At construction time, the domain-table is specified by providing a specification String, see * {@link ITabularDataSource}.

* * * @author YSD, 20.07.2003 22:38:32 */ public class Domain { /** * Identifies the domain table */ private String specTable_; /** * Lazy initialized reference to data source plugin */ private static ITabularDataSource dsPlugin_; /** * xma session used to retrieve datasource plugin */ private XMASession session_; /** * Returns an Domain object associated with a * domain identified by specTable * This constructor may only be used at the server side of XMA. * @param specTable Example: "type=rsc,bundle=at.spardat.xma.samplespar.data.kestpflicht" * @author s3460 */ public static Domain getInstance(String specTable){ return new Domain(specTable,null); } /** * Returns an Domain object associated with a * domain identified by specTable * @param specTable Example: "type=rsc,bundle=at.spardat.xma.samplespar.data.kestpflicht" * @author gub * @since 2.2.0 */ public static Domain getInstance(String specTable,XMASession session) { return new Domain(specTable,session); } /** * Constructor * * @param specTable a XMA datasource table specification string, see {@link ITabularDataSource}. */ private Domain (String specTable,XMASession session) { if (specTable == null || specTable.length() == 0) throw new IllegalArgumentException(); specTable_ = specTable; session_=session; } /** * Returns the String that specifies the domain table. */ public String getSpecTable () { return specTable_; } // /** // * Sets the String that specifies the domain table. // * // * @param spec according to {@link ITabularDataSource}. // */ // public void setSpecTable (String spec) { // specTable_ = spec; // } /** * Returns the data source plugin */ private void getDSPlugin () { if (dsPlugin_ == null) { // acquiring the DS plugin need not to be thread safe since it is a singleton. // it does not harm if two threads execute this code. if(session_!=null) { dsPlugin_ = (ITabularDataSource)session_.getPluginManager().getPlugin(ITabularDataSource.class); } else { dsPlugin_ = (ITabularDataSource)PluginManagerServer.getInstance().getPlugin(ITabularDataSource.class); } } } /** * Returns the table of domain values associated with the current environment. Note * that the returned table is dependent on the current session, particularely on * the values in the XMAContext.

* * Note that this method may only be used if the executing thread is the same * that dispatched the XMA-RemoteCall. * * @return an Object encapsulating the list of domain values of the domain table * specified at construction time. */ public ITabularDomData getDomTable () { if (dsPlugin_ == null) getDSPlugin(); if(session_!=null) { return dsPlugin_.getDomTable(specTable_, session_); } else { return dsPlugin_.getDomTable(specTable_, XMASessionServer.getXMASession()); } } /** * Returns an object providing information about a domain value whose key is * given. The domain table is looked up for the key and * the right IDomRow object for the key is returned.

* * Note that this method may only be used if the executing thread is the same * that dispatched the XMA-RemoteCall. * * @return IDomRow object or null, if !hasValue() or * the table does not contain a record with the stored key. */ public IDomRow getDomRow (String key) { if (key == null || key.length() == 0) throw new IllegalArgumentException(); ITabularDomData domTable = getDomTable(); return domTable.getDomRow(key); } /** * Returns the Locale-dependent short value associated with the key. * * @return short value or the empty String if the key is not in the domain table. */ public String getShortValue (String key) { IDomRow row = getDomRow(key); return row == null ? "" : row.getShortValue(); } /** * Returns the Locale-dependent long value associated with the key stored in this. * * @return long value or the empty String if the key is not in the domain table. */ public String getLongValue (String key) { IDomRow row = getDomRow(key); return row == null ? "" : row.getLongValue(); } /** * Returns whether the key identifies a row in the associated domain * table and the row is valid with respect to the valid-begin- and end-dates. Hence, * this method defines if the value is a end-user visible one or not. Programmers * should use isInTable() to figure out if a value is contained in the * table. * * @see ITabularDomData * @return boolean indicating that the value is in the validity-time-range. */ public boolean isValid (String key) { IDomRow row = getDomRow(key); return row == null ? false : row.isInValidTimeRange(); } /** * Returns whether there exists a row in the associated domain table whose key is * the one stored in this. * * @return true, if the key is present in the dom table. true implies * that getDomRow() != null and vice versa. */ public boolean isInTable (String key) { return getDomRow(key) != null; } /** * Extracts the value of the type-parameter from the baseSpec. */ public String getDomainType () { // extract type int firstComma = specTable_.indexOf(',', 5); if (firstComma == -1) return specTable_.substring(5); return specTable_.substring (5, firstComma); } /** * Returns an array with all IDomRows of a domain. * A IDomRow provides information about a domain row. * * Note that this method may only be used if the executing thread is the same * that dispatched the XMA-RemoteCall. * * @param onlyInValidTimeRange if true then only rows with IDomRow.isInValidTimeRange() are returned * - if false all rows are returned. * @return An array with IDomRows of a domain. * @since version_number * @author s3460 */ public IDomRow[] getDomRows(boolean onlyInValidTimeRange){ ITabularDomData domTable = getDomTable(); List list = new ArrayList(); int size = domTable.size(); //IDomRow[] rows = new IDomRow[size]; for (int i=0; iIDomRows of a domain. * A IDomRow provides information about a domain row. * * Note that this method may only be used if the executing thread is the same * that dispatched the XMA-RemoteCall. * @return An array with all time valid IDomRows of a domain.. * @since version_number * @author s3460 */ public IDomRow[] getDomRows(){ return getDomRows(true); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy