~ubuntu-branches/ubuntu/vivid/eucalyptus/vivid

« back to all changes in this revision

Viewing changes to .pc/26-google-collections-1.0-ftbfs.patch/clc/modules/msgs/src/main/java/com/eucalyptus/util/Composites.java

  • Committer: Bazaar Package Importer
  • Author(s): James Page
  • Date: 2011-05-18 10:46:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110518104658-umi4lvp0yqtu8cl9
Tags: 2.0.1+bzr1256-0ubuntu5
* Fix FTBFS against libgoogle-collections-java 1.0 (LP: #784491). 
  - debian/patches/26-google-collections-1.0-ftbfs.patch: refactoring
    to use 1.0 API.
* Fix libjibx-java to version 1.1 to allow entry of libjibx1.2-java 
  into universe without breaking eucalyptus:
  - debian/eucalyptus-java-common.links: use jibx-*-1.1.jar.
  - debian/build-jars: use jibx-*-1.1.jar.
  - debian/control: use libjibx1.1-java instead of libjibx-java.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.util;
 
2
 
 
3
import java.util.Arrays;
 
4
import java.util.List;
 
5
import java.util.concurrent.ConcurrentMap;
 
6
import org.apache.log4j.Logger;
 
7
import com.eucalyptus.system.Ats;
 
8
import com.google.common.base.Function;
 
9
import com.google.common.collect.Lists;
 
10
import com.google.common.collect.Maps;
 
11
 
 
12
public class Composites {
 
13
  private static Logger LOG = Logger.getLogger( Composites.class );
 
14
  private static ConcurrentMap<Class, CompositeHelper> subTypeCache = Maps.newConcurrentHashMap( );
 
15
  
 
16
  private static <T> CompositeHelper<T> build( Class<T> destType ) {
 
17
    List<Class> sourceTypes = Lists.newArrayList( );
 
18
    if ( !Ats.from( destType ).has( Composite.class ) ) {
 
19
      sourceTypes.add( destType );
 
20
    } else {
 
21
      sourceTypes = Arrays.asList( Ats.from( destType ).get( Composite.class ).value( ) );
 
22
    }
 
23
    CompositeHelper<T> helper = null;
 
24
    if ( !subTypeCache.containsKey( destType ) ) {
 
25
      helper = new CompositeHelper<T>( destType, sourceTypes );
 
26
      subTypeCache.putIfAbsent( destType, helper );
 
27
    } else {
 
28
      helper = subTypeCache.get( destType );
 
29
    }
 
30
    return helper;
 
31
  }  
 
32
 
 
33
  public static <A,B> B updateNulls( A source, B dest ) {
 
34
    return ( B ) CompositeHelper.updateNulls( source, dest );
 
35
  }
 
36
 
 
37
  public static <A,B> B update( A source, B dest ) {
 
38
    return ( B ) CompositeHelper.update( source, dest );
 
39
  }
 
40
 
 
41
  public static <T> T composeNew( Class<T> destType, Object... sources ) {
 
42
    T dest;
 
43
    try {
 
44
      dest = destType.newInstance( );
 
45
      return compose( dest, sources );
 
46
    } catch ( Exception e ) {
 
47
      LOG.error( e, e );
 
48
      throw new RuntimeException( "Composition for " + destType.getCanonicalName( ) + " failed because of " + e.getMessage( ), e );
 
49
    }
 
50
  }
 
51
  
 
52
  public static <T> T compose( T dest, Object... sources ) {
 
53
    CompositeHelper<T> helper = Composites.build( (Class<T>)dest.getClass( ) );
 
54
    return helper.compose( dest, sources );
 
55
  }
 
56
 
 
57
  public static <A,B> B updateNew( A source, Class<B> destType ) {
 
58
    try {
 
59
      return ( B ) CompositeHelper.update( source, destType.newInstance( ) );
 
60
    } catch ( Exception e ) {
 
61
      LOG.error( e, e );
 
62
      throw new RuntimeException( "Failed to update composable object because of: " + e.getMessage( ), e );
 
63
    }    
 
64
  }
 
65
  public static <T> List<Object> projectNew( T source, Class... destTypes ) {
 
66
    List<Object> dests = Lists.transform( Arrays.asList( destTypes ), new Function<Class,Object>( ) {
 
67
      @Override
 
68
      public Object apply( Class arg0 ) {
 
69
        try {
 
70
          return arg0.newInstance( );
 
71
        } catch ( Exception e ) {
 
72
          throw new RuntimeException( e );
 
73
        }
 
74
      }});
 
75
    return project( source, dests );
 
76
  }
 
77
 
 
78
  public static <T> List<Object> projectNew( T source ) {
 
79
    try {
 
80
      List<Object> dests = Lists.transform( subTypeCache.get( source ).getSourceTypes( ), new Function<Class,Object>() {
 
81
        @Override
 
82
        public Object apply( Class arg0 ) {
 
83
          try {
 
84
            return arg0.newInstance( );
 
85
          } catch ( Exception e ) {
 
86
            throw new RuntimeException( e );
 
87
          }
 
88
        }} );
 
89
      return project( source, dests );
 
90
    } catch ( Exception e ) {
 
91
      LOG.error( e, e );
 
92
      throw new RuntimeException( "Projection for " + source.getClass( ).getCanonicalName( ) + " failed because of " + e.getMessage( ), e );
 
93
    }
 
94
  }
 
95
  
 
96
  public static <T> List<Object> project( T source, Object... dests ) {
 
97
    CompositeHelper<T> helper = ( CompositeHelper<T> ) Composites.build( source.getClass( ) );
 
98
    return helper.project( source, dests );
 
99
  }
 
100
 
 
101
}