/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author Prashant Baliga <prabalig@in.ibm.com>
*
*/
package org.apache.imperius.cimspl;
import java.util.logging.Logger;
import org.apache.imperius.spl.core.TypeConstants;
import org.apache.imperius.util.SPLLogger;
import org.pegasus.jmpi.CIMObjectPath;
public class CIMSPLTypeConstants
{
private static Logger logger = SPLLogger.getSPLLogger().getLogger();
private static final String sourceClass="CIMSPLTypeConstants";
public static final int SIZE_SINGLE = 0;
public static final int SIZE_UNLIMITED = 1;
public static final int SIZE_LIMITED = 2;
private final static int ARRAY = 0x10;
private final static int OTHER = 0x20;
public static final int INVALID = 0;
public static final int UINT8 = 1;
public static final int SINT8 = 2;
public static final int UINT16 = 3;
public static final int SINT16 = 4;
public static final int UINT32 = 5;
public static final int SINT32 = 6;
public static final int UINT64 = 7;
public static final int SINT64 = 8;
public static final int STRING = 9;
public static final int BOOLEAN = 10;
public static final int REAL32 = 11;
public static final int REAL64 = 12;
public static final int DATETIME = 13;
public static final int CHAR16 = 14;
public static final int OBJECT = 15;
public static final int UINT8_ARRAY = ARRAY + UINT8;
public static final int SINT8_ARRAY = ARRAY + SINT8;
public static final int UINT16_ARRAY = ARRAY + UINT16;
public static final int SINT16_ARRAY = ARRAY + SINT16;
public static final int UINT32_ARRAY = ARRAY + UINT32;
public static final int SINT32_ARRAY = ARRAY + SINT32;
public static final int UINT64_ARRAY = ARRAY + UINT64;
public static final int SINT64_ARRAY = ARRAY + SINT64;
public static final int STRING_ARRAY = ARRAY + STRING;
public static final int BOOLEAN_ARRAY = ARRAY + BOOLEAN;
public static final int REAL32_ARRAY = ARRAY + REAL32;
public static final int REAL64_ARRAY = ARRAY + REAL64;
public static final int DATETIME_ARRAY = ARRAY + DATETIME;
public static final int CHAR16_ARRAY = ARRAY + CHAR16;
public static final int OBJECT_ARRAY = ARRAY + OBJECT;
public static final int REFERENCE = OTHER + 1;
public static boolean getIsArray(int type)
{
if(type> 10)
{
return true;
}
return false;
}
public static int convertInternalTypeToCIMType(int type, boolean isArray, Object obj)
{
int cimType = -1;
if(type == TypeConstants.byteType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.UINT8_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.UINT8;
}
}
else if(type == TypeConstants.shortType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.UINT16_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.UINT16;
}
}
else if(type == TypeConstants.intType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.UINT32_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.UINT32;
}
}
else if(type == TypeConstants.longType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.UINT64_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.UINT64;
}
}
else if(type == TypeConstants.floatType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.REAL32_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.REAL32_ARRAY;
}
}
else if(type == TypeConstants.doubleType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.REAL64_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.REAL64;
}
}
else if(type == TypeConstants.booleanType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.BOOLEAN_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.BOOLEAN;
}
}
else if(type == TypeConstants.charType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.CHAR16_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.CHAR16;
}
}
else if(type == TypeConstants.stringType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.STRING_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.STRING;
}
}
else if(type == TypeConstants.dateTime)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.DATETIME_ARRAY;
}
else
{
cimType = CIMSPLTypeConstants.DATETIME;
}
}
else if(type == TypeConstants.referenceType)
{
if(isArray)
{
cimType = CIMSPLTypeConstants.REFERENCE;
//System.out.println("encountered reference array, no equivalent CIM type");
}
else
{
cimType = CIMSPLTypeConstants.REFERENCE;
}
}
return cimType;
}
public static int convertCIMTypeToInternalType(int type)
{
int retTp = -1;
if ((type == CIMSPLTypeConstants.UINT8)
|| (type == CIMSPLTypeConstants.SINT8)
|| (type == CIMSPLTypeConstants.UINT8_ARRAY)
|| (type == CIMSPLTypeConstants.SINT8_ARRAY))
{
retTp = TypeConstants.byteType;
}
else if ((type == CIMSPLTypeConstants.UINT16)
|| (type == CIMSPLTypeConstants.SINT16)
|| (type == CIMSPLTypeConstants.UINT16_ARRAY)
|| (type == CIMSPLTypeConstants.SINT16_ARRAY))
{
retTp = TypeConstants.shortType;
}
else if ((type == CIMSPLTypeConstants.UINT32)
|| (type == CIMSPLTypeConstants.SINT32)
|| (type == CIMSPLTypeConstants.UINT32_ARRAY)
|| (type == CIMSPLTypeConstants.SINT32_ARRAY))
{
retTp = TypeConstants.intType;
}
else if ((type == CIMSPLTypeConstants.UINT64)
|| (type == CIMSPLTypeConstants.SINT64)
|| (type == CIMSPLTypeConstants.UINT64_ARRAY)
|| (type == CIMSPLTypeConstants.SINT64_ARRAY))
{
retTp = TypeConstants.longType;
}
else if ((type == CIMSPLTypeConstants.REAL32)
|| (type == CIMSPLTypeConstants.REAL32_ARRAY))
{
retTp = TypeConstants.floatType;
}
else if ((type == CIMSPLTypeConstants.REAL64)
|| (type == CIMSPLTypeConstants.REAL64_ARRAY))
{
retTp = TypeConstants.doubleType;
}
else if ((type == CIMSPLTypeConstants.BOOLEAN)
|| (type == CIMSPLTypeConstants.BOOLEAN_ARRAY))
{
retTp = TypeConstants.booleanType;
}
else if ((type == CIMSPLTypeConstants.CHAR16)
|| (type == CIMSPLTypeConstants.CHAR16_ARRAY))
{
retTp = TypeConstants.charType;
}
else if ((type == CIMSPLTypeConstants.STRING)
|| (type == CIMSPLTypeConstants.STRING_ARRAY))
{
retTp = TypeConstants.stringType;
}
else if ((type == CIMSPLTypeConstants.DATETIME)
|| (type == CIMSPLTypeConstants.DATETIME_ARRAY))
{
retTp = TypeConstants.dateTime;
}
else if (type == CIMSPLTypeConstants.REFERENCE)
{
retTp = TypeConstants.referenceType;
}
//logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "cimToLocalTypeConversion");
return retTp;
}
public static int getTypeOfObject(Object ob)
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getTypeOfObject");
int currentLocaltype = -1;
if (ob instanceof java.lang.Boolean)
{
currentLocaltype = TypeConstants.booleanType;
}
else if (ob instanceof java.lang.String)
{
currentLocaltype = TypeConstants.stringType;
}
else if (ob instanceof java.util.Calendar)
{
currentLocaltype = TypeConstants.dateTime;
}
else if (ob instanceof java.lang.Byte)
{
currentLocaltype = TypeConstants.byteType;
}
else if (ob instanceof java.lang.Character)
{
currentLocaltype = TypeConstants.charType;
}
else if (ob instanceof java.lang.Short)
{
currentLocaltype = TypeConstants.shortType;
}
else if (ob instanceof java.lang.Integer)
{
currentLocaltype = TypeConstants.intType;
}
else if (ob instanceof java.lang.Long)
{
currentLocaltype = TypeConstants.longType;
}
else if (ob instanceof java.lang.Float)
{
currentLocaltype = TypeConstants.floatType;
}
else if (ob instanceof java.lang.Double)
{
currentLocaltype = TypeConstants.doubleType;
}
else if (ob instanceof java.util.Date)
{
currentLocaltype = TypeConstants.dateTime;
}
else
{
currentLocaltype = TypeConstants.referenceType;
}
// if (ob instanceof com.ibm.ac.spl.parser.expressions.Reference)
// currentLocaltype = 13;
// public static final int referenceType = 13;
// PB:what do we do about references
return currentLocaltype;
}
public static String getReferenceTypeName(String reference)
{
//extract class name and return
String referenceType = null;
CIMObjectPath cop=CIMObjectPath.toCop(reference);
referenceType=cop.getObjectName();
return referenceType;
}
}