Exemplo n.º 1
0
  /**
   * Implement the decorator pattern for the factory implementation.
   *
   * <p>
   *
   * <p>If <code>previousImpl</code> is non-<code>null</code> and the class named by the argument
   * <code>implName</code> has a one arg contstructor of type <code>factoryName</code>, instantiate
   * it, passing previousImpl to the constructor.
   *
   * <p>
   *
   * <p>Otherwise, we just instantiate and return <code>implName</code>.
   *
   * @param classLoader the ClassLoader from which to load the class
   * @param factoryName the fully qualified class name of the factory.
   * @param implName the fully qualified class name of a class that implements the factory.
   * @param previousImpl if non-<code>null</code>, the factory instance to be passed to the
   *     constructor of the new factory.
   */
  private static Object getImplGivenPreviousImpl(
      ClassLoader classLoader, String factoryName, String implName, Object previousImpl) {
    Class clazz;
    Class factoryClass = null;
    Class[] getCtorArg;
    Object[] newInstanceArgs = new Object[1];
    Constructor ctor;
    Object result = null;
    InjectionProvider provider = null;

    // if we have a previousImpl and the appropriate one arg ctor.
    if ((null != previousImpl) && (null != (factoryClass = getFactoryClass(factoryName)))) {
      try {
        clazz = Class.forName(implName, false, classLoader);
        getCtorArg = new Class[1];
        getCtorArg[0] = factoryClass;
        ctor = clazz.getConstructor(getCtorArg);
        newInstanceArgs[0] = previousImpl;
        result = ctor.newInstance(newInstanceArgs);

        FactoryManager fm = FACTORIES_CACHE.getApplicationFactoryManager(classLoader);
        provider = fm.getInjectionProvider();
        if (null != provider) {
          provider.inject(result);
          provider.invokePostConstruct(result);
        } else {
          if (LOGGER.isLoggable(Level.SEVERE)) {
            LOGGER.log(
                Level.SEVERE,
                "Unable to inject {0} because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?",
                result);
          }
        }

      } catch (NoSuchMethodException nsme) {
        // fall through to "zero-arg-ctor" case
        factoryClass = null;
      } catch (Exception e) {
        throw new FacesException(implName, e);
      }
    }
    if (null == previousImpl || null == factoryClass) {
      // we have either no previousImpl or no appropriate one arg
      // ctor.
      try {
        clazz = Class.forName(implName, false, classLoader);
        // since this is the hard coded implementation default,
        // there is no preceding implementation, so don't bother
        // with a non-zero-arg ctor.
        result = clazz.newInstance();
      } catch (Exception e) {
        throw new FacesException(implName, e);
      }
    }
    return result;
  }
Exemplo n.º 2
0
  /**
   * This method will store the argument <code>factoryName/implName</code> mapping in such a way
   * that {@link #getFactory} will find this mapping when searching for a match.
   *
   * <p>
   *
   * <p>This method has no effect if <code>getFactory()</code> has already been called looking for a
   * factory for this <code>factoryName</code>.
   *
   * <p>
   *
   * <p>This method can be used by implementations to store a factory mapping while parsing the
   * Faces configuration file
   *
   * @throws IllegalArgumentException if <code>factoryName</code> does not identify a standard
   *     JavaServer Faces factory name
   * @throws NullPointerException if <code>factoryname</code> is null
   */
  public static void setFactory(String factoryName, String implName) {

    validateFactoryName(factoryName);

    // Identify the web application class loader
    ClassLoader classLoader = getClassLoader();

    FactoryManager manager = FACTORIES_CACHE.getApplicationFactoryManager(classLoader);
    manager.addFactory(factoryName, implName);
  }
Exemplo n.º 3
0
  /**
   * <span class="changed_modified_2_0">Create</span> (if necessary) and return a
   * per-web-application instance of the appropriate implementation class for the specified
   * JavaServer Faces factory class, based on the discovery algorithm described in the class
   * description.
   *
   * <p class="changed_added_2_0">The standard factories and wrappers in JSF all implement the
   * interface {@link FacesWrapper}. If the returned <code>Object</code> is an implementation of one
   * of the standard factories, it must be legal to cast it to an instance of <code>FacesWrapper
   * </code> and call {@link FacesWrapper#getWrapped} on the instance.
   *
   * @param factoryName Fully qualified name of the JavaServer Faces factory for which an
   *     implementation instance is requested
   * @throws FacesException if the web application class loader cannot be identified
   * @throws FacesException if an instance of the configured factory implementation class cannot be
   *     loaded
   * @throws FacesException if an instance of the configured factory implementation class cannot be
   *     instantiated
   * @throws IllegalArgumentException if <code>factoryName</code> does not identify a standard
   *     JavaServer Faces factory name
   * @throws IllegalStateException if there is no configured factory implementation class for the
   *     specified factory name
   * @throws NullPointerException if <code>factoryname</code> is null
   */
  public static Object getFactory(String factoryName) throws FacesException {

    validateFactoryName(factoryName);

    // Identify the web application class loader
    ClassLoader classLoader = getClassLoader();

    FactoryManager manager = FACTORIES_CACHE.getApplicationFactoryManager(classLoader);
    return manager.getFactory(classLoader, factoryName);
  }
  FactoryManagerGUI(FactoryManager parent, int pWidth, int pHeight) {
    this.parent = parent;
    this.PAGE_WIDTH = pWidth;
    this.PAGE_HEIGHT = pHeight;

    // initialize class variables
    activeKitsContainer = new JPanel();
    activeKitsPanel = new JPanel();
    kitDataPanel = new JPanel();
    kits = new TreeMap<Integer, Kits>();
    buildInfo = new ArrayList<Kits>();
    images = parent.getImageArray();
    greyLine = BorderFactory.createLineBorder(Color.DARK_GRAY);

    // build Active Kits Container
    activeKitsContainer.setLayout(new BoxLayout(activeKitsContainer, BoxLayout.X_AXIS));
    setComponentSize(activeKitsContainer, PAGE_WIDTH, PAGE_HEIGHT);
    setComponentSize(kitDataPanel, 450, PAGE_HEIGHT);
    buildActiveKits(activeKitsPanel);
    activeKitsContainer.add(activeKitsPanel);
    activeKitsContainer.add(kitDataPanel);

    // add master containers to frame
    this.add(activeKitsContainer);
  }
Exemplo n.º 5
0
    public void removeApplicationFactoryManager(ClassLoader cl) {
      FactoryManager fm = this.getApplicationFactoryManager(cl, false);
      if (null != fm) {
        fm.clearInjectionProvider();
      }

      FacesContext facesContext = FacesContext.getCurrentInstance();
      boolean isSpecialInitializationCase = detectSpecialInitializationCase(facesContext);

      FactoryManagerCacheKey key = new FactoryManagerCacheKey(facesContext, cl, applicationMap);

      applicationMap.remove(key);
      if (isSpecialInitializationCase) {
        logNullFacesContext.set(false);
        logNonNullFacesContext.set(false);
      }
    }
Exemplo n.º 6
0
  /**
   * <span class="changed_modified_2_0">Release</span> any references to factory instances
   * associated with the class loader for the calling web application. <span
   * class="changed_modified_2_0">This method must be called during of web application
   * shutdown.</span>
   *
   * @throws FacesException if the web application class loader cannot be identified
   */
  public static void releaseFactories() throws FacesException {

    // Identify the web application class loader
    ClassLoader cl = getClassLoader();

    if (!FACTORIES_CACHE.applicationMap.isEmpty()) {

      FactoryManager fm = FACTORIES_CACHE.getApplicationFactoryManager(cl);
      InjectionProvider provider = fm.getInjectionProvider();
      if (null != provider) {
        Collection factories = null;
        for (Map.Entry<FactoryManagerCacheKey, FactoryManager> entry :
            FACTORIES_CACHE.applicationMap.entrySet()) {
          factories = entry.getValue().getFactories();
          for (Object curFactory : factories) {
            try {
              provider.invokePreDestroy(curFactory);
            } catch (Exception ex) {
              if (LOGGER.isLoggable(Level.SEVERE)) {
                String message =
                    MessageFormat.format(
                        "Unable to invoke @PreDestroy annotated methods on {0}.", curFactory);
                LOGGER.log(Level.SEVERE, message, ex);
              }
            }
          }
        }
      } else {
        if (LOGGER.isLoggable(Level.SEVERE)) {
          LOGGER.log(
              Level.SEVERE,
              "Unable to call @PreDestroy annotated methods because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?");
        }
      }
    }

    FACTORIES_CACHE.removeApplicationFactoryManager(cl);
  }
 public void actionPerformed(ActionEvent ae) {
   try {
     String sbuildQuantity = buildQuantity.getText();
     System.out.println(sbuildQuantity);
     int buildNumber = Integer.parseInt(sbuildQuantity);
     if (buildNumber <= 0) {
       System.out.println("Invalid kit build amount");
     } else {
       Kits selectedKit = (Kits) kitList.getSelectedValue();
       selectedKit.setBuildNumber(buildNumber);
       buildInfo.add(selectedKit);
       parent.syncBuildInfo(buildInfo);
     }
   } catch (Exception e) {
     System.out.println("Invalid kit build amount");
   }
 }
  public static void loadPagesAndDrawers(
      Workspace workspace, Element root, FactoryManager manager) {
    List<Page> pageList = new ArrayList<Page>();
    // pagesToAdd is needed so that we can add pages all at once
    // to the page bar once all the the pages been loaded
    // Before adding all the pages, this method makes a check
    // if there is only one page with an empty name - if so, it will just
    // add the page to the workspace/block canvas but not add it to this
    // LinkedHashMap<Page, PageBlockDrawer> pagesToAdd = new LinkedHashMap<Page, PageBlockDrawer>();
    LinkedHashMap<String, ArrayList<RenderableBlock>> blocksForDrawers =
        new LinkedHashMap<String, ArrayList<RenderableBlock>>();
    LinkedHashMap<Page, ArrayList<RenderableBlock>> blocksForPages =
        new LinkedHashMap<Page, ArrayList<RenderableBlock>>();

    NodeList pagesRoot = root.getElementsByTagName("Pages");
    if (pagesRoot != null) {
      // isBlankPage denotes if the page being loaded is a default blank page
      // in other words, the project did not specify any pages for their environment.
      // EvoBeaker does this
      boolean isBlankPage = false;
      Node pagesNode = pagesRoot.item(0);
      if (pagesNode == null) {
        return; // short-circuit exit if there's nothing to load
      }
      Node opt_item = pagesNode.getAttributes().getNamedItem("drawer-with-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          Workspace.everyPageHasDrawer = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }
      opt_item = pagesNode.getAttributes().getNamedItem("is-blank-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          isBlankPage = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }

      // whether pages should show a control to collapse them or not
      boolean collapsiblePages = getBooleanValue(pagesNode, "collapsible-pages");

      Page page;
      NodeList pages = pagesNode.getChildNodes();
      Node pageNode;
      String pageName = "";
      String pageDrawer = null;
      Color pageColor = null;
      boolean pageInFullView = true;
      int pageWidth = -1;
      String pageId = null;
      for (int i = 0; i < pages.getLength(); i++) { // find them
        pageNode = pages.item(i);
        if (pageNode.getNodeName().equals("Page")) { // a page entry
          pageName = getNodeValue(pageNode, "page-name");
          pageColor = getColorValue(pageNode, "page-color");
          pageWidth = getIntValue(pageNode, "page-width");
          pageDrawer = getNodeValue(pageNode, "page-drawer");
          pageInFullView = getBooleanValue(pageNode, "page-infullview");
          pageId = getNodeValue(pageNode, "page-id");
          page =
              new Page(
                  workspace,
                  pageName,
                  pageWidth,
                  0,
                  pageDrawer,
                  pageInFullView,
                  pageColor,
                  collapsiblePages);
          page.setPageId(pageId);

          NodeList pageNodes = pageNode.getChildNodes();
          String drawer = null;
          if (Workspace.everyPageHasDrawer) {
            // create drawer instance
            manager.addDynamicDrawer(page.getPageDrawer());
            ArrayList<RenderableBlock> drawerBlocks = new ArrayList<RenderableBlock>();

            for (int k = 0; k < pageNodes.getLength(); k++) {
              Node drawerNode = pageNodes.item(k);
              if (drawerNode.getNodeName().equals("PageDrawer")) {
                NodeList genusMembers = drawerNode.getChildNodes();
                String genusName;
                for (int j = 0; j < genusMembers.getLength(); j++) {
                  Node genusMember = genusMembers.item(j);
                  if (genusMember.getNodeName().equals("BlockGenusMember")) {
                    genusName = genusMember.getTextContent();
                    assert BlockGenus.getGenusWithName(genusName) != null
                        : "Unknown BlockGenus: " + genusName;
                    Block block = new Block(workspace, genusName);
                    drawerBlocks.add(
                        new FactoryRenderableBlock(workspace, manager, block.getBlockID()));
                  }
                }
                blocksForDrawers.put(drawer, drawerBlocks);
                break; // there can only be one drawer for this page
              }
            }
          }

          if (isBlankPage) {
            // place a blank page as the first page
            workspace.putPage(page, 0);
            // if the system uses blank pages, then we expect only one page
            break; // we anticipate only one page
          } else {
            // we add to the end of the set of pages
            int position = pageList.size();
            // add to workspace
            if (position == 0) {
              // replace the blank default page
              workspace.putPage(page, 0);
            } else {
              workspace.addPage(page, position);
            }
            pageList.add(position, page);
          }

          blocksForPages.put(page, page.loadPageFrom(pageNode, false));
        }
      }
      // add blocks in drawers
      for (String d : blocksForDrawers.keySet()) {
        manager.addDynamicBlocks(blocksForDrawers.get(d), d);
      }
      // blocks in pages
      for (Page p : blocksForPages.keySet()) {
        p.addLoadedBlocks(blocksForPages.get(p), false);
      }
    }
  }
  public static void loadBlockDrawerSets(
      Workspace workspace, Element root, FactoryManager manager) {
    Pattern attrExtractor = Pattern.compile("\"(.*)\"");
    Matcher nameMatcher;
    NodeList drawerSetNodes = root.getElementsByTagName("BlockDrawerSet");
    Node drawerSetNode;
    for (int i = 0; i < drawerSetNodes.getLength(); i++) {
      drawerSetNode = drawerSetNodes.item(i);
      if (drawerSetNode.getNodeName().equals("BlockDrawerSet")) {
        NodeList drawerNodes = drawerSetNode.getChildNodes();
        Node drawerNode;
        // retreive drawer information of this bar
        for (int j = 0; j < drawerNodes.getLength(); j++) {
          drawerNode = drawerNodes.item(j);
          if (drawerNode.getNodeName().equals("BlockDrawer")) {
            String drawerName = null;
            Color buttonColor = Color.blue;
            StringTokenizer col;
            nameMatcher =
                attrExtractor.matcher(drawerNode.getAttributes().getNamedItem("name").toString());
            if (nameMatcher.find()) { // will be true
              drawerName = nameMatcher.group(1);
            }

            // get drawer's color:
            Node colorNode = drawerNode.getAttributes().getNamedItem("button-color");
            //    					if(colorNode == null){
            //    						buttonColor = Color.blue;
            //    						System.out.println("Loading a drawer without defined color: ");
            //    						for(int ai=0; ai<drawerNode.getAttributes().getLength(); ai++){
            //
            //	System.out.println("\t"+drawerNode.getAttributes().item(ai).getNodeName()+
            //        								", "+drawerNode.getAttributes().item(ai).getNodeValue());
            //        					}
            //    					}else{
            if (colorNode != null) {
              nameMatcher = attrExtractor.matcher(colorNode.toString());
              if (nameMatcher.find()) { // will be true
                col = new StringTokenizer(nameMatcher.group(1));
                if (col.countTokens() == 3) {
                  buttonColor =
                      new Color(
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()));
                } else {
                  buttonColor = Color.BLACK;
                }
              }
            }

            manager.addStaticDrawer(drawerName, buttonColor);

            // get block genuses in drawer and create blocks
            NodeList drawerBlocks = drawerNode.getChildNodes();
            Node blockNode;
            ArrayList<RenderableBlock> drawerRBs = new ArrayList<RenderableBlock>();
            for (int k = 0; k < drawerBlocks.getLength(); k++) {
              blockNode = drawerBlocks.item(k);
              if (blockNode.getNodeName().equals("BlockGenusMember")) {
                String genusName = blockNode.getTextContent();
                assert BlockGenus.getGenusWithName(genusName) != null
                    : "Unknown BlockGenus: " + genusName;
                Block newBlock;
                // don't link factory blocks to their stubs because they will
                // forever remain inside the drawer and never be active
                newBlock = new Block(workspace, genusName, false);
                drawerRBs.add(
                    new FactoryRenderableBlock(workspace, manager, newBlock.getBlockID()));
              }
            }
            manager.addStaticBlocks(drawerRBs, drawerName);
          }
        }
      }
    }
  }