~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/configurable/StaticPropertyEntry.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.configurable;
 
2
 
 
3
import java.lang.reflect.Field;
 
4
import java.lang.reflect.Modifier;
 
5
import org.apache.log4j.Logger;
 
6
import com.eucalyptus.configurable.PropertyDirectory.NoopEventListener;
 
7
import com.eucalyptus.event.PassiveEventListener;
 
8
 
 
9
public class StaticPropertyEntry extends AbstractConfigurableProperty {
 
10
  static Logger LOG = Logger.getLogger( StaticPropertyEntry.class );
 
11
  private Field         field;
 
12
  public StaticPropertyEntry( Class definingClass, String entrySetName, Field field, String description, String defaultValue, PropertyTypeParser typeParser, Boolean readOnly, String displayName, ConfigurableFieldType widgetType, String alias, PassiveEventListener changeListener ) {
 
13
    super( definingClass, entrySetName, field.getName( ), defaultValue, description, typeParser, readOnly, displayName, widgetType, alias, changeListener );
 
14
    this.field = field;
 
15
  }
 
16
  public Field getField( ) {
 
17
    return this.field;
 
18
  }
 
19
  @Override
 
20
  public String getValue( ) {
 
21
    try {
 
22
      return ""+this.field.get( null );
 
23
    } catch ( Exception e ) {
 
24
      LOG.debug( e, e );
 
25
      return super.getDefaultValue();
 
26
    }
 
27
  }
 
28
  @Override
 
29
  public String setValue( String s ) {
 
30
    try {
 
31
      Object o = super.getTypeParser( ).parse( s );
 
32
      this.field.set( null, o );
 
33
      this.fireChange( );
 
34
      LOG.info( "Set configurable property: " + super.getQualifiedName( ) + " to " + s );
 
35
    } catch ( Throwable t ) {
 
36
      LOG.warn( "Failed to set property: " + super.getQualifiedName( ) + " because of " + t.getMessage( ) );
 
37
      LOG.debug( t, t );
 
38
    }
 
39
    return this.getValue( );
 
40
  }
 
41
 
 
42
  public static class StaticPropertyBuilder implements ConfigurablePropertyBuilder {
 
43
    private static String qualifiedName( Class c, Field f ) {
 
44
      ConfigurableClass annote = ( ConfigurableClass ) c.getAnnotation( ConfigurableClass.class );
 
45
      return annote.root( ) + "." + f.getName( ).toLowerCase( );
 
46
    }
 
47
 
 
48
    @Override
 
49
    public ConfigurableProperty buildProperty( Class c, Field field ) throws ConfigurablePropertyException {
 
50
      if( c.isAnnotationPresent( ConfigurableClass.class ) && field.isAnnotationPresent( ConfigurableField.class ) ) {
 
51
        ConfigurableClass classAnnote = ( ConfigurableClass ) c.getAnnotation( ConfigurableClass.class );
 
52
        ConfigurableField annote = ( ConfigurableField ) field.getAnnotation( ConfigurableField.class );
 
53
        String description = annote.description( );
 
54
        String defaultValue = annote.initial( );
 
55
        String fq = qualifiedName( c, field );
 
56
        String fqPrefix = fq.replaceAll( "\\..*", "" );
 
57
        String alias = classAnnote.alias();
 
58
        PropertyTypeParser p = PropertyTypeParser.get( field.getType( ) );
 
59
        ConfigurableProperty entry = null;
 
60
        Class<? extends PassiveEventListener> changeListenerClass = annote.changeListener( );
 
61
        PassiveEventListener changeListener;
 
62
        if( !changeListenerClass.equals( NoopEventListener.class ) ) {
 
63
          try {
 
64
            changeListener = changeListenerClass.newInstance( );
 
65
          } catch ( Throwable e ) {
 
66
            changeListener = NoopEventListener.NOOP;
 
67
          }          
 
68
        } else {
 
69
          changeListener = NoopEventListener.NOOP; 
 
70
        }
 
71
        int modifiers = field.getModifiers( );
 
72
        if ( Modifier.isPublic( modifiers ) && Modifier.isStatic( modifiers ) ) {
 
73
          entry = new StaticPropertyEntry( c, fqPrefix, field, description, defaultValue, p, annote.readonly( ), annote.displayName(), annote.type(), alias, changeListener );
 
74
          entry.setValue( defaultValue );
 
75
          return entry;
 
76
        } 
 
77
      } 
 
78
      return null;
 
79
    }
 
80
  }
 
81
}