Examples of UnWrapper


Examples of com.comphenix.protocol.injector.PacketConstructor.Unwrapper

      return handleCollection((Collection<Object>) wrappedObject);
    } else if (Primitives.isWrapperType(currentClass) || wrappedObject instanceof String) {
      return null;
    }
   
    Unwrapper specificUnwrapper = getSpecificUnwrapper(currentClass);
   
    // Retrieve the handle
    if (specificUnwrapper != null)
      return specificUnwrapper.unwrapItem(wrappedObject);
    else
      return null;
  }
View Full Code Here

Examples of com.comphenix.protocol.injector.PacketConstructor.Unwrapper

   
    try {
      final Method find = type.getMethod("getHandle");
     
      // It's thread safe, as getMethod should return the same handle
      Unwrapper methodUnwrapper = new Unwrapper() {
        @Override
        public Object unwrapItem(Object wrappedObject) {
          try {
            if (wrappedObject instanceof Class)
              return checkClass((Class<?>) wrappedObject, type, find.getReturnType());
            return find.invoke(wrappedObject);
           
          } catch (IllegalArgumentException e) {
            reporter.reportDetailed(this,
                Report.newBuilder(REPORT_ILLEGAL_ARGUMENT).error(e).callerParam(wrappedObject, find)
            );
          } catch (IllegalAccessException e) {
            // Should not occur either
            return null;
          } catch (InvocationTargetException e) {
            // This is really bad
            throw new RuntimeException("Minecraft error.", e);
          }
         
          return null;
        }
      };
     
      unwrapperCache.put(type, methodUnwrapper);
      return methodUnwrapper;
     
    } catch (SecurityException e) {
      reporter.reportDetailed(this,
          Report.newBuilder(REPORT_SECURITY_LIMITATION).error(e).callerParam(type)
      );
    } catch (NoSuchMethodException e) {
      // Try getting the field unwrapper too
      Unwrapper fieldUnwrapper = getFieldUnwrapper(type);
     
      if (fieldUnwrapper != null)
        return fieldUnwrapper;
      else
        reporter.reportDetailed(this,
View Full Code Here

Examples of com.comphenix.protocol.injector.PacketConstructor.Unwrapper

  private Unwrapper getFieldUnwrapper(final Class<?> type) {
    final Field find = FieldUtils.getField(type, "handle", true);
   
    // See if we succeeded
    if (find != null) {
      Unwrapper fieldUnwrapper = new Unwrapper() {
        @Override
        public Object unwrapItem(Object wrappedObject) {
          try {
            if (wrappedObject instanceof Class)
              return checkClass((Class<?>) wrappedObject, type, find.getType());
View Full Code Here

Examples of com.comphenix.protocol.injector.PacketConstructor.Unwrapper

   * @param nativeType - the native NMS type the converter produces.
   * @param converter - the converter.
   * @return The equivalent unwrapper.
   */
  public static Unwrapper asUnwrapper(final Class<?> nativeType, final EquivalentConverter<Object> converter) {
    return new Unwrapper() {
      @SuppressWarnings("rawtypes")
      @Override
      public Object unwrapItem(Object wrappedObject) {
        Class<?> type = PacketConstructor.getClass(wrappedObject);
       
View Full Code Here

Examples of org.geotools.data.jdbc.datasource.UnWrapper

    public void connect() throws Exception {
        super.connect();
        fixture = new GeometryFixture();
        this.connection = setup.getDataSource().getConnection();
       
        UnWrapper unwrapper = DataSourceFinder.getUnWrapper(this.connection);
        OracleConnection oraConn = (OracleConnection) unwrapper.unwrap(this.connection);
        converter = new GeometryConverter(oraConn);
    }
View Full Code Here

Examples of org.geotools.data.jdbc.datasource.UnWrapper

        try {
            // first lookup ever? (we have UNWRAPPER_NOT_FOUND as a sentinel for a lookup that
            // will not work (we assume the datasource will always return connections we can
            // unwrap, or never).
            if (uw == null) {
                UnWrapper unwrapper = DataSourceFinder.getUnWrapper(cx);
                if (unwrapper == null) {
                    uw = UNWRAPPER_NOT_FOUND;
                } else {
                    uw = unwrapper;
                }
View Full Code Here

Examples of org.geotools.data.jdbc.datasource.UnWrapper

       ds.setDriverClassName("org.h2.Driver");
       ds.setUrl("jdbc:h2:mem:test_mem");
       ds.setAccessToUnderlyingConnectionAllowed(true);
      
       Connection conn = ds.getConnection();
       UnWrapper uw = DataSourceFinder.getUnWrapper(conn);
       assertNotNull(uw);
       assertTrue(uw.canUnwrap(conn));
       Connection unwrapped = uw.unwrap(conn);
       assertNotNull(unwrapped);
       assertTrue(unwrapped instanceof org.h2.jdbc.JdbcConnection);
      
       Statement st = conn.createStatement();
       uw = DataSourceFinder.getUnWrapper(st);
       assertNotNull(uw);
       assertTrue(uw.canUnwrap(st));
       Statement uwst = uw.unwrap(st);
       assertNotNull(uwst);
       assertTrue(uwst instanceof org.h2.jdbc.JdbcStatement);
       st.close();
      
       PreparedStatement ps = conn.prepareStatement("select curtime()");
       uw = DataSourceFinder.getUnWrapper(ps);
       assertNotNull(uw);
       assertTrue(uw.canUnwrap(ps));
       PreparedStatement uwps = (PreparedStatement) uw.unwrap(ps);
       assertNotNull(uwps);
       assertTrue(uwps instanceof org.h2.jdbc.JdbcPreparedStatement);
       ps.close();
      
          
View Full Code Here

Examples of org.geotools.data.jdbc.datasource.UnWrapper

        assertTrue( wrapper.isWrapperFor( Connection.class ) );       
        Connection unwrap = wrapper.unwrap( Connection.class );
       
        assertSame( connection, unwrap );
       
        UnWrapper unwrapper = new GenericUnWrapper();
       
        assertFalse( unwrapper.canUnwrap( wrapper ) );
        try {
            assertNull( unwrapper.unwrap( wrapper ));
            fail("Cannot unwrap yet");
        }
        catch (Exception expected){
        }
        GenericUnWrapper.CONNECTION_METHODS.put(WrapperConnection.class,
                WrapperConnection.class.getMethod("getUnderlyingConnection", null));
       
        assertTrue( unwrapper.canUnwrap( wrapper ) );
        assertSame( connection, unwrapper.unwrap( wrapper ) );
    }
View Full Code Here

Examples of org.geotools.data.jdbc.datasource.UnWrapper

    @Test
    public void testSPIRegistration() throws Exception {
        Connection connection = new TestConnection();
        Connection wrapper = new WrapperConnection( connection );
       
         UnWrapper uw = DataSourceFinder.getUnWrapper( wrapper );
         if( uw != null ){
             assertTrue("picked up by jdbc4 extractor", uw instanceof SpringUnWrapper );
         }
        
         GenericUnWrapper.CONNECTION_METHODS.put(WrapperConnection.class,
                 WrapperConnection.class.getMethod("getUnderlyingConnection", null));
        
         uw = DataSourceFinder.getUnWrapper( wrapper );
         assertNotNull("registed and canUnwrap",uw);
         if( uw instanceof GenericUnWrapper ){
             assertSame( "Generic unwrapper is working", connection, uw.unwrap( wrapper ));
         }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.