Refine search
/** * Determine if the given model is writable, which requires that the * source file also be writable. * * @param model the model to be tested. * @return true if model source is editable and the source file is writable. */ public static boolean isWritable(Model model) { if (model != null) { ModelSource ms = model.getModelSource(); if (ms.isEditable()) { FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); if (fo != null) { return fo.canWrite(); } } } return false; } }
@Override public void run() { NbMavenProject im = prj.getLookup().lookup(NbMavenProject.class); MavenProject mvnprj = im.getMavenProject(); DependencyNode tree = DependencyTreeFactory.createDependencyTree(mvnprj, EmbedderFactory.getProjectEmbedder(), Artifact.SCOPE_TEST); FileObject fo = prj.getLookup().lookup(FileObject.class); POMModel pommodel = null; if (fo != null) { ModelSource ms = Utilities.createModelSource(fo); if (ms.isEditable()) { POMModel model = POMModelFactory.getDefault().getModel(ms); if (model != null) { pommodel = model; } } } //add all in one place to prevent large time delays between additions if (pommodel != null) { ic.add(pommodel); } ic.add(tree); ic.add(mvnprj); } });
/** * Can return null if the created model is not faces-config model. */ protected JSFConfigModel createModel(FileObject fo) { if (fo.isFolder()) { LOG.log(Level.WARNING, "Creation of faces-config model for directory: {0}", fo.getPath()); return null; } JSFConfigModel model = getCachedModel(fo); if (model == null) { try { ModelSource source = Utilities.createModelSource(fo, true); Lookup lookup = source.getLookup(); lookup = new ProxyLookup(lookup, Lookups.singleton(this)); source = new ModelSource(lookup, true); model = JSFConfigModelFactory.getInstance().getModel(source); Node rootElement = model.getDocument().getDocumentElement(); if (rootElement == null || !JSFConfigQNames.areSameQName(JSFConfigQNames.FACES_CONFIG, (Element) rootElement)) { return null; } else { putCachedModel(fo, model); } } catch (CatalogModelException ex) { Exceptions.printStackTrace(ex); } } return model; }
public void save(JSFConfigModel model) { DataObject dObj = (DataObject)model.getModelSource().getLookup().lookup(DataObject.class); if (dObj != null) { SaveCookie saveCookie = (SaveCookie)dObj.getLookup().lookup(SaveCookie.class); if(saveCookie != null) { try { saveCookie.save(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } } }
public List<SystemEventListener> getSystemEventListeners() { List<FacesSystemEventListener> list = getChildren( FacesSystemEventListener.class ); List<SystemEventListener> result = new LinkedList<SystemEventListener>(); result.addAll( list ); AbstractJsfModel model = getModel().getModelSource().getLookup().lookup( AbstractJsfModel.class); if ( model != null ){ result.addAll( model.getSystemEventListeners() ); } return result; }
public List<ClientBehaviorRenderer> getClientBehaviorRenderers() { List<FacesClientBehaviorRenderer> list = getChildren( FacesClientBehaviorRenderer.class ); List<ClientBehaviorRenderer> result = new LinkedList<ClientBehaviorRenderer>(); result.addAll( list ); AbstractJsfModel model = getModel().getModelSource().getLookup().lookup( AbstractJsfModel.class ); if ( model != null && getRenderKitId()!= null ){ result.addAll(model.getClientBehaviorRenderers( getRenderKitId() )); } return result; }
public List<Renderer> getRenderers() { List<FacesRenderer> list = getChildren( FacesRenderer.class); List<Renderer> result = new LinkedList<Renderer>(); result.addAll( list ); AbstractJsfModel model = getModel().getModelSource().getLookup().lookup( AbstractJsfModel.class ); if ( model != null && getRenderKitId()!= null ){ result.addAll(model.getRenderers( getRenderKitId() )); } return result; }
public void fileDeleted( FileEvent event ) { FileObject file = event.getFile(); if ( !wasBeansFile(file)){ return; } WebBeansModel model = null; beanArchType = null; synchronized (myLock) { if ( myModels == null){ return; } for (WebBeansModel mod : myModels) { FileObject fileObject = mod.getModelSource() .getLookup().lookup(FileObject.class); if (fileObject.equals(event.getFile())) { model = mod; break; } } if (model != null) { myModels.remove(model); } } }
public List<ValidatorId> getValidatorIds() { List<FacesValidatorId> list = getChildren( FacesValidatorId.class ); List<ValidatorId> result = new ArrayList<ValidatorId>( list ); AbstractJsfModel model = getModel().getModelSource().getLookup().lookup( AbstractJsfModel.class); List<Validator> validators = model.getElements( Validator.class ); for (Validator validator : validators) { if ( validator instanceof FacesValidatorImpl){ if ( ((FacesValidatorImpl)validator).isDefault() ){ result.add( new AnnotationValidatorId( validator.getValidatorId() )); } } } return result; }
DataObject dobj = model.getModelSource().getLookup().lookup(DataObject.class); if (dobj == null) { final Document doc = model.getModelSource().getLookup().lookup(Document.class); final File file = model.getModelSource().getLookup().lookup(File.class); LOGGER.log(Level.FINE, "saving changes in {0}", file); File parent = file.getParentFile();
private void processXsds( Map<String,? extends Iterable<? extends FileObject>> files, Context context) { for (FileObject fileObject : findSpringLibraryDescriptors(files.get(XSD_MIME), XSD_SUFFIX)) { try { ModelSource modelSource = Utilities.getModelSource(fileObject, true); if (modelSource.getLookup().lookup(Document.class) != null) { SchemaModel model = SchemaModelFactory.getDefault().getModel(modelSource); Schema schema = model.getSchema(); String targetNamespace = schema.getTargetNamespace(); if (targetNamespace !=null) { IndexingSupport sup = IndexingSupport.getInstance(context); IndexDocument doc = sup.createDocument(fileObject); doc.addPair(NAMESPACE_MARK_KEY, targetNamespace, true, true); doc.addPair(LIBRARY_MARK_KEY, Boolean.TRUE.toString(), true, true); sup.addDocument(doc); LOGGER.log(Level.INFO, "The file " + fileObject + " indexed as a XSD (namespace=" + targetNamespace + ")"); //NOI18N } } }catch(Exception ex) { Exceptions.printStackTrace(ex); } } }
/** * Creates new form ExternalReferenceCustomizer * * @param component external reference to customize. */ public ExternalReferenceCustomizer(T component, Model model) { super(component); initComponents(); sourceFO = (FileObject) component.getModel().getModelSource(). getLookup().lookup(FileObject.class); catalogSupport = DefaultProjectCatalogSupport.getInstance(sourceFO); init(component, model); initializeUI(); // View for selecting an external reference. BeanTreeView locationView = new BeanTreeView(); locationView.setPopupAllowed(false); locationView.setDefaultActionAllowed(false); locationView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); locationView.setRootVisible(false); locationView.getAccessibleContext().setAccessibleName(locationLabel.getToolTipText()); locationView.getAccessibleContext().setAccessibleDescription(locationLabel.getToolTipText()); locationPanel.add(locationView, BorderLayout.CENTER); explorerManager = new ExplorerManager(); explorerManager.addPropertyChangeListener(this); explorerManager.setRootContext(createRootNode()); }
public void applyChanges() throws IOException { List<Node> nodes = getSelectedNodes(); for (Node node : nodes) { if (node instanceof ExternalReferenceNode) { Model model = ((ExternalReferenceNode) node).getModel(); // Without a model, the selection is completely invalid. if (model != null && model != getModelComponent().getModel()) { FileObject fileObj = (FileObject) model.getModelSource(). getLookup().lookup(FileObject.class); if (fileObj != null) { try { if (catalogSupport.needsCatalogEntry(sourceFO, fileObj)) { // Remove the previous catalog entry, then create new one. URI uri = catalogSupport.getReferenceURI(sourceFO, fileObj); catalogSupport.removeCatalogEntry(uri); catalogSupport.createCatalogEntry(sourceFO, fileObj); } } catch (URISyntaxException use) { ErrorManager.getDefault().notify(use); } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } catch (CatalogModelException cme) { ErrorManager.getDefault().notify(cme); } } } } } }