From imperius-commits-return-183-apmail-incubator-imperius-commits-archive=incubator.apache.org@incubator.apache.org Thu Feb 14 20:53:22 2008 Return-Path: Delivered-To: apmail-incubator-imperius-commits-archive@locus.apache.org Received: (qmail 66211 invoked from network); 14 Feb 2008 20:53:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Feb 2008 20:53:22 -0000 Received: (qmail 88142 invoked by uid 500); 14 Feb 2008 20:53:16 -0000 Delivered-To: apmail-incubator-imperius-commits-archive@incubator.apache.org Received: (qmail 88123 invoked by uid 500); 14 Feb 2008 20:53:16 -0000 Mailing-List: contact imperius-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: imperius-dev@incubator.apache.org Delivered-To: mailing list imperius-commits@incubator.apache.org Received: (qmail 88114 invoked by uid 99); 14 Feb 2008 20:53:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Feb 2008 12:53:16 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Feb 2008 20:52:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 76EEF1A9842; Thu, 14 Feb 2008 12:53:01 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r627867 [3/3] - in /incubator/imperius/trunk: imperius-cimsplclientsideprovider/ imperius-cimsplclientsideprovider/resources/ imperius-cimsplclientsideprovider/resources/mofs/ imperius-cimsplclientsideprovider/resources/policies/ imperius-c... Date: Thu, 14 Feb 2008 20:52:47 -0000 To: imperius-commits@incubator.apache.org From: jneeraj@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080214205301.76EEF1A9842@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/imperius/trunk/imperius-cimsplcommon/src/main/java/org/apache/imperius/cimspl/userdefinedmethods/ToUINT8.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplcommon/src/main/java/org/apache/imperius/cimspl/userdefinedmethods/ToUINT8.java?rev=627867&view=auto ============================================================================== --- incubator/imperius/trunk/imperius-cimsplcommon/src/main/java/org/apache/imperius/cimspl/userdefinedmethods/ToUINT8.java (added) +++ incubator/imperius/trunk/imperius-cimsplcommon/src/main/java/org/apache/imperius/cimspl/userdefinedmethods/ToUINT8.java Thu Feb 14 12:52:39 2008 @@ -0,0 +1,134 @@ +/* + * 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 + * + */ +package org.apache.imperius.cimspl.userdefinedmethods; + + +import java.util.List; +import java.util.logging.Logger; + +//import org.pegasus.jmpi.UnsignedInt8; +import org.sblim.wbem.cim.UnsignedInt8; +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.exceptions.SPLException; +import org.apache.imperius.spl.parser.expressions.NumericExpression; +import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression; +import org.apache.imperius.spl.parser.util.TypeInfo; +import org.apache.imperius.spl.parser.util.TypeResolver; +import org.apache.imperius.util.SPLLogger; + +public class ToUINT8 extends SingleArgumentExpression implements + NumericExpression +{ + + public static final String className = ToUINT8.class.getName(); + + private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + private static final String sourceClass="ToUINT8"; + + + + public ToUINT8(List exprList, boolean validateExpression) + throws SPLException + { + super(exprList); + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "ToUINT8"); + + if (validateExpression) + { + if (!validate()) + { + logger.severe(Thread.currentThread().getName()+" "+"validation error: " + className + + " has wrong data type passed in."); + + throw new SPLException("validation error: " + className + + " has wrong data type passed in."); + } + } + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "ToUINT8"); + + } + + public Object evaluate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + try + { + Object obj = _exp.evaluate(); + if (obj instanceof Number) + { + UnsignedInt8 x = null; + x = new UnsignedInt8(((Number) obj).shortValue()); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + + return x; + + } + else + { + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + // must be string type + return new UnsignedInt8(Short.parseShort((String) obj)); + } + } + catch (NumberFormatException e) + { + + logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString()); + + throw new SPLException("evaluation error: " + e.toString()); + } + catch (Exception e) + { + + logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString()); + + throw new SPLException("evaluation error: " + e.toString()); + } + } + + public boolean validate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + TypeInfo eType = _exp.getType(); + + // dataType = TypeConstants.numericType; + if (TypeResolver.isNumeric(eType) || TypeResolver.isString(eType)) + { + _dataType.setType(TypeConstants.byteType); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + } + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + + return false; + } + +} Propchange: incubator/imperius/trunk/imperius-cimsplcommon/src/main/java/org/apache/imperius/cimspl/userdefinedmethods/ToUINT8.java ------------------------------------------------------------------------------ svn:eol-style = native