Source Code Cross Referenced for TestUtil.java in  » IDE-Netbeans » project.ant » org » netbeans » modules » project » libraries » 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 » project.ant » org.netbeans.modules.project.libraries 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         *
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         *
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         *
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.project.libraries;
021:
022:        import java.beans.PropertyChangeListener;
023:        import java.beans.PropertyChangeSupport;
024:        import java.io.IOException;
025:        import java.net.MalformedURLException;
026:        import java.net.URL;
027:        import java.util.ArrayList;
028:        import java.util.Arrays;
029:        import java.util.HashMap;
030:        import java.util.HashSet;
031:        import java.util.List;
032:        import java.util.Map;
033:        import java.util.Set;
034:        import java.util.regex.Matcher;
035:        import java.util.regex.Pattern;
036:        import org.netbeans.spi.project.libraries.ArealLibraryProvider;
037:        import org.netbeans.spi.project.libraries.LibraryImplementation;
038:        import org.netbeans.spi.project.libraries.LibraryProvider;
039:        import org.netbeans.spi.project.libraries.LibraryStorageArea;
040:        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
041:        import org.openide.util.WeakSet;
042:
043:        /**
044:         * Common support classes for unit tests in this module.
045:         */
046:        public class TestUtil {
047:
048:            private TestUtil() {
049:            }
050:
051:            public static class NWLP implements 
052:                    LibraryProvider<LibraryImplementation> {
053:
054:                public final List<LibraryImplementation> libs = new ArrayList<LibraryImplementation>();
055:                final PropertyChangeSupport pcs = new PropertyChangeSupport(
056:                        this );
057:
058:                public void set(LibraryImplementation... nue) {
059:                    libs.clear();
060:                    libs.addAll(Arrays.asList(nue));
061:                    pcs.firePropertyChange(PROP_LIBRARIES, null, null);
062:                }
063:
064:                public LibraryImplementation[] getLibraries() {
065:                    return libs.toArray(new LibraryImplementation[0]);
066:                }
067:
068:                public void addPropertyChangeListener(
069:                        PropertyChangeListener listener) {
070:                    pcs.addPropertyChangeListener(listener);
071:                }
072:
073:                public void removePropertyChangeListener(
074:                        PropertyChangeListener listener) {
075:                    pcs.removePropertyChangeListener(listener);
076:                }
077:
078:            }
079:
080:            public static final class WLP extends NWLP implements 
081:                    WritableLibraryProvider<LibraryImplementation> {
082:
083:                public void addLibrary(LibraryImplementation library)
084:                        throws IOException {
085:                    libs.add(library);
086:                    pcs.firePropertyChange(PROP_LIBRARIES, null, null);
087:                }
088:
089:                public void removeLibrary(LibraryImplementation library)
090:                        throws IOException {
091:                    libs.remove(library);
092:                    pcs.firePropertyChange(PROP_LIBRARIES, null, null);
093:                }
094:
095:                public void updateLibrary(LibraryImplementation oldLibrary,
096:                        LibraryImplementation newLibrary) throws IOException {
097:                    libs.remove(oldLibrary);
098:                    libs.add(newLibrary);
099:                    pcs.firePropertyChange(PROP_LIBRARIES, null, null);
100:                }
101:
102:            }
103:
104:            public static final class Area implements  LibraryStorageArea {
105:
106:                final String id;
107:
108:                public Area(String id) {
109:                    this .id = id;
110:                }
111:
112:                public URL getLocation() {
113:                    try {
114:                        return new URL("http://nowhere.net/" + id);
115:                    } catch (MalformedURLException x) {
116:                        throw new AssertionError(x);
117:                    }
118:                }
119:
120:                public String getDisplayName() {
121:                    return id;
122:                }
123:
124:                public boolean equals(Object obj) {
125:                    return obj instanceof  Area && ((Area) obj).id.equals(id);
126:                }
127:
128:                public int hashCode() {
129:                    return id.hashCode();
130:                }
131:
132:                public @Override
133:                String toString() {
134:                    return "Area[" + id + "]";
135:                }
136:
137:            }
138:
139:            public static final class ALP implements 
140:                    ArealLibraryProvider<Area, LibraryImplementation> {
141:
142:                final PropertyChangeSupport pcs = new PropertyChangeSupport(
143:                        this );
144:                public final Map<Area, List<LibraryImplementation>> libs = new HashMap<Area, List<LibraryImplementation>>();
145:                final Set<LP> lps = new WeakSet<LP>();
146:                final Set<Area> open = new HashSet<Area>();
147:
148:                public void addPropertyChangeListener(
149:                        PropertyChangeListener listener) {
150:                    pcs.addPropertyChangeListener(listener);
151:                }
152:
153:                public void removePropertyChangeListener(
154:                        PropertyChangeListener listener) {
155:                    pcs.removePropertyChangeListener(listener);
156:                }
157:
158:                public Class<Area> areaType() {
159:                    return Area.class;
160:                }
161:
162:                public Class<LibraryImplementation> libraryType() {
163:                    return LibraryImplementation.class;
164:                }
165:
166:                public Area createArea() {
167:                    return new Area("new");
168:                }
169:
170:                public Area loadArea(URL location) {
171:                    Matcher m = Pattern.compile("http://nowhere\\.net/(.+)$")
172:                            .matcher(location.toExternalForm());
173:                    if (m.matches()) {
174:                        return new Area(m.group(1));
175:                    } else {
176:                        return null;
177:                    }
178:                }
179:
180:                public Set<Area> getOpenAreas() {
181:                    return open;
182:                }
183:
184:                public void setOpen(Area... areas) {
185:                    open.clear();
186:                    open.addAll(Arrays.asList(areas));
187:                    pcs.firePropertyChange(PROP_OPEN_AREAS, null, null);
188:                }
189:
190:                private class LP implements 
191:                        LibraryProvider<LibraryImplementation> {
192:
193:                    final PropertyChangeSupport pcs = new PropertyChangeSupport(
194:                            this );
195:                    final Area area;
196:
197:                    LP(Area area) {
198:                        this .area = area;
199:                        lps.add(this );
200:                    }
201:
202:                    public LibraryImplementation[] getLibraries() {
203:                        if (libs.containsKey(area)) {
204:                            return libs.get(area).toArray(
205:                                    new LibraryImplementation[0]);
206:                        } else {
207:                            return new LibraryImplementation[0];
208:                        }
209:                    }
210:
211:                    public void addPropertyChangeListener(
212:                            PropertyChangeListener listener) {
213:                        pcs.addPropertyChangeListener(listener);
214:                    }
215:
216:                    public void removePropertyChangeListener(
217:                            PropertyChangeListener listener) {
218:                        pcs.removePropertyChangeListener(listener);
219:                    }
220:
221:                }
222:
223:                public LibraryProvider<LibraryImplementation> getLibraries(
224:                        Area area) {
225:                    return new LP(area);
226:                }
227:
228:                public LibraryImplementation createLibrary(String type,
229:                        String name, Area area, Map<String, List<URL>> contents)
230:                        throws IOException {
231:                    LibraryImplementation lib = LibrariesSupport
232:                            .createLibraryImplementation(type, contents
233:                                    .keySet().toArray(new String[0]));
234:                    lib.setName(name);
235:                    for (Map.Entry<String, List<URL>> entry : contents
236:                            .entrySet()) {
237:                        lib.setContent(entry.getKey(), entry.getValue());
238:                    }
239:                    List<LibraryImplementation> l = libs.get(area);
240:                    if (l == null) {
241:                        l = new ArrayList<LibraryImplementation>();
242:                        libs.put(area, l);
243:                    }
244:                    l.add(lib);
245:                    for (LP lp : lps) {
246:                        if (lp.area.equals(area)) {
247:                            lp.pcs.firePropertyChange(
248:                                    LibraryProvider.PROP_LIBRARIES, null, null);
249:                        }
250:                    }
251:                    return lib;
252:                }
253:
254:                public void remove(LibraryImplementation library)
255:                        throws IOException {
256:                    for (Map.Entry<Area, List<LibraryImplementation>> entry : libs
257:                            .entrySet()) {
258:                        if (entry.getValue().remove(library)) {
259:                            for (LP lp : lps) {
260:                                if (lp.area.equals(entry.getKey())) {
261:                                    lp.pcs.firePropertyChange(
262:                                            LibraryProvider.PROP_LIBRARIES,
263:                                            null, null);
264:                                }
265:                            }
266:                        }
267:                    }
268:                }
269:
270:            }
271:
272:            public static URL mkJar(String name) throws MalformedURLException {
273:                return new URL("jar:http://nowhere.net/" + name + "!/");
274:            }
275:
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.