Beispiel #1
0
        /// <summary>
        /// Creates a new scriptable wrapper for the specified object. Use this function instead
        /// of calling the JsObject constructor.
        /// </summary>
        /// <param name="wrappableObject">The object to wrap. It's type will be used as a key
        /// in a lookup for creating the correct wrappable type.</param>
        /// <returns>A new scriptable object that has been created with a type corresponding
        /// to the wrappableObject's type.</returns>
        public static J CreateWrapper <J>(object wrappableObject, ISvgScriptEngine scriptEngine)
            where J : class, IScriptableObject
        {
            // return null if we get null
            if (wrappableObject == null || scriptEngine == null)
            {
                return(null);
            }
            if (scriptEngine.ReferenceCache == null)
            {
                scriptEngine.ReferenceCache = new JsObjectReferenceCache();
            }

            var jsRefCache = scriptEngine.ReferenceCache;

            // Check that the static table is built
            if (_jsMappedTypes == null || _jsMappedTypes.Count == 0)
            {
                InitializeWrapperTypes();
            }

            // Do we already have a wrapper for this object?
            J jsObj = null;
            IScriptableObject jsObjBase = null;

            if (jsRefCache.TryGetValue(wrappableObject, out jsObjBase) && jsObjBase != null)
            {
                jsObj = jsObjBase as J;
                if (jsObj != null)
                {
                    return(jsObj);
                }
            }

            // Return a new instance
            try
            {
                _wrapperArgs[0] = wrappableObject;
                _wrapperArgs[1] = scriptEngine;
                // Normal
                try
                {
                    jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().Name, _wrapperArgs);
                    jsRefCache.Add(wrappableObject, jsObjBase);
                    return(jsObjBase as J);
                }
                catch (Exception)
                {
                    // Try the ancestor
                    jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().BaseType.Name, _wrapperArgs);
                    jsRefCache.Add(wrappableObject, jsObjBase);
                    return(jsObjBase as J);
                }
            }
            catch (Exception e)
            {
                throw new SvgException(SvgExceptionType.SvgWrongTypeErr,
                                       "Could not create wrappable type for " + wrappableObject.GetType().FullName, e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes the wrapper and base object key value pair. This function is called by the JsObject destructor.
        /// </summary>
        /// <param name="wrappableObject">The key object that was wrapped, to be removed.</param>
        public static void RemoveWrapper(object wrappableObject, ISvgScriptEngine scriptEngine)
        {
            // return null if we get null
            if (wrappableObject == null || scriptEngine == null)
            {
                return;
            }
            if (scriptEngine.ReferenceCache == null)
            {
                scriptEngine.ReferenceCache = new JsObjectReferenceCache();
            }

            var jsRefCache = scriptEngine.ReferenceCache;

            // Remove it
            jsRefCache.Remove(wrappableObject.GetType().Name);
        }
Beispiel #3
0
 public JsSvgVKernElement(ISvgVKernElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #4
0
 public JsProcessingInstruction(IProcessingInstruction baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #5
0
 public JsEntity(IEntity baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #6
0
 public JsNode(INode baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #7
0
 public JsComment(IComment baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #8
0
 public JsElement(IElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #9
0
 public JsCharacterData(ICharacterData baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #10
0
 public JsSvgDefinitionSrcElement(ISvgDefinitionSrcElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #11
0
 public JsSvgZoomEvent(ISvgZoomEvent baseObject, ISvgScriptEngine engine) : base(baseObject, engine)
 {
 }
Beispiel #12
0
 public JsSvgAnimateTransformElement(ISvgAnimateTransformElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #13
0
 public JsSvgAnimateColorElement(ISvgAnimateColorElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #14
0
 public JsSvgFontFaceNameElement(ISvgFontFaceNameElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #15
0
 public JsNamedNodeMap(INamedNodeMap baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #16
0
 public JsSvgMetadataElement(ISvgMetadataElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #17
0
 public JsDomImplementation(IDomImplementation baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #18
0
 public JsSvgForeignObjectElement(ISvgForeignObjectElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #19
0
 public JsAttr(IAttribute baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #20
0
 public JsSvgCursorElement(ISvgCursorElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #21
0
 public JsText(IText baseObject, ISvgScriptEngine engine) : base(baseObject, engine)
 {
 }
Beispiel #22
0
 public JsSvgElementInstanceList(ISvgElementInstanceList baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #23
0
 public JsCDataSection(ICDataSection baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #24
0
 public JsSvgColorProfileElement(ISvgColorProfileElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #25
0
 public JsNotation(INotation baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #26
0
 public JsSvgColorProfileRule(ISvgColorProfileRule baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #27
0
 public JsEntityReference(IEntityReference baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #28
0
 public JsDomTimeStamp(IDomTimeStamp baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #29
0
 public JsDocument(IDocument baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }
Beispiel #30
0
 public JsSvgMissingGlyphElement(ISvgMissingGlyphElement baseObject, ISvgScriptEngine engine)
     : base(baseObject, engine)
 {
 }