001/* 002 * This file is part of OCaml-Java runtime. 003 * Copyright (C) 2007-2013 Xavier Clerc. 004 * 005 * OCaml-Java runtime is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * OCaml-Java runtime is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.ocamljava.runtime.wrappers; 020 021import org.ocamljava.runtime.values.Value; 022 023/** 024 * The {@code OCamlExn} class is the wrapper class for OCaml values of 025 * type {@code exn}. 026 * 027 * @author <a href="mailto:xclerc@ocamljava.org">Xavier Clerc</a> 028 * @version 2.0 029 * @since 2.0 030 */ 031public final class OCamlExn extends OCamlValue { 032 033 /** Wrapper for {@code OCamlExn} values. */ 034 public static final Wrapper<OCamlExn> WRAPPER = new SimpleWrapper<OCamlExn>() { 035 036 /** 037 * {@inheritDoc} 038 */ 039 @Override 040 public OCamlExn wrap(final Value v) { 041 return new OCamlExn(v); 042 } // end method 'wrap(Value)' 043 044 }; // end anonymous inner-class 045 046 /** 047 * Constructs a new instance wrapping the passed value. 048 * @param v value to wrap - should not be {@code null} 049 */ 050 private OCamlExn(final Value v) { 051 super(v); 052 } // end constructor(Value) 053 054 /** 055 * {@inheritDoc} 056 */ 057 @Override 058 public Wrapper<? extends OCamlExn> getWrapper() { 059 return OCamlExn.WRAPPER; 060 } // end method 'getWrapper()' 061 062 /** 063 * {@inheritDoc} 064 */ 065 @Override 066 public Wrapper<? extends OCamlValue> getWrapper(final int idx) { 067 return OCamlUnit.WRAPPER; 068 } // end method 'getWrapper(int)' 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public int hashCode() { 075 return this.value.hashCode(); 076 } // end method 'hashCode()' 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public boolean equals(final Object obj) { 083 if (obj instanceof OCamlExn) { 084 final OCamlExn that = (OCamlExn) obj; 085 return this.value == that.value; 086 } else { 087 return false; 088 } // end if/else 089 } // end method 'equals(Object)' 090 091 /** 092 * Returns the string representation of the underlying exception. 093 * @return the string representation of the underlying exception 094 */ 095 public final String stringValue() { 096 /* from OCamlException.getOCamlStringRepresentation 097 final FailException e = (FailException) getCause(); 098 final Value v = e.asValue(); 099 return Misc.convertException(v, null); 100 */ 101 return "OCamlExn(...)"; // XXX 102 } // end method 'asString()' 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public String toString() { 109 return "OCamlExn(...)"; 110 } // end method 'toString()' 111 112 /** 113 * Wraps the passed value. 114 * @param v value to wrap - should not be {@code null} 115 * @return a new {@code OCamlExn} instance wrapping the passed value 116 */ 117 public static OCamlExn wrap(final Value v) { 118 assert v != null : "null v"; 119 return new OCamlExn(v); 120 } // end method 'wrap(Value)' 121 122 /** 123 * Returns a wrapper for {@code OCamlExn} values. 124 * @return a wrapper for {@code OCamlExn} values 125 */ 126 public static Wrapper<? extends OCamlExn> wrapper() { 127 return OCamlExn.WRAPPER; 128 } // end method 'wrapper()' 129 130} // end class 'OCamlExn'