001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.jasig.portal.ISequenceGenerator;
011: import org.jasig.portal.ISequenceGeneratorFactory;
012: import org.jasig.portal.PortalException;
013: import org.jasig.portal.properties.PropertiesManager;
014:
015: /**
016: * @author Dan Ellentuck
017: * @version $Revision: 34787 $
018: */
019: public class SequenceGenerator {
020: private static final Log log = LogFactory
021: .getLog(SequenceGenerator.class);
022:
023: protected ISequenceGenerator m_sequenceGenerator = null;
024: private static SequenceGenerator m_instance;
025: protected static String s_factoryName = PropertiesManager
026: .getProperty("org.jasig.portal.SequenceGeneratorFactory.implementation");
027: protected static ISequenceGeneratorFactory m_Factory = null;
028: static {
029: // Look for our factory and instantiate an instance.
030: if (s_factoryName == null) {
031: log
032: .error(
033: "Sequence Provider not specified or incorrect in portal.properties",
034: new PortalException(
035: "Sequence Provider not specified or incorrect in portal.properties"));
036: } else {
037: try {
038: m_Factory = (ISequenceGeneratorFactory) Class.forName(
039: s_factoryName).newInstance();
040: } catch (Exception e) {
041: log.error("Failed to instantiate " + s_factoryName,
042: new PortalException("Failed to instantiate "
043: + s_factoryName));
044: }
045: }
046: }
047:
048: /**
049: */
050: public SequenceGenerator() {
051: m_sequenceGenerator = m_Factory.getSequenceGenerator();
052: }
053:
054: /**
055: * @param name String
056: */
057: public void createCounter(String name) throws Exception {
058: m_sequenceGenerator.createCounter(name);
059: }
060:
061: /**
062: * @return String
063: */
064: public String getNext() throws Exception {
065: return m_sequenceGenerator.getNext();
066: }
067:
068: /**
069: * @param name String
070: * @return String
071: */
072: public String getNext(String name) throws Exception {
073: return m_sequenceGenerator.getNext(name);
074: }
075:
076: /**
077: * @return int
078: */
079: public int getNextInt() throws Exception {
080: return m_sequenceGenerator.getNextInt();
081: }
082:
083: /**
084: * @param name String
085: * @return int
086: */
087: public int getNextInt(String name) throws Exception {
088: return m_sequenceGenerator.getNextInt(name);
089: }
090:
091: /**
092: * @return SequenceGenerator
093: */
094: public final static synchronized SequenceGenerator instance() {
095: if (m_instance == null) {
096: m_instance = new SequenceGenerator();
097: }
098: return m_instance;
099: }
100:
101: /**
102: * @param name java.lang.String
103: * @param newValue int
104: */
105: public void setCounter(String name, int newValue) throws Exception {
106: m_sequenceGenerator.setCounter(name, newValue);
107: }
108:
109: }
|