java 如何在类中获取PATH注解

oknrviil  于 2023-04-04  发布在  Java
关注(0)|答案(1)|浏览(114)

我有下一个无法解决的问题。
我不知道如何访问下一个annotation(IdentificationCluster的@Path annotation),它位于与main不同的类中。问题是我遵循了典型的方法,通过使用getAnnotation()方法来获取annotation,但它是不可能获取的。

package org.example.n2composition;

import com.nedap.archie.rm.archetyped.FeederAudit;
import com.nedap.archie.rm.generic.Participation;
import com.nedap.archie.rm.generic.PartyIdentified;
import com.nedap.archie.rm.generic.PartyProxy;
import java.lang.String;
import java.time.temporal.TemporalAccessor;
import java.util.List;
import javax.annotation.processing.Generated;
import org.ehrbase.client.annotations.Archetype;
import org.ehrbase.client.annotations.Entity;
import org.ehrbase.client.annotations.Id;
import org.ehrbase.client.annotations.Path;
import org.ehrbase.client.annotations.Template;
import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;
import org.ehrbase.client.classgenerator.shareddefinition.Category;
import org.ehrbase.client.classgenerator.shareddefinition.Language;
import org.ehrbase.client.classgenerator.shareddefinition.Setting;
import org.ehrbase.client.classgenerator.shareddefinition.Territory;
import org.ehrbase.client.openehrclient.VersionUid;
import org.example.n2composition.definition.CodedTextDefiningCode;
import org.example.n2composition.definition.IdentificationCluster;
import org.example.n2composition.definition.PatientroleCluster;
import org.example.n2composition.definition.ProblemDiagnosisEvaluation;

@Entity
@Archetype("openEHR-EHR-COMPOSITION.information.v0")
@Generated(
    value = "org.ehrbase.client.classgenerator.ClassGenerator",
    date = "2023-03-24T11:50:15.994180+01:00",
    comments = "https://github.com/ehrbase/openEHR_SDK Version: 1.26.0-SNAPSHOT"
)
@Template("2")
public class N2Composition implements CompositionEntity {
  /**
   * Path: 2/Coded text
   */
  @Path("/category[at0001]|defining_code")
  private CodedTextDefiningCode codedTextDefiningCode;

  /**
   * Path: 2/Event Context/CLUSTER/identification
   * Description: identification
   */
  @Path("/context[at0002]/other_context[at0018]/items[at0019]/items[openEHR-EHR-CLUSTER.identification.v0]")
  private IdentificationCluster identification;

一旦我尝试调用注解,就会发生下一个错误。

package org.example;


import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.nedap.archie.rm.datavalues.DvCodedText;
import org.ehrbase.client.annotations.Template;
import org.example.n2composition.N2Composition;
import org.example.n2composition.definition.IdentificationCluster;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws NoSuchFieldException {

        //Lectura del fichero para obtener los path y los valores

        ReadingFile r = new ReadingFile();

        r.resultado();

        String s1 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\MAPEO1_1.txt";

        String s2 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\ATRIBUTOSYVALORES-DIAGNÓSTICO2.txt";

        r.reading(s1,s2);

        /*System.out.println(r.getResult1());

        System.out.println(r.getResult1().size());

        System.out.println(r.getResult2());

        System.out.println(r.getResult2().size());

        System.out.println(r.getElements());

        System.out.println(r.getElements().size());*/

        List<String> list1 = r.getResult1();

        List<String> list2 = r.getResult2();

        //Finalización de la lectura del path

        //Creación de la composición y empezar a darle valores

        N2Composition n2 = new N2Composition(); //crear nueva COMPOSITION

        IdentificationCluster i = new IdentificationCluster();

        DvCodedText dv = new DvCodedText();

        dv.setValue("hola");

        i.setDvCodedText(dv);

        Field f = N2Composition.class.getDeclaredField("identification");

        String p = f.getAnnotation(Path.class).value();

        n2.setIdentification(i);

        //String p = s.g

        //System.out.println(p);




        //n2.setIdentification((i.setDvCodedText(dv.setValue(list2[])));

    }

}

enter image description here
有人知道怎么解吗?

pkwftd7m

pkwftd7m1#

看来你的进口是不正确的。
在N2Composition类中,使用import org.ehrbase.client.annotations.Path;
然后在Main类中(以及错误消息中)java.nio.file.Path

相关问题