Source Code Cross Referenced for ServerLibraryTypeProvider.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » impl » sharability » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » j2eeserver » org.netbeans.modules.j2ee.deployment.impl.sharability 
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         * If you wish your version of this file to be governed by only the CDDL
025         * or only the GPL Version 2, indicate your decision by adding
026         * "[Contributor] elects to include this software in this distribution
027         * under the [CDDL or GPL Version 2] license." If you do not indicate a
028         * single choice of license, a recipient has the option to distribute
029         * your version of this file under either the CDDL, the GPL Version 2 or
030         * to extend the choice of license to its licensees as provided above.
031         * However, if you add GPL Version 2 code and therefore, elected the GPL
032         * Version 2 license, then the option applies only if the new code is
033         * made subject to such option by the copyright holder.
034         *
035         * Contributor(s):
036         *
037         * Portions Copyrighted 2008 Sun Microsystems, Inc.
038         */
039
040        package org.netbeans.modules.j2ee.deployment.impl.sharability;
041
042        import java.beans.Customizer;
043        import java.io.File;
044        import java.io.IOException;
045        import java.net.URI;
046        import java.net.URL;
047        import java.util.Iterator;
048        import java.util.List;
049        import org.netbeans.api.project.ProjectManager;
050        import org.netbeans.spi.project.libraries.LibraryImplementation;
051        import org.netbeans.spi.project.libraries.LibraryTypeProvider;
052        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
053        import org.netbeans.spi.project.support.ant.EditableProperties;
054        import org.netbeans.spi.project.support.ant.PropertyUtils;
055        import org.openide.ErrorManager;
056        import org.openide.filesystems.FileObject;
057        import org.openide.filesystems.FileUtil;
058        import org.openide.filesystems.URLMapper;
059        import org.openide.util.Lookup;
060        import org.openide.util.NbBundle;
061
062        /**
063         *
064         * @author Petr Hejl
065         */
066        public final class ServerLibraryTypeProvider implements 
067                LibraryTypeProvider {
068
069            public static final String LIBRARY_TYPE = "j2eeshared"; // NOI18N
070
071            public static final String VOLUME_CLASSPATH = "classpath";
072
073            public static final String VOLUME_WS_COMPILE_CLASSPATH = "wscompile";
074
075            public static final String VOLUME_WS_GENERATE_CLASSPATH = "wsgenerate";
076
077            public static final String VOLUME_WS_IMPORT_CLASSPATH = "wsimport";
078
079            public static final String VOLUME_WS_INTEROP_CLASSPATH = "wsinterop";
080
081            public static final String VOLUME_WS_JWSDP_CLASSPATH = "wsjwsdp";
082
083            public static final String VOLUME_JAVADOC = "javadoc";
084
085            public static final String VOLUME_SOURCE = "src";
086
087            // This is runtime only
088            //public static final String VOLUME_APP_CLIENT_CLASSPATH = "appclient";
089
090            private static final String LIB_PREFIX = "libs.";
091
092            private static final String[] VOLUME_TYPES = new String[] {
093                    VOLUME_CLASSPATH, VOLUME_WS_COMPILE_CLASSPATH,
094                    VOLUME_WS_GENERATE_CLASSPATH, VOLUME_WS_IMPORT_CLASSPATH,
095                    VOLUME_WS_INTEROP_CLASSPATH, VOLUME_WS_JWSDP_CLASSPATH,
096                    VOLUME_JAVADOC, VOLUME_SOURCE };
097
098            private ServerLibraryTypeProvider() {
099                super ();
100            }
101
102            public static LibraryTypeProvider create() {
103                return new ServerLibraryTypeProvider();
104            }
105
106            public LibraryImplementation createLibrary() {
107                return LibrariesSupport.createLibraryImplementation(
108                        LIBRARY_TYPE, VOLUME_TYPES);
109            }
110
111            public Customizer getCustomizer(String volumeType) {
112                // avoid user confusion
113                if (VOLUME_CLASSPATH.equals(volumeType)
114                        || VOLUME_JAVADOC.equals(volumeType)
115                        || VOLUME_SOURCE.equals(volumeType)) {
116                    return new ServerVolumeCustomizer(volumeType);
117                }
118                return null;
119            }
120
121            public String getDisplayName() {
122                return NbBundle.getMessage(ServerLibraryTypeProvider.class,
123                        "ServerLibraryTypeProvider.typeName");
124            }
125
126            public String getLibraryType() {
127                return LIBRARY_TYPE;
128            }
129
130            public String[] getSupportedVolumeTypes() {
131                return VOLUME_TYPES.clone();
132            }
133
134            // XXX copied from j2se
135            public void libraryCreated(final LibraryImplementation libraryImpl) {
136                assert libraryImpl != null;
137                ProjectManager.mutex().postWriteRequest(new Runnable() {
138                    public void run() {
139                        try {
140                            EditableProperties props = PropertyUtils
141                                    .getGlobalProperties();
142                            boolean save = addLibraryIntoBuild(libraryImpl,
143                                    props);
144                            if (save) {
145                                PropertyUtils.putGlobalProperties(props);
146                            }
147                        } catch (IOException ioe) {
148                            ErrorManager.getDefault().notify(ioe);
149                        }
150                    }
151                });
152            }
153
154            // XXX copied from j2se
155            public void libraryDeleted(final LibraryImplementation libraryImpl) {
156                assert libraryImpl != null;
157                ProjectManager.mutex().postWriteRequest(new Runnable() {
158                    public void run() {
159                        try {
160                            EditableProperties props = PropertyUtils
161                                    .getGlobalProperties();
162                            for (int i = 0; i < VOLUME_TYPES.length; i++) {
163                                String property = LIB_PREFIX
164                                        + libraryImpl.getName() + '.'
165                                        + VOLUME_TYPES[i]; //NOI18N
166                                props.remove(property);
167                            }
168                            PropertyUtils.putGlobalProperties(props);
169                        } catch (IOException ioe) {
170                            ErrorManager.getDefault().notify(ioe);
171                        }
172                    }
173                });
174            }
175
176            public Lookup getLookup() {
177                return Lookup.EMPTY;
178            }
179
180            // XXX copied from j2se
181            private static boolean addLibraryIntoBuild(
182                    LibraryImplementation impl, EditableProperties props) {
183                boolean modified = false;
184                for (int i = 0; i < VOLUME_TYPES.length; i++) {
185                    String propName = LIB_PREFIX + impl.getName() + '.'
186                            + VOLUME_TYPES[i]; //NOI18N
187                    List roots = impl.getContent(VOLUME_TYPES[i]);
188                    if (roots == null) {
189                        //Non valid library, but try to recover
190                        continue;
191                    }
192                    StringBuffer propValue = new StringBuffer();
193                    boolean first = true;
194                    for (Iterator rootsIt = roots.iterator(); rootsIt.hasNext();) {
195                        URL url = (URL) rootsIt.next();
196                        if ("jar".equals(url.getProtocol())) {
197                            url = FileUtil.getArchiveFile(url);
198                            // XXX check whether this is really the root
199                        }
200                        File f = null;
201                        FileObject fo = URLMapper.findFileObject(url);
202                        if (fo != null) {
203                            f = FileUtil.toFile(fo);
204                        } else if ("file".equals(url.getProtocol())) { //NOI18N
205                            //If the file does not exist (eg library from cleaned project)
206                            // and it is a file protocol URL, add it.
207                            URI uri = URI.create(url.toExternalForm());
208                            if (uri != null) {
209                                f = new File(uri);
210                            }
211                        }
212                        if (f != null) {
213                            if (!first) {
214                                propValue.append(File.pathSeparatorChar);
215                            }
216                            first = false;
217                            f = FileUtil.normalizeFile(f);
218                            propValue.append(f.getAbsolutePath());
219                        } else {
220                            ErrorManager.getDefault().log(
221                                    "ServerLibraryTypeProvider: Can not resolve URL: "
222                                            + url); //NOI18N
223                        }
224                    }
225                    String oldValue = props.getProperty(propName);
226                    String newValue = propValue.toString();
227                    if (!newValue.equals(oldValue)) {
228                        props.setProperty(propName, newValue);
229                        modified = true;
230                    }
231                }
232                return modified;
233            }
234        }
ww_w.___j_a___v___a___2__s___.___c__o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.