001    /*
002     * To change this template, choose Tools | Templates
003     * and open the template in the editor.
004     */
005    
006    package org.bridj.cs.mono;
007    
008    import org.bridj.AbstractBridJRuntime;
009    import org.bridj.BridJ;
010    import static org.bridj.BridJ.*;
011    import org.bridj.NativeLibrary;
012    import org.bridj.NativeObject;
013    import org.bridj.Pointer;
014    import org.bridj.ann.Library;
015    import org.bridj.cs.CSharpRuntime;
016    import java.io.FileNotFoundException;
017    import java.lang.reflect.Type;
018    
019    /**
020     * Stub, not implemented (see <a href="http://ochafik.com/blog/?p=165">this blog entry</a> for a proof of concept).
021     * @author Olivier
022     */
023    @Library("mono")
024    public class MonoRuntime extends AbstractBridJRuntime implements CSharpRuntime {
025    
026        public MonoRuntime() {
027            try {
028                BridJ.register();
029            } catch (Exception ex) {
030                // Accept failure
031                info("Failed to register " + getClass().getName(), ex);
032            }
033        }
034    
035        //@Override
036        public boolean isAvailable() {
037            return getMonoLibrary() != null;
038        }
039    
040        //@Override
041        public <T extends NativeObject> Class<? extends T> getActualInstanceClass(Pointer<T> pInstance, Type officialType) {
042            throw new UnsupportedOperationException("Not supported yet.");
043        }
044    
045        //@Override
046        public void register(Type type) {
047            throw new UnsupportedOperationException("Not supported yet.");
048        }
049    
050        NativeLibrary monoLibrary;
051        boolean fetchedLibrary;
052        private synchronized NativeLibrary getMonoLibrary() {
053            if (!fetchedLibrary && monoLibrary == null) {
054                try {
055                    fetchedLibrary = true;
056                    monoLibrary = BridJ.getNativeLibrary("mono");
057                } catch (Exception ex) {
058                    info(null, ex);
059                }
060            }
061            return monoLibrary;
062        }
063    
064        //@Override
065        public <T extends NativeObject> TypeInfo<T> getTypeInfo(Type type) {
066            throw new UnsupportedOperationException("Not supported yet.");
067        }
068    
069    }