Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.managed.plugins;
 
 import java.util.Map;
 import java.util.Set;
 
ManagedProperty.

Author(s):
Adrian Brock
Version:
$Revision: 1.1 $
 
 public class ManagedPropertyImpl implements ManagedProperty
 {
   
The serialVersionUID
 
    private static final long serialVersionUID = 2;
    /* writeObject format:
     * - int version
     * - Fields fields
     * - ManagedObject managedObject
     * - ManagedObject targetManagedObject
     */
    private static final int VERSION1 = 1;
   
The serialization version used by writeObject
 
    private static final int STREAM_VERSION = ;

   
The managed object
 
    private ManagedObject managedObject;
   
The managed object target for a ManagementObjectRef
 
    private ManagedObject targetManagedObject;
   
   
The fields
 
    private Fields fields;

   
The property name
 
    private transient String name;

   
Create a new ManagedProperty that is not associated to a ManagedObject.

Parameters:
name the managed property name
Throws:
java.lang.IllegalArgumentException for null fields or missing Fields.NAME
 
    public ManagedPropertyImpl(String name)
    {
       this(nullnew DefaultFieldsImpl(name));
    }

   
Create a new ManagedProperty that is not associated to a ManagedObject.

Parameters:
fields the fields
Throws:
java.lang.IllegalArgumentException for null fields or missing Fields.NAME
 
    public ManagedPropertyImpl(Fields fields)
    {
       this(nullfields);
    }

   
Create a new ManagedProperty.

Parameters:
managedObject the managed object, may be null
fields the fields
Throws:
java.lang.IllegalArgumentException for null fields or missing Fields.NAME
   public ManagedPropertyImpl(ManagedObject managedObjectFields fields)
   {
      init(managedObjectfields);
   }
   
   {
      return ;
   }

   
Set managed object

Parameters:
managedObject the managed object
   public void setManagedObject(ManagedObject managedObject)
   {
      this. = managedObject;
   }
   {
      return ;
   }
   public void setTargetManagedObject(ManagedObject target)
   {
      this. = target;
   }
   public Fields getFields()
   {
      return ;
   }
   
   // TODO general reconstruction code for metatypes
   @SuppressWarnings("unchecked")
   public <T> T getField(String fieldNameClass<T> expected)
   {
      if (fieldName == null)
         throw new IllegalArgumentException("Null field name");
      if (expected == null)
         throw new IllegalArgumentException("Null expected type");
      
      Serializable field = getFields().getField(fieldName);
      
      if (field == null)
         return null;
      if (expected.isInstance(field))
         return expected.cast(field);
      
      if (field instanceof SimpleValue)
      {
         SimpleValue value = (SimpleValuefield;
         Object result = value.getValue();
         if (result == null)
            return null;
         return expected.cast(result);
      }
      
      throw new IllegalStateException("Field " + fieldName + " with value " + field + " is not of the expected type: " + expected.getName());
   }
   
   // TODO metaType stuff
   public void setField(String fieldNameSerializable value)
   {
      if (fieldName == null)
         throw new IllegalArgumentException("Null field name");
      
      getFields().setField(fieldNamevalue);
   }
   
   public String getName()
   {
      return ;
   }
   public String getMappedName()
   {
      return getField(.String.class);
   }
   public String getDescription()
   {
      return getField(.String.class);
   }
   
   
Set the description

Parameters:
description the description
   public void setDescription(String description)
   {
      setField(.description);
   }


   
Get the annotations associated with the property

Returns:
the annotations associated with the property
   @SuppressWarnings("unchecked")
   {
      Object set = getField(.Object.class);
      return (Mapset;
   }
   public void setAnnotations(Map<StringAnnotationannotations)
   {
      setField(., (Serializableannotations);      
   }

   
See if the property has the indicated ViewUse among its

Parameters:
use - the ViewUse to check for
Returns:
true if the ViewUse exists in the property uses, false otherwise
ManagementProperty:
annotation uses.
   public boolean hasViewUse(ViewUse use)
   {
      boolean hasViewUse = false;
      Map<StringAnnotationannotations = getAnnotations();
      if(annotations != null)
      {
         ManagementProperty mp = (ManagementPropertyannotations.get(ManagementProperty.class.getName());
         if(mp != null)
         {
            for(ViewUse vu : mp.use())
               hasViewUse |= vu == use;
         }
      }
      return hasViewUse;
   }
   public MetaType getMetaType()
   {
      return getField(.MetaType.class);
   }
   
   
Set the meta type

Parameters:
type the meta type
   public void setMetaType(MetaType type)
   {
      setField(.type);
   }
   public Object getValue()
   {
      return getField(.Object.class);
   }
   public void setValue(Serializable value)
   {
      setField(.value);
   }
   @SuppressWarnings("unchecked")
   public Set<MetaValuegetLegalValues()
   {
      return getField(.Set.class);
   }
   
   
Set the legal values

Parameters:
values the values
   public void setLegalValues(Set<MetaValuevalues)
   {
   }
   public Comparable<?> getMinimumValue()
   {
      return getField(.Comparable.class);
   }
   
   
Set the minimum value

Parameters:
value the value
   public void setMinimumValue(Comparable<?> value)
   {
   }
   public Comparable<?> getMaximumValue()
   {
      return getField(.Comparable.class);
   }

   
Set the maximum value

Parameters:
value the value
   public void setMaximumValue(Comparable<?> value)
   {
   }
   public String checkValidValue(Serializable value)
   {
      // TODO check min/max/etc.
      return null;
   }
   
   public boolean isMandatory()
   {
      Boolean result = getField(.Boolean.class);
      if (result == null)
         return false;
      return result;
   }
   
   
Set whether the field is mandatory

Parameters:
flag true for mandatory
   public void setMandatory(boolean flag)
   {
      if (flag)
         setField(.flag);
      else
         setField(.null);
   }
   public String toString()
   {
      StringBuilder tmp = new StringBuilder("ManagedProperty");
      tmp.append('{');
      tmp.append();
      ifgetMappedName() != null )
      {
         tmp.append(',');
         tmp.append(getMappedName());
      }
      tmp.append(",metaType=");
      tmp.append(this.getMetaType());
      tmp.append('}');
      return tmp.toString(); 
   }
   public int hashCode()
   {
      return .hashCode(); 
   }
   public boolean equals(Object obj)
   {
      if (obj == this)
         return true;
      if (obj == null || obj instanceof ManagedProperty == false)
         return false;
      
      ManagedProperty other = (ManagedPropertyobj;
      return getName().equals(other.getName());
   }
   
   
Initialise a ManagedPropertyImpl.

Parameters:
managedObject the managed object, may be null
fields the fields
Throws:
java.lang.IllegalArgumentException for null fields or missing Fields.NAME
   private void init(ManagedObject managedObjectFields fields)
   {
      if (fields == null)
         throw new IllegalArgumentException("Null fields");
      
      this. = managedObject;
      this. = fields;
      
       = getField(.String.class);
      if ( == null)
         throw new IllegalArgumentException("No " + . + " in fields");
   }

   
Read from a stream

Parameters:
in the stream
Throws:
java.io.IOException for IO problem
java.lang.ClassNotFoundException for a classloading problem
   private void readObject(ObjectInputStream in)
   {
      int version = in.readInt();
      ifversion ==  )
         readVersion1(in);
      else
         throw new InvalidObjectException("Unknown version="+version);
   }
   
Write out the property fields

Parameters:
out
Throws:
java.io.IOException
   private void writeObject(ObjectOutputStream out)
      throws IOException
   {
      out.writeInt();
      out.writeObject();
      out.writeObject();
   }

   
The VERSION1 expected format: - Fields fields - ManagedObject managedObject
   private void readVersion1(ObjectInputStream in)
   {
       = (Fieldsin.readObject();
       = getField(.String.class);
      if ( == null)
         throw new IOException("No " + . + " in fields");
       = (ManagedObjectin.readObject();      
       = (ManagedObjectin.readObject();      
   }
New to GrepCode? Check out our FAQ X