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

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/binding/HoldMe.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.binding;
 
2
 
 
3
import java.io.ByteArrayInputStream;
 
4
import java.io.InputStream;
 
5
import java.util.concurrent.TimeUnit;
 
6
import java.util.concurrent.locks.Condition;
 
7
import java.util.concurrent.locks.Lock;
 
8
import javax.xml.stream.XMLInputFactory;
 
9
import javax.xml.stream.XMLOutputFactory;
 
10
import javax.xml.stream.XMLStreamException;
 
11
import javax.xml.stream.XMLStreamReader;
 
12
import org.apache.axiom.om.OMAbstractFactory;
 
13
import org.apache.axiom.om.OMException;
 
14
import org.apache.axiom.om.OMFactory;
 
15
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 
16
import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
 
17
import org.apache.axiom.soap.SOAPFactory;
 
18
 
 
19
public class HoldMe implements Lock {
 
20
  public static final String      OM_FACTORY_NAME_PROPERTY          = "om.factory";
 
21
  public static final String      SOAP11_FACTORY_NAME_PROPERTY      = "soap11.factory";
 
22
  public static final String      SOAP12_FACTORY_NAME_PROPERTY      = "soap12.factory";
 
23
  private static final String     DEFAULT_OM_FACTORY_CLASS_NAME     = "org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory";
 
24
  private static final String     DEFAULT_SOAP11_FACTORY_CLASS_NAME = "org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory";
 
25
  private static final String     DEFAULT_SOAP12_FACTORY_CLASS_NAME = "org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory";
 
26
  static {
 
27
    System.setProperty( "javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory" );
 
28
    System.setProperty( "javax.xml.stream.XMLOutputFactory", "com.ctc.wstx.stax.WstxOutputFactory" );
 
29
    System.setProperty( "javax.xml.stream.XMLEventFactory", "com.ctc.wstx.stax.WstxEventFactory" );
 
30
    System.setProperty( "org.jibx.runtime.impl.parser", "org.jibx.runtime.impl.StAXReaderFactory" );
 
31
//    System.setProperty( "org.jibx.runtime.impl.parser", "org.jibx.runtime.impl.XMLPullReaderFactory" );
 
32
  }
 
33
  private static XMLInputFactory  xmlInputFactory                   = XMLInputFactory.newInstance( );
 
34
  private static XMLOutputFactory xmlOutputFactory                  = XMLOutputFactory.newInstance( );
 
35
  
 
36
  public static Lock              canHas                            = maybeGetLock( );
 
37
  public static boolean           reuse                             = true;
 
38
  
 
39
  @Override
 
40
  public void lock( ) {}
 
41
  
 
42
  private static Lock maybeGetLock( ) {
 
43
    if ( reuse ) {
 
44
      //      return new ReentrantLock( );
 
45
      return new HoldMe( );
 
46
    } else {
 
47
      return new HoldMe( );
 
48
    }
 
49
  }
 
50
  
 
51
  @Override
 
52
  public void lockInterruptibly( ) throws InterruptedException {}
 
53
  
 
54
  @Override
 
55
  public Condition newCondition( ) {
 
56
    return null;
 
57
  }
 
58
  
 
59
  @Override
 
60
  public boolean tryLock( ) {
 
61
    return true;
 
62
  }
 
63
  
 
64
  @Override
 
65
  public boolean tryLock( long arg0, TimeUnit arg1 ) throws InterruptedException {
 
66
    return true;
 
67
  }
 
68
  
 
69
  @Override
 
70
  public void unlock( ) {}
 
71
  
 
72
  public static OMFactory getDOOMFactory( ) {
 
73
    if ( reuse )
 
74
      return DOOMAbstractFactory.getOMFactory( );
 
75
    else return new org.apache.axiom.om.impl.dom.factory.OMDOMFactory( );
 
76
  }
 
77
  
 
78
  public static SOAPFactory getDOOMSOAP11Factory( ) {
 
79
    if ( reuse )
 
80
      return DOOMAbstractFactory.getSOAP11Factory( );
 
81
    else return new org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory( );
 
82
  }
 
83
  
 
84
  public static SOAPFactory getDOOMSOAP12Factory( ) {
 
85
    if ( reuse )
 
86
      return DOOMAbstractFactory.getSOAP12Factory( );
 
87
    else return new org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory( );
 
88
  }
 
89
  
 
90
  public static SOAPFactory getOMSOAP11Factory( ) {
 
91
    if ( reuse ) return OMAbstractFactory.getSOAP11Factory( );
 
92
    String omFactory;
 
93
    try {
 
94
      omFactory = System.getProperty( SOAP11_FACTORY_NAME_PROPERTY );
 
95
      if ( omFactory == null || "".equals( omFactory ) ) {
 
96
        omFactory = DEFAULT_SOAP11_FACTORY_CLASS_NAME;
 
97
      }
 
98
    } catch ( SecurityException e ) {
 
99
      omFactory = DEFAULT_SOAP11_FACTORY_CLASS_NAME;
 
100
    }
 
101
    SOAPFactory defaultSOAP11OMFactory;
 
102
    try {
 
103
      defaultSOAP11OMFactory = ( SOAPFactory ) ClassLoader.getSystemClassLoader( ).loadClass( omFactory ).newInstance( );
 
104
    } catch ( InstantiationException e ) {
 
105
      throw new OMException( e );
 
106
    } catch ( IllegalAccessException e ) {
 
107
      throw new OMException( e );
 
108
    } catch ( ClassNotFoundException e ) {
 
109
      throw new OMException( e );
 
110
    }
 
111
    return defaultSOAP11OMFactory;
 
112
  }
 
113
  
 
114
  public static SOAPFactory getOMSOAP12Factory( ) {
 
115
    if ( reuse ) return OMAbstractFactory.getSOAP12Factory( );
 
116
    String omFactory;
 
117
    try {
 
118
      omFactory = System.getProperty( SOAP12_FACTORY_NAME_PROPERTY );
 
119
      if ( omFactory == null || "".equals( omFactory ) ) {
 
120
        omFactory = DEFAULT_SOAP12_FACTORY_CLASS_NAME;
 
121
      }
 
122
    } catch ( SecurityException e ) {
 
123
      omFactory = DEFAULT_SOAP12_FACTORY_CLASS_NAME;
 
124
    }
 
125
    
 
126
    SOAPFactory defaultSOAP12OMFactory;
 
127
    try {
 
128
      defaultSOAP12OMFactory = ( SOAPFactory ) ClassLoader.getSystemClassLoader( ).loadClass( omFactory ).newInstance( );
 
129
    } catch ( InstantiationException e ) {
 
130
      throw new OMException( e );
 
131
    } catch ( IllegalAccessException e ) {
 
132
      throw new OMException( e );
 
133
    } catch ( ClassNotFoundException e ) {
 
134
      throw new OMException( e );
 
135
    }
 
136
    return defaultSOAP12OMFactory;
 
137
  }
 
138
  
 
139
  public static OMFactory getOMFactory( ) {
 
140
    if ( reuse ) return OMAbstractFactory.getOMFactory( );
 
141
    String omFactory;
 
142
    try {
 
143
      omFactory = System.getProperty( OM_FACTORY_NAME_PROPERTY );
 
144
      if ( omFactory == null || "".equals( omFactory ) ) {
 
145
        omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
 
146
      }
 
147
    } catch ( SecurityException e ) {
 
148
      omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
 
149
    }
 
150
    
 
151
    OMFactory defaultOMFactory;
 
152
    try {
 
153
      defaultOMFactory = ( OMFactory ) ClassLoader.getSystemClassLoader( ).loadClass( omFactory ).newInstance( );
 
154
    } catch ( InstantiationException e ) {
 
155
      throw new OMException( e );
 
156
    } catch ( IllegalAccessException e ) {
 
157
      throw new OMException( e );
 
158
    } catch ( ClassNotFoundException e ) {
 
159
      throw new OMException( e );
 
160
    }
 
161
    return defaultOMFactory;
 
162
  }
 
163
  
 
164
  public static class ThrowAwayStAXOMBuilder extends StAXOMBuilder {
 
165
    
 
166
    public ThrowAwayStAXOMBuilder( XMLStreamReader parser ) {
 
167
      super( HoldMe.getOMFactory( ), parser );
 
168
    }
 
169
    
 
170
    public ThrowAwayStAXOMBuilder( OMFactory doomFactory, XMLStreamReader parser ) {
 
171
      super( doomFactory, parser );
 
172
    }
 
173
  }
 
174
  
 
175
  public static StAXOMBuilder getStAXOMBuilder( XMLStreamReader parser ) {
 
176
    if ( reuse )
 
177
      return new StAXOMBuilder( parser );
 
178
    else return new ThrowAwayStAXOMBuilder( parser );
 
179
  }
 
180
  
 
181
  public static StAXOMBuilder getStAXOMBuilder( OMFactory doomFactory, XMLStreamReader xmlStreamReader ) {
 
182
    if ( reuse )
 
183
      return new StAXOMBuilder( doomFactory, xmlStreamReader );
 
184
    else return new ThrowAwayStAXOMBuilder( doomFactory, xmlStreamReader );
 
185
  }
 
186
  
 
187
  public static XMLStreamReader getXMLStreamReader( InputStream in ) throws XMLStreamException {
 
188
    return HoldMe.getXMLInputFactory( ).createXMLStreamReader( in );
 
189
  }
 
190
  
 
191
  public static XMLStreamReader getXMLStreamReader( String text ) throws XMLStreamException {
 
192
    return HoldMe.getXMLInputFactory( ).createXMLStreamReader( new ByteArrayInputStream( text.getBytes( ) ) );
 
193
  }
 
194
  
 
195
  public static XMLInputFactory getXMLInputFactory( ) {
 
196
    return reuse ? xmlInputFactory : XMLInputFactory.newInstance( );
 
197
  }
 
198
  
 
199
  public static XMLOutputFactory getXMLOutputFactory( ) {
 
200
    return reuse ? xmlOutputFactory : XMLOutputFactory.newInstance( );
 
201
  }
 
202
  
 
203
}