incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnee...@apache.org
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 GMT
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 <prabalig@in.ibm.com>
+ *
+ */
+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



Mime
View raw message