Package javax.management

Examples of javax.management.AttributeList


     
      if (!getState())
         return null;
     
      // Real stuff starts here
      AttributeList attrs = null;
     
      // returns null to indicate file does not exist
      File file = checkFileForRead(id);
     
      if (file != null) {
       // parse the saved XML doc
       Document doc = parseXmlFile(file);
      
       // top level - look for AL_ROOT_ELEMENT
       NodeList docList = doc.getChildNodes();
       Element root = null;
      
       for (int i = 0; i < docList.getLength(); i++) {
          Node node = docList.item(i);
         
          if (node.getNodeType() == Node.ELEMENT_NODE &&
              node.getNodeName().equals(AL_ROOT_ELEMENT)) {
            
             root = (Element)node;
             break; // found
          }
       }
      
       // root element must be there
       if (root == null) {
          throw new Exception("Expected XML element: " + AL_ROOT_ELEMENT);
       }
       else {
          // proceed iterating over AL_ATTRIBUTE_ELEMENT elements
          // and fill the AttributeList
          attrs = new AttributeList();
         
          NodeList rootList = root.getChildNodes();
         
          for (int i = 0; i < rootList.getLength(); i++) {
             Node node = rootList.item(i);
            
             // only interested in ELEMENT nodes
             if (node.getNodeType() == Node.ELEMENT_NODE &&
                 node.getNodeName().equals(AL_ATTRIBUTE_ELEMENT)) {
               
                Element element = (Element)node;
               
                // name attribute must always be there
                String name = element.getAttribute(AL_NAME_ATTRIBUTE);
               
                if (!(name.length() > 0)) {
                   throw new Exception("Attribute '" + AL_NAME_ATTRIBUTE +
                                       "' must be specified for element '" + AL_ATTRIBUTE_ELEMENT + "'");
                }
               
                // Process the attribute depending on how the attributes are set
               
                if (element.getAttribute(AL_NULL_ATTRIBUTE).toLowerCase().equals(AL_TRUE_VALUE)) {
                    
                   //  (a) null value - just add it to the AttributeList
                   attrs.add(new Attribute(name, null));
                }
                else if (element.getAttribute(AL_SERIALIZED_ATTRIBUTE).toLowerCase().equals(AL_TRUE_VALUE)) {
                  
                   // (b) serialized value - decode the HexString
                   String hexStr = getElementContent(element);
                   Serializable obj = decodeFromHexString(hexStr);
                  
                   if (obj == null) {
                      throw new Exception("Failed to deserialize attribute '" + name + "'");
                   }
                   else {
                      attrs.add(new Attribute(name, obj));
                   }
                }
                else {
                   String type = element.getAttribute(AL_TYPE_ATTRIBUTE);
                  
                   // type must be specified
                   if (!(type.length() > 0)) {
                      throw new Exception("Attribute '" + AL_TYPE_ATTRIBUTE +
                                          "' must be specified for name='" + name + "'");
                   }
                  
                   if (type.equals("org.w3c.dom.Element")) {

                      // (c) org.w3c.dom.Element - deep copy first Element child node found
                     
                       NodeList nlist = element.getChildNodes();
                       Element el = null;
                      
                       for (int j = 0; j < nlist.getLength(); j++) {
                         
                          Node n = nlist.item(j);
                          if (n.getNodeType() == Node.ELEMENT_NODE)
                          {
                             el = (Element)n;
                             break;
                          }
                       }
                      
                       if (el != null) {
                          attrs.add(new Attribute(name, el.cloneNode(true)));
                       }
                       else {
                          attrs.add(new Attribute(name, null));
                       }
                   }
                   else {
                      // Get the classloader for loading attribute classes.
                      ClassLoader cl = Thread.currentThread().getContextClassLoader();
                      Class clazz = null;
                     
                       try {
                          clazz = cl.loadClass(type);
                       }
                       catch (ClassNotFoundException e) {
                          throw new Exception("Class not found for attribute '" + name +
                                              "' of type '" + type + "'");
                       }

                       PropertyEditor peditor = PropertyEditorManager.findEditor(clazz);

                      if (peditor != null) {
                      
                         // (d) use a PropertyEditor - extract the value
                        
                         String value = getElementContent(element);
                         peditor.setAsText(value);
                        
                         attrs.add(new Attribute(name, peditor.getValue()));
                      }
                      else {
                         throw new Exception("Cannot find a way to load attribute '" + name +
                                             "' of type '" + type + "'");
                      }
View Full Code Here


            throw new RuntimeOperationsException(
            new IllegalArgumentException("attributeNames[] cannot be null"),
            "Cannot invoke a getter of " + dClassName);
        }
       
        AttributeList resultList = new AttributeList();
       
        // if attributeNames is empty, return an empty result list
        if (attributeNames.length == 0)
            return resultList;
       
        // build the result attribute list
        for (int i = 0; i < attributeNames.length; i++) {
            try {
                Object value = getAttribute((String) attributeNames[i]);
                resultList.add(new Attribute(attributeNames[i], value));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return (resultList);
View Full Code Here

        if (attributes == null) {
            throw new RuntimeOperationsException(
            new IllegalArgumentException("AttributeList attributes cannot be null"),
            "Cannot invoke a setter of " + dClassName);
        }
        AttributeList resultList = new AttributeList();
       
        // if attributeNames is empty, nothing more to do
        if (attributes.isEmpty())
            return resultList;
       
        // for each attribute, try to set it and add to the result list if successfull
        for (Iterator i = attributes.iterator(); i.hasNext();) {
            Attribute attr = (Attribute) i.next();
            try {
                setAttribute(attr);
                String name = attr.getName();
                Object value = getAttribute(name);
                resultList.add(new Attribute(name, value));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return (resultList);
View Full Code Here

        }
    }

    public synchronized AttributeList getAttributes(String[] attrs)
    {
        AttributeList al = new AttributeList();
        for (int i = 0, len = attrs.length; i < len; ++i)
        {
            String attr = attrs[i];
            try
            {
                Object val = getAttribute(attr);
                al.add(new Attribute(attr, val));
            }
            catch (Exception e)
            {
                if (logger.isLoggable(MLevel.WARNING))
                    logger.log(MLevel.WARNING, "Failed to get requested attribute (for list): " + attr, e);
View Full Code Here

        }
    }

    public synchronized AttributeList setAttributes(AttributeList al)
    {
        AttributeList out = new AttributeList();
        for (int i = 0, len = al.size(); i < len; ++i)
        {
            Attribute attrObj = (Attribute) al.get(i);
           
            try
            {
                this.setAttribute( attrObj );
                out.add(attrObj);
            }
            catch (Exception e)
            {
                if (logger.isLoggable(MLevel.WARNING))
                    logger.log(MLevel.WARNING, "Failed to set requested attribute (from list): " + attrObj, e);
View Full Code Here

  }

  @Override
  public AttributeList getAttributes(String[] attributes)
  {
    AttributeList list = new AttributeList();
   
    for (String attr : attributes) {
      try {
        list.add(getAttribute(attr));
      } catch (Exception e) {
        log.log(Level.FINE, e.toString(), e);
      }
    }
   
View Full Code Here

    public final MBeanInfo getMBeanInfo() {
        return info;
    }

    public final AttributeList getAttributes(String names[]) {
        AttributeList answer = new AttributeList();
        for (int i = 0; i < names.length; i++) {
            try {
                answer.add(new Attribute(names[i], getAttribute(names[i])));
            } catch (Exception e) {
                // Ignore.
            }
        }
        return answer;
View Full Code Here

     *
     * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
     */
    public AttributeList getAttributes(String[] attributes)
    {
        AttributeList list = new AttributeList();
        if (attributes != null)
        {
            for (int i = 0; i < attributes.length; i++)
            {
                String attribute = attributes[i];
                try
                {
                    Object result = getAttribute(attribute);
                    list.add(new Attribute(attribute, result));
                }
                catch (AttributeNotFoundException ignored)
                {
                }
                catch (MBeanException ignored)
View Full Code Here

    /**
     * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
     */
    public AttributeList setAttributes(AttributeList attributes)
    {
        AttributeList list = new AttributeList();

        if (attributes != null)
        {
            for (int i = 0; i < attributes.size(); ++i)
            {
                Attribute attribute = (Attribute) attributes.get(i);
                try
                {
                    setAttribute(attribute);
                    list.add(attribute);
                }
                catch (AttributeNotFoundException ignored)
                {
                }
                catch (InvalidAttributeValueException ignored)
View Full Code Here

    @Override
    public Object getAttribute(final String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
        // we should call getAttributes - and not vice versa to have the result
        // of a single check call - and not do a check call for each attribute
        final AttributeList result = this.getAttributes(new String[] {attribute});
        if ( result.size() == 0 ) {
            throw new AttributeNotFoundException(attribute);
        }
        final Attribute attr = (Attribute) result.get(0);
        return attr.getValue();
    }
View Full Code Here

TOP

Related Classes of javax.management.AttributeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.