Package org.apache.felix.scrplugin.description

Examples of org.apache.felix.scrplugin.description.ReferenceDescription


     * @param describedClass
     *            The described class.
     */
    private void createReferences(final List<? extends ScannedAnnotation> descs, final ClassDescription describedClass) {
        for (final ScannedAnnotation ad : descs) {
            final ReferenceDescription ref = new ReferenceDescription(ad);

            // check for field annotation
            final FieldAnnotation fieldAnnotation;
            if (ad instanceof FieldAnnotation) {
                fieldAnnotation = (FieldAnnotation) ad;
                ref.setField(fieldAnnotation.getAnnotatedField());
            } else {
                fieldAnnotation = null;
            }

            ref.setName(ad.getStringValue("name",
                            (fieldAnnotation != null ? fieldAnnotation.getAnnotatedField().getName() : null)));
            String defaultInterfaceName = null;
            if ( fieldAnnotation != null ) {
                if ( fieldAnnotation.getAnnotatedField().getType().isArray() ) {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getComponentType().getName();
                } else {
                    defaultInterfaceName = fieldAnnotation.getAnnotatedField().getType().getName();
                }
            }
            ref.setInterfaceName(ad.getStringValue("referenceInterface", defaultInterfaceName));
            ref.setTarget(ad.getStringValue("target", null));
            ref.setCardinality(ReferenceCardinality.valueOf(ad.getEnumValue("cardinality",
                            ReferenceCardinality.MANDATORY_UNARY.name())));
            ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name())));
            ref.setPolicyOption(ReferencePolicyOption.valueOf(ad.getEnumValue("policyOption", ReferencePolicyOption.RELUCTANT.name())));
            ref.setStrategy(ReferenceStrategy.valueOf(ad.getEnumValue("strategy", ReferenceStrategy.EVENT.name())));

            ref.setBind(ad.getStringValue("bind", null));
            ref.setUnbind(ad.getStringValue("unbind", null));
            ref.setUpdated(ad.getStringValue("updated", null));

            describedClass.add(ref);
        }
    }
View Full Code Here


                } else if (localName.equals(INTERFACE)) {
                    this.currentService.addInterface(attributes.getValue(INTERFACE_ATTR_NAME));

                } else if (localName.equals(REFERENCE)) {
                    final ReferenceDescription ref = new ReferenceDescription(null);

                    ref.setName(attributes.getValue(ATTR_NAME));
                    ref.setInterfaceName(attributes.getValue(INTERFACE_ATTR_NAME));
                    final String cardinality = attributes.getValue(ATTR_CARDINALITY);
                    if ( cardinality != null ) {
                        ref.setCardinality(ReferenceCardinality.fromValue(cardinality));
                        if ( ref.getCardinality() == null ) {
                            iLog.addWarning("Invalid value for attribute cardinality : " + cardinality, this.location);
                        }
                    }
                    ref.setPolicy(ReferencePolicy.STATIC);
                    final String policy = attributes.getValue(REFERENCE_ATTR_POLICY);
                    if ( policy != null ) {
                        try {
                            ref.setPolicy(ReferencePolicy.valueOf(policy.toUpperCase()));
                        } catch (final IllegalArgumentException iae) {
                            iLog.addWarning("Invalid value for attribute policy : " + policy, this.location);
                        }
                    }
                    ref.setPolicyOption(ReferencePolicyOption.RELUCTANT);
                    final String policyOption = attributes.getValue(REFERENCE_ATTR_POLICY_OPTION);
                    if ( policyOption != null ) {
                        try {
                            ref.setPolicyOption(ReferencePolicyOption.valueOf(policyOption.toUpperCase()));
                        } catch (final IllegalArgumentException iae) {
                            iLog.addWarning("Invalid value for attribute policy-option : " + policyOption, this.location);
                        }
                    }
                    ref.setTarget(attributes.getValue(REFERENCE_ATTR_TARGET));
                    if ( attributes.getValue(REFERENCE_ATTR_BIND) != null ) {
                        ref.setBind(attributes.getValue(REFERENCE_ATTR_BIND));
                    }
                    if ( attributes.getValue(REFERENCE_ATTR_UNBIND) != null ) {
                        ref.setUnbind(attributes.getValue(REFERENCE_ATTR_UNBIND));
                    }
                    if ( attributes.getValue(REFERENCE_ATTR_UPDATED) != null ) {
                        ref.setUnbind(attributes.getValue(REFERENCE_ATTR_UPDATED));
                    }

                    final String strategy = attributes.getValue(REFERENCE_ATTR_STRATEGY);
                    if ( strategy != null ) {
                        try {
                            ref.setStrategy(ReferenceStrategy.valueOf(strategy.toUpperCase()));
                        } catch (final IllegalArgumentException iae) {
                            throw new SAXException("Invalid value for attribute strategy : " + strategy);
                        }
                    }
View Full Code Here

    /**
     * Process a reference
     */
    private void processReference(final ClassDescription describedClass, final MethodAnnotation ad) {
        final ReferenceDescription ref = new ReferenceDescription(ad);
        describedClass.add(ref);

        ref.setStrategy(ReferenceStrategy.EVENT);

        final String methodName = ad.getAnnotatedMethod().getName();
        final String defaultUnbindMethodName;
        final String refNameByMethod;
        if ( methodName.startsWith("add") ) {
            refNameByMethod = methodName.substring(3);
            defaultUnbindMethodName = "remove" + refNameByMethod;
        } else if ( methodName.startsWith("set") ) {
            refNameByMethod = methodName.substring(3);
            defaultUnbindMethodName = "unset" + refNameByMethod;
        } else if ( methodName.startsWith("bind") ) {
            refNameByMethod = methodName.substring(4);
            defaultUnbindMethodName = "unbind" + refNameByMethod;
        } else {
            refNameByMethod = methodName;
            defaultUnbindMethodName = "un" + refNameByMethod;
        }
        final String defaultUpdateMethodName = "updated" + refNameByMethod;

        // bind method
        ref.setBind(ad.getAnnotatedMethod().getName());
        // unbind method
        final String unbind = ad.getStringValue("unbind",
                        this.hasMethod(describedClass, defaultUnbindMethodName) ? defaultUnbindMethodName : "-");
        if ( !unbind.equals("-") ) {
            ref.setUnbind(unbind);
        }
        // update method
        final String updated = ad.getStringValue("updated",
                        this.hasMethod(describedClass, defaultUpdateMethodName) ? defaultUpdateMethodName : "-");
        if ( !updated.equals("-") ) {
            ref.setUpdated(updated);
        }

        // name
        ref.setName(ad.getStringValue("name", refNameByMethod));
        // service
        final String serviceName = ad.getStringValue("service", null);
        if ( serviceName != null ) {
            ref.setInterfaceName(serviceName);
        } else {
            final Class<?>[] params = ad.getAnnotatedMethod().getParameterTypes();
            if ( params != null && params.length > 0 ) {
                ref.setInterfaceName(params[0].getName());
            }
        }
        // cardinality
        final String cardinality = ad.getEnumValue("cardinality", "MANDATORY");
        if ( cardinality.equals("OPTIONAL") ) {
            ref.setCardinality(ReferenceCardinality.OPTIONAL_UNARY);
        } else if ( cardinality.equals("MULTIPLE") ) {
            ref.setCardinality(ReferenceCardinality.OPTIONAL_MULTIPLE);
        } else if ( cardinality.equals("AT_LEAST_ONE") ) {
            ref.setCardinality(ReferenceCardinality.MANDATORY_MULTIPLE);
        } else {
            ref.setCardinality(ReferenceCardinality.MANDATORY_UNARY);
        }

        // policy
        ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name())));
        // policy option
        ref.setPolicyOption(ReferencePolicyOption.valueOf(ad.getEnumValue("policyOption", ReferencePolicyOption.RELUCTANT.name())));
        // target
        ref.setTarget(ad.getStringValue("target", null));
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.scrplugin.description.ReferenceDescription

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.