Exemplo n.º 1
1
 /**
  * Factory method, equivalent to a "fromXML" for step creation. Looks for a class with the same
  * name as the XML tag, with the first letter capitalized. For example, <call /> is
  * abbot.script.Call.
  */
 public static Step createStep(Resolver resolver, Element el) throws InvalidScriptException {
   String tag = el.getName();
   Map attributes = createAttributeMap(el);
   String name = tag.substring(0, 1).toUpperCase() + tag.substring(1);
   if (tag.equals(TAG_WAIT)) {
     attributes.put(TAG_WAIT, "true");
     name = "Assert";
   }
   try {
     name = "abbot.script." + name;
     Log.debug("Instantiating " + name);
     Class cls = Class.forName(name);
     try {
       // Steps with contents require access to the XML element
       Class[] argTypes = new Class[] {Resolver.class, Element.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, el, attributes});
     } catch (NoSuchMethodException nsm) {
       // All steps must support this ctor
       Class[] argTypes = new Class[] {Resolver.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, attributes});
     }
   } catch (ClassNotFoundException cnf) {
     String msg = Strings.get("step.unknown_tag", new Object[] {tag});
     throw new InvalidScriptException(msg);
   } catch (InvocationTargetException ite) {
     Log.warn(ite);
     throw new InvalidScriptException(ite.getTargetException().getMessage());
   } catch (Exception exc) {
     Log.warn(exc);
     throw new InvalidScriptException(exc.getMessage());
   }
 }
Exemplo n.º 2
0
  // ------------------------------------------------------------------------------------------------
  // 描述:
  // 设计: Skyline(2001.12.29)
  // 实现: Skyline
  // 修改:
  // ------------------------------------------------------------------------------------------------
  public JFunctionStub getFunctionByID(String ID, Object OwnerObject) {
    IFunction IF = null;
    JFunctionStub FS = null;
    String FT;
    try {
      for (int i = 0; i < FunctionList.size(); i++) {
        FS = (JFunctionStub) FunctionList.get(i);
        //        System.out.println(FS.FunctionID);
        FT = FS.FunctionID + "_";
        if (FS.FunctionID.equals(ID) || FT.equals(ID)) {
          if (FS.Function == null) {
            FS.FunctionClass = Class.forName(FS.ClassName);
            FS.Function = (IFunction) FS.FunctionClass.newInstance();
            FS.Function.InitFunction(FS);
          }
          /* else { // modify by liukun 找到了就直接返回吧 20100715
            return FS;
          }
          */
          //
          if (OwnerObject != null && OwnerObject instanceof Hashtable) {
            Hashtable OTable = (Hashtable) OwnerObject;
            JFunctionStub fs = (JFunctionStub) OTable.get(ID);
            if (fs == null) {
              fs = new JFunctionStub();
              fs.ClassName = FS.ClassName;
              fs.FunctionClass = FS.FunctionClass;
              fs.FunctionID = FS.FunctionID;
              OTable.put(ID, fs);
            }
            if (fs.Function == null) {
              fs.FunctionClass = Class.forName(FS.ClassName);
              fs.Function = (IFunction) FS.FunctionClass.newInstance();
              fs.Function.InitFunction(FS);
            }
            FS = fs;
          } else {
            /**
             * 如果不在用户列表中则需要重新初始化函数 不能直接用系统缓存因为系统缓存只在登录时初始 这样对于像BB类函数,缓冲坐标的行为就可能会出错(中间修改过行列) modified
             * by hufeng 2007.11.20
             */
            FS.Function = (IFunction) FS.FunctionClass.newInstance();
            FS.Function.InitFunction(FS);
          }

          return FS;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Exemplo n.º 3
0
  private /*synchronized*/ StructureType assignStructureType(String structType)
      throws VisualizerLoadException {

    if (debug) System.out.println("In assignStructureType with " + structType);

    // Handle objects whose constructors require args separately
    if ((structType.toUpperCase().compareTo("BAR") == 0)
        || (structType.toUpperCase().compareTo("SCAT") == 0))
      return (new BarScat(structType.toUpperCase()));
    else if ((structType.toUpperCase().compareTo("GRAPH") == 0)
        || (structType.toUpperCase().compareTo("NETWORK") == 0))
      return (new Graph_Network(structType.toUpperCase()));
    else { // Constructor for object does not require args

      try {
        return ((StructureType)
            ((Class.forName(insure_text_case_correct_for_legacy_scripts(structType)))
                .newInstance()));
      } catch (InstantiationException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (IllegalAccessException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (ClassNotFoundException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      }
    }
  }
Exemplo n.º 4
0
 /**
  * This creates an empty <code>Document</code> object based on a specific parser implementation.
  *
  * @return <code>Document</code> - created DOM Document.
  * @throws JDOMException when errors occur.
  */
 public Document createDocument() throws JDOMException {
   try {
     return (Document) Class.forName("org.apache.xerces.dom.DocumentImpl").newInstance();
   } catch (Exception e) {
     throw new JDOMException(
         e.getClass().getName() + ": " + e.getMessage() + " when creating document", e);
   }
 }
Exemplo n.º 5
0
 /**
  * Look up an appropriate ComponentTester given an arbitrary Component-derived class. If the class
  * is derived from abbot.tester.ComponentTester, instantiate one; if it is derived from
  * java.awt.Component, return a matching Tester. Otherwise return abbot.tester.ComponentTester.
  *
  * <p>
  *
  * @throws ClassNotFoundException If the given class can't be found.
  * @throws IllegalArgumentException If the tester cannot be instantiated.
  */
 protected ComponentTester resolveTester(String className) throws ClassNotFoundException {
   Class testedClass = resolveClass(className);
   if (Component.class.isAssignableFrom(testedClass))
     return ComponentTester.getTester(testedClass);
   else if (ComponentTester.class.isAssignableFrom(testedClass)) {
     try {
       return (ComponentTester) testedClass.newInstance();
     } catch (Exception e) {
       String msg =
           "Custom ComponentTesters must provide "
               + "an accessible no-args Constructor: "
               + e.getMessage();
       throw new IllegalArgumentException(msg);
     }
   }
   String msg = "The given class '" + className + "' is neither a Component nor a ComponentTester";
   throw new IllegalArgumentException(msg);
 }
Exemplo n.º 6
0
  /**
   * This creates a new <code>{@link Document}</code> from an existing <code>InputStream</code> by
   * letting a DOM parser handle parsing using the supplied stream.
   *
   * @param in <code>InputStream</code> to parse.
   * @param validate <code>boolean</code> to indicate if validation should occur.
   * @return <code>Document</code> - instance ready for use.
   * @throws IOException when I/O error occurs.
   * @throws JDOMException when errors occur in parsing.
   */
  public Document getDocument(InputStream in, boolean validate) throws IOException, JDOMException {

    try {
      // Load the parser class
      Class parserClass = Class.forName("org.apache.xerces.parsers.DOMParser");
      Object parser = parserClass.newInstance();

      // Set validation
      Method setFeature =
          parserClass.getMethod("setFeature", new Class[] {java.lang.String.class, boolean.class});
      setFeature.invoke(
          parser, new Object[] {"http://xml.org/sax/features/validation", new Boolean(validate)});

      // Set namespaces true
      setFeature.invoke(
          parser, new Object[] {"http://xml.org/sax/features/namespaces", new Boolean(true)});

      // Set the error handler
      if (validate) {
        Method setErrorHandler =
            parserClass.getMethod("setErrorHandler", new Class[] {ErrorHandler.class});
        setErrorHandler.invoke(parser, new Object[] {new BuilderErrorHandler()});
      }

      // Parse the document
      Method parse = parserClass.getMethod("parse", new Class[] {org.xml.sax.InputSource.class});
      parse.invoke(parser, new Object[] {new InputSource(in)});

      // Get the Document object
      Method getDocument = parserClass.getMethod("getDocument", null);
      Document doc = (Document) getDocument.invoke(parser, null);

      return doc;
    } catch (InvocationTargetException e) {
      Throwable targetException = e.getTargetException();
      if (targetException instanceof org.xml.sax.SAXParseException) {
        SAXParseException parseException = (SAXParseException) targetException;
        throw new JDOMException(
            "Error on line "
                + parseException.getLineNumber()
                + " of XML document: "
                + parseException.getMessage(),
            e);
      } else if (targetException instanceof IOException) {
        IOException ioException = (IOException) targetException;
        throw ioException;
      } else {
        throw new JDOMException(targetException.getMessage(), e);
      }
    } catch (Exception e) {
      throw new JDOMException(e.getClass().getName() + ": " + e.getMessage(), e);
    }
  }
  public DBConnection(String type) {
    if (type.equals("mysql")) {
      try {
        String userName = "";
        String password = "";
        String url = "";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        mysqlCon = DriverManager.getConnection(url, userName, password);
        System.out.println("Database connection established");

        if (!mysqlCon.isClosed())
          System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");

      } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
      }
    } else if (type.equals("postgre")) {

    }
  }
Exemplo n.º 8
0
  /**
   * Creates a SAX XMLReader.
   *
   * @return <code>XMLReader</code> a SAX2 parser.
   * @throws Exception if no parser can be created.
   */
  protected XMLReader createParser() throws Exception {
    XMLReader parser = null;

    // Try using JAXP...
    // Note we need JAXP 1.1, and if JAXP 1.0 is all that's
    // available then the getXMLReader call fails and we skip
    // to the hard coded default parser
    try {
      Class factoryClass = Class.forName("javax.xml.parsers.SAXParserFactory");

      // MODIFIED: Added (Class[]) and (Object[]) cast sentences in "null" parameters
      // to avoid warnings during compilation

      // factory = SAXParserFactory.newInstance();
      Method newParserInstance = factoryClass.getMethod("newInstance", (Class[]) null);
      Object factory = newParserInstance.invoke(null, (Object[]) null);

      // jaxpParser = factory.newSAXParser();
      Method newSAXParser = factoryClass.getMethod("newSAXParser", (Class[]) null);
      Object jaxpParser = newSAXParser.invoke(factory, (Object[]) null);

      // parser = jaxpParser.getXMLReader();
      Class parserClass = jaxpParser.getClass();
      Method getXMLReader = parserClass.getMethod("getXMLReader", (Class[]) null);
      parser = (XMLReader) getXMLReader.invoke(jaxpParser, (Object[]) null);
    } catch (ClassNotFoundException e) {
      // e.printStackTrace();
    } catch (InvocationTargetException e) {
      // e.printStackTrace();
    } catch (NoSuchMethodException e) {
      // e.printStackTrace();
    } catch (IllegalAccessException e) {
      // e.printStackTrace();
    }

    // Check to see if we got a parser yet, if not, try to use a
    // hard coded default
    if (parser == null) {
      parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    }
    return parser;
  }
Exemplo n.º 9
0
 /**
  * Returns the Class corresponding to the given class name. Provides just-in-time classname
  * resolution to ensure loading by the proper class loader.
  *
  * <p>
  */
 public Class resolveClass(String className) throws ClassNotFoundException {
   ClassLoader cl = getResolver().getContextClassLoader();
   return Class.forName(className, true, cl);
 }
Exemplo n.º 10
0
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }