Package library :: Package pyjamas :: Package gears :: Module Factory
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.gears.Factory

  1  """ 
  2  * Copyright 2008 Google Inc. 
  3  * 
  4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  5  * use this file except in compliance with the License. You may obtain a copy of 
  6  * the License at 
  7  * 
  8  * http:#www.apache.org/licenses/LICENSE-2.0 
  9  * 
 10  * Unless required by applicable law or agreed to in writing, software 
 11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 13  * License for the specific language governing permissions and limitations under 
 14  * the License. 
 15  """ 
 16   
 17   
 18  from pyjamas.gears.database.Database import GearsDatabase 
 19  #from pyjamas.gears.localserver import LocalServer 
 20  #from pyjamas.gears.workerpool import WorkerPool 
 21  from __pyjamas__ import JS 
 22   
 23  JS(""" 
 24  // Copyright 2007 Google Inc. All Rights Reserved. 
 25  // 
 26  // Sets up google['gears'].*, which is *the only* supported way to access Gears. 
 27  // 
 28  // Circumvent this file at your own risk! 
 29  // 
 30  // In the future, Gears may automatically define google['gears'].* without this 
 31  // file. Gears may use these objects to transparently fix bugs and compatibility 
 32  // issues. Applications that use the code below will continue to work seamlessly 
 33  // when that happens. 
 34   
 35  @{{!init_gears}} = function() { 
 36    // We are already defined. Hooray! 
 37    if ($wnd['google'] && $wnd['google']['gears']) { 
 38      return; 
 39    } 
 40   
 41    var factory = null; 
 42   
 43    // Firefox 
 44    if (typeof @{{!GearsFactory}} != 'undefined') { 
 45      factory = new @{{!GearsFactory}}(); 
 46    } else { 
 47      // IE 
 48      try { 
 49        factory = new ActiveXObject('Gears['Factory']'); 
 50      } catch (e) { 
 51        // Safari 
 52        if (navigator['mimeTypes']["application/x-googlegears"]) { 
 53          factory = $doc['createElement']("object"); 
 54          factory['style']['display'] = "none"; 
 55          factory['width'] = 0; 
 56          factory['height'] = 0; 
 57          factory['type'] = "application/x-googlegears"; 
 58          $doc['documentElement']['appendChild'](factory); 
 59        } 
 60      } 
 61    } 
 62   
 63    // *Do not* define any objects if Gears is not installed. This mimics the 
 64    // behavior of Gears defining the objects in the future. 
 65    if (!factory) { 
 66      return; 
 67    } 
 68   
 69    // Now set up the objects, being careful not to overwrite anything. 
 70    if (!$wnd['google']) { 
 71      $wnd['google'] = {}; 
 72    } 
 73   
 74    if (!$wnd['google']['gears']) { 
 75      $wnd['google']['gears'] = {factory: factory}; 
 76    } 
 77  } 
 78   
 79  """) 
 80   
 81  """* 
 82  * Returns the singleton instance of the Factory class or <code>None</code> 
 83  * if Gears is not installed or accessible. 
 84  * 
 85  * @return singleton instance of the Factory class or <code>None</code> if 
 86  *         Gears is not installed or accessible 
 87  """ 
88 -def getInstance():
89 JS(""" 90 @{{!init_gears}}(); 91 return $wnd['google'] && $wnd['google']['gears'] && $wnd['google']['gears']['factory']; 92 """)
93 94 95 """* 96 * Creates a {@link Database} instance. 97 * 98 * @return a {@link Database} instance 99 """
100 -def createDatabase():
101 return GearsDatabase(create("beta.database"))
102 103 104 """* 105 * Creates a {@link LocalServer} instance. 106 * 107 * @return a {@link LocalServer} instance 108 """
109 -def createLocalServer():
110 return LocalServer(create("beta.localserver"))
111 112 113 """* 114 * Creates a {@link WorkerPool} instance. 115 * 116 * @return a {@link WorkerPool} instance 117 """
118 -def createWorkerPool():
119 return WorkerPool(create("beta.workerpool"))
120 121 122 """* 123 * Returns a description of the build of Gears installed. This string is 124 * purely informational. Application developers should not rely on the format 125 * of data returned. The contents and layout may change over time. 126 * 127 * @return build description string 128 """
129 -def getBuildInfo():
130 return getInstance().getBuildInfo()
131 132 133 """* 134 * Returns the version of Gears installed, as a string of the form 135 * Major.Minor.Build.Patch (e.g., '0.10.2.0'). 136 * 137 * @return string of the form Major.Minor.Build.Patch 138 """
139 -def getVersion():
140 return getInstance().version
141 142 143 """* 144 * Creates an instance of the specified Gears object. 145 * 146 * @param <T> Gears object type to return 147 * @param className name of the object to create 148 * @return an instance of the specified Gears object 149 """
150 -def create(className):
151 return getInstance().create(className)
152