org.oasisopen.sca.annotation.Reference.name()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.oasisopen.sca.annotation.Reference.name方法的一些代码示例,展示了Reference.name的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.name方法的具体详情如下:
包路径:org.oasisopen.sca.annotation.Reference
类名称:Reference
方法名:name

Reference.name介绍

暂无

代码示例

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public ReferenceInjectable(Reference referenceAnnotation,
               ParamType paramType,
               Class<?> type,
               Type genericType,
               Annotation[] annotations,
               Member member) {
  super(paramType, type, genericType, annotations, member);
  this.referenceName = getReferenceName(referenceAnnotation.name(), member);
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-wink

public ReferenceInjectable(Reference referenceAnnotation,
               ParamType paramType,
               Class<?> type,
               Type genericType,
               Annotation[] annotations,
               Member member) {
  super(paramType, type, genericType, annotations, member);
  this.referenceName = getReferenceName(referenceAnnotation.name(), member);
}

代码示例来源:origin: com.carecon.fabric3/fabric3-introspection-java

public void visitField(Reference annotation, Field field, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) {
  String name = annotation.name();
  boolean required = annotation.required();
  referenceProcessor.addDefinition(field, name, required, implClass, componentType, context);
}

代码示例来源:origin: com.carecon.fabric3/fabric3-introspection-java

public void visitMethod(Reference annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) {
  String name = annotation.name();
  boolean required = annotation.required();
  referenceProcessor.addDefinition(method, name, required, implClass, componentType, context);
}

代码示例来源:origin: com.carecon.fabric3/fabric3-introspection-java

public void visitConstructorParameter(Reference annotation,
                   Constructor<?> constructor,
                   int index,
                   Class<?> implClass,
                   InjectingComponentType componentType,
                   IntrospectionContext context) {
  String name = annotation.name();
  boolean required = annotation.required();
  referenceProcessor.addDefinition(constructor, name, index, required, implClass, componentType, context);
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-implementation-spring-runtime

public void doWith(Field field) {
    Reference annotation = (Reference)field.getAnnotation(getReferenceAnnotationType());
    if (annotation != null) {
      if (Modifier.isStatic(field.getModifiers())) {
        throw new IllegalStateException("Reference annotation is not supported on static fields");
      }
      /*
      if (Modifier.isPrivate(field.getModifiers())) {
        throw new IllegalStateException("Reference annotation is not supported on private fields");
      }
      */
      ReflectionUtils.makeAccessible(field);
      Object referenceObj = null;
      String refName = annotation.name();
      if ("".equals(refName)) {
        referenceObj = component.getService(field.getType(), field.getName());
      } else {
        referenceObj = component.getService(field.getType(), refName);
      }
      if (referenceObj != null)
        ReflectionUtils.setField(field, bean, referenceObj);
    }
  }
});

代码示例来源:origin: org.apache.tuscany.sca/tuscany-implementation-spring-runtime

public void doWith(Method method) {
    Reference annotation = (Reference)method.getAnnotation(getReferenceAnnotationType());
    if (annotation != null) {
      if (Modifier.isStatic(method.getModifiers())) {
        throw new IllegalStateException("Reference annotation is not supported on static methods");
      }
      /*
      if (Modifier.isPrivate(method.getModifiers())) {
        throw new IllegalStateException("Reference annotation is not supported on private methods");
      }
      */
      if (method.getParameterTypes().length == 0) {
        throw new IllegalStateException(
                        "Reference annotation requires at least one argument: " + method);
      }
      PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
      if (pd != null) {
        String refName = annotation.name();
        if ("".equals(refName)) {
          injectReference(bean, pd, pd.getName());
        } else {
          injectReference(bean, pd, refName);
        }
      }
    }
  }
});

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

try {
  Reference scaReference = m.getAnnotation(Reference.class);
  boolean nameSupplied = !"".equals(scaReference.name());
  String name = nameSupplied ? scaReference.name() : methodToPropertyName(m);
  Class<?> beanType = m.getParameterTypes()[0];
  Object managedBean = findReference(ctx, name, beanType, !nameSupplied);
try {
  Reference scaReference = f.getAnnotation(Reference.class);
  boolean nameSupplied = !"".equals(scaReference.name());
  String name = nameSupplied ? scaReference.name() : f.getName();
  Object managedBean = findReference(ctx, name, f.getType(), !nameSupplied);
  f.set(bean, managedBean);

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

@Override
public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
  Reference annotation = field.getAnnotation(Reference.class);
  if (annotation == null) {
    return;
  }
  
  if(Modifier.isStatic(field.getModifiers())) {
    throw new IllegalReferenceException("Static field " + field.getName() +" in class " + field.getDeclaringClass().getName() + " can not be annotated as Reference");
  }
  String name = annotation.name();
  if ("".equals(name)) {
    name = field.getName();
  }
  JavaElementImpl ref = type.getReferenceMembers().get(name);
  if (ref != null && ref.getElementType() == ElementType.FIELD) {
    throw new DuplicateReferenceException(name);
  }
  // Setter method override field
  if (ref == null) {
    JavaElementImpl element = new JavaElementImpl(field);
    org.apache.tuscany.sca.assembly.Reference reference = createReference(type, element, name);
    type.getReferences().add(reference);
    type.getReferenceMembers().put(name, element);
  }
}

代码示例来源:origin: org.codehaus.fabric3/fabric3-introspection-java

public void visitField(Reference annotation,
            Field field,
            Class<?> implClass,
            InjectingComponentType componentType,
            IntrospectionContext context) {
  String name = helper.getSiteName(field, annotation.name());
  Type type = field.getGenericType();
  FieldInjectionSite site = new FieldInjectionSite(field);
  Annotation[] annotations = field.getAnnotations();
  boolean required = annotation.required();
  ReferenceDefinition definition = createDefinition(name, required, type, implClass, annotations, componentType, context);
  componentType.add(definition, site);
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-implementation-web-runtime

if (field.isAnnotationPresent(Reference.class)) {
  Reference ref = field.getAnnotation(Reference.class);
  String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
  Object value = getReference(name, field.getType(), sc);
  setField(instance, field, value);
  String name = ref.name() != null && !ref.name().equals("") ? ref.name() : targetName;
  Object value = getReference(name, type, sc);
  setMethod(instance, method, value);

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

if (field.isAnnotationPresent(Reference.class)) {
  Reference ref = field.getAnnotation(Reference.class);
  String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
  Object value = getReference(name, field.getType(), sc);
  setField(instance, field, value);
  String name = ref.name() != null && !ref.name().equals("") ? ref.name() : targetName;
  Object value = getReference(name, type, sc);
  setMethod(instance, method, value);

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

String name = annotation.name();
if ("".equals(name)) {
  name = JavaIntrospectionHelper.toPropertyName(method.getName());

代码示例来源:origin: org.codehaus.fabric3/fabric3-introspection-java

public void visitMethod(Reference annotation,
            Method method,
            Class<?> implClass,
            InjectingComponentType componentType,
            IntrospectionContext context) {
  String name = helper.getSiteName(method, annotation.name());
  Type type = helper.getGenericType(method);
  MethodInjectionSite site = new MethodInjectionSite(method, 0);
  Annotation[] annotations = method.getAnnotations();
  ReferenceDefinition definition = createDefinition(name, annotation.required(), type, implClass, annotations, componentType, context);
  componentType.add(definition, site);
}

代码示例来源:origin: org.codehaus.fabric3/fabric3-introspection-java

public void visitConstructorParameter(Reference annotation,
                   Constructor<?> constructor,
                   int index,
                   Class<?> implClass,
                   InjectingComponentType componentType,
                   IntrospectionContext context) {
  String name = helper.getSiteName(constructor, index, annotation.name());
  Type type = helper.getGenericType(constructor, index);
  ConstructorInjectionSite site = new ConstructorInjectionSite(constructor, index);
  Annotation[] annotations = constructor.getParameterAnnotations()[index];
  boolean required = annotation.required();
  ReferenceDefinition definition = createDefinition(name, required, type, implClass, annotations, componentType, context);
  componentType.add(definition, site);
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

@Override
public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
  throws IntrospectionException {
  Reference refAnnotation = parameter.getAnnotation(Reference.class);
  if (refAnnotation == null) {
    return;
  }
  
  if (!refAnnotation.required()) {
    throw new InvalidReferenceException("[JCA90016] Constructor has @Reference with required=false: " + type.getName());
  }
  
  if (refAnnotation.name() == null || refAnnotation.name().length() < 1) {
    throw new InvalidReferenceException("[JCA90018] @Reference in a Constructor must have a name attribute" + type.getName());
  }
  
  String paramName = parameter.getName();
  String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
  JavaElementImpl ref = type.getReferenceMembers().get(name);
  // Setter override field
  if (ref != null && ref.getElementType() != ElementType.FIELD) {
    throw new DuplicateReferenceException(name);
  }
  removeReference(ref, type);
  org.apache.tuscany.sca.assembly.Reference reference = createReference(type, parameter, name);
  type.getReferences().add(reference);
  type.getReferenceMembers().put(name, parameter);
  parameter.setClassifer(Reference.class);
  parameter.setName(name);
}

相关文章