Search in sources :

Example 1 with Policy

use of org.apache.cxf.annotations.Policy in project cxf by apache.

the class PolicyAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, Endpoint endpoint, Class<?> cls, List<Policy> list, Policy.Placement defaultPlace) {
    ListIterator<Policy> it = list.listIterator();
    InterfaceInfo inf = endpoint.getEndpointInfo().getInterface();
    BindingInfo binf = endpoint.getBinding().getBindingInfo();
    ServiceInfo si = endpoint.getService().getServiceInfos().get(0);
    while (it.hasNext()) {
        Policy p = it.next();
        Policy.Placement place = p.placement();
        if (place == Policy.Placement.DEFAULT) {
            place = defaultPlace;
        }
        switch(place) {
            case PORT_TYPE:
                {
                    addPolicy(inf, si, p, cls, inf.getName().getLocalPart() + "PortTypePolicy");
                    it.remove();
                    break;
                }
            case BINDING:
                {
                    addPolicy(binf, si, p, cls, binf.getName().getLocalPart() + "BindingPolicy");
                    it.remove();
                    break;
                }
            case SERVICE:
                {
                    addPolicy(si, si, p, cls, si.getName().getLocalPart() + "ServicePolicy");
                    it.remove();
                    break;
                }
            case SERVICE_PORT:
                {
                    addPolicy(endpoint.getEndpointInfo(), si, p, cls, endpoint.getEndpointInfo().getName().getLocalPart() + "PortPolicy");
                    it.remove();
                    break;
                }
            default:
        }
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 2 with Policy

use of org.apache.cxf.annotations.Policy in project cxf by apache.

the class PolicyAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, OperationInfo inf, Method m) {
    if (m == null) {
        return;
    }
    Policy p = m.getAnnotation(Policy.class);
    Policies ps = m.getAnnotation(Policies.class);
    if (p != null || ps != null) {
        List<Policy> list = new ArrayList<>();
        if (p != null) {
            list.add(p);
        }
        if (ps != null) {
            Collections.addAll(list, ps.value());
        }
        ListIterator<Policy> it = list.listIterator();
        while (it.hasNext()) {
            p = it.next();
            Policy.Placement place = p.placement();
            if (place == Policy.Placement.DEFAULT) {
                place = Policy.Placement.BINDING_OPERATION;
            }
            ServiceInfo service = inf.getInterface().getService();
            Class<?> cls = m.getDeclaringClass();
            switch(place) {
                case PORT_TYPE_OPERATION:
                    addPolicy(inf, service, p, cls, inf.getName().getLocalPart() + "PortTypeOpPolicy");
                    it.remove();
                    break;
                case PORT_TYPE_OPERATION_INPUT:
                    addPolicy(inf.getInput(), service, p, cls, inf.getName().getLocalPart() + "PortTypeOpInputPolicy");
                    it.remove();
                    break;
                case PORT_TYPE_OPERATION_OUTPUT:
                    addPolicy(inf.getOutput(), service, p, cls, inf.getName().getLocalPart() + "PortTypeOpOutputPolicy");
                    it.remove();
                    break;
                case PORT_TYPE_OPERATION_FAULT:
                    {
                        for (FaultInfo f : inf.getFaults()) {
                            if (p.faultClass().equals(f.getProperty(Class.class.getName()))) {
                                addPolicy(f, service, p, cls, f.getName().getLocalPart() + "PortTypeOpFaultPolicy");
                                it.remove();
                            }
                        }
                        break;
                    }
                default:
            }
        }
        if (!list.isEmpty()) {
            List<Policy> stuff = CastUtils.cast((List<?>) inf.getProperty(EXTRA_POLICIES));
            if (stuff != null) {
                for (Policy p2 : list) {
                    if (!stuff.contains(p2)) {
                        stuff.add(p2);
                    }
                }
            } else {
                inf.setProperty(EXTRA_POLICIES, list);
            }
        }
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Policies(org.apache.cxf.annotations.Policies) ArrayList(java.util.ArrayList)

Example 3 with Policy

use of org.apache.cxf.annotations.Policy in project cxf by apache.

the class PolicyAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, InterfaceInfo ii, Class<?> cls) {
    if (cls == null) {
        return;
    }
    Policy p = cls.getAnnotation(Policy.class);
    Policies ps = cls.getAnnotation(Policies.class);
    if (p != null || ps != null) {
        List<Policy> list = new ArrayList<>();
        if (p != null) {
            list.add(p);
        }
        if (ps != null) {
            Collections.addAll(list, ps.value());
        }
        ListIterator<Policy> it = list.listIterator();
        while (it.hasNext()) {
            p = it.next();
            Policy.Placement place = p.placement();
            if (place == Policy.Placement.DEFAULT) {
                place = Policy.Placement.BINDING;
            }
            switch(place) {
                case PORT_TYPE:
                    {
                        addPolicy(ii, ii.getService(), p, cls, ii.getName().getLocalPart() + "PortTypePolicy");
                        it.remove();
                        break;
                    }
                case SERVICE:
                    {
                        addPolicy(ii.getService(), ii.getService(), p, cls, ii.getService().getName().getLocalPart() + "ServicePolicy");
                        it.remove();
                        break;
                    }
                default:
            }
        }
        if (!list.isEmpty()) {
            List<Policy> stuff = CastUtils.cast((List<?>) ii.getProperty(EXTRA_POLICIES));
            if (stuff != null) {
                for (Policy p2 : list) {
                    if (!stuff.contains(p2)) {
                        stuff.add(p2);
                    }
                }
            } else {
                ii.setProperty(EXTRA_POLICIES, list);
            }
        }
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) Policies(org.apache.cxf.annotations.Policies) ArrayList(java.util.ArrayList)

Example 4 with Policy

use of org.apache.cxf.annotations.Policy in project cxf by apache.

the class PolicyAnnotationListener method addEndpointImplPolicies.

private void addEndpointImplPolicies(AbstractServiceFactoryBean factory, Endpoint endpoint, Class<?> cls) {
    List<Policy> list = CastUtils.cast((List<?>) endpoint.getEndpointInfo().getInterface().removeProperty(EXTRA_POLICIES));
    if (list != null) {
        addPolicies(factory, endpoint, cls, list, Policy.Placement.BINDING);
    }
    if (cls == null) {
        return;
    }
    Policy p = cls.getAnnotation(Policy.class);
    Policies ps = cls.getAnnotation(Policies.class);
    if (p != null || ps != null) {
        list = new ArrayList<>();
        if (p != null) {
            list.add(p);
        }
        if (ps != null) {
            Collections.addAll(list, ps.value());
        }
        addPolicies(factory, endpoint, cls, list, Policy.Placement.SERVICE);
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) Policies(org.apache.cxf.annotations.Policies)

Example 5 with Policy

use of org.apache.cxf.annotations.Policy in project cxf by apache.

the class PolicyAnnotationListener method addPolicies.

private void addPolicies(AbstractServiceFactoryBean factory, Endpoint ep, Class<?> cls) {
    List<Policy> list = CastUtils.cast((List<?>) ep.getEndpointInfo().getInterface().removeProperty(EXTRA_POLICIES));
    if (list != null) {
        addPolicies(factory, ep, cls, list, Policy.Placement.BINDING);
    }
    ServiceInfo service = ep.getService().getServiceInfos().get(0);
    for (BindingOperationInfo binfo : ep.getBinding().getBindingInfo().getOperations()) {
        List<Policy> later = CastUtils.cast((List<?>) binfo.getOperationInfo().removeProperty(EXTRA_POLICIES));
        if (later != null) {
            for (Policy p : later) {
                switch(p.placement()) {
                    case DEFAULT:
                    case BINDING_OPERATION:
                        addPolicy(binfo, service, p, cls, binfo.getName().getLocalPart() + "BindingOpPolicy");
                        break;
                    case BINDING_OPERATION_INPUT:
                        addPolicy(binfo.getInput(), service, p, cls, binfo.getName().getLocalPart() + "BindingOpInputPolicy");
                        break;
                    case BINDING_OPERATION_OUTPUT:
                        addPolicy(binfo.getOutput(), service, p, cls, binfo.getName().getLocalPart() + "BindingOpOutputPolicy");
                        break;
                    case BINDING_OPERATION_FAULT:
                        {
                            for (BindingFaultInfo f : binfo.getFaults()) {
                                if (p.faultClass().equals(f.getFaultInfo().getProperty(Class.class.getName()))) {
                                    addPolicy(f, service, p, cls, f.getFaultInfo().getName().getLocalPart() + "BindingOpFaultPolicy");
                                }
                            }
                            break;
                        }
                    default:
                }
            }
        }
    }
}
Also used : Policy(org.apache.cxf.annotations.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Aggregations

Policy (org.apache.cxf.annotations.Policy)5 Policies (org.apache.cxf.annotations.Policies)3 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)3 ArrayList (java.util.ArrayList)2 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 FaultInfo (org.apache.cxf.service.model.FaultInfo)1 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)1