KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > MultiFileLoaderHid


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 /*
21  * MultiFileLoaderHid.java
22  *
23  * Created on September 12, 2001, 7:35 PM
24  */

25
26 package org.openide.loaders;
27
28 import org.openide.filesystems.*;
29 import java.io.*;
30
31 /**
32  *
33  * @author Vitezslav Stejskal
34  */

35 public class MultiFileLoaderHid extends MultiFileLoader {
36
37     private static final String JavaDoc PRIMARY_EXT = "primary";
38     private static final String JavaDoc SECONDARY_EXT = "secondary";
39
40     /** Creates new MultiFileLoaderHid */
41     public MultiFileLoaderHid () {
42         super ("org.openide.loaders.DataObject");
43     }
44
45     /** For a given file finds the primary file.
46      * @param fo the (secondary) file
47      *
48      * @return the primary file for the file or <code>null</code> if the file is not
49      * recognized by this loader
50      */

51     protected FileObject findPrimaryFile (FileObject fo) {
52         if (PRIMARY_EXT.equals (fo.getExt ())) {
53             return fo;
54         }
55         if (SECONDARY_EXT.equals (fo.getExt ())) {
56             return FileUtil.findBrother (fo, PRIMARY_EXT);
57         }
58         return null;
59     }
60
61     /** Creates a new secondary entry for a given file.
62      * Note that separate entries must be created for every secondary
63      * file within a given multi-file data object.
64      *
65      * @param obj requesting object
66      * @param secondaryFile a secondary file
67      * @return the entry
68      */

69     protected MultiDataObject.Entry createSecondaryEntry (MultiDataObject obj, FileObject secondaryFile) {
70         return new FileEntry (obj, secondaryFile);
71     }
72
73     /** Creates the right primary entry for a given primary file.
74      *
75      * @param obj requesting object
76      * @param primaryFile primary file recognized by this loader
77      * @return primary entry for that file
78      */

79     protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) {
80         return new FileEntry (obj, primaryFile);
81     }
82
83     /** Creates the right data object for a given primary file.
84      * It is guaranteed that the provided file will actually be the primary file
85      * returned by {@link #findPrimaryFile}.
86      *
87      * @param primaryFile the primary file
88      * @return the data object for this file
89      * @exception DataObjectExistsException if the primary file already has a data object
90      */

91     protected MultiDataObject createMultiObject (FileObject primaryFile) throws DataObjectExistsException, IOException {
92         return new MDO (primaryFile, this);
93     }
94     
95     private static class MDO extends MultiDataObject {
96         public MDO (FileObject primaryFile, MultiFileLoader loader) throws DataObjectExistsException {
97             super (primaryFile, loader);
98         }
99     }
100 }
101
Popular Tags