Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / compile / XMLTypeCompiler.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/XMLTypeCompiler.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/XMLTypeCompiler.java
new file mode 100644 (file)
index 0000000..f961f10
--- /dev/null
@@ -0,0 +1,161 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.XMLTypeCompiler\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.services.loader.ClassFactory;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.sql.compile.TypeCompiler;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.types.TypeId;\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+/**\r
+ * This class implements TypeCompiler for the XML type.\r
+ */\r
+\r
+public class XMLTypeCompiler extends BaseTypeCompiler\r
+{\r
+    /**\r
+     * Tell whether this type (XML) can be converted to the given type.\r
+     *\r
+     * An XML value can't be converted to any other type, per\r
+     * SQL/XML[2003] 6.3 <cast specification>\r
+     *\r
+     * @see TypeCompiler#convertible\r
+     */\r
+    public boolean convertible(TypeId otherType, \r
+                            boolean forDataTypeFunction)\r
+    {\r
+        // An XML value cannot be converted to any non-XML type.  If\r
+        // user wants to convert an XML value to a string, then\r
+        // s/he must use the provided SQL/XML serialization operator\r
+        // (namely, XMLSERIALIZE).\r
+        return otherType.isXMLTypeId();\r
+    }\r
+\r
+    /**\r
+     * Tell whether this type (XML) is compatible with the given type.\r
+     *\r
+     * @param otherType The TypeId of the other type.\r
+     */\r
+    public boolean compatible(TypeId otherType)\r
+    {\r
+        // An XML value is not compatible (i.e. cannot be "coalesced")\r
+        // into any non-XML type.\r
+        return otherType.isXMLTypeId();\r
+    }\r
+\r
+    /**\r
+     * Tell whether this type (XML) can be stored into from the given type.\r
+     * Only XML values can be stored into an XML type, per SQL/XML spec:\r
+     *\r
+     * 4.2.2 XML comparison and assignment\r
+     * Values of XML type are assignable to sites of XML type.\r
+     *\r
+     * @param otherType The TypeId of the other type.\r
+     * @param cf A ClassFactory\r
+     */\r
+    public boolean storable(TypeId otherType, ClassFactory cf)\r
+    {\r
+        // The only type of value that can be stored as XML\r
+        // is an XML value.  Strings are not allowed.  If\r
+        // the user wants to store a string value as XML,\r
+        // s/he must use the provided XML parse operator\r
+        // (namely, XMLPARSE) to parse the string into\r
+        // XML.\r
+        return otherType.isXMLTypeId();\r
+    }\r
+\r
+    /**\r
+     * @see TypeCompiler#interfaceName\r
+     */\r
+    public String interfaceName() {\r
+        return ClassName.XMLDataValue;\r
+    }\r
+\r
+    /**\r
+     * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+     */\r
+    public String getCorrespondingPrimitiveTypeName()\r
+    {\r
+        int formatId = getStoredFormatIdFromTypeId();\r
+        if (formatId == StoredFormatIds.XML_TYPE_ID)\r
+            return "org.apache.derby.iapi.types.XML";\r
+\r
+        if (SanityManager.DEBUG) {\r
+            SanityManager.THROWASSERT(\r
+                "unexpected formatId in getCorrespondingPrimitiveTypeName(): "\r
+                + formatId);\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
+    /**\r
+     * @see TypeCompiler#getCastToCharWidth\r
+     *\r
+     * While it is true XML values can't be cast to char, this method\r
+     * can get called before we finish type checking--so we return a dummy\r
+     * value here and let the type check throw the appropriate error.\r
+     */\r
+    public int getCastToCharWidth(DataTypeDescriptor dts)\r
+    {\r
+        return -1;\r
+    }\r
+\r
+    /**\r
+     * @see BaseTypeCompiler#nullMethodName\r
+     */\r
+    String nullMethodName()\r
+    {\r
+        if (SanityManager.DEBUG) {\r
+            if (getStoredFormatIdFromTypeId() != StoredFormatIds.XML_TYPE_ID)\r
+                SanityManager.THROWASSERT(\r
+                "unexpected formatId in nullMethodName(): " + \r
+                     getStoredFormatIdFromTypeId());\r
+        }\r
+        \r
+        return "getNullXML";\r
+    }\r
+\r
+    /**\r
+     * @see BaseTypeCompiler#dataValueMethodName\r
+     */\r
+    protected String dataValueMethodName()\r
+    {\r
+        int formatId = getStoredFormatIdFromTypeId();\r
+        if (formatId == StoredFormatIds.XML_TYPE_ID)\r
+            return "getXMLDataValue";\r
+\r
+        if (SanityManager.DEBUG) {\r
+            SanityManager.THROWASSERT(\r
+                "unexpected formatId in dataValueMethodName() - " + formatId);\r
+        }\r
+\r
+        return null;\r
+    }\r
+}\r