Source Code Cross Referenced for InsyncTestBase.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » insync » 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 » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.insync 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         * 
024:         * Contributor(s):
025:         * 
026:         * Portions Copyrighted 2007 Sun Microsystems, Inc.
027:         */
028:        package org.netbeans.modules.visualweb.insync;
029:
030:        import com.sun.rave.designtime.Constants;
031:        import java.beans.BeanInfo;
032:        import java.io.File;
033:        import java.io.IOException;
034:        import java.lang.reflect.Constructor;
035:        import java.net.URL;
036:        import java.net.URLStreamHandlerFactory;
037:        import java.util.ArrayList;
038:        import java.util.List;
039:        import java.util.regex.Pattern;
040:        import junit.framework.*;
041:        import org.netbeans.api.project.Project;
042:        import org.netbeans.api.project.libraries.LibraryManager;
043:        import org.netbeans.core.startup.layers.NbinstURLStreamHandlerFactory;
044:        import org.netbeans.junit.NbTestCase;
045:        import org.netbeans.modules.visualweb.insync.beans.Bean;
046:        import org.netbeans.modules.visualweb.insync.beans.BeansUnit;
047:        import org.netbeans.modules.visualweb.insync.models.FacesModel;
048:        import org.netbeans.modules.visualweb.insync.models.FacesModelSet;
049:        import org.netbeans.modules.web.project.WebProject;
050:        import org.openide.filesystems.FileObject;
051:        import org.openide.util.Exceptions;
052:        import org.openide.util.test.MockLookup;
053:
054:        /**
055:         *
056:         * @author sc32560, jdeva
057:         * 
058:         */
059:        public class InsyncTestBase extends NbTestCase {
060:            public InsyncTestBase(String name) {
061:                super (name);
062:                _setUp();
063:            }
064:
065:            String[] pageBeans, requestBeans, sessionBeans, applicationBeans,
066:                    facesConfigs;
067:            Project project;
068:
069:            static {
070:                setupServices();
071:            }
072:
073:            @Override
074:            protected void setUp() throws Exception {
075:                super .setUp();
076:                //_setUp();
077:            }
078:
079:            private void _setUp() {
080:                //Set up the system properties
081:                System.setProperty("jdk.home", System.getProperty("java.home"));
082:                try {
083:
084:                    System.setProperty("netbeans.user", new File(getWorkDir()
085:                            .getParentFile(), "user").getAbsolutePath());
086:                } catch (IOException ex) {
087:                    Exceptions.printStackTrace(ex);
088:                }
089:                //Load the required libraries. This allows evaluation of project properties
090:                //ex:- ${libs.jsf12-support.classpath}
091:                LibraryManager.getDefault().getLibraries();
092:                openProject();
093:                pageBeans = System.getProperty("visualweb.project.pagebeans")
094:                        .split(
095:                                Pattern.quote(System
096:                                        .getProperty("path.separator")));
097:                requestBeans = System.getProperty(
098:                        "visualweb.project.requestbeans").split(
099:                        Pattern.quote(System.getProperty("path.separator")));
100:                sessionBeans = System.getProperty(
101:                        "visualweb.project.sessionbeans").split(
102:                        Pattern.quote(System.getProperty("path.separator")));
103:                applicationBeans = System.getProperty(
104:                        "visualweb.project.applicationbeans").split(
105:                        Pattern.quote(System.getProperty("path.separator")));
106:                facesConfigs = System.getProperty(
107:                        "visualweb.project.facesconfig").split(
108:                        Pattern.quote(System.getProperty("path.separator")));
109:
110:            }
111:
112:            @Override
113:            protected void tearDown() throws Exception {
114:                super .tearDown();
115:                clearWorkDir();
116:            }
117:
118:            public FacesModelSet createFacesModelSet() {
119:                FileObject file = getProject().getProjectDirectory();
120:                FacesModelSet set = FacesModelSet.getInstance(file);
121:                return set;
122:            }
123:
124:            protected int getBeansCount() {
125:                return getPageBeans().length + getNonPageBeansCount();
126:            }
127:
128:            protected int getNonPageBeansCount() {
129:                return getRequestBeans().length + getSessionBeans().length
130:                        + getApplicationBeans().length;
131:            }
132:
133:            protected String[] getBeanNames() {
134:                String[] str = new String[getBeansCount()];
135:                int i = 0;
136:                for (String s : getPageBeans()) {
137:                    str[i++] = s;
138:                }
139:                for (String s : getRequestBeans()) {
140:                    str[i++] = s;
141:                }
142:                for (String s : getSessionBeans()) {
143:                    str[i++] = s;
144:                }
145:                for (String s : getApplicationBeans()) {
146:                    str[i++] = s;
147:                }
148:                return str;
149:            }
150:
151:            protected List<Bean> createBeans(String[] types) {
152:                FacesModelSet modelSet = createFacesModelSet();
153:                FacesModel model = modelSet
154:                        .getFacesModel(getJavaFile(getPageBeans()[0]));
155:                model.sync();
156:                BeansUnit bu = model.getBeansUnit();
157:                List<Bean> beans = new ArrayList<Bean>();
158:                for (String type : types) {
159:                    beans.add(createBean(bu, type));
160:                }
161:                return beans;
162:            }
163:
164:            private Bean createBean(BeansUnit bu, String type) {
165:                Constructor ctor = null;
166:                java.lang.reflect.Method m = null;
167:                ClassLoader oldContextClassLoader = Thread.currentThread()
168:                        .getContextClassLoader();
169:                try {
170:                    Class clazz = Class
171:                            .forName("org.netbeans.modules.visualweb.insync.beans.Bean");
172:                    ctor = clazz.getDeclaredConstructor(BeansUnit.class,
173:                            BeanInfo.class, String.class);
174:                    ctor.setAccessible(true);
175:                    clazz = Class
176:                            .forName("org.netbeans.modules.visualweb.insync.beans.BeansUnit");
177:                    m = clazz
178:                            .getDeclaredMethod("nextNameForType", String.class);
179:                    m.setAccessible(true);
180:                } catch (Exception ex) {
181:                    Exceptions.printStackTrace(ex);
182:                }
183:                try {
184:                    Thread.currentThread().setContextClassLoader(
185:                            bu.getClassLoader());
186:                    Class beanClass = bu.getBeanClass(type);
187:                    if (beanClass != null) {
188:                        BeanInfo beanInfo = BeansUnit.getBeanInfo(beanClass, bu
189:                                .getClassLoader());
190:                        String name = (String) beanInfo.getBeanDescriptor()
191:                                .getValue(
192:                                        Constants.BeanDescriptor.INSTANCE_NAME);
193:                        if (name == null) {
194:                            name = (String) m.invoke(bu, type);
195:                        }
196:                        return (Bean) ctor.newInstance(bu, beanInfo, name);
197:                    }
198:                } catch (Exception ex) {
199:                    Exceptions.printStackTrace(ex);
200:                } finally {
201:                    Thread.currentThread().setContextClassLoader(
202:                            oldContextClassLoader);
203:                }
204:                return null;
205:            }
206:
207:            protected FileObject getJavaFile(String name) {
208:                FileObject[] roots = ((WebProject) getProject())
209:                        .getSourceRoots().getRoots();
210:                for (FileObject f : roots) {
211:                    FileObject result = findFileObject(f, name);
212:                    if (result != null) {
213:                        return result;
214:                    }
215:                }
216:                return null;
217:            }
218:
219:            protected FileObject findFileObject(FileObject f, String name) {
220:                FileObject result = null;
221:                if (f.isFolder()) {
222:                    for (FileObject child : f.getChildren()) {
223:                        result = findFileObject(child, name);
224:                        if (result != null) {
225:                            return result;
226:                        }
227:                    }
228:                } else {
229:                    if (name.equals(f.getName())) {
230:                        result = f;
231:                    }
232:                }
233:                return result;
234:            }
235:
236:            protected String getFQN(String className) {
237:                FileObject[] roots = ((WebProject) getProject())
238:                        .getSourceRoots().getRoots();
239:                for (FileObject f : roots) {
240:                    FileObject result = findFileObject(f, className);
241:                    if (result != null) {
242:                        String filePath = result.getPath().substring(0,
243:                                result.getPath().lastIndexOf("."));
244:                        String relativePath = filePath.replace(f.getPath(), "");
245:                        return relativePath.replace('/', '.').substring(1);
246:                    }
247:                }
248:                return null;
249:            }
250:
251:            protected String getPackageName(String className) {
252:                String relativePath = getFQN(className);
253:                int lastDotIndex = relativePath.lastIndexOf('.');
254:                return relativePath.substring(0, lastDotIndex);
255:            }
256:
257:            public Project openProject() {
258:                String projectName = System
259:                        .getProperty("visualweb.project.name");
260:                String relativeProjectPath = "projects" + File.separator
261:                        + projectName;
262:                //Check for a directory and then a zip file by project name
263:                File f = new File(getDataDir().getAbsolutePath(),
264:                        relativeProjectPath);
265:                if (!f.exists()) {
266:                    f = new File(getDataDir().getAbsolutePath(),
267:                            relativeProjectPath + ".zip");
268:                }
269:                try {
270:                    project = ProjectUtils.openProject(getWorkDir(), f
271:                            .getAbsolutePath(), projectName);
272:                    //Necessary for FacesConfigModel
273:                    JSFConfigUtils.setUp(project);
274:                } catch (IOException ex) {
275:                    Exceptions.printStackTrace(ex);
276:                }
277:                return project;
278:            }
279:
280:            public Project getProject() {
281:                return project;
282:            }
283:
284:            public void destroyProject() throws IOException {
285:                ProjectUtils.destroyProject(project);
286:            }
287:
288:            public String[] getApplicationBeans() {
289:                return applicationBeans;
290:            }
291:
292:            public String[] getPageBeans() {
293:                return pageBeans;
294:            }
295:
296:            public String[] getRequestBeans() {
297:                return requestBeans;
298:            }
299:
300:            public String[] getSessionBeans() {
301:                return sessionBeans;
302:            }
303:
304:            public String[] getFacesConfigs() {
305:                return facesConfigs;
306:            }
307:
308:            private static void setupServices() {
309:                URLStreamHandlerFactory urlStreamHandlerFactory = new NbinstURLStreamHandlerFactory();
310:                URL.setURLStreamHandlerFactory(urlStreamHandlerFactory);
311:                MockLookup.setInstances(new RepositoryImpl(),
312:                        new InsyncMimeResolver(), urlStreamHandlerFactory);
313:            }
314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.