KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > ProvidedExtensionsProxy


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * 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 Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.masterfs;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.netbeans.modules.masterfs.providers.AnnotationProvider;
27 import org.netbeans.modules.masterfs.providers.InterceptionListener;
28 import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
29 import org.netbeans.modules.masterfs.providers.ProvidedExtensions.IOHandler;
30 import org.openide.filesystems.FileObject;
31
32 /**
33  *
34  * @author Radek Matous
35  */

36 public class ProvidedExtensionsProxy extends ProvidedExtensions {
37     private Collection JavaDoc/*AnnotationProvider*/ annotationProviders;
38     
39     /** Creates a new instance of ProvidedExtensionsProxy */
40     public ProvidedExtensionsProxy(Collection JavaDoc/*AnnotationProvider*/ annotationProviders) {
41         this.annotationProviders = annotationProviders;
42     }
43     
44     public ProvidedExtensions.DeleteHandler getDeleteHandler(final File JavaDoc f) {
45         ProvidedExtensions.DeleteHandler retValue = null;
46         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
47             AnnotationProvider provider = (AnnotationProvider) it.next();
48             final InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
49             if (iListener instanceof ProvidedExtensions) {
50                 retValue = ((ProvidedExtensions)iListener).getDeleteHandler(f);
51             }
52         }
53         return retValue;
54     }
55     
56     public ProvidedExtensions.IOHandler getRenameHandler(final File JavaDoc from, final String JavaDoc newName) {
57         final File JavaDoc to = new File JavaDoc(from.getParentFile(), newName);
58         IOHandler retValue = null;
59         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
60             AnnotationProvider provider = (AnnotationProvider) it.next();
61             final InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
62             if (iListener instanceof ProvidedExtensions) {
63                 retValue = ((ProvidedExtensions)iListener).getRenameHandler(from, newName);
64             }
65         }
66         return retValue;
67     }
68     
69     public ProvidedExtensions.IOHandler getMoveHandler(final File JavaDoc from, final File JavaDoc to) {
70         IOHandler retValue = null;
71         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext() && retValue == null;) {
72             AnnotationProvider provider = (AnnotationProvider) it.next();
73             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
74             if (iListener instanceof ProvidedExtensions) {
75                 retValue = ((ProvidedExtensions)iListener).getMoveHandler(from, to);
76             }
77         }
78         return retValue;
79     }
80     
81     public void createFailure(FileObject parent, String JavaDoc name, boolean isFolder) {
82         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
83             AnnotationProvider provider = (AnnotationProvider) it.next();
84             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
85             if (iListener != null) {
86                 iListener.createFailure(parent, name, isFolder);
87             }
88         }
89     }
90     
91     public void beforeCreate(FileObject parent, String JavaDoc name, boolean isFolder) {
92         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
93             AnnotationProvider provider = (AnnotationProvider) it.next();
94             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
95             if (iListener != null) {
96                 iListener.beforeCreate(parent, name, isFolder);
97             }
98         }
99     }
100     
101     public void deleteSuccess(FileObject fo) {
102         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
103             AnnotationProvider provider = (AnnotationProvider) it.next();
104             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
105             if (iListener != null) {
106                 iListener.deleteSuccess(fo);
107             }
108         }
109     }
110     
111     public void deleteFailure(FileObject fo) {
112         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
113             AnnotationProvider provider = (AnnotationProvider) it.next();
114             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
115             if (iListener != null) {
116                 iListener.deleteFailure(fo);
117             }
118         }
119     }
120     
121     public void createSuccess(FileObject fo) {
122         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
123             AnnotationProvider provider = (AnnotationProvider) it.next();
124             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
125             if (iListener != null) {
126                 iListener.createSuccess(fo);
127             }
128         }
129     }
130     
131     public void beforeDelete(FileObject fo) {
132         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
133             AnnotationProvider provider = (AnnotationProvider) it.next();
134             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
135             if (iListener != null) {
136                 iListener.beforeDelete(fo);
137             }
138         }
139     }
140
141     public void beforeChange(FileObject f) {
142         for (Iterator JavaDoc it = annotationProviders.iterator(); it.hasNext();) {
143             AnnotationProvider provider = (AnnotationProvider) it.next();
144             InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
145             if (iListener instanceof ProvidedExtensions) {
146                 ((ProvidedExtensions)iListener).beforeChange(f);
147             }
148         }
149     }
150 }
151
Popular Tags