BooleanRange.java :  » Content-Management-System » harmonise » org » openharmonise » rm » resources » metadata » properties » ranges » Java Open Source

Java Open Source » Content Management System » harmonise 
harmonise » org » openharmonise » rm » resources » metadata » properties » ranges » BooleanRange.java
/*
 * The contents of this file are subject to the 
 * Mozilla Public License Version 1.1 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 *
 * 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.
 *
 * The Initial Developer of the Original Code is Simulacra Media Ltd.
 * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
 *
 * All Rights Reserved.
 *
 * Contributor(s):
 */
package org.openharmonise.rm.resources.metadata.properties.ranges;

import java.text.*;
import java.util.StringTokenizer;

import org.openharmonise.rm.metadata.GeneralPropertyInstance;


/**
 * Class which represents a <code>Property</code> range which is
 * restricted to <code>Boolean</code> values.
 * 
 * @author Michael Bell
 * @version $Revision: 1.2 $
 *
 */
public class BooleanRange extends AbstractRange {
  
  /**
   * Default label for the boolean 'true'
   */
  private static final String DEFAULT_TRUE_LABEL = "yes";
  
  /**
   * Default label for the boolean 'false'
   */
  private static final String DEFAULT_FALSE_LABEL = "no";
  
  /**
   * Separator character used to separate labels in details field
   */
  private static final String SEPARATOR = "|";
  
  /**
   * Current label for the boolean 'true'
   */
  private String m_sTrueLabel = DEFAULT_TRUE_LABEL;
  
  /**
   * Current label for the boolean 'false'
   */
  private String m_sFalseLabel = DEFAULT_FALSE_LABEL;
  
  /**
   * Boolean range tag name
   */
  public final static String TAG_BOOLEAN_RANGE = "BooleanRange";

  /**
   * Constructs a new <code>BooleanRange</code>
   */
  public BooleanRange() {
    super(Boolean.class.getName());
  }


  /* (non-Javadoc)
   * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
   */
  public boolean isValid(Object obj) {
    
    return obj instanceof Boolean;
  }
  
  /**
   * Return the label for the boolean 'true' value.
   * 
   * @return the label for the boolean 'true' value.
   */
  public String getTrueLabel() {
    return m_sTrueLabel;
  }
  
  /**
   * Return the label for the boolean 'false' value.
   * 
   * @return the label for the boolean 'false' value.
   */
  public String getFalseLabel() {
    return m_sFalseLabel;
  }
  
  /**
   * Sets the label for the boolean 'true' label.
   * 
   * @param sTrueLabel the label for the boolean 'true' label
   */
  public void setTrueLabel(String sTrueLabel) {
    if(sTrueLabel != null && m_sTrueLabel.equals(sTrueLabel) == false) {
      isChanged(true);
      m_sTrueLabel = sTrueLabel;
    }
  }
  
  /**
   * Sets the label for the boolean 'false' label.
   * 
   * @param sTrueLabel the label for the boolean 'false' label
   */
  public void setFalseLabel(String sFalseLabel) {
    if(sFalseLabel != null && m_sTrueLabel.equals(sFalseLabel) == false) {
      isChanged(true);
      m_sFalseLabel = sFalseLabel;
    }
  }

  /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(Object obj) {
    boolean bResult = false;

    if (obj instanceof BooleanRange) {
      bResult = super.equals(obj);
    }

    return bResult;
  }

  /* (non-Javadoc)
   * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getPropertyInstanceClass()
   */
  public Class getPropertyInstanceClass() throws ClassNotFoundException {
    return GeneralPropertyInstance.class;
  }
  
  /* (non-Javadoc)
   * @see org.openharmonise.rm.publishing.Publishable#getTagName()
   */
  public String getTagName() {
    return TAG_BOOLEAN_RANGE;
  }
  
  /* (non-Javadoc)
   * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getDetails()
   */
  public String getDetails() {

    if (isChanged()) {
      StringBuffer strbuf = new StringBuffer();
      
      strbuf.append(m_sTrueLabel)
        .append(SEPARATOR)
        .append(m_sFalseLabel);
      
      super.setDetails(strbuf.toString());
    }

    return super.getDetails();
  }
  
  /* (non-Javadoc)
   * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#setDetails(java.lang.String)
   */
  public void setDetails(String sDetails) {
    if (sDetails != null) {
      StringTokenizer tokenizer =
        new StringTokenizer(sDetails, SEPARATOR);
      SimpleDateFormat formatter = null;

      int i = 0;
      int nTmp = 0;
      while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();

        if (token != null && token.length() > 0) {
          
          if(i == 0) {
            m_sTrueLabel = token;
          } else {
            m_sFalseLabel = token;
          }
        }
        i++;
      }
    }

    super.setDetails(sDetails);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.