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: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.java.api.common.classpath.j2ee;
043:
044: import java.io.IOException;
045: import java.net.URL;
046:
047: import org.openide.filesystems.FileObject;
048: import org.openide.filesystems.FileUtil;
049:
050: import org.netbeans.api.project.libraries.Library;
051: import org.netbeans.modules.java.api.common.classpath.ProjectClassPathModifierSupport.Operation;
052: import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
053:
054: // will be moved to j2ee.common
055: /**
056: *
057: * @author Tomas Mysik
058: * @deprecated
059: */
060: @Deprecated
061: public abstract class J2EEProjectClassPathExtender implements
062: ProjectClassPathExtender {
063:
064: private static final String DEFAULT_CLASS_PATH = "javac.classpath"; // NOI18N
065: private static final String DEFAULT_INCLUDED_LIBS_ELEMENT = WebClassPathSupport.TAG_WEB_MODULE_LIBRARIES;
066:
067: private final J2EEProjectClassPathModifier delegate;
068:
069: public J2EEProjectClassPathExtender(
070: final J2EEProjectClassPathModifier delegate) {
071: assert delegate != null;
072: this .delegate = delegate;
073: }
074:
075: public boolean addLibrary(final Library library) throws IOException {
076: return addLibraries(DEFAULT_CLASS_PATH,
077: new Library[] { library },
078: DEFAULT_INCLUDED_LIBS_ELEMENT);
079: }
080:
081: public boolean addLibraries(final String classPathId,
082: final Library[] libraries, final String elementName)
083: throws IOException {
084: return delegate.handleLibraries(libraries, classPathId,
085: elementName, Operation.ADD);
086: }
087:
088: public boolean addArchiveFile(final FileObject archiveFile)
089: throws IOException {
090: return addArchiveFiles(DEFAULT_CLASS_PATH,
091: new FileObject[] { archiveFile },
092: DEFAULT_INCLUDED_LIBS_ELEMENT);
093: }
094:
095: public boolean addArchiveFiles(final String classPathId,
096: final FileObject[] archiveFiles, final String elementName)
097: throws IOException {
098: for (int i = 0; i < archiveFiles.length; i++) {
099: FileObject archiveFile = archiveFiles[i];
100: if (FileUtil.isArchiveFile(archiveFile)) {
101: archiveFiles[i] = FileUtil.getArchiveRoot(archiveFile);
102: }
103: }
104: URL[] archiveFileURLs = new URL[archiveFiles.length];
105: for (int i = 0; i < archiveFiles.length; i++) {
106: archiveFileURLs[i] = archiveFiles[i].getURL();
107: }
108: return delegate.handleRoots(archiveFileURLs, classPathId,
109: elementName, Operation.ADD);
110: }
111:
112: // TODO: AB: AntArtifactItem should not be in LibrariesChooser
113:
114: // has to be probably handled in project module itself
115: /*public boolean addAntArtifact (AntArtifact artifact, URI artifactElement) throws IOException {
116: return addAntArtifacts(CP_CLASS_PATH, new AntArtifactChooser.ArtifactItem[] { new AntArtifactChooser.ArtifactItem(artifact, artifactElement) }, DEFAULT_WEB_MODULE_ELEMENT_NAME);
117: }
118:
119: public boolean addAntArtifacts(final String classPathId, final AntArtifactChooser.ArtifactItem[] artifactItems, final String webModuleElementName) throws IOException {
120: AntArtifact[] artifacts = new AntArtifact[artifactItems.length];
121: URI[] artifactElements = new URI[artifactItems.length];
122: for (int i = 0; i < artifactItems.length; i++) {
123: artifacts[i] = artifactItems[i].getArtifact();
124: artifactElements[i] = artifactItems[i].getArtifactURI();
125: }
126: return delegate.handleAntArtifacts(artifacts, artifactElements, classPathId, webModuleElementName, J2EEProjectClassPathModifier.ADD);
127: }*/
128: }
|