1 /*2 * The contents of this file are subject to the terms of the Common Development3 * and Distribution License (the License). You may not use this file except in4 * compliance with the License.5 *6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html7 * or http://www.netbeans.org/cddl.txt.8 *9 * When distributing Covered Code, include this CDDL Header Notice in each file10 * and include the License file at http://www.netbeans.org/cddl.txt.11 * If applicable, add the following below the CDDL Header, with the fields12 * enclosed by brackets [] replaced by your own identifying information:13 * "Portions Copyrighted [year] [name of copyright owner]"14 *15 * The Original Software is NetBeans. The Initial Developer of the Original16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun17 * Microsystems, Inc. All Rights Reserved.18 */19 package org.netbeans.modules.refactoring.plugins;20 21 import java.io.File ;22 import java.io.IOException ;23 import java.net.URISyntaxException ;24 import java.net.URL ;25 import java.util.Collection ;26 import org.netbeans.modules.refactoring.api.AbstractRefactoring;27 import org.netbeans.modules.refactoring.api.MoveRefactoring;28 import org.netbeans.modules.refactoring.api.RenameRefactoring;29 import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;30 import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;31 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;32 import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;33 import org.openide.filesystems.FileObject;34 import org.openide.filesystems.FileUtil;35 import org.openide.filesystems.URLMapper;36 37 /**38 *39 * @author Jan Becicka40 */41 public class FileHandlingFactory implements RefactoringPluginFactory {42 43 public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {44 Collection <? extends FileObject> o = refactoring.getRefactoringSource().lookupAll(FileObject.class);45 if (refactoring instanceof RenameRefactoring) {46 if (!o.isEmpty()) {47 return new FileRenamePlugin((RenameRefactoring) refactoring);48 }49 } else if (refactoring instanceof MoveRefactoring) {50 if (!o.isEmpty()) {51 return new FileMovePlugin((MoveRefactoring) refactoring);52 }53 } else if (refactoring instanceof SafeDeleteRefactoring) {54 if (!o.isEmpty()) {55 return new FileDeletePlugin((SafeDeleteRefactoring) refactoring);56 }57 } else if (refactoring instanceof SingleCopyRefactoring) {58 if (!o.isEmpty()) {59 return new FileCopyPlugin((SingleCopyRefactoring) refactoring);60 }61 }62 return null;63 }64 65 /**66 * creates or finds FileObject according to 67 * @param url68 * @return FileObject69 */70 static FileObject getOrCreateFolder(URL url) throws IOException {71 try {72 FileObject result = URLMapper.findFileObject(url);73 if (result != null)74 return result;75 File f = new File (url.toURI());76 77 result = FileUtil.createFolder(f);78 return result;79 } catch (URISyntaxException ex) {80 throw (IOException ) new IOException ().initCause(ex);81 }82 }83 84 }85