Source Code Cross Referenced for LuaStateFactory.java in  » Scripting » LuaJava » org » keplerproject » luajava » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » LuaJava » org.keplerproject.luajava 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: LuaStateFactory.java,v 1.4 2006/12/22 14:06:40 thiago Exp $
003:         * Copyright (C) 2003-2007 Kepler Project.
004:         *
005:         * Permission is hereby granted, free of charge, to any person obtaining
006:         * a copy of this software and associated documentation files (the
007:         * "Software"), to deal in the Software without restriction, including
008:         * without limitation the rights to use, copy, modify, merge, publish,
009:         * distribute, sublicense, and/or sell copies of the Software, and to
010:         * permit persons to whom the Software is furnished to do so, subject to
011:         * the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be
014:         * included in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
017:         * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
021:         * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
022:         * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:
025:        package org.keplerproject.luajava;
026:
027:        import java.util.ArrayList;
028:        import java.util.List;
029:
030:        /**
031:         * This class is responsible for instantiating new LuaStates.
032:         * When a new LuaState is instantiated it is put into a List
033:         * and an index is returned. This index is registred in Lua
034:         * and it is used to find the right LuaState when lua calls
035:         * a Java Function.
036:         * 
037:         * @author Thiago Ponte
038:         */
039:        public final class LuaStateFactory {
040:            /**
041:             * Array with all luaState's instances
042:             */
043:            private static final List states = new ArrayList();
044:
045:            /**
046:             * Non-public constructor. 
047:             */
048:            private LuaStateFactory() {
049:            }
050:
051:            /**
052:             * Method that creates a new instance of LuaState
053:             * @return LuaState
054:             */
055:            public synchronized static LuaState newLuaState() {
056:                int i = getNextStateIndex();
057:                LuaState L = new LuaState(i);
058:
059:                states.add(i, L);
060:
061:                return L;
062:            }
063:
064:            /**
065:             * Returns a existing instance of LuaState
066:             * @param index
067:             * @return LuaState
068:             */
069:            public synchronized static LuaState getExistingState(int index) {
070:                return (LuaState) states.get(index);
071:            }
072:
073:            /**
074:             * Receives a existing LuaState and checks if it exists in the states list.
075:             * If it doesn't exist adds it to the list.
076:             * @param L
077:             * @return int
078:             */
079:            public synchronized static int insertLuaState(LuaState L) {
080:                int i;
081:                for (i = 0; i < states.size(); i++) {
082:                    LuaState state = (LuaState) states.get(i);
083:
084:                    if (state != null) {
085:                        if (state.getCPtrPeer() == L.getCPtrPeer())
086:                            return i;
087:                    }
088:                }
089:
090:                i = getNextStateIndex();
091:
092:                states.set(i, L);
093:
094:                return i;
095:            }
096:
097:            /**
098:             * removes the luaState from the states list
099:             * @param idx
100:             */
101:            public synchronized static void removeLuaState(int idx) {
102:                states.add(idx, null);
103:            }
104:
105:            /**
106:             * Get next available index
107:             * @return int
108:             */
109:            private synchronized static int getNextStateIndex() {
110:                int i;
111:                for (i = 0; i < states.size() && states.get(i) != null; i++)
112:                    ;
113:
114:                return i;
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.