Package org.apache.hivemind.util

Examples of org.apache.hivemind.util.PropertyAdaptor


        ServicePropertyFactoryParameter p = (ServicePropertyFactoryParameter) parameters.get(0);

        Object targetService = p.getService();
        String propertyName = p.getPropertyName();

        PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);

        String readMethodName = pa.getReadMethodName();

        if (readMethodName == null)
            throw new ApplicationRuntimeException(
                ImplMessages.servicePropertyNotReadable(propertyName, targetService),
                null,
                p.getLocation(),
                null);

        if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
            throw new ApplicationRuntimeException(
                ImplMessages.servicePropertyWrongType(
                    propertyName,
                    targetService,
                    pa.getPropertyType(),
                    serviceInterface),
                p.getLocation(),
                null);

        // Now we're good to go.
View Full Code Here


                .getParameters().get(0);

        Object targetService = p.getService();
        String propertyName = p.getPropertyName();

        PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);

        String readMethodName = pa.getReadMethodName();

        if (readMethodName == null)
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyNotReadable(
                    propertyName,
                    targetService), null, p.getLocation(), null);
        Class serviceInterface = factoryParameters.getServiceInterface();

        if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyWrongType(
                    propertyName,
                    targetService,
                    pa.getPropertyType(),
                    serviceInterface), p.getLocation(), null);

        // Now we're good to go.

        String name = ClassFabUtils.generateClassName(serviceInterface);
View Full Code Here

        ServicePoint targetServicePoint = p.getServicePoint();
        final Class targetServiceInterface = targetServicePoint.getServiceInterface();
    final Object targetService = targetServicePoint.getService( targetServiceInterface );
        String propertyName = p.getPropertyName();

        PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);

        String readMethodName = pa.getReadMethodName();

        if (readMethodName == null)
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyNotReadable(
                    propertyName,
                    targetService), null, p.getLocation(), null);
        Class serviceInterface = factoryParameters.getServiceInterface();

        if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyWrongType(
                    propertyName,
                    targetService,
                    pa.getPropertyType(),
                    serviceInterface), p.getLocation(), null);

        // Now we're good to go.

        String name = ClassFabUtils.generateClassName(serviceInterface);
View Full Code Here

                __CLOVER_210_0.S[4896]++;LOG.debug("Connecting to property " + propertyName + ".");}

            // Next,verify that there is a writable property with the same
            // name as the parameter.

            __CLOVER_210_0.S[4897]++;PropertyAdaptor adaptor = null;

            __CLOVER_210_0.S[4898]++;try
            {
                __CLOVER_210_0.S[4899]++;adaptor = PropertyUtils.getPropertyAdaptor(_component, propertyName);
            }
            catch (Exception ex)
            {
                __CLOVER_210_0.S[4900]++;throw new ConnectedParameterException(ex.getMessage(), _component, name,
                        propertyName, binding.getLocation(), ex);
            }

            __CLOVER_210_0.S[4901]++;if ((((!(adaptor.isReadable() && adaptor.isWritable())) && (++__CLOVER_210_0.CT[890] != 0)) || (++__CLOVER_210_0.CF[890] == 0))){
            {
                __CLOVER_210_0.S[4902]++;throw new ConnectedParameterException(Tapestry.format(
                        "ParameterManager.property-not-read-write",
                        _component.getExtendedId(),
                        propertyName), _component, name, propertyName, binding.getLocation(), null);
            }}

            // Check if the parameter type matches the property type

            __CLOVER_210_0.S[4903]++;Class propertyType = adaptor.getPropertyType();
            __CLOVER_210_0.S[4904]++;Class parameterType = getType(pspec.getType(), resolver);

            __CLOVER_210_0.S[4905]++;if ((((parameterType == null) && (++__CLOVER_210_0.CT[891] != 0)) || (++__CLOVER_210_0.CF[891] == 0))){
            {
                __CLOVER_210_0.S[4906]++;throw new ConnectedParameterException(Tapestry.format(
View Full Code Here

        ServicePropertyFactoryParameter p = (ServicePropertyFactoryParameter) parameters.get(0);

        Object targetService = p.getService();
        String propertyName = p.getPropertyName();

        PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);

        String readMethodName = pa.getReadMethodName();

        if (readMethodName == null)
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyNotReadable(propertyName, targetService),
                    null, p.getLocation(), null);

        if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
            throw new ApplicationRuntimeException(ImplMessages.servicePropertyWrongType(propertyName, targetService, pa
                    .getPropertyType(), serviceInterface), p.getLocation(), null);

        // Now we're good to go.

        String name = ClassFabUtils.generateClassName("ServicePropertyProxy");
View Full Code Here

        ServicePropertyFactoryParameter p = (ServicePropertyFactoryParameter) parameters.get(0);

        Object targetService = p.getService();
        String propertyName = p.getPropertyName();

        PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);

        String readMethodName = pa.getReadMethodName();

        if (readMethodName == null)
            throw new ApplicationRuntimeException(
                ImplMessages.servicePropertyNotReadable(propertyName, targetService),
                null,
                p.getLocation(),
                null);

        if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
            throw new ApplicationRuntimeException(
                ImplMessages.servicePropertyWrongType(
                    propertyName,
                    targetService,
                    pa.getPropertyType(),
                    serviceInterface),
                p.getLocation(),
                null);

        // Now we're good to go.
View Full Code Here

            props.remove(exclude);
        }
        int wiredCount = 0;

        for (String prop : props) {
            PropertyAdaptor type = getPropertyAdaptor(obj, prop);
            Class propertyType = type.getPropertyType();
            if (propertyType.isPrimitive() || propertyType.isAnnotation() || propertyType.isArray() || propertyType.isEnum()) {
                // and primitive types of course can't be injected!
                alwaysExcludedCollection.add(prop);
                continue;
            }
            if ( propertyType.getPackage().getName().startsWith("java")) {
                // if it is a standard java class then lets exclude it.
                alwaysExcludedCollection.add(prop);
                continue;
            }
            // if it is not readable then, then we can't verify that
            // we are not overwriting non-null property.
            if ( !type.isReadable() || !type.isWritable()) {
                alwaysExcludedCollection.add(prop);
                continue;
            }
            if ( propertyType.getAnnotation(NotService.class) != null) {
                alwaysExcludedCollection.add(prop);
                continue;
            }

            // check to see if we have a service to offer before bothering
            // to checking if the property can be set. This avoids triggering
            // actions caused by calling the get/setters.
            Object srv = null;
            if ( type.getPropertyType() == Log.class) {
                // log is special.
                srv = LogFactory.getLog(obj.getClass());
            } else {
                ConcurrentMap<String, String> classServiceMap = serviceMap.get(obj.getClass());
                if (classServiceMap == null) {
                    serviceMap.putIfAbsent(obj.getClass(), new ConcurrentHashMap<String, String>());
                    classServiceMap = serviceMap.get(obj.getClass());
                }
                String serviceName = classServiceMap.get(prop);
                if ( serviceName == null) {
                    InjectService service;
                    try {
                        service = findInjectService(obj, type);
                    } catch(DontInjectException e) {
                        // do nothing
                        alwaysExcludedCollection.add(prop);
                        continue;
                    }

                    if ( service != null ) {
                        serviceName = service.value();
                        if ( StringUtils.isNotBlank(serviceName)) {
                            for (String attempt: new String[] {
                                serviceName,
                                serviceName +'.' +type.getPropertyName(),
                                serviceName +'.' +StringUtils.capitalize(type.getPropertyName())
                            }) {
                                try {
                                    srv = module.getService(attempt, propertyType);
                                    if ( srv != null ) {
                                        serviceName = attempt;
                                        break;
                                    }
                                }catch(Exception e) {
                                    // oh well... not around.
                                }
                            }
                        }
                    }
                    if ( srv != null ) {
                        classServiceMap.putIfAbsent(prop, serviceName);
                    } else {
                        // we looked but did not find... no need to look again.
                        classServiceMap.putIfAbsent(prop, "");
                    }
                } else if ( !serviceName.isEmpty()){
                    // we already found the service.
                    srv = module.getService(serviceName, propertyType);
                }
                if ( srv == null) {
                    try {
                        srv = module.getService(propertyType);
                    } catch (Exception e) {
                    }
                }
            }
            if (srv == null) {
                alwaysExcludedCollection.add(prop);
            } else if ( type.read(obj) == null) {
                // Doing the read check last avoids
                // triggering problems caused by lazy initialization and read-only properties.
                if ( type.getPropertyType().isAssignableFrom(srv.getClass())) {
                    type.write(obj, srv);
                    wiredCount++;
                } else {
                    // this is probably an error so we do not just add to the exclude list.
                    throw new ApplicationRuntimeException("Trying to set property "+obj.getClass()+"."+prop+" however, the property type="+type.getPropertyType()+
                        " is not a superclass or same class as "+srv.getClass()+". srv="+srv);
                }
            }
        }
        if ( getLog().isDebugEnabled()) {
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public void wrapWithMocks(Object objectToMockWrap) {
        List<String> writableProperties = PropertyUtils.getWriteableProperties(objectToMockWrap);
        for(String prop : writableProperties) {
            PropertyAdaptor adaptor = PropertyUtils.getPropertyAdaptor(objectToMockWrap, prop);
            Class<?> interfaceClass = adaptor.getPropertyType();
            if (adaptor.isReadable() && isMockable(interfaceClass)) {
                adaptor.write(objectToMockWrap, getServiceToUse(interfaceClass,
                        adaptor.read(objectToMockWrap), true));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.hivemind.util.PropertyAdaptor

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.