Re: getting to ProjectMember from SourceElement

Tomas Zezula <[email protected]> Thu, 31 Jul 2003 09:20:44 +0200
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Organization Sun Microsystems
Message-ID <[email protected]>
On Thu, 2003-07-31 at 07:09, Peter Wisnovsky wrote:
> Svata Dedic writes:
>  > Peter Wisnovsky wrote:
>  > > I have a class constructed built off a source element. I find I need
>  > > access to the project I'm in for various API calls. I used to access
>  > > the public class from the source element, then do:
>  > > 
>  > >             Repository repository = Repository.getDefault();
>  > >             String fileName = classElement.getName().getFullName().replace('.', '/') + ".java";
>  > >             FileObject fileObject = repository.findResource(fileName);
>  > >             if (fileObject == null)
>  > >             {
>  > >                 throw new FileStateInvalidException(fileName);
>  > >             }
>  > >                 
>  > >             ProjectMember dataObject = ProjectMember.find(fileObject);
>  > > 
>  > If you really need to find the Project from a file, use findAll, *not* 
>  > find. *Do read* documentation for ProjectMember.find(), Project.find() 
>  > and Project.getProjectMember(). According to Project.find(), this call 
>  > *can not* work, since Project.find() and ProjectMember.find() are 
>  > designed to do a completely other thing.
> 
> Thanks, I'll try this! 
> 
> I do notice that in the Project.find docs it says that if you pass a
> file object, "if FileObject lies on filesystem of some project then
> this project is returned, otherwise it returns null"; moreover that
> projectmember.find is equivelent to using this. I inferred from this
> that since the file lives in a project that it would locate the
> file. Are there different kinds of fileobjects in the system that
> differ based on how they are extracted?
There is a big difference among files which are on the ProjectFileSystem
(the FS which contains the project definition, the project file system
always implies a single Project) and file object which are belonging to
the project(s) but are on the other filesystems (local, ftp,...).
These fileobject can belong to more than one Project, so the Project is
not implied by the FileObject and Project.findAll must be used to return
all these projects. The problem with findAll is how to find out which
project to choose from the returned array.
Tomas
> 
> Thanks,
> 
> Peter
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>