/**
  * Try to load a config XML file from a named path. If the file does not exist, return
  * NONEXISTENT; or if there is any load error, return null.
  */
 private Document loadXml(String path) {
   assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
   assert Thread.holdsLock(modifiedMetadataPaths);
   FileObject xml = dir.getFileObject(path);
   if (xml == null || !xml.isData()) {
     return NONEXISTENT;
   }
   try {
     Document doc =
         XMLUtil.parse(
             new InputSource(xml.getInputStream()),
             false,
             true,
             XMLUtil.defaultErrorHandler(),
             null);
     return doc;
   } catch (IOException e) {
     if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
       LOG.log(Level.INFO, "Load XML: {0}", xml.getPath()); // NOI18N
       ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
     }
   } catch (SAXException e) {
     if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
       LOG.log(Level.INFO, "Load XML: {0}", xml.getPath()); // NOI18N
       ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
     }
   }
   return null;
 }
예제 #2
0
 public PasteType[] getPasteTypes(Transferable t) {
   if (t.isDataFlavorSupported(ExTransferable.multiFlavor)) {
     try {
       MultiTransferObject mto =
           (MultiTransferObject) t.getTransferData(ExTransferable.multiFlavor);
       boolean hasPackageFlavor = false;
       for (int i = 0; i < mto.getCount(); i++) {
         DataFlavor[] flavors = mto.getTransferDataFlavors(i);
         if (isPackageFlavor(flavors)) {
           hasPackageFlavor = true;
         }
       }
       return hasPackageFlavor ? new PasteType[0] : super.getPasteTypes(t);
     } catch (UnsupportedFlavorException e) {
       ErrorManager.getDefault().notify(e);
       return new PasteType[0];
     } catch (IOException e) {
       ErrorManager.getDefault().notify(e);
       return new PasteType[0];
     }
   } else {
     DataFlavor[] flavors = t.getTransferDataFlavors();
     if (isPackageFlavor(flavors)) {
       return new PasteType[0];
     } else {
       return super.getPasteTypes(t);
     }
   }
 }
예제 #3
0
 public /*@Override*/ PasteType getDropType(Transferable t, int action, int index) {
   if (t.isDataFlavorSupported(ExTransferable.multiFlavor)) {
     try {
       MultiTransferObject mto =
           (MultiTransferObject) t.getTransferData(ExTransferable.multiFlavor);
       boolean hasPackageFlavor = false;
       for (int i = 0; i < mto.getCount(); i++) {
         DataFlavor[] flavors = mto.getTransferDataFlavors(i);
         if (isPackageFlavor(flavors)) {
           hasPackageFlavor = true;
         }
       }
       return hasPackageFlavor ? null : super.getDropType(t, action, index);
     } catch (UnsupportedFlavorException e) {
       ErrorManager.getDefault().notify(e);
       return null;
     } catch (IOException e) {
       ErrorManager.getDefault().notify(e);
       return null;
     }
   } else {
     DataFlavor[] flavors = t.getTransferDataFlavors();
     if (isPackageFlavor(flavors)) {
       return null;
     } else {
       return super.getDropType(t, action, index);
     }
   }
 }
예제 #4
0
 public static String getBeanDisplayName(CommonDDBean bean, String nameProperty) {
   String name = null;
   try {
     name = (String) bean.getValue(nameProperty);
   } catch (IllegalArgumentException ex) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
   } catch (Schema2BeansRuntimeException ex) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
   }
   return name != null ? name : "unknown"; // NOI18N
 }
예제 #5
0
 @Override
 protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream out)
     throws IOException, BadLocationException {
   // Detect the encoding, using UTF8 if the encoding is not set.
   String enc = EncodingUtil.detectEncoding(doc);
   if (enc == null) {
     enc = "UTF8"; // NOI18N
   }
   try {
     // Test the encoding on a dummy stream.
     new OutputStreamWriter(new ByteArrayOutputStream(1), enc);
     // If that worked, we can go ahead with the encoding.
     Writer writer = new OutputStreamWriter(out, enc);
     kit.write(writer, doc, 0, doc.getLength());
   } catch (UnsupportedEncodingException uee) {
     // Safest option is to write nothing, preserving the original file.
     IOException ioex = new IOException("Unsupported encoding " + enc); // NOI18N
     ErrorManager.getDefault()
         .annotate(
             ioex,
             NbBundle.getMessage(
                 WadlEditorSupport.class, "MSG_WadlEditorSupport_Unsupported_Encoding", enc));
     throw ioex;
   }
 }
 /* Singleton accessor. As WelcomeComponent is persistent singleton this
  * accessor makes sure that WelcomeComponent is deserialized by window system.
  * Uses known unique TopComponent ID "VisualVMWelcome" to get WelcomeComponent instance
  * from window system. "VisualVMWelcome" is name of settings file defined in module layer.
  */
 public static synchronized WelcomeComponent findComp() {
   WelcomeComponent wc = component.get();
   if (wc == null) {
     TopComponent tc = WindowManager.getDefault().findTopComponent(PREFERRED_ID); // NOI18N
     if (tc != null) {
       if (tc instanceof WelcomeComponent) {
         wc = (WelcomeComponent) tc;
         component = new WeakReference<WelcomeComponent>(wc);
       } else {
         // Incorrect settings file?
         IllegalStateException exc =
             new IllegalStateException(
                 "Incorrect settings file. Unexpected class returned." // NOI18N
                     + " Expected:"
                     + WelcomeComponent.class.getName() // NOI18N
                     + " Returned:"
                     + tc.getClass().getName()); // NOI18N
         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
         // Fallback to accessor reserved for window system.
         wc = WelcomeComponent.createComp();
       }
     } else {
       // WelcomeComponent cannot be deserialized
       // Fallback to accessor reserved for window system.
       wc = WelcomeComponent.createComp();
     }
   }
   return wc;
 }
예제 #7
0
  protected void performAction(BpelEntity[] bpelEntities) {
    if (!enable(bpelEntities)) {
      return;
    }

    final BpelContainer parent = bpelEntities[0].getParent();
    final BpelEntity movingEntity = bpelEntities[0];
    if (parent == null) {
      return;
    }
    //        System.out.println("moveUpEntity - try to perform action...; ");

    Callable performActionCall =
        new Callable<Object>() {
          public Object call() throws Exception {
            moveEntity(movingEntity, parent);
            //                parent.getBpelModel().sync();
            return null;
          }
        };

    try {
      parent.getBpelModel().invoke(performActionCall, null);
    } catch (Exception ex) {
      ErrorManager.getDefault().notify(ex);
    }

    //        int curIndex = parent.indexOf(Copy.class,(Copy)bpelEntities[0]);

    //        BpelEntity cuttedCopy = bpelEntities[0].cut();
    //        ((Assign)parent.insertAssignChild(cuttedCopy,curIndex-1);
  }
예제 #8
0
    @Override
    protected void updateDataFromModel(
        Object model, org.openide.filesystems.FileLock lock, boolean modify) {
      if (model == null) {
        return;
      }
      Writer out = new StringWriter();
      try {
        javax.xml.bind.JAXBContext jaxbCtx =
            javax.xml.bind.JAXBContext.newInstance(model.getClass().getPackage().getName());
        javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); // NOI18N
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // Here we marshal the data back into a StringWriter object to update the editor's DataCache
        // and achieve syncronization.
        marshaller.marshal(model, out);
        out.close();
        getDataCache().setData(lock, out.toString(), modify);

        // If we wanted to write it away to a file instead we'd use:
        // marshaller.marshal(model, FileUtil.toFile(TgmDataObject.this.getPrimaryFile()));
        // But this would generate a read/write every time we changed something.

      } catch (javax.xml.bind.JAXBException ex) {
        // XXXTODO Handle exception
        java.util.logging.Logger.getLogger("global")
            .log(java.util.logging.Level.SEVERE, null, ex); // NOI18N
      } catch (IOException e) {
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
      }
    }
예제 #9
0
 public void setUnknownLayoutDelegate() {
   try {
     setLayoutDelegate(new UnknownLayoutSupport());
   } catch (Exception ex) { // nothing should happen, ignore
     ErrorManager.getDefault().notify(ex);
   }
 }
예제 #10
0
  /** Create DOM builder using JAXP libraries. */
  static DocumentBuilder makeBuilder(boolean validate) throws IOException, SAXException {

    DocumentBuilder builder;
    DocumentBuilderFactory factory;

    // create factory according to javax.xml.parsers.SAXParserFactory property
    // or platform default (i.e. com.sun...)
    try {
      factory = DocumentBuilderFactory.newInstance();
      factory.setValidating(validate);
      factory.setNamespaceAware(false);
    } catch (FactoryConfigurationError err) {
      notifyFactoryErr(err, "javax.xml.parsers.DocumentBuilderFactory"); // NOI18N
      throw err;
    }

    try {
      builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
      SAXException sex = new SAXException("Configuration exception."); // NOI18N
      ErrorManager emgr = ErrorManager.getDefault();
      emgr.annotate(sex, ex);
      emgr.annotate(
          sex,
          "Can not create a DOM builder!\nCheck javax.xml.parsers.DocumentBuilderFactory property and the builder library presence on classpath."); // NOI18N
      throw sex;
    }

    return builder;
  }
예제 #11
0
    public void run() {
      for (int i = 0; i < prepareSetups.length; i++) {
        if (prepareSetups != setups) {
          return;
        }
        try {
          prepareSetups[i].initSources(); // slow network I/O
          final int fi = i;
          StreamSource ss1 = prepareSetups[fi].getFirstSource();
          StreamSource ss2 = prepareSetups[fi].getSecondSource();
          final DiffController view =
              DiffController.create(ss1, ss2); // possibly executing slow external diff
          view.addPropertyChangeListener(MultiDiffPanel.this);
          SwingUtilities.invokeLater(
              new Runnable() {

                public void run() {
                  prepareSetups[fi].setView(view);
                  if (prepareSetups != setups) {
                    return;
                  }
                  if (currentModelIndex == fi) {
                    setDiffIndex(currentIndex, 0);
                  }
                }
              });
        } catch (IOException e) {
          ErrorManager.getDefault().notify(e);
        }
      }
    }
예제 #12
0
 private String getSDKProperties(String javaPath, String path) throws IOException {
   Runtime runtime = Runtime.getRuntime();
   try {
     String[] command = new String[5];
     command[0] = javaPath;
     command[1] = "-classpath"; // NOI18N
     command[2] =
         InstalledFileLocator.getDefault()
             .locate(
                 "modules/ext/org-netbeans-modules-visage-platform-probe.jar",
                 "org.netbeans.modules.visage.platform",
                 false)
             .getAbsolutePath(); // NOI18N
     command[3] = "org.netbeans.modules.visage.platform.wizard.SDKProbe"; // NOI18N
     command[4] = path;
     final Process process = runtime.exec(command);
     // PENDING -- this may be better done by using ExecEngine, since
     // it produces a cancellable task.
     process.waitFor();
     int exitValue = process.exitValue();
     if (exitValue != 0) throw new IOException();
     return command[2];
   } catch (InterruptedException ex) {
     IOException e = new IOException();
     ErrorManager.getDefault().annotate(e, ex);
     throw e;
   }
 }
