⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roletypeparametersconfiguration.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            Element child = (Element)nlist1.item(i);
            if ((childToCheck.getAttribute("Name").equals(child.getAttribute("Name"))) ||
                (childToCheck.getAttribute("OID").equals(child.getAttribute("OID"))))
            {
                return true;
            }
        }        
        return false;
    }
    
    /**
     * Reads the Fields from the TextBoxes. Checks that the required entries 
     * to create a valid connection are not empty fields. Then adds the 
     * new Directory to the XML document.
     */
    public void addItem()
    {
        oidTextField.focusLost(new FocusEvent(oidTextField, FocusEvent.FOCUS_LOST));
        if (!oidTextField.isValidFormat)
        {
            JOptionPane.showMessageDialog(this, roleTypesParamsConfigError3, rbl.getString("ErrorHeader"), JOptionPane.ERROR_MESSAGE);
            oidTextField.grabFocus();
            return;
        }
        
        if (oidTextField.getText().intern().equals("") || typeTextField.getText().intern().equals(""))
        {
            JOptionPane.showMessageDialog(xmlED, roleTypesParamsConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
            return;
        } 
        
        if (dataTypeField.getSelectedIndex() <= 0)
        {
            JOptionPane.showMessageDialog(xmlED, roleTypesParamsConfigError4, errorHeader, JOptionPane.ERROR_MESSAGE);
            return;
        }
       
        Element child = xmlED.DOM.createElement("RoleSpec"); 
        child.setAttribute("OID", oidTextField.getText());
        child.setAttribute("Name", typeTextField.getText());
        child.setAttribute("Type", (String)dataTypeField.getSelectedItem());
        if (isInPolicy(child))
        {
            JOptionPane.showMessageDialog(xmlED, roleTypesParamsConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
            return;
        }
        xmlED.addItem(child, (Element)getParentNode());        
        typeTextField.grabFocus();
    }
    
    /**
     * Deletes the Currently Selected node from the NodeList.
     */    
    public void deleteItem()
    {
        if (this.getSelectedNode() != null)
        {  
            xmlED.deleteItem((Element)this.getSelectedNode(), ((Element)getParentNode()));
            //Set the TextFields to an empty value
            clearTextFields();
        }
    }
 
    /**
     * Method that resets all the Textfields to empty or a predefined value.
     */
    public void clearTextFields()
    {
        oidTextField.setText("");
        typeTextField.setText("");
        dataTypeField.setSelectedIndex(0);
    }
    
    /**
     * Method that replaces a Selected Node with the contents of the textfields,
     * Provided that the required fields have a valid Variable Definition, are not
     * empty.
     */
    public void replaceItem()
    {
        if (this.getSelectedNode() != null)
        {
            if (!oidTextField.getText().intern().equals("") && 
                !typeTextField.getText().intern().equals("") && 
                dataTypeField.getSelectedIndex() > 0)
            {
                //Setting the New Attributes to Replace --
                String attribs[] = { "OID", "Name", "Type" };
                String values[] = { oidTextField.getText(), typeTextField.getText(), (String)dataTypeField.getSelectedItem() }; 

                Element child = xmlED.DOM.createElement("RoleSpec");
                child.setAttribute("OID", oidTextField.getText());
                if (isInPolicy(child) && !((Element)this.getSelectedNode()).getAttribute("OID").equals(oidTextField.getText()))
                {
                    JOptionPane.showMessageDialog(xmlED, roleTypesParamsConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
                    return;
                }                                    
                                    
                xmlED.setAttributeValue((Element)this.getSelectedNode(), attribs, values);
                //----------------------------------------
            }
            else
            {
                JOptionPane.showMessageDialog(xmlED, roleTypesParamsConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
                return;
            } 
        }        
    }
    
    /**
     * Method That Populates the NodeList with the current Environment Variables.
     */
    public void refreshView()
    {
        if (xmlED == null || xmlED.DOM == null) return;
        
        if (getParentNode() != null)
        {            
            NodeList nlist = ((Element)getParentNode()).getElementsByTagName("RoleSpec");
            Node n;
            String envNames[] = new String[nlist.getLength()];
            
            for (int i = 0 ; i < nlist.getLength(); i++)
            {
                n = nlist.item(i);   
                envNames[i] = (((Element)n).getAttribute("Name"));
            }
            setNodeList(nlist, envNames);        
        }
    }
    
    /**
     * When the NodeItemList has a selected Element, the contents of that node, 
     * will populate the textfields, so the user will see exactly what the 
     * Environment Variable has as a defined type. 
     * <p> 
     * Users might then want to modify the Selected node, and therefore the 
     * refreshed textfields, would just need to be modified.
     * <p>
     * If nothing is selected in the NodeItemList, the textfields are reset
     * using the clearTextFields() method.
     */
    public void itemSelected()
    {      
        Element selectedNode; 
        dataTypeField.removeItemListener(this);
        
        super.itemSelected();
  
        addButton.setEnabled(false);
        replaceButton.setEnabled(false);
        
        if (getSelectedNode() == null)
        {
            clearTextFields();
        }
        else
        {
            selectedNode = (Element)getSelectedNode();
            typeTextField.setText(selectedNode.getAttribute("Name")); 
            oidTextField.setText(selectedNode.getAttribute("OID"));             
            dataTypeField.setSelectedItem(selectedNode.getAttribute("Type"));
        }
        dataTypeField.addItemListener(this);
    }
    
    /**
     * The root node of the Current Document.
     *
     * @return   a node with the root Element of the 'pe.cfg' XML file.
     */
    public Node getParentNode()
    {
        return xmlED.DOM.getElementsByTagName("RoleTypes").item(0);
    }     
    
    public void keyTyped(KeyEvent e)
    {   
    }
    
    /**
     * Method That enables/disables the appropriate buttons when the Text Fields
     * are being typed into.
     */
    public void keyPressed(KeyEvent e)
    {
    }
    
    public void keyReleased(KeyEvent e)
    {       
        oidTextField.focusLost(new FocusEvent(oidTextField, FocusEvent.FOCUS_LOST));        
        
        if (e.getSource() == oidTextField || e.getSource() == typeTextField)
        {
            if (this.listBox.getSelectedValue() == null &&
                !oidTextField.getText().intern().equals("") &&
                !typeTextField.getText().intern().equals("") &&
                oidTextField.isValidFormat &&
                dataTypeField.getSelectedIndex() > 0)
            {
                addButton.setEnabled(true);
            }
            else if (!oidTextField.getText().intern().equals("") &&
                    !typeTextField.getText().intern().equals("") &&
                    oidTextField.isValidFormat &&
                    dataTypeField.getSelectedIndex() > 0)
            {
                replaceButton.setEnabled(true);
                addButton.setEnabled(true);                
            }
            else if (oidTextField.getText().intern().equals("") ||
                    typeTextField.getText().intern().equals("") ||
                    !oidTextField.isValidFormat ||
                    dataTypeField.getSelectedIndex() <= 0)
            {
                replaceButton.setEnabled(false);
                addButton.setEnabled(false);                
            }
        }
    }         
    
    public void actionPerformed(ActionEvent e)
    {
        if (e.getActionCommand().intern().equals("oid_tf") && !oidTextField.getText().intern().equals(""))
        {
            dataTypeField.grabFocus();
        }
        else if (e.getActionCommand().intern().equals("type_tf") && !typeTextField.getText().intern().equals(""))
        {
            oidTextField.grabFocus();
        }
        else super.actionPerformed(e);
    }    
    
    public void itemStateChanged(ItemEvent e)
    {
        if (dataTypeField.getSelectedIndex() <= 0)
        {
            replaceButton.setEnabled(false);
            addButton.setEnabled(false);
            return;
        }
        if (getSelectedIndex() >= 0 && e.getStateChange() == ItemEvent.SELECTED)
        {
            replaceButton.setEnabled(true);
        }
        else if (listBox.getSelectedValue() == null && 
            !typeTextField.getText().intern().equals("") && 
            !oidTextField.getText().intern().equals("") && 
            oidTextField.isValidFormat &&
            !((String)dataTypeField.getSelectedItem()).equals("") &&
            getSelectedIndex() < 0)
                addButton.setEnabled(true);
        else if (!typeTextField.getText().intern().equals("") && 
                 !oidTextField.getText().intern().equals("") && 
                 oidTextField.isValidFormat &&
                 !((String)dataTypeField.getSelectedItem()).equals("") &&
                 getSelectedIndex() < 0)
        {
            replaceButton.setEnabled(true);
            addButton.setEnabled(true);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -