Package java.beans

Examples of java.beans.PropertyEditor


    * @param mustExist
    * @return
    */
   private Object getValue(String propertyName, Class actualType, String value, boolean mustExist)
   {
      PropertyEditor editor = PropertyEditorManager.findEditor(actualType);
      if (editor == null)
      {
         String error = "No property editor found for property " + propertyName;
         if (mustExist)
         {
            throw new IllegalArgumentException(error);
         }
         else
         {
            log.warn(error);
            return null;
         }
      }
      try
      {
         editor.setAsText(value);
      }
      catch (IllegalArgumentException iae)
      {
         if (mustExist)
         {
            throw iae;
         }
         log.warn("Value '" + value + "' is not valid for property '" + propertyName + "' of class '" + actualType
               + "' - skipping " + "property");
         return null;
      }

      return editor.getValue();
   }
View Full Code Here


                      continue;
                    }
                 }

                 Method setter = clazz.getMethod("set" + name, new Class[] { type });
                 PropertyEditor editor = PropertyEditorManager.findEditor(type);
                 if (editor == null)
                    throw new JBossResourceException("No property editor found for type: " + type);
                 editor.setAsText(value);
                 setter.invoke(dataSource, new Object[] { editor.getValue() });
              }
           }
           catch (ClassNotFoundException cnfe)
           {
              throw new JBossResourceException("Class not found for DataSource " + getDriverClass(), cnfe);
View Full Code Here

       * @return an <code>Object</code> value
       * @exception Exception if an error occurs
       */
      public Object getValue() throws Exception
      {
         PropertyEditor editor = PropertyEditors.getEditor(type);
         editor.setAsText(arg);
         return editor.getValue();
      }
View Full Code Here

            }
            catch (ClassNotFoundException e) {
               throw new RuntimeException("Class not found for property '" + pi.getName() +
                                    "' of type '" + pi.getType() + "'");
            }
            PropertyEditor peditor = PropertyEditorManager.findEditor(clazz);

            if (peditor != null) {
               peditor.setAsText(value);
               pi.setDefaultValue(peditor.getValue());
            }
            else
               throw new RuntimeException("Property editor not found for property '" + pi.getName() +
                                    "' of type '" + pi.getType() + "'");
         }
View Full Code Here

            typeClass = loader.loadClass(attrType);
      }
      catch(ClassNotFoundException ignore)
      {
      }
      PropertyEditor editor = null;
      if( typeClass != null )
         editor = PropertyEditorManager.findEditor(typeClass);

      return new AttrResultInfo(attrName, editor, value, throwable);
   }
View Full Code Here

                           ("Class not found for type: " + signature, e);
                     }
                  }

                  // Convert the string to the real value
                  PropertyEditor editor = PropertyEditorManager.findEditor(typeClass);
                  if (editor == null)
                  {
                     try
                     {
                        // See if there is a ctor(String) for the type
                        Class[] sig = {String.class};
                        Constructor ctor = typeClass.getConstructor(sig);
                        Object[] args = {value};
                        realValue = ctor.newInstance(args);
                     }
                     catch (Exception e)
                     {
                        throw new ConfigurationException("No property editor for type: " + typeClass);
                     }
                  }
                  else
                  {
                     editor.setAsText(value);
                     realValue = editor.getValue();
                  }
               }
               info.signature[j] = signature;
               info.params[j] = realValue;
            }
View Full Code Here

            }
         }
         // Replace any ${x} references in the element text
         if (replace)
         {
            PropertyEditor editor = PropertyEditorManager.findEditor(typeClass);
            if (editor == null)
            {
               log.warn("Cannot perform property replace on Element");
            }
            else
            {
               editor.setValue(value);
               String text = editor.getAsText();
               text = StringPropertyReplacer.replaceProperties(text);
               editor.setAsText(text);
               value = editor.getValue();
            }
         }
      }

      if (value == null)
      {
         PropertyEditor editor = PropertyEditorManager.findEditor(typeClass);
         if (editor == null)
         {
            throw new DeploymentException
               ("No property editor for attribute: " + attributeName +
               "; type=" + typeClass);
         }

         // JBAS-1709, temporarily switch the TCL so that property
         // editors have access to the actual deployment ClassLoader.
         ClassLoader tcl = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(cl);
         try
         {
            editor.setAsText(attributeText);
            value = editor.getValue();
         }
         finally
         {
            Thread.currentThread().setContextClassLoader(tcl);
         }
View Full Code Here

            root.appendChild(element);
         }
         else {
            Class clazz = value.getClass();
            String type = clazz.getName();
          PropertyEditor peditor = PropertyEditorManager.findEditor(clazz);

          if (peditor != null) {
           // (c) use a PropertyEditor - mark the type and append the value as string              
             peditor.setValue(value);
            
             element.setAttribute(AL_TYPE_ATTRIBUTE, type);
             element.appendChild(doc.createTextNode(peditor.getAsText()));
            
             // append the attribute to the attribute-list
             root.appendChild(element);
          }
          else if (value instanceof Serializable) {
View Full Code Here

                       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

         typeInfo = info;
      if (typeInfo == null)
         throw new IllegalArgumentException("Unable to determine type for value: " + value);
        
      Class clazz = typeInfo.getType();
      PropertyEditor editor = PropertyEditorManager.findEditor(clazz);
      if (editor != null)
      {
         editor.setAsText((String) value);
         return editor.getValue();
      }
      else
      {
         // TODO improve <init>(String) might not be relevent?
         Constructor constructor = clazz.getConstructor(new Class[] { String.class });
View Full Code Here

TOP

Related Classes of java.beans.PropertyEditor

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.