//
// MOFParse.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 MOFParse.java
// 
// The Initial Developer of the Original Code is David Simons.
//
// Contributor(s):
// cv.vick@intel.com
// m.chang@intel.com
// hfcheng
// Scott Baker
//
// 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: MOFParse.java,v 1.1 2003/07/17 18:32:55 kumpf Exp $
//
// $Log: MOFParse.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.2  2002/06/06 16:12:24  viktor
// Added Provider Adapter Support as announced in mailing list.
// The provider support is backward compatible.
//
// Revision 1.10  2001/08/05 12:18:28  davidsi
// - Fixed key qualifiers (etc) on references (thanks to Daniel Abramovich
//   for pointing this out).
//
// Revision 1.9  2001/03/20 17:28:11  davidsi
// - From scott baker - modified the INTELMOD in valueInitializer so that
//   aliases work.
//
// Revision 1.7  2000/11/11 15:37:06  davidsi
// - From hfcheng, added support for forcing update.
//
// Revision 1.6  2000/08/16 05:59:58  shawn
// merge P_TOMCAT31 branch
//
// Revision 1.5.8.1  2000/08/10 00:03:33  shawn
// head merge
//
// Revision 1.5  2000/05/11 10:11:35  davidsi
// - Fixed tabs.
//
// Revision 1.4  2000/05/06 17:10:24  davidsi
// - Brought in line with SUN WBEM APIs 2.2
// - Various fixes (handle no qualifiers on classes and the setting
//   of references)
// - Significant number of performance improvements -- no longer rely
//   on being able to look ahead arbitrary numbers of tokens.
//
// Revision 1.3  2000/04/09 14:18:28  davidsi
// - Modified parse mechanism to use single token lookaheads.
// - Improved error handling to ensure errors are accurately reported
//   against the line on which they occurred.
//
// Revision 1.2  2000/02/13 15:09:54  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.wbemcmd.mof;

import java.io.*;
import java.util.*;
import java.util.Vector;

import org.snia.wbem.client.CIMClient;
import org.snia.wbem.cim.CIMNameSpace;
import org.snia.wbem.cim.CIMElement;
import org.snia.wbem.cim.CIMObjectPath;
import org.snia.wbem.cim.CIMException;
import org.snia.wbem.cim.CIMClass;
import org.snia.wbem.cim.CIMInstance;
import org.snia.wbem.cim.CIMNameSpace;
import org.snia.wbem.cim.CIMQualifierType;
import org.snia.wbem.cim.CIMQualifier;
import org.snia.wbem.cim.CIMException;
import org.snia.wbem.cim.CIMFlavor;
import org.snia.wbem.cim.CIMScope;
import org.snia.wbem.cim.CIMProperty;
import org.snia.wbem.cim.CIMParameter;
import org.snia.wbem.cim.CIMValue;
import org.snia.wbem.cim.CIMDataType;
import org.snia.wbem.cim.CIMMethod;
import org.snia.wbem.cim.CIMException;
import org.snia.wbem.cim.CIMValue;
import org.snia.wbemcfg.GlobalConfig;

//
// TODO: need to ensures an idenifier isn't a reserved word
//
public class MOFParse {
    MOFStatus status;
    MOFLexer lex;
    String directory;	 
    boolean forceUpdate=false;
    boolean extendedMode=false;
    Vector aliasIdentifiers=new Vector();   // String - names of aliases
    Vector aliasValues=new Vector();	    // CIMObjectPath - corresponding values
					    // for aliases
    Vector instancesPaths=new Vector();     // CIMObjectPath - instance paths
    Vector instancesToCreate=new Vector();  // CIMInstance - corresponding values
					    // to instancesPaths
    StringBuffer strBuf=new StringBuffer();
    CIMNameSpace currentNameSpace=null;
    CIMNameSpace callerNameSpace=null;

    private boolean nameSpaceOk(CIMClient cc, String nsn) {
        try {
           Enumeration elist=cc.enumNameSpace(
                   new CIMObjectPath("",(Vector)null),
                   CIMClient.DEEP);
           Vector v=new Vector();
           if (elist!=null) {
               while (elist.hasMoreElements())
                  if (((String)(elist.nextElement())).equalsIgnoreCase(nsn))
                     return true;

           }
        }
        catch (CIMException ce) { }

        return false;
    }



    CIMObjectPath makeCIMObjectPath(String name) {
	 CIMObjectPath cop=new CIMObjectPath(name);
         cop.setNameSpace(currentNameSpace.getNameSpace());
	 return(cop);
    }
	 
    //
    // Extracts a sequence of strings (must be at least 1)
    //
    String stringSequence() throws MOFParseFailException {
	MOFToken tk=lex.token();
	
	if (tk.id!=tk.STRING_VALUE)
	    throw new MOFParseException(tk,"Required at least one string");
	String str=tk.tokenString();
	tk=lex.token();
	if (tk.id==tk.STRING_VALUE) {
	    strBuf.setLength(0);
	    strBuf.append(str);
	    do {
		strBuf.append(tk.tokenString());
		tk=lex.token();
	    } while (tk.id==tk.STRING_VALUE);
	    str=strBuf.toString();
	}
	lex.setLookAhead(tk);
	
	return(str);
    }
    
    
    void checkToken(String pos,int val) throws MOFParseException {
	MOFToken tk;
       
	tk=lex.token();
	if (tk.id!=val) {
	   throw new MOFParseException(tk,
		    "Missing token in \""+pos+"\" declaration wanted "+tk.tokenName(val));
	}
    }
    
    //
    // dataType
    //
    CIMDataType []typeInfo;
    CIMDataType dataType(MOFToken tk)  {
	if (typeInfo==null) {
	    typeInfo=new CIMDataType[MOFToken.getMaxID()];
	    typeInfo[MOFToken.DT_UINT8]=new CIMDataType(CIMDataType.UINT8);
	    typeInfo[MOFToken.DT_SINT8]=new CIMDataType(CIMDataType.SINT8);
	    typeInfo[MOFToken.DT_UINT16]=new CIMDataType(CIMDataType.UINT16);
	    typeInfo[MOFToken.DT_SINT16]=new CIMDataType(CIMDataType.SINT16);
	    typeInfo[MOFToken.DT_UINT32]=new CIMDataType(CIMDataType.UINT32);
	    typeInfo[MOFToken.DT_SINT32]=new CIMDataType(CIMDataType.SINT32);
	    typeInfo[MOFToken.DT_UINT64]=new CIMDataType(CIMDataType.UINT64);
	    typeInfo[MOFToken.DT_SINT64]=new CIMDataType(CIMDataType.SINT64);
	    typeInfo[MOFToken.DT_REAL32]=new CIMDataType(CIMDataType.REAL32);
	    typeInfo[MOFToken.DT_REAL64]=new CIMDataType(CIMDataType.REAL64);
	    typeInfo[MOFToken.DT_CHAR16]=new CIMDataType(CIMDataType.CHAR16);
	    typeInfo[MOFToken.DT_STR]=new CIMDataType(CIMDataType.STRING);
	    typeInfo[MOFToken.DT_BOOL]=new CIMDataType(CIMDataType.BOOLEAN);
	    typeInfo[MOFToken.DT_DATETIME]=new CIMDataType(CIMDataType.DATETIME);
	}
	return(typeInfo[tk.id]);
    }
    
    
    //
    // 
    CIMDataType array(CIMDataType intype) throws MOFParseFailException {
	MOFToken tk;
	CIMDataType adn;
	
	tk=lex.token();
	if (tk.id==tk.DECIMAL_VALUE) {
	   adn=new CIMDataType(
		       CIMDataType.findArrayType(intype.getType()),
		       tk.tokenNumber());
	   tk=lex.token();
	} else
	    adn=new CIMDataType(
		       CIMDataType.findArrayType(intype.getType()));
	    
	if (tk.id!=tk.CLOSE_SQU_BRA)
	   throw new MOFParseFailException(tk,"Badly constructed array declaration");
	return(adn);
    }
   
    //
    // initializer = constantValue | arrayInitializer | referenceInitalizer
    //
    CIMValue initializer(MOFToken tk) throws MOFParseFailException {
       
	//
	// referenceInitializers that are strings get handled in the normal
	// manner, aliases can't so we deal with them here
	//
	if (tk.id==MOFToken.ALIAS_IDENTIFIER) {
	    CIMObjectPath cop=new CIMObjectPath();
	    CIMValue cv=new CIMValue(cop);
	    aliasIdentifiers.addElement(tk.tokenString());
	    aliasValues.addElement(cop);
	    return(cv);
	}
	lex.setLookAhead(tk);
	
	 //
	// Deal with constantValue
	//
	try {
	    return(constantValue());
	} catch (MOFParseException pe) {
	    //
	    // May not be an array declaration
	    //
	    lex.setLookAhead(tk);
	    return(arrayInitializer());
	}
    }
    
    //
    // constantValue =DECIMAL_VALUE|...| FALSE_VALUE
    //
    CIMValue constantValue() throws MOFParseFailException {
	MOFToken tk;
	int tkint=(tk=lex.token()).id;
	int id;
	String str;
	    
	if (tkint==tk.DECIMAL_VALUE) {
	    id=CIMDataType.UINT32;
	    str=tk.tokenString();
	} else if (tkint==tk.BINARY_VALUE) {
	    id=CIMDataType.UINT32;
	    str=tk.tokenString();
	} else if (tkint==tk.OCTAL_VALUE) {
	    id=CIMDataType.UINT32;
	    str=tk.tokenString();
	} else if (tkint==tk.HEX_VALUE) {
	    id=CIMDataType.UINT32;
	    str=tk.tokenString();
	} else if (tkint==tk.REAL_VALUE) {
	    id=CIMDataType.REAL32;
	    str=tk.tokenString();    
	} else if (tkint==tk.CHAR_VALUE) {
	    id=CIMDataType.CHAR16;
	    str=tk.tokenString();
	} else if (tkint==tk.STRING_VALUE) {
	    str=tk.tokenString();

	    tkint=(tk=lex.token()).id;
	    if(tkint==tk.STRING_VALUE) {
		strBuf.setLength(0);
		strBuf.append(str);
		do {
		    strBuf.append(tk.tokenString());
		    tkint=(tk=lex.token()).id;
		} while (tkint==tk.STRING_VALUE);
		str=strBuf.toString();
	    }
	    lex.setLookAhead(tk);

	    id=CIMDataType.STRING;
	} else if (tkint==tk.NULL_VALUE) {
	    str=new String("NULL");
	    id=CIMDataType.NULL;
	} else if (tkint==tk.TRUE_VALUE) {
	    str=new String("TRUE");
	    id=CIMDataType.BOOLEAN;
	} else if (tkint==tk.FALSE_VALUE) {
	    str=new String("FALSE");
	    id=CIMDataType.BOOLEAN;
	} else 
	    throw new MOFParseException(tk,"Expected a constant");
	
	return(new CIMValue(str,CIMDataType.getPredefinedType(id)));
    }
    

    //
    // arrayInitializer = "{" constantValue ( "," constantValue )* "}"
    //
    CIMValue arrayInitializer() throws MOFParseFailException {
	Vector vect=new Vector();
	CIMDataType dt=null;
	CIMValue si;
	int arraytype;
	int arraylen=0;
	
	MOFToken tk=null;
	checkToken("Array Initializer",MOFToken.OPEN_CUR_BRA);
	for(;;) {
	    si=constantValue();
	    if (dt==null) {
		dt=si.getType();
	    } else {
		CIMDataType newdt=si.getType();
		if (newdt.getType()!=dt.getType())
		     throw new MOFParseException(tk,"Bad array initialization list - mixed types");
	    }
	    vect.addElement(si);
	    arraylen++;
	    tk=lex.token();
	    if (tk.id!=MOFToken.COMMA)
		break;
	}
	if (tk==null || tk.id!=tk.CLOSE_CUR_BRA)
		throw new MOFParseException(tk,"Bad array initialization list");
	
	if (dt!=null) {
	    arraytype=dt.findArrayType(dt.getType());
	    dt=new CIMDataType(arraytype,arraylen);
	 }
		
	 return(new CIMValue(vect,dt));
    }
    
    //
    // defaultValue = "=" initializer
    //	 
    CIMValue defaultValue(MOFToken tk) throws MOFParseFailException {
	if (tk.id!=MOFToken.EQUAL) {
	    lex.setLookAhead(tk);
	    throw new MOFParseException("no default value");
	}
	try {
	    return(initializer(lex.token()));
	} catch (MOFParseException mpe) {
	    throw new MOFParseFailException ("Failed to parse default value\n"+mpe);
	}
    }
    
    
    //
    // defaultFlavor = FLAVOR "(" flavor ("," flavor)* ")"
    //
    // NOTE: Assumes comma has already been parsed
    void defaultFlavor(Vector flavors) throws MOFParseException {
	boolean sflag=true;
	boolean aflag=true;
	boolean iflag=true;
	boolean qflag=true;
	boolean tflag=true;

	checkToken("Flavor",MOFToken.FLAVOR);
	checkToken("Flavor",MOFToken.OPEN_BRA);

	MOFToken tk=null;
	for(;;) {
	    
	    int tkint=(tk=lex.token()).id;

	    if (tkint==tk.SCHEMA) {
	    } else if (sflag && tkint==tk.ENABLEOVERRIDE) {
		sflag=false;
		flavors.addElement(CIMFlavor.getFlavor(CIMFlavor.ENABLEOVERRIDE));
	    } else if (aflag && tkint==tk.DISABLEOVERRIDE) {
		aflag=false;
		flavors.addElement(CIMFlavor.getFlavor(CIMFlavor.DISABLEOVERRIDE));
	    } else if (iflag && tkint==tk.RESTRICTED) {
		iflag=false;
		flavors.addElement(CIMFlavor.getFlavor(CIMFlavor.RESTRICTED));
	    } else if (qflag && tkint==tk.TOSUBCLASS) {
		qflag=false;
		flavors.addElement(CIMFlavor.getFlavor(CIMFlavor.TOSUBCLASS));
	    } else if (tflag && tkint==tk.TRANSLATABLE) {
		tflag=false;
		flavors.addElement(CIMFlavor.getFlavor(CIMFlavor.TRANSLATE));
	    } else 
	      throw new MOFParseException(tk,"Missing or bad meta element in flavor");
 
	     tk=lex.token();
	    if (tk.id!=tk.COMMA)
		break;
	}
    
	if ( tk==null )
	    throw new MOFParseException("At least one flavor must be specified");

		
	if ( sflag && aflag && iflag && qflag && tflag )
	    throw new MOFParseException(tk,"At least one flavor must be specified");

	if (tk.id!=tk.CLOSE_BRA)
	    throw new MOFParseException(tk,"Bad flavor list");
    }
    
    // PRAGMA rule (assumed PRAGMA already located)
    //
    void mofPragma(CIMClient cc) throws MOFParseFailException {
	String pragmaval;

	MOFToken tkid=lex.tokenIdentifier();
	if (tkid.id!=tkid.IDENTIFIER)
	    throw new MOFParseException(tkid,"Missing identifier in pragma declaration\n"+
		"Found token "+tkid.tokenName());


	checkToken("Pragma",tkid.OPEN_BRA);

	pragmaval=stringSequence();
		
	checkToken("Pragma",tkid.CLOSE_BRA);
	
	if (tkid.tokenString().equalsIgnoreCase("include")) {
	    MOFLexer oldlex=lex;
	    
	    lex=new MOFLexer(status);
	    String pathname=new String(directory+pragmaval);
	    
	    lex.load(pathname);
    
	    try { 
                mofSpecification(cc);
	    } catch (CIMException ce) {
		throw new MOFParseException("Failed to include file "+pathname+
				"\nCIM Error:"+ce);
	    } catch (MOFParseFailException ce) {
		throw new MOFParseException("Failed to include file "+pathname+
				"\n"+ce);
	    }
	    lex=oldlex;
	    status.fileOpened(lex.getPathName());
	}
        else if (tkid.tokenString().equalsIgnoreCase("namespace")) {
           if (nameSpaceOk(cc,pragmaval))
              currentNameSpace.setNameSpace(pragmaval);
           else if (forceUpdate) {
              try {
                 cc.createNameSpace(
                    new CIMNameSpace(currentNameSpace.getHost(),pragmaval));
                 currentNameSpace.setNameSpace(pragmaval);
              }
              catch (CIMException e) {
                 throw new MOFParseException(tkid,"Failed to create namespace "+pragmaval);
              }
           }
           else {
               throw new MOFParseException(tkid,"Namespace "+pragmaval+" does not exist");
           }
        }
	//
	// TODO, other pragams...
	//
	return;
    }
    
    //
    // qualifierDeclaration = QUALIFIER qualiferName qualifierType scope
    //				[ defaultFlavor ] ";"
    //
    // QUALIFIER rule (assumed QUALIFIER already located)
    //
    void qualifierDeclaration(CIMClient cc) throws MOFParseFailException, CIMException {

	CIMDataType datatype;	    // DT_SINT8 etc from token
	String qualifierName;
	MOFToken tkid=lex.tokenIdentifier();
	if (tkid.id!=MOFToken.IDENTIFIER)
	    throw new MOFParseException(tkid,"Missing identifier in qualifier declaration");
	qualifierName=tkid.tokenString();
	checkToken("QUALIFIER",MOFToken.COLON);
	
	//
	// Set up after QUALIFIER has been identified
	//
	boolean sflag=true;
	boolean cflag=true;
	boolean aflag=true;
	boolean iflag=true;
	boolean qflag=true;
	boolean pflag=true;
	boolean rflag=true;
	boolean mflag=true;
	boolean yflag=true;
	boolean paflag=true;
	CIMDataType arraydecl=null;	     // array declaration info
	CIMValue dvn=null;		    // default value
	Vector flavor=new Vector();	    // CIMFlavor 
	Vector scope=new Vector();	    // CIMScope
	MOFToken tk=lex.token();
	
	datatype=dataType(tk);
	if (datatype==null)
	    throw new MOFParseFailException("No data type found for qualifier");

	//
	// Deal with [ array ]
	//
	tk=lex.token();
	if (tk.id==MOFToken.OPEN_SQU_BRA) {
	    datatype=array(datatype);
	    tk=lex.token();
	} 
	
	//
	// Deal with [ defaultValue ]
	//
	try {
	    dvn=defaultValue(tk);
	} catch (MOFParseException pe) {
	}

	//
	// Deal with scope
	//
	checkToken("QUALIFIER",MOFToken.COMMA);

	checkToken("QUALIFIER",MOFToken.SCOPE);
	checkToken("QUALIFIER",MOFToken.OPEN_BRA);

	
	for(;;) {
	    int tkint=(tkid=lex.token()).id;
	    
	    if (sflag && tkint==MOFToken.SCHEMA) {
		sflag=false;
		 scope.addElement(new CIMScope(CIMScope.SCHEMA));
	    } else if (cflag && tkint==MOFToken.CLASS) {
		cflag=false;
		scope.addElement(new CIMScope(CIMScope.CLASS));
	    } else if (aflag && tkint==MOFToken.ASSOCIATION) {
		aflag=false;
		  scope.addElement(new CIMScope(CIMScope.ASSOCIATION));
	    } else if (iflag && tkint==MOFToken.INDICATION) {
		iflag=false;
		scope.addElement(new CIMScope(CIMScope.INDICATION));
	//
	// Although the BNF allows this it wouldn't make much sense..
	//
	//    } else if (qflag && tkint==tk.QUALIFIER) {
	//	  qflag=false;
	//	  qdn.declareQualifier();
	    } else if (pflag && tkint==MOFToken.PROPERTY) {
		pflag=false;
		scope.addElement(new CIMScope(CIMScope.PROPERTY ));
	    } else if (rflag && tkint==MOFToken.REFERENCE) {
		rflag=false;
		 scope.addElement(new CIMScope(CIMScope.REFERENCE));
	    } else if (mflag && tkint==MOFToken.METHOD) {
		mflag=false;
		scope.addElement(new CIMScope(CIMScope.METHOD));
	    } else if (yflag && tkint==MOFToken.ANY) {
		yflag=false;
		scope.addElement(new CIMScope(CIMScope.ANY));
	    } else if (paflag && tkint==MOFToken.PARAMETER) {
		paflag=false;
		scope.addElement(new CIMScope(CIMScope.PARAMETER));
	    } else 
		throw new MOFParseException(tkid,"Missing or bad meta element in QUALIFIER");

	    tkint=(tkid=lex.token()).id;
	    if (tkint==MOFToken.CLOSE_BRA)
		break;
	    else if (tkint!=MOFToken.COMMA)
		throw new MOFParseException(tkid,"Expected a comma in QUALIFIER");
	}

	if ( sflag && cflag && aflag && iflag && 
	     qflag && pflag && rflag && mflag && yflag && paflag)
	     throw new MOFParseException(tkid,"No meta element specified in QUALIFIER");
	//
	// Deal with [ defaultFlavor ]
	//
	tk=lex.token();
	if (tk.id==MOFToken.COMMA) {
	    try {
		defaultFlavor(flavor);
		tk=lex.token();
	    } catch (MOFParseException pe) {
		throw new MOFParseFailException("Failed to parse default flavor qualifier declaration\n"+
				pe);
	    }
	}
	if (tk.id!=MOFToken.SEMICOLON)
	    throw new MOFParseFailException("Failed to locate semicolon in qualifier declaration");

	CIMObjectPath cop;
	CIMQualifierType cimQualifierType=new CIMQualifierType();

	//
	// Qualifier appears at root level
	//
        cop=makeCIMObjectPath(qualifierName);
	    
	//
	// Initialize qualifier
	//
	cimQualifierType.setName(qualifierName);
	cimQualifierType.setDefaultValue(dvn);
	cimQualifierType.setType(datatype);
	for(int i=0;i<flavor.size();i++) {
	    CIMFlavor cf=(CIMFlavor)(flavor.elementAt(i));
	    cimQualifierType.addFlavor(cf);
	}
	for(int i=0;i<scope.size();i++) {
	    CIMScope cf=(CIMScope)(scope.elementAt(i));
	    cimQualifierType.addScope(cf);
	}
	//
	// Add the class definition
	//
	cc.createQualifierType(cop,cimQualifierType);
    }

    //
    // qualifier = qualifierName [ qualifierParameter] [ ":" flavor*1 ]
    //
    CIMQualifier qualifier() throws MOFParseFailException {
	MOFToken tkid=lex.tokenIdentifier();
	MOFToken tk;
	int count;
	int id;
	CIMValue value=null;
	String identifier=null;
	Vector flavor=new Vector();		    // CIMFlavor
	
	
	if (tkid.id!=tkid.IDENTIFIER)
	    throw new MOFParseException(tkid,"Missing identifier in qualifier declaration");
	identifier=tkid.tokenString();
	tk=lex.token();
	if (tk.id==tk.OPEN_BRA) {
	    value=constantValue();
	    checkToken("qualifier instance",tk.CLOSE_BRA);
	    tk=lex.token();
	} else if (tk.id==tk.OPEN_CUR_BRA) {
	    lex.setLookAhead(tk);
	    value=arrayInitializer();
	    tk=lex.token();
	} else {
	    value=new CIMValue("true",CIMDataType.getPredefinedType(
				    CIMDataType.BOOLEAN));
	}
	//
	// Process optional ":" flavor*1
	//
	if (tk.id==MOFToken.COLON) {
	    count=0;
	    
	    for(;;) {
		tk=lex.token();
		id=tk.id;
		if (id==MOFToken.ENABLEOVERRIDE)
		    flavor.addElement(CIMFlavor.getFlavor(CIMFlavor.ENABLEOVERRIDE));
		else if (id==MOFToken.DISABLEOVERRIDE)
		    flavor.addElement(CIMFlavor.getFlavor(CIMFlavor.DISABLEOVERRIDE));
		else if (id==MOFToken.RESTRICTED) 
		    flavor.addElement(CIMFlavor.getFlavor(CIMFlavor.RESTRICTED));
		else if (id==MOFToken.TOSUBCLASS)
		    flavor.addElement(CIMFlavor.getFlavor(CIMFlavor.TOSUBCLASS));
		else if (id==MOFToken.TRANSLATABLE) 
		    flavor.addElement(CIMFlavor.getFlavor(CIMFlavor.TRANSLATE));
		else
		    break;
		count++;
	    }
	    lex.setLookAhead(tk);
	    if (count==0)
		 throw new MOFParseException(tkid,"Require at least one flavor");
	} else
	    lex.setLookAhead(tk);
	
	
	CIMQualifierType qtype=new CIMQualifierType();
	qtype.setType(value.getType());
	if (value!=null) {
	    for(int i=0;i<flavor.size();i++)
		qtype.addFlavor((CIMFlavor)flavor.elementAt(i));
	}
	 CIMQualifier qual=new CIMQualifier(identifier,qtype);
	 qual.setValue(value);
	
	return(qual);
    }
    
    //
    // qualiferList =  qualifier ( "," qualifer ) "]"
    //
    // NOTE: There is no '[' - it is assumed the caller has
    // already found this!
    //
    Vector qualifierList() throws MOFParseFailException {
	Vector v=new Vector();
	MOFToken tk;
       
	for(;;) {
	    v.addElement(qualifier());
	    tk=lex.token();
	    if (tk.id!=MOFToken.COMMA)
		break;
	}
	if (tk.id!=MOFToken.CLOSE_SQU_BRA)
		throw new MOFParseException(tk,"Bad array initialization list");
	return(v);
    }
    
    

    
    //
    // alias = AS aliasIdentifier 
    //
    String alias() throws MOFParseFailException {
	MOFToken tk=lex.token();
	if (tk.id!=MOFToken.AS) {
	    lex.setLookAhead(tk);
	    throw new MOFParseException("no alias");
	}
	MOFToken tkid=lex.token();
	if (tkid.id!=tkid.ALIAS_IDENTIFIER)
	    throw new MOFParseFailException(tkid,"Missing alias in AS declaration");
	    
	return(tkid.tokenString());
    }
    
    
    //
    // superClass = : className 
    //
    String superClass() throws MOFParseFailException {
	MOFToken tk=lex.token();
	if (tk.id!=MOFToken.COLON) {
	    lex.setLookAhead(tk);
	    throw new MOFParseException("no superClass declaration");
	}
	MOFToken tkid=lex.className();
	if (tkid.id!=tkid.IDENTIFIER)
	    throw new MOFParseFailException(tkid,"Missing classname in declaration");
	return(tkid.tokenString());
    }
    
       
    //
    // parameter= [qualifierList] methodType [ array ] parameterName
    //
    CIMParameter parameter() throws MOFParseFailException {
	MOFToken tkid;
	CIMDataType datatype;
	Vector qualList=null;  
	CIMDataType afn=null;
	CIMParameter pm=new CIMParameter();
	
	
	
	//
	// Get Qualifiers
	//
	MOFToken tk=lex.token();
	if (tk.id==MOFToken.OPEN_SQU_BRA) {
	    qualList=qualifierList();
	    pm.setQualifiers(qualList);
	    tk=lex.token();
	} 

	//
	// Set the data type
	//
	datatype=dataType(tk);
	if (datatype==null) {
	    if (tk.id!=MOFToken.IDENTIFIER)
		throw new MOFParseFailException(tk,"Bad data type for property");
	    checkToken("property ref declaration",MOFToken.REF);
	    datatype=new CIMDataType(tk.tokenString());
	} 
	tkid=lex.tokenIdentifier();
	if (tkid.id!=tkid.IDENTIFIER)
	    throw new MOFParseException(tkid,"Missing parameter name");

	//
	// Deal with [ array ]
	//
	tk=lex.token();
	if (tk.id==MOFToken.OPEN_SQU_BRA) {
	    datatype=array(datatype);
	} else {
	    lex.setLookAhead(tk);
	}
	
	pm.setType(datatype);
	pm.setName(tkid.tokenString());
   
	return(pm);
    }
    
    //
    // propertyDeclaration= [qualifierList] dataType 
    //		    propertyName [ array ] [defaultValue] ";"
    //
    // Caller is responsible for parsing everything upto and including the propertyname
    //
    CIMProperty propertyDeclaration(Vector qfn,CIMDataType datatype,String propertyName,String className) throws MOFParseFailException, CIMException {
	CIMProperty cp=new CIMProperty();

	cp.setName(propertyName);   
	
	//
	// Deal with [ array ]
	//
	MOFToken tk=lex.token();
	if (tk.id==MOFToken.OPEN_SQU_BRA) {
	    datatype=array(datatype);
	    tk=lex.token();
	} 
	//
	// Set datatype for property
	//
	cp.setType(datatype);

	try {
	    cp.setValue(defaultValue(tk));
	} catch (MOFParseException pe) {
	}
	checkToken("property declaration",MOFToken.SEMICOLON);
	
	//
	// Finally set up rest of property, now that parsing is complete...
	//
	// Add qualifiers vector to this property
	//
	if (qfn!=null) {
	    cp.setQualifiers(qfn);
	    for(int i=0;i<qfn.size();i++) {
		CIMQualifier qual=(CIMQualifier)(qfn.elementAt(i));
		if (qual.getName().equals("OVERRIDE"))
		   cp.setOverridingProperty((String)(qual.getValue().getValue()));
	    }
	}
	
	
	//
	// Set name of owning class
	//
	if (className!=null)
	    cp.setOriginClass(className);
	
	
	return(cp);
    }
    
    //
    // referenceDeclaration= [qualifierList] className REF  
    //		    propertyName [defaultValue] ";"
    CIMProperty referenceDeclaration(Vector qfn,String srcClassName,String className) throws MOFParseFailException, CIMException {
	CIMDataType datatype;
	MOFToken tkid;
	CIMProperty cp=new CIMProperty();
    

	//
	// Set name of owning class
	//
	if (className!=null)
	    cp.setOriginClass(className);
	
	
	datatype=new CIMDataType(srcClassName);
	//
	// Set datatype for property
	//
	cp.setType(datatype);
    
	//
	// Set name for property
	//
	tkid=lex.tokenIdentifier();
	if (tkid.id!=tkid.IDENTIFIER)
	    throw new MOFParseException(tkid,"Missing propertyname");
	cp.setName(tkid.tokenString()); ;
	      
	try {
	     cp.setValue(defaultValue(lex.token()));
	} catch (MOFParseException pe) {
	}
	checkToken("property declaration",tkid.SEMICOLON);

	//
	// Finally set up rest of property, now that parsing is complete...
	//
	// Add qualifiers vector to this property
	//
	if (qfn!=null) {
	    cp.setQualifiers(qfn);
	    for(int i=0;i<qfn.size();i++) {
		CIMQualifier qual=(CIMQualifier)(qfn.elementAt(i));
		if (qual.getName().equals("OVERRIDE"))
		   cp.setOverridingProperty((String)(qual.getValue().getValue()));
	    }
	}

	//
	// Set name of owning class
	//
	if (className!=null)
	    cp.setOriginClass(className);
	

	return(cp);
    }
    
    //
    // methodDeclaration = [qualifierList] methodType methodName 
    //				"(" [ parameterList ] ")" ";"
    //
    // NOTE, caller is responsible for parsing everything upto and including
    // the opening bracket "(".
    //
    CIMMethod methodDeclaration(Vector qfn,CIMDataType datatype,String methodName,String className) throws MOFParseFailException {
	MOFToken tk;
	CIMMethod cp=new CIMMethod();

	cp.setName(methodName);
	
	Vector parameters=new Vector();
	tk=lex.token();
	if (tk.id!=MOFToken.CLOSE_BRA) {
	    lex.setLookAhead(tk);
	    try {
		for(;;) {
		    parameters.addElement(parameter());
		    tk=lex.token();
		    if (tk.id!=tk.COMMA)
			break;
		}
	    } catch (MOFParseException pe) {
		throw new MOFParseFailException("Failed to process parameters in method\n"+pe);
	    }
	}
	
	if (parameters.size()>0)
	    cp.setParameters(parameters);

	if (tk.id!=tk.CLOSE_BRA)
		throw new MOFParseException(tk,"Bad parameter list for method");
      
	checkToken("method declaration",tk.SEMICOLON);

	//
	// Now parsing is complete set method up...
	//
	// Create qualifiers vector to this method
	//
	if (qfn!=null) {
	    cp.setQualifiers(qfn);
	    for(int i=0;i<qfn.size();i++) {
		CIMQualifier qual=(CIMQualifier)(qfn.elementAt(i));
		if (qual.getName().equals("OVERRIDE"))
		   cp.setOverridingMethod((String)(qual.getValue().getValue()));
	    }
	}

	//
	// Set name of owning class
	//
	if (className!=null)
	    cp.setOriginClass(className);
	
		
	//
	// Set datatype for method return
	//
	cp.setType(datatype);
	
	return(cp);

    }
    
    //
    // classFeature = propertyDeclaration | methodDeclaration
    //
    CIMElement classFeature(boolean isAssocation,String className) throws MOFParseFailException, CIMException {
	Vector qfn=null;	    // qualifiers
    
	//
	// Get Qualifiers
	//
	MOFToken tk=lex.token();
	if (tk.id==MOFToken.OPEN_SQU_BRA) {
	    qfn=qualifierList();
	    tk=lex.token();
	} 
	
	//
	// Get datatype for property/method
	//
	CIMDataType datatype=dataType(tk);
	if (datatype==null) {
	    
	    //
	    // Can't be an association ref decln
	    //
	    if (GlobalConfig.strictParse && !isAssocation) {
		lex.setLookAhead(tk);
		throw new MOFParseException("Failed to find data type");
	    }
	    //
	    // Assume it might be a reference declaration
	    //	   
	    if (tk.id!=MOFToken.IDENTIFIER)
		throw new MOFParseFailException("Expected either a property/method name"+
		    " or a class identifier for a reference");
	    String dstClassName=tk.tokenString();
	
	    //
	    // Look for a reference
	    //
	    tk=lex.token();
	    if (tk.id!=MOFToken.REF)
		throw new MOFParseFailException("Failed to locate ref token\n"+
			    "Found "+tk.tokenName());
	    //
	    // Reference declaration
	    //
	    return(referenceDeclaration(qfn,dstClassName,className));
	}
	
	
	//
	// Set name for property
	//     
	tk=lex.tokenIdentifier();
	String entityName=tk.tokenString();
	if (entityName==null)
	    throw new MOFParseFailException("Missing propertyname or methodname");
	
	
	tk=lex.token();
	if (tk.id==MOFToken.OPEN_BRA) {
	    //
	    // Method declaration
	    //
	    return(methodDeclaration(qfn,datatype,entityName,className));
	}  else {
	    //
	    // Property declaration
	    //
	    lex.setLookAhead(tk);
	    return(propertyDeclaration(qfn,datatype,entityName,className));
	}
    }
    
    //
    // classDeclaration = [ qualifierList ] CLASS className [alias] [superClass]
    //			    "{" classFeature* "}" ";"
    //
    void classDeclaration(CIMClient cc,Vector iqn)
	    throws MOFParseFailException,CIMException {
	CIMObjectPath cop;
	
	try {
	    Vector icfn=new Vector();	    //ClassElementNode
	    String aliasName=null;
	
	    MOFToken tkid=lex.className();
	    if (tkid.id!=MOFToken.IDENTIFIER)
		throw new MOFParseException(tkid,"Missing classname in pragma declaration");
	    String className=tkid.tokenString();

	    CIMClass cimClass=new CIMClass();
	    //
	    // Class appears at root level
	    //
            cop=makeCIMObjectPath(className);
	    cimClass.setName(className);

	    //
	    // Add qualifiers
	    //
	    if (iqn!=null) {
		cimClass.setQualifiers(iqn);
	    }
	
	
	    //
	    // Deal with [ alias ]
	    //
	    try {
		aliasName=alias();
	    } catch (MOFParseException pe) {
	    }
	    //
	    // Deal with [ superClass ]
	    //
	    try {
		cimClass.setSuperClass(superClass());
	    } catch (MOFParseException pe) {
	    }
	
	    checkToken("class declaration",MOFToken.OPEN_CUR_BRA);
	    //
	    // Deal with *classFeature
	    //
	    for(;;) {
		MOFToken tk=lex.token();	
		if (tk.id==MOFToken.CLOSE_CUR_BRA)
		    break;
		lex.setLookAhead(tk);
		icfn.addElement(classFeature(false,className));
	    }
	    int fSize=icfn.size();
	    for(int i=0;i<fSize;i++) {
		CIMElement ce=(CIMElement)(icfn.elementAt(i));
		if (ce instanceof CIMMethod)
		    cimClass.addMethod((CIMMethod)ce);
		else // assume its a property
		    cimClass.addProperty((CIMProperty)ce);
	    }
	    checkToken("class declaration",MOFToken.SEMICOLON);
	    
	    //
	    // TODO - ALIAS Information is being ignored
	    //
	    //
	    // Add the class definition
	    //
	    try {
		cc.createClass(cop,cimClass);
                // Pam Wright, Imation Add progress messages
                status.setMessage("Created class: "+cop);
	    } catch (CIMException ce) {
		// code to support update of the mof file
		if (ce.getID() == CIMException.CIM_ERR_ALREADY_EXISTS && forceUpdate == true) {
		    try{
			cc.setClass(cop, cimClass);
                        // Pam Wright, Imation Add progress messages
                        status.setMessage("Updated class: "+cop);
		    } catch (CIMException ce2) {
			if (status.errorHandler("CIMOM Error:\n"+ce)==-1)
			    throw ce;
		    }
		} else {
		    if (status.errorHandler("CIMOM Error:\n"+ce)==-1)
			throw ce;
		}
	    }
	} catch (MOFParseException mpe) {
	    throw new MOFParseFailException("Failed to parse class declaration\n"+mpe);
	}
    }
    

    
    //
    // assocDeclaration = "[" ASSOCIATION ("," qualifier )* "]" CLASS className
    //			    [ alias] [ superClass ] "{" associationFeature* "}" ";"
    //
    void assocDeclaration(CIMClient cc,Vector iqn) throws MOFParseFailException, CIMException{
	MOFToken tk;
	MOFToken tkid;
	CIMObjectPath cop;
	String className;
	
	
	try {
	    //
	    // Do assignment's after we're sure its an association
	    //
	    String aliasName=null;
	    Vector iafn=new Vector();
	
	    CIMClass cimClass=new CIMClass();
	    cimClass.setIsAssociation(true);

	    if (iqn!=null)
		cimClass.setQualifiers(iqn);

	    tkid=lex.className();    
	    if (tkid.id!=tkid.IDENTIFIER)
		throw new MOFParseFailException(tkid,"Missing classname in pragma declaration");
	
	    className=tkid.tokenString();
	    //
	    // Class appears at root level
	    //
            cop=makeCIMObjectPath(className);
	    cimClass.setName(className);

	    //
	    // Deal with [ alias ]
	    //
	    try {
		aliasName=alias();
	    } catch (MOFParseException pe) {
	    }
	
	    //
	    // Deal with [ superClass ]
	    //
	    try {
		cimClass.setSuperClass(superClass());
	    } catch (MOFParseException pe) {
	    }
	    checkToken("association declaration",MOFToken.OPEN_CUR_BRA);
	    //
	    // Deal with *associationFeature
	    //
	    for(;;) {
		tk=lex.token();     
		if (tk.id==MOFToken.CLOSE_CUR_BRA)
		    break;
		lex.setLookAhead(tk);
		iafn.addElement(classFeature(true,className));
	    }
	    int fSize=iafn.size();
	    for(int i=0;i<fSize;i++) {
		CIMElement ce=(CIMElement)(iafn.elementAt(i));
		if (ce instanceof CIMMethod)
		    cimClass.addMethod((CIMMethod)ce);
		else // assume its a property
		    cimClass.addProperty((CIMProperty)ce);
	    }		    
	    checkToken("association declaration",tk.SEMICOLON);
	    //
	    // TODO - ALIAS Information is being ignored
	    //

	
	    //
	    // Add the class definition
	    //
	    try {
		cc.createClass(cop,cimClass);
	    } catch (CIMException ce) {
		// code to support update of the mof file
		if (ce.getID() == CIMException.CIM_ERR_ALREADY_EXISTS && forceUpdate == true) {
		    try{
			cc.setClass(cop, cimClass);
		    } catch (CIMException ce2) {
			if (status.errorHandler("CIMOM Error:\n"+ce)==-1)
			    throw ce;
		    }
		} else {
		    if (status.errorHandler("CIMOM Error:\n"+ce)==-1)
			throw ce;
		}
	    }
	} catch (MOFParseException mpe) {
	    //
	    // If there is a failure to parse once we've spotted the association
	    // keyword then assume recovery is not worthwhile!
	    //
	    throw new MOFParseFailException("Could not parse assocation declaration\n"+mpe);
	}
    }
  
    
    
    //
    // valueInitializer= [qualifierList] 
    //		    propertyName | referenceName "=" initializer ";"
    void valueInitializer(CIMInstance ci, CIMNameSpace cn)
		throws MOFParseFailException, CIMException {
	CIMProperty cp;
	Vector qualifiers=null;
	MOFToken tkid;
	
	try {
	    tkid=lex.tokenIdentifier();
	} catch (MOFLexerException mle) {
	    //
	    // Get Qualifiers
	    //
	    MOFToken tk=lex.token();
	    if (tk.id==MOFToken.OPEN_SQU_BRA) {
		qualifiers=qualifierList();
	    } else {
		lex.setLookAhead(tk);
		throw new MOFParseException("Failed to obtain qualifiers for instance property");
	    }
	    tkid=lex.tokenIdentifier();
	}
	//
	// Get property name
	//
	try {
	    cp=ci.getProperty(tkid.tokenString());
	    if (cp==null)
		 throw new MOFParseException(tkid,"property not defined in class");
	    if (qualifiers!=null) {
		int len=qualifiers.size();
		for(int i=0;i<len;i++) {
		    CIMQualifier cq=(CIMQualifier)(qualifiers.elementAt(i));
		    cp.addQualifier(cq);
		}
	    }
	    try {
		    //
		    // Scott Baker- Aristos Logic 2/17/01
		    // Modified the following INTELMOD because it
		    // had broken the Alias feature.
			//////////////////////////////////
			//   mchang, Intel, 4/12/2000, start
			// 
			/// cp.setValue(defaultValue());
			// BEGIN ACTUAL MOD
			if (cp.getType().isReferenceType()) {
				CIMValue cv;
				MOFToken tk = lex.token();
	    		if (tk.id!=MOFToken.EQUAL) {
	        		lex.setLookAhead(tk);
	        		throw new MOFParseException("no default value");
	    		}
	    		try {
					tk = lex.token();
	        		cv = initializer(tk);
	    		} catch (MOFParseException mpe) {
	        		throw new MOFParseFailException ("Failed to parse reference value\n"+mpe);
	    		}
  				if (tk.id!=MOFToken.ALIAS_IDENTIFIER)
		    		try {
 	    	  			CIMObjectPath path=new CIMObjectPath();
			  			path.parse((String)cv.toString());
	    	  			path.setNameSpace(cn.getNameSpace());
	    	  			cv = new CIMValue(path,CIMDataType.getPredefinedType(CIMDataType.REFERENCE));
		    		} catch (CIMException ce) {
			  			throw new MOFParseFailException("Failed to parse value initializer\n"+ce);
			  		}
		    	cp.setValue(cv);
			// END INTELMOD.2
			}
			else
	        	cp.setValue(defaultValue(lex.token()));

	    } catch (MOFParseException pe) {
	    }
	    checkToken("property declaration",MOFToken.SEMICOLON);
	} catch (MOFParseException pe) {
	    throw new MOFParseFailException("Failed to parse value initializer\n"+pe);
	}
    }
	
    //
    // instanceDeclaration = [ qualifierList ] INSTANCE OF className [alias]
    //			    "{" 1*valueInitializer* "}" ";"
    //
    private void instanceDeclaration(CIMClient cc,Vector iqn)
	    throws MOFParseFailException, CIMException {
	CIMInstance ci;
	
	// This is performed before this function is called!
	//
	//  checkToken("instance declaration",MOFToken.INSTANCE);
	checkToken("instance declaration",MOFToken.OF);
	try {
	    MOFToken tkid=lex.className();
	    if (tkid.id!=tkid.IDENTIFIER)
		throw new MOFParseException(tkid,"Missing identifier");

	    CIMObjectPath path=new CIMObjectPath(tkid.tokenString());
            path.setNameSpace(currentNameSpace.getNameSpace());
	    CIMClass cimClass=cc.getClass(path,false);
	    if (cimClass==null)
		throw new MOFParseException(tkid,"Class not defined:"+path);
	    ci=cimClass.newInstance();
	
	    //
	    // Deal with [ alias ]
	    //
	    try {
		ci.setAlias(alias());
	    } catch (MOFParseException pe) {
	    }
	
	    checkToken("instance declaration",MOFToken.OPEN_CUR_BRA);
	    //
	    // Deal with *valueInitializer
	    //
	    boolean done=false;
	    for(;;) {
		try {
                    valueInitializer(ci,currentNameSpace);
		    done=true;
		} catch (MOFParseException pe) {
		    break;
		}
	    }
	    if (!done)
		throw new MOFParseException(tkid,"Missing property assignment");
	
	    checkToken("class declaration",MOFToken.CLOSE_CUR_BRA);
	    checkToken("class declaration",MOFToken.SEMICOLON);
	
	    CIMObjectPath instancePath=new CIMObjectPath(cimClass.getName(),ci.getKeyValuePairs());
            instancePath.setNameSpace(currentNameSpace.getNameSpace());
	    instancesPaths.addElement(instancePath);
	    instancesToCreate.addElement(ci);
            // Pam Wright, Imation Add progress messages
	    status.setMessage("Parsed instance: " + instancePath);
	} catch (MOFParseException mpe) {
	    throw new MOFParseFailException("Failed to parse instance declaration\n"+mpe);
	}
    }
    
    //
    private void mofProduction(CIMClient cc)
		 throws MOFParseFailException, CIMException {
	MOFToken tk=lex.token();
	Vector iqn=null;	    // qualifiers

	//
	// Look for #PRAGMA
	//
	if (tk.id==tk.PRAGMA) {
            mofPragma(cc);
	    return;
	} else if (tk.id==tk.QUALIFIER) {
            qualifierDeclaration(cc);
	    return;
	} else {
	    
	    //
	    // Deal with [ qualifierList ]
	    //
	    if (tk.id==MOFToken.OPEN_SQU_BRA) {
		iqn=qualifierList();
		tk=lex.token();
	    }
	    
	    //
	    // Look for assocDeclaration - must do this before classDeclaration
	    //
	    if (tk.id==MOFToken.CLASS) {
		//
		// MOD: cv.vick@intel.com. The for loop was not handling the
		// case where a class had no qualifier (e.g. no description)
		//
		if (iqn!=null) {
		    int fSize=iqn.size();
		    for(int i=0;i<fSize;i++) {
			CIMQualifier cq=(CIMQualifier)(iqn.elementAt(i));
			if (cq.getName().equalsIgnoreCase("ASSOCIATION")) {
			    try {
                                assocDeclaration(cc,iqn);
				return;
			    } catch (MOFParseException pe) {
				throw new MOFParseFailException("Failed to parse association\n"+pe);
			    }
			}
		    }
		}
		//
		// Look for classDeclaration
		//	    
                classDeclaration(cc,iqn);
		return;
	    } 
	    
	    //
	    // Look for instances
	    //
	    if (tk.id==MOFToken.INSTANCE) {
                instanceDeclaration(cc,iqn);
		return;
	    }
	    throw new MOFParseFailException("Failed to locate pragma, qualifier, association, class or instance declaration"+
		"\nFound token ="+tk.tokenName()); 
	}
    }
       
    void mofSpecification(CIMClient cc)throws MOFParseFailException,CIMException {
	
	for(;;) {
	    try {
                mofProduction(cc);
	    } catch (MOFLexerException mle) {
		if (mle.getValue().equals(MOFLexerException.LEX_ERR_EOF))
		    return;
		throw mle;
	    }
	}
    }	 
    

	
			    
    public void mofParse(CIMClient cc,CIMNameSpace cn,String idir,
       String filename, MOFStatus istatus) {
	String pathname=new String(idir+filename);
	directory=idir;
	status=istatus;
	lex=new MOFLexer(istatus);
	
        callerNameSpace=cn;
        currentNameSpace=new CIMNameSpace(cn.getHost(),cn.getNameSpace());

	try { 
	    lex.load(pathname);
	    
	    try {
                mofSpecification(cc);
                // Pam Wright, Imation Add progress messages
                status.setMessage("Parse complete");
	    } catch (MOFParseFailException pe) {
		if (istatus.errorHandler("Parse Failed at line "+lex.getLineno()+":\n"+pe)==-1)
		    return;
	    } catch (CIMException ce) {
		if (istatus.errorHandler("CIMOM Error at line "+lex.getLineno()+":\n"+ce)==-1)
		    return;
	    }
	    //
	    // Fix up aliases
	    //
	    for(int i=0;i<aliasIdentifiers.size();i++) {
		int j;
		String aliasName=(String)(aliasIdentifiers.elementAt(i));
		CIMObjectPath aliasCOP=(CIMObjectPath)(aliasValues.elementAt(i));
		System.err.println("Used alias :"+aliasName);
		for(j=0;j<instancesPaths.size();j++) {
		    CIMInstance ci=(CIMInstance)(instancesToCreate.elementAt(j));
		    String alias=ci.getAlias();
		    if (alias!=null && alias.equalsIgnoreCase(aliasName)) {
			break;
		    }
		}
		if (j<instancesPaths.size()) {
			
		    CIMObjectPath realCOP=(CIMObjectPath)(instancesPaths.elementAt(j));
		    aliasCOP.setNameSpace(new String(realCOP.getNameSpace()));
		    aliasCOP.setObjectName(new String(realCOP.getObjectName()));
		    aliasCOP.setKeys(realCOP.getKeys());
	    /*	    Vector v=realCOP.getKeys();
		    Vector v2=new Vector();
		    for(int m=0;m<v.size();m++) {
			CIMProperty cp=(CIMProperty)(v.elementAt(m));
			
			v2.addElement(cp.clone());
		    }
		    aliasCOP.setKeys(v2);*/
		} else {
		    System.err.println("Could not find alias "+aliasName); // TODO
		}
	    }
            // Pam Wright, Imation Add progress messages
            if (instancesPaths.size()>0) {
                status.setMessage("Creating instances");
            }
	    for(int j=0;j<instancesPaths.size();j++) {
		CIMObjectPath cop=(CIMObjectPath)(instancesPaths.elementAt(j));
		CIMInstance ci=(CIMInstance)(instancesToCreate.elementAt(j));
		cc.createInstance(cop,ci);
                // Pam Wright, Imation Add progress messages
                status.setMessage("Created instance: "+cop);
	    }
	} catch (MOFParseException pe) {
	    istatus.errorHandler("Parse Failed:\n"+pe);
	} catch (CIMException ce) {
	    istatus.errorHandler("CIMOM Error:\n"+ce);
	}
    }

    public void mofParse(CIMClient cc,CIMNameSpace cn,String idir,
       String filename, MOFStatus istatus, boolean update) {
        forceUpdate = update;
        mofParse(cc, cn, idir, filename, istatus);
    }

    public void mofParse(CIMClient cc,CIMNameSpace cn,String idir,
       String filename, MOFStatus istatus, boolean update, boolean extended) {
	forceUpdate = update;
        extendedMode=extended;
	mofParse(cc, cn, idir, filename, istatus);
    }

}
