//
// CIMScope.java
//
// The contents of this file are subject to the SNIA 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://www.snia.org/resources/openSource.html
//
// 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 Original Code is CIMScope.java
// 
// The Initial Developer of the Original Code is David Simons.
//
// Contributor(s): Peter Rivera
//
//
// This source uses the Solaris WBEM APIs version 2.2. 
// Synchronization will be maintained with the Solaris WBEM APIS,
// which are being standardized through the Java Community Process.
//
//
// $Id: CIMScope.java,v 1.1 2003/07/17 18:32:55 kumpf Exp $
//
// $Log: CIMScope.java,v $
// Revision 1.1  2003/07/17 18:32:55  kumpf
// HP-BAPU: PEP-64 CIM Client and CIM Listener Java Interface
//
// Revision 1.1.1.1  2001/10/31 18:14:38  karl
// import of SNIA 0_7
//
// Revision 1.7  2001/01/02 19:32:06  davidsi
// - Added missing INSTANCE check for toMof() method.
//
// Revision 1.6  2000/11/06 18:13:21  davidsi
// - Reconciled error ids.
//
// Revision 1.5  2000/08/16 05:59:52  shawn
// merge P_TOMCAT31 branch
//
// Revision 1.4.8.1  2000/08/10 00:03:27  shawn
// head merge
//
// Revision 1.4  2000/05/11 10:12:20  davidsi
// - Fixed tabs.
//
// Revision 1.3  2000/05/06 17:04:23  davidsi
// - Modifications to bring classes inline with the SUN WBEM APIs 2.2.
//
// Revision 1.2  2000/02/13 15:09:08  davidsi
// - Added text to cover re-use of Solaris WBEM APIs.
//
// Revision 1.1.1.1  2000/02/06 16:41:03  davidsi
// Initial version.
//
//
//
package org.snia.wbem.cim;

import java.io.Serializable;

/**
    Creates and instantiates a CIM scope, a qualifier attribute that
    indicates the CIM objects with which the qualifier can be used. 
    For example, the qualifier 'ABSTRACT' has the following scope
    definition: Scope (Class Association Indication), meaning that
    it can only be used with classes, associations, and indications.
 */

public class CIMScope extends Object implements Serializable {

    private static final int BAD=0;	    // Indicates unset or bad
    public static final int SCHEMA=1;	    // A CIM schema
    public static final int CLASS=2;	    // A CIM class
    public static final int ASSOCIATION=3;  // A CIM association
    public static final int INDICATION=4;   // A CIM indication
    public static final int PROPERTY=5;     // A CIM property
    public static final int REFERENCE=6;    // A CIM reference
    public static final int METHOD=7;	    // A CIM method
    public static final int PARAMETER=8;    // A CIM parameter
    public static final int INSTANCE=9;     // An instance (NOT SUN)
    public static final int ANY=10;	    // Any CIM element
    
    private static CIMScope[] predefined=new CIMScope[11]; // Initializes an array of predefined CIM scope objects
  
    private int scope=BAD;
    
    static {
	int cnt=0;
	
	predefined[cnt++]=new CIMScope(SCHEMA);
	predefined[cnt++]=new CIMScope(CLASS);
	predefined[cnt++]=new CIMScope(ASSOCIATION);
	predefined[cnt++]=new CIMScope(INDICATION);
	predefined[cnt++]=new CIMScope(PROPERTY);
	predefined[cnt++]=new CIMScope(REFERENCE);
	predefined[cnt++]=new CIMScope(METHOD);
	predefined[cnt++]=new CIMScope(PARAMETER);
	predefined[cnt++]=new CIMScope(INSTANCE);
	predefined[cnt++]=new CIMScope(ANY);
	
    }
    


    private boolean validScope(int iscope) {
	//
	// NOTE: has implicit knowledge of value scope values!
	//
	return(iscope>=SCHEMA && iscope<=ANY);
    }
	
 
    // CIMScope 
    //
    public CIMScope(int iscope) {
	if (!validScope(iscope))
	    throw new ExceptionInInitializerError("Bad scope "+iscope);
	else
	    scope=iscope;  
    }

 
 
    // getScope 
    //
    // Returns a CIMScope with the specified scoping 
    //
    public static CIMScope getScope(int iscope) {
	int i;
	
	for(i=0;i<predefined.length;i++) {
	    if (predefined[i].scope==iscope)
		return(predefined[i]);
	}
	return(null);
    }

    // getScope
    //
    // Returns the integer for the scope
    //
    public int getScope() {
	return(scope);
    } 


    // equals 
    //
    // Determines if the object is a valid CIM scope and is
    // equal to this object
    //
    public boolean equals(Object o) {
       if (! (o instanceof CIMScope) )
	   return(false);
       
       CIMScope cs=(CIMScope)o;
       return(cs.scope==scope);
    }

 
 
 
    // toString 
    public String toString() {
	return(toMOF());
    }
 
    // toMOF 
    public String toMOF() {
	if (scope==SCHEMA)
	    return("SCHEMA");
	if (scope==CLASS)
	    return("CLASS");
	if (scope==ASSOCIATION)
	    return("ASSOCIATION");
	if (scope==INDICATION) 
	    return("INDICATION");
	if (scope==PROPERTY)
	    return("PROPERTY");
	if (scope==REFERENCE)
	    return("REFERENCE");
	if (scope==METHOD)
	    return("METHOD");
	if (scope==PARAMETER)
	    return("PARAMETER");
	if (scope==ANY)
	    return("ANY");
	if (scope==INSTANCE)
	    return("INSTANCE");		
	return("BAD SCOPE");
    }
}