예제 #13
0
  private static SAXParserFactory createFastSAXParserFactory()
      throws ParserConfigurationException, SAXException {
    if (fastParserFactoryClass == null) {
      try {
        fastParserFactoryClass =
            Class.forName("org.apache.crimson.jaxp.SAXParserFactoryImpl"); // NOI18N
      } catch (Exception ex) {
        useFastSAXParserFactory = false;
        if (System.getProperty("java.version").startsWith("1.4")) { // NOI18N
          ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        }
      }
    }
    if (fastParserFactoryClass != null) {
      try {
        SAXParserFactory factory = (SAXParserFactory) fastParserFactoryClass.newInstance();

        return factory;
      } catch (Exception ex) {
        useFastSAXParserFactory = false;
        throw new ParserConfigurationException(ex.getMessage());
      }
    }

    return SAXParserFactory.newInstance();
  }
 public static final void updateBlockChain(final NbEditorDocument doc) {
   if (doc == null) return;
   final Project p = J2MEProjectUtils.getProjectForDocument(doc);
   // TODO J2MEProject?
   if (p != null && p instanceof J2MEProject) {
     final ProjectConfigurationsHelper configHelper =
         p.getLookup().lookup(ProjectConfigurationsHelper.class);
     if (configHelper == null || !configHelper.isPreprocessorOn()) return;
     final HashMap<String, String> activeIdentifiers =
         new HashMap<String, String>(configHelper.getActiveAbilities());
     activeIdentifiers.put(configHelper.getActiveConfiguration().getDisplayName(), null);
     try {
       J2MEProjectUtilitiesProvider utilProvider =
           Lookup.getDefault().lookup(J2MEProjectUtilitiesProvider.class);
       if (utilProvider == null)
         return; // we do not run in full NetBeans, but this should not happen here (no editor)
       final CommentingPreProcessor cpp =
           new CommentingPreProcessor(
               utilProvider.createPPDocumentSource((NbEditorDocument) doc),
               null,
               activeIdentifiers);
       cpp.run();
       setLineInfo(doc, cpp.getLines(), cpp.getBlockList());
     } catch (PreprocessorException e) {
       ErrorManager.getDefault().notify(e);
     }
   }
 }
예제 #15
0
 public void fileRenamed(FileRenameEvent fe) {
   try {
     this.setURL(((FileObject) fe.getSource()).getURL().toString());
   } catch (FileStateInvalidException ex) {
     ErrorManager.getDefault().notify(ex);
   }
 }
예제 #16
0
 /**
  * Invokes endTransaction() without throwing exceptions (they are sent to ErrorManager). This is
  * intended only for the deserialization process, and should not be used outside of the model
  * package.
  */
 public void safeEndTransaction() {
   try {
     endTransaction();
   } catch (IOException ioe) {
     ErrorManager.getDefault().notify(ioe);
   }
 }
예제 #17
0
 /** Annotate & notify the exception. */
 private static void notifyNewSAXParserEx(Exception ex) {
   ErrorManager emgr = ErrorManager.getDefault();
   emgr.annotate(
       ex,
       "Can not create a SAX parser!\nCheck javax.xml.parsers.SAXParserFactory property features and the parser library presence on classpath."); // NOI18N
   emgr.notify(ex);
 }
예제 #18
0
 @Override
 protected void reloadModelFromData() {
   try {
     parseDocument();
   } catch (IOException e) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   }
 }
예제 #19
0
 /** Annotate & notify the error. */
 private static void notifyFactoryErr(Error err, String property) {
   ErrorManager emgr = ErrorManager.getDefault();
   emgr.annotate(
       err,
       "Can not create a factory!\nCheck "
           + property
           + "  property and the factory library presence on classpath."); // NOI18N
   emgr.notify(err);
 }
예제 #20
0
 public static Color getColor(String resId) {
   ResourceBundle bundle = NbBundle.getBundle("net.phyloviz.welcome.resources.Bundle"); // NOI18N
   try {
     Integer rgb = Integer.decode(bundle.getString(resId));
     return new Color(rgb.intValue());
   } catch (NumberFormatException nfE) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, nfE);
     return Color.BLACK;
   }
 }
예제 #21
0
  protected void performAction(Node[] activatedNodes) {
    DataObject c = activatedNodes[0].getCookie(DataObject.class);
    FileObject f = c.getPrimaryFile();
    // get classpath
    String cp = SmartFrogSvcUtil.getSFClassPath();

    // set options
    String iniFile = SmartFrogSvcUtil.getIniFile();
    String sfDefault = SmartFrogSvcUtil.getSFDefault();
    String userDir = FileUtil.getFileDisplayName(f.getParent());

    // call jvm

    Process proc = null;
    try {
      String[] procString = new String[8];
      procString[0] = "java";
      procString[1] = "-cp";
      procString[2] = cp;
      procString[3] = "-Duser.dir=\"" + userDir + "\"";
      procString[4] = "org.smartfrog.SFParse";
      procString[5] = "-d";
      procString[6] = "-v";
      procString[7] = FileUtil.getFileDisplayName(f);

      proc = Runtime.getRuntime().exec(procString);
    } catch (IOException ex) {
      ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
    }
    if (proc != null) {
      ExecSupport es = new ExecSupport();
      try {
        es.displayProcessOutputs(proc, "Smart Frog Parse");
      } catch (InterruptedException ex) {
        ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
      } catch (IOException ex) {
        ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
      }
    } else {
      ErrorManager.getDefault()
          .notify(ErrorManager.EXCEPTION, new RuntimeException("Error starting Smart Frog"));
    }
  }
  /** Gets additional bean infos. */
  @Override
  public BeanInfo[] getAdditionalBeanInfo() {
    try {
      return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException ie) {
      ErrorManager.getDefault().notify(ie);

      return null;
    }
  }
예제 #23
0
 public void setName(String arg0) {
   try {
     String o = getName();
     getDataObject().rename(arg0);
     fireDisplayNameChange(o, arg0);
     fireNameChange(o, arg0);
   } catch (IOException e) {
     ErrorManager.getDefault().notify(e);
   }
 }
 private void generationFailed(Exception e, Object file) {
   OutputLogger.getInstance().log(e);
   ErrorManager.getDefault().notify(e);
   OutputLogger.getInstance()
       .log(
           MessageFormat.format(
               NbBundle.getMessage(
                   ClientBeanGeneratorTemplate.class, "MSG_FailJavonClientGeneration"),
               file));
 }
예제 #25
0
 /* Uses NetBeans module classloader to load the class.
  * @param v description of the class to load
  */
 protected Class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException {
   ClassLoader cl = getNBClassLoader();
   try {
     return Class.forName(v.getName(), false, cl);
   } catch (ClassNotFoundException cnfe) {
     String msg = "Offending classloader: " + cl; // NOI18N
     ErrorManager.getDefault().annotate(cnfe, ErrorManager.INFORMATIONAL, msg, null, null, null);
     throw cnfe;
   }
 }
 @Override
 public NodeList<?> createNodes(Project aProject) {
   try {
     assert aProject instanceof PlatypusProjectImpl;
     PlatypusProjectImpl project = (PlatypusProjectImpl) aProject;
     return new PlatypusProjectNodesList(project);
   } catch (Exception ex) {
     ErrorManager.getDefault().notify(ex);
     return null;
   }
 }
예제 #27
0
 protected void removeNotify() {
   VisibilityQuery.getDefault().removeChangeListener(wvqcl);
   try {
     root.getFileSystem().removeFileChangeListener(wfcl);
   } catch (FileStateInvalidException e) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   }
   setKeys(Collections.EMPTY_SET);
   names2nodes.clear();
   super.removeNotify();
 }
  /*
   * @see org.openthinclient.console.Refreshable#refresh()
   */
  public void refresh() {
    final Realm realm = (Realm) getLookup().lookup(Realm.class);
    final DirectoryObject o = (DirectoryObject) getLookup().lookup(DirectoryObject.class);

    try {
      realm.getDirectory().refresh(o);
      fireCookieChange();
    } catch (final DirectoryException e) {
      ErrorManager.getDefault().notify(e);
    }
  }
예제 #29
0
 private LineBreakpointComparable(String url) {
   setURL(url);
   try {
     fo = URLMapper.findFileObject(new URL(getURL()));
     if (fo != null) {
       fo.addFileChangeListener(WeakListeners.create(FileChangeListener.class, this, fo));
     }
   } catch (MalformedURLException ex) {
     ErrorManager.getDefault().notify(ex);
   }
 }
예제 #30
0
 /**
  * Obtain the window instance, first by looking for it in the window system, then if not found,
  * creating the instance.
  *
  * <p>
  *
  * @return the window instance.
  */
 public static synchronized SourcesView findInstance() {
   TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
   if (win == null) {
     ErrorManager.getDefault()
         .log(
             ErrorManager.WARNING,
             "Cannot find '" + PREFERRED_ID + "' component in the window system");
     return getDefault();
   }
   if (win instanceof SourcesView) {
     return (SourcesView) win;
   }
   ErrorManager.getDefault()
       .log(
           ErrorManager.WARNING,
           "There seem to be multiple components with the '"
               + PREFERRED_ID
               + "' ID, this a potential source of errors");
   return getDefault();
 }