Java Code Examples for org.openide.loaders.DataObject#setValid()

The following examples show how to use org.openide.loaders.DataObject#setValid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConvertAsBeanTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testReadWrite() throws Exception {
    AnnoFoo foo = new AnnoFoo();
    foo.setName("xxx");

    DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
    DataObject obj = InstanceDataObject.create(test, null, foo, null);
    final FileObject pf = obj.getPrimaryFile();
    final String content = pf.asText();
    if (content.indexOf("<string>xxx</string>") == -1) {
        fail(content);
    }
    obj.setValid(false);
    DataObject newObj = DataObject.find(pf);
    if (newObj == obj) {
        fail("Strange, objects shall differ");
    }
    InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
    assertNotNull("Instance cookie found", ic);

    Object read = ic.instanceCreate();
    assertNotNull("Instance created", read);
    assertEquals("Correct class", AnnoFoo.class, read.getClass());
    AnnoFoo readFoo = (AnnoFoo)read;
    assertEquals("property changed", "xxx", readFoo.getName());
}
 
Example 2
Source File: ConvertAsBeanTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testReadWriteOnSubclass() throws Exception {
    HooFoo foo = new HooFoo();
    foo.setName("xxx");

    DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
    DataObject obj = InstanceDataObject.create(test, null, foo, null);
    final FileObject pf = obj.getPrimaryFile();
    final String content = pf.asText();
    if (content.indexOf("<string>xxx</string>") == -1) {
        fail(content);
    }
    obj.setValid(false);
    DataObject newObj = DataObject.find(pf);
    if (newObj == obj) {
        fail("Strange, objects shall differ");
    }
    InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
    assertNotNull("Instance cookie found", ic);

    Object read = ic.instanceCreate();
    assertNotNull("Instance created", read);
    assertEquals("Correct class", HooFoo.class, read.getClass());
    HooFoo readFoo = (HooFoo)read;
    assertEquals("property changed", "xxx", readFoo.getName());
}
 
Example 3
Source File: JavaDataLoader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void destroyDataObject(FileObject fo) throws IOException {
    DataObject dobj = DataObject.find(fo);
    try {
        dobj.setValid(false);
    } catch (PropertyVetoException ex) {
        throw (IOException) new IOException().initCause(ex);
    }
}
 
Example 4
Source File: EjbJarMultiViewDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected DataObject handleCopy(DataFolder f) throws IOException {
    DataObject dataObject = super.handleCopy(f);
    try {
        dataObject.setValid(false);
    } catch (PropertyVetoException e) {
        // should not occur
    }
    return dataObject;
}
 
Example 5
Source File: SunDescriptorDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected DataObject handleCopy(DataFolder f) throws IOException {
    DataObject dataObject = super.handleCopy(f);
    try {
        dataObject.setValid(false);
    } catch (PropertyVetoException e) {
        // should not occur
    }
    return dataObject;
}
 
Example 6
Source File: JaxWsServiceCreator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private FileObject generateJaxWSImplFromTemplate(FileObject pkg, String wsName, 
        int projectType) throws Exception 
{
    DataFolder df = DataFolder.findFolder(pkg);
    FileObject template = Templates.getTemplate(wiz);

    if ((Boolean)wiz.getProperty(WizardProperties.IS_STATELESS_BEAN)) { //EJB Web Service
        FileObject templateParent = template.getParent();
        template = templateParent.getFileObject("EjbWebService", "java"); //NOI18N
    }
    DataObject dTemplate = DataObject.find(template);
    DataObject dobj = dTemplate.createFromTemplate(df, wsName);
    FileObject createdFile = dobj.getPrimaryFile();
    createdFile.setAttribute("jax-ws-service", java.lang.Boolean.TRUE); // NOI18N
    dobj.setValid(false);
    dobj = DataObject.find(createdFile);
    final JaxWsModel jaxWsModel = projectInfo.getProject().getLookup().
        lookup(JaxWsModel.class);
    if (jaxWsModel != null) {
        
        ClassPath classPath = getClassPathForFile( projectInfo.getProject(), 
                createdFile);
            if (classPath != null) {
                String serviceImplPath = classPath.getResourceName(createdFile, 
                    '.', false);
                jaxWsModel.addService(wsName, serviceImplPath);
                ProjectManager.mutex().writeAccess(new Runnable() {

                public void run() {
                    try {
                        jaxWsModel.write();
                    } catch (IOException ex) {
                        ErrorManager.getDefault().notify(ex);
                    }
                }
            });
        }            
        JaxWsUtils.openFileInEditor(dobj);
        displayDuplicityWarning(createdFile);
    }

    return createdFile;
}
 
Example 7
Source File: JaxWsServiceCreator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void generateWebServiceFromEJB(String wsName, FileObject pkg, 
        ProjectInfo projectInfo, Node[] nodes) 
        throws IOException, ServiceAlreadyExistsExeption, PropertyVetoException 
{

    if (nodes != null && nodes.length == 1) {

        EjbReference ejbRef = nodes[0].getLookup().lookup(EjbReference.class);
        if (ejbRef != null) {

            DataFolder df = DataFolder.findFolder(pkg);
            FileObject template = Templates.getTemplate(wiz);
            FileObject templateParent = template.getParent();
            if ((Boolean)wiz.getProperty(WizardProperties.IS_STATELESS_BEAN)) { //EJB Web Service
                template = templateParent.getFileObject("EjbWebServiceNoOp", 
                        "java"); //NOI18N
            } else {
                template = templateParent.getFileObject("WebServiceNoOp", 
                        "java"); //NOI18N
            }
            DataObject dTemplate = DataObject.find(template);
            DataObject dobj = dTemplate.createFromTemplate(df, wsName);
            FileObject createdFile = dobj.getPrimaryFile();
            createdFile.setAttribute("jax-ws-service", java.lang.Boolean.TRUE);     // NOI18N
            dobj.setValid(false);
            dobj = DataObject.find(createdFile);

            ClassPath classPath = getClassPathForFile(projectInfo.getProject(), 
                    createdFile);
            if (classPath != null) {
                String serviceImplPath = classPath.getResourceName(createdFile, 
                        '.', false);
                generateDelegateMethods(createdFile, ejbRef);

                final JaxWsModel jaxWsModel = projectInfo.getProject().
                    getLookup().lookup(JaxWsModel.class);
                if (jaxWsModel != null) {
                    jaxWsModel.addService(wsName, serviceImplPath);
                    ProjectManager.mutex().writeAccess(new Runnable() {

                        public void run() {
                            try {
                                jaxWsModel.write();
                            } catch (IOException ex) {
                                ErrorManager.getDefault().notify(ex);
                            }
                        }
                    });
                }
            }
            JaxWsUtils.openFileInEditor(dobj);
            displayDuplicityWarning(createdFile);
        }
    }
}
 
Example 8
Source File: EarDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected DataObject handleCopy(DataFolder f) throws IOException {
    DataObject dObj = super.handleCopy(f);
    try { dObj.setValid(false); }catch(java.beans.PropertyVetoException e){}
    return dObj;
}
 
Example 9
Source File: TransformPerformer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
         * External XSLT processor is called from this method.
         */
        private void fileOutput() throws IOException, FileStateInvalidException, TransformerException {
            OutputStream outputStream = null;
            FileLock fileLock = null;

            try {
                fileLock = resultFO.lock();
                outputStream = resultFO.getOutputStream(fileLock);
                
                Result outputResult = new StreamResult(outputStream); // throws IOException, FileStateInvalidException
                
//                if ( Util.THIS.isLoggable() ) /* then */ {
//                    Util.THIS.debug("    resultFO = " + resultFO);
//                    Util.THIS.debug("    outputResult = " + outputResult);
//                }
                String xmlName = data.getInput();
                String xslName = data.getXSL();
                TransformPerformer.this.getCookieObserver().message(NbBundle.getMessage(TransformPerformer.class, "MSG_transformation_1", xmlName, xslName));
                TransformUtil.transform(xmlSource, transformableCookie, xslSource, outputResult, TransformPerformer.this.getCookieObserver()); // throws TransformerException
                // #186348  - should unlock first, then revalidate DO
            } catch (FileAlreadyLockedException exc) {
                throw (FileAlreadyLockedException) ErrorManager.getDefault().annotate(exc, NbBundle.getMessage(TransformPerformer.class, "ERR_FileAlreadyLockedException_output"));
            } finally {
                try {
                    if ( outputStream != null ) {
                        outputStream.close();
                    }
                } catch (IOException ex) {
                    // ignore, but log:
                    ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Could not close output stream for: " + resultFO);
                }
                if ( fileLock != null ) {
                    fileLock.releaseLock();
                }
            }
            // revalidate DataObject associated with possibly partially written file #28079
            try {
                DataObject dataObject = DataObject.find(resultFO);
                dataObject.setValid(false);
            } catch (DataObjectNotFoundException dnf) {
                throw new IllegalStateException();
            } catch (PropertyVetoException pve) {
                ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Cannot invalidate " + resultFO);
            }
            // vlv # 103384
            if ( data.getProcessOutput() == TransformHistory.APPLY_DEFAULT_ACTION ) {
                GuiUtil.performDefaultAction(resultFO);
            } else if ( data.getProcessOutput() == TransformHistory.OPEN_IN_BROWSER ) {
                showURL(resultFO.getURL());
            }
        }
 
Example 10
Source File: DataEditorSupportTest.java    From netbeans with Apache License 2.0 3 votes vote down vote up
private void doGetOpenedPanesWorksAfterDeserialization (int size) throws Exception {
    support().open ();
    
    waitEQ ();

    CloneableEditor ed = (CloneableEditor)support().getRef ().getAnyComponent ();
    
    JEditorPane[] panes = getPanes();
    assertNotNull (panes);
    assertEquals ("One is there", 1, panes.length);
    
    NbMarshalledObject marshall = new NbMarshalledObject (ed);
    ed.close ();
    
    panes = getPanes();
    assertNull ("No panes anymore", panes);

    DataObject oldObj = DataObject.find (fileObject);
    oldObj.setValid (false);
    
    expectedSize = size;
    
    ed = (CloneableEditor)marshall.get ();
    
    DataObject newObj = DataObject.find (fileObject);
    
    if (oldObj == newObj) {
        fail ("Object should not be the same, new one shall be created after marking the old invalid");
    }
    
    panes = getPanes ();
    assertNotNull ("One again", panes);
    assertEquals ("One is there again", 1, panes.length);
}