Example usage for java.lang Package equals

List of usage examples for java.lang Package equals

Introduction

In this page you can find the example usage for java.lang Package equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:IntrospectionUtil.java

public static boolean isInheritable(Package pack, Member member) {
    if (pack == null)
        return false;
    if (member == null)
        return false;

    int modifiers = member.getModifiers();
    if (Modifier.isPublic(modifiers))
        return true;
    if (Modifier.isProtected(modifiers))
        return true;
    if (!Modifier.isPrivate(modifiers) && pack.equals(member.getDeclaringClass().getPackage()))
        return true;

    return false;
}

From source file:ca.uhn.fhir.jaxrs.server.AbstractJaxRsConformanceProvider.java

/**
 * This method will add a provider to the conformance. This method is almost an exact copy of {@link ca.uhn.fhir.rest.server.RestfulServer#findResourceMethods }
 * /*from   w  w w  .j  a  v a2s . c  o  m*/
 * @param theProvider
 *           an instance of the provider interface
 * @param theProviderInterface
 *           the class describing the providers interface
 * @return the numbers of basemethodbindings added
 * @see ca.uhn.fhir.rest.server.RestfulServer#findResourceMethods
 */
public int addProvider(IResourceProvider theProvider, Class<? extends IResourceProvider> theProviderInterface)
        throws ConfigurationException {
    int count = 0;

    for (Method m : ReflectionUtil.getDeclaredMethods(theProviderInterface)) {
        BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(),
                theProvider);
        if (foundMethodBinding == null) {
            continue;
        }

        count++;

        // if (foundMethodBinding instanceof ConformanceMethodBinding) {
        // myServerConformanceMethod = foundMethodBinding;
        // continue;
        // }

        if (!Modifier.isPublic(m.getModifiers())) {
            throw new ConfigurationException(
                    "Method '" + m.getName() + "' is not public, FHIR RESTful methods must be public");
        } else {
            if (Modifier.isStatic(m.getModifiers())) {
                throw new ConfigurationException(
                        "Method '" + m.getName() + "' is static, FHIR RESTful methods must not be static");
            } else {
                ourLog.debug("Scanning public method: {}#{}", theProvider.getClass(), m.getName());

                String resourceName = foundMethodBinding.getResourceName();
                ResourceBinding resourceBinding;
                if (resourceName == null) {
                    resourceBinding = myServerBinding;
                } else {
                    RuntimeResourceDefinition definition = getFhirContext().getResourceDefinition(resourceName);
                    if (myResourceNameToBinding.containsKey(definition.getName())) {
                        resourceBinding = myResourceNameToBinding.get(definition.getName());
                    } else {
                        resourceBinding = new ResourceBinding();
                        resourceBinding.setResourceName(resourceName);
                        myResourceNameToBinding.put(resourceName, resourceBinding);
                    }
                }

                List<Class<?>> allowableParams = foundMethodBinding.getAllowableParamAnnotations();
                if (allowableParams != null) {
                    for (Annotation[] nextParamAnnotations : m.getParameterAnnotations()) {
                        for (Annotation annotation : nextParamAnnotations) {
                            Package pack = annotation.annotationType().getPackage();
                            if (pack.equals(IdParam.class.getPackage())) {
                                if (!allowableParams.contains(annotation.annotationType())) {
                                    throw new ConfigurationException("Method[" + m.toString()
                                            + "] is not allowed to have a parameter annotated with "
                                            + annotation);
                                }
                            }
                        }
                    }
                }

                resourceBinding.addMethod(foundMethodBinding);
                ourLog.debug(" * Method: {}#{} is a handler", theProvider.getClass(), m.getName());
            }
        }
    }

    return count;
}

From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java

public boolean isJaxbClass(Class<?> clazz) {
    if (clazz == null) {
        throw new IllegalArgumentException("No class, no fun");
    }/*  w  w  w .j a v  a  2  s .  c o  m*/
    if (clazz.getPackage() == null) {
        // No package: this is most likely a primitive type and definitely
        // not a JAXB class
        return false;
    }
    for (Package jaxbPackage : getSchemaRegistry().getCompileTimePackages()) {
        if (jaxbPackage.equals(clazz.getPackage())) {
            return true;
        }
    }
    return false;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

public PrismSchema findSchemaByCompileTimeClass(Class<?> compileTimeClass) {
    Package compileTimePackage = compileTimeClass.getPackage();
    for (SchemaDescription desc : schemaDescriptions) {
        if (compileTimePackage.equals(desc.getCompileTimeClassesPackage())) {
            PrismSchema schema = desc.getSchema();
            return schema;
        }//from   w w  w  .j av a 2 s. com
    }
    return null;
}

From source file:ca.uhn.fhir.rest.server.RestfulServer.java

private int findResourceMethods(Object theProvider, Class<?> clazz) throws ConfigurationException {
    int count = 0;

    for (Method m : ReflectionUtil.getDeclaredMethods(clazz)) {
        BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(),
                theProvider);// w w w. j a  va 2s  .  co m
        if (foundMethodBinding == null) {
            continue;
        }

        count++;

        if (foundMethodBinding instanceof ConformanceMethodBinding) {
            myServerConformanceMethod = foundMethodBinding;
            continue;
        }

        if (!Modifier.isPublic(m.getModifiers())) {
            throw new ConfigurationException(
                    "Method '" + m.getName() + "' is not public, FHIR RESTful methods must be public");
        } else {
            if (Modifier.isStatic(m.getModifiers())) {
                throw new ConfigurationException(
                        "Method '" + m.getName() + "' is static, FHIR RESTful methods must not be static");
            } else {
                ourLog.debug("Scanning public method: {}#{}", theProvider.getClass(), m.getName());

                String resourceName = foundMethodBinding.getResourceName();
                ResourceBinding resourceBinding;
                if (resourceName == null) {
                    resourceBinding = myServerBinding;
                } else {
                    RuntimeResourceDefinition definition = getFhirContext().getResourceDefinition(resourceName);
                    if (myResourceNameToBinding.containsKey(definition.getName())) {
                        resourceBinding = myResourceNameToBinding.get(definition.getName());
                    } else {
                        resourceBinding = new ResourceBinding();
                        resourceBinding.setResourceName(resourceName);
                        myResourceNameToBinding.put(resourceName, resourceBinding);
                    }
                }

                List<Class<?>> allowableParams = foundMethodBinding.getAllowableParamAnnotations();
                if (allowableParams != null) {
                    for (Annotation[] nextParamAnnotations : m.getParameterAnnotations()) {
                        for (Annotation annotation : nextParamAnnotations) {
                            Package pack = annotation.annotationType().getPackage();
                            if (pack.equals(IdParam.class.getPackage())) {
                                if (!allowableParams.contains(annotation.annotationType())) {
                                    throw new ConfigurationException("Method[" + m.toString()
                                            + "] is not allowed to have a parameter annotated with "
                                            + annotation);
                                }
                            }
                        }
                    }
                }

                resourceBinding.addMethod(foundMethodBinding);
                ourLog.debug(" * Method: {}#{} is a handler", theProvider.getClass(), m.getName());
            }
        }
    }

    return count;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

@Override
public PrismSchema findSchemaByCompileTimeClass(@NotNull Class<?> compileTimeClass) {
    Package compileTimePackage = compileTimeClass.getPackage();
    if (compileTimePackage == null) {
        return null; // e.g. for arrays
    }/*from   w w w  .j ava  2 s.  c  o m*/
    for (SchemaDescription desc : schemaDescriptions) {
        if (compileTimePackage.equals(desc.getCompileTimeClassesPackage())) {
            return desc.getSchema();
        }
    }
    return null;
}

From source file:org.javaan.model.CallGraph.java

private void addUsageOfPackage(Method caller, Method callee) {
    Package packageOfCaller = classContext.getPackageOfType(caller.getType());
    Package packageOfCallee = classContext.getPackageOfType(callee.getType());
    if (packageOfCaller.equals(packageOfCallee)) {
        return;/*from   w  w  w .j  a v  a 2 s  .  c om*/
    }
    Dependency.addDependency(usageOfPackage, packageOfCaller, packageOfCallee, callee);
}

From source file:org.javaan.model.CallGraph.java

/**
 * For each type contained in package retrieves the leave used types.
 * Returns set of packages of these leave types.
 *//*from  www.ja  v  a  2s .  c o  m*/
public Set<Package> getLeafUsedPackages(Package using) {
    Set<Type> usedTypes = new HashSet<>();
    Set<Type> typesOfPackage = classContext.getTypesOfPackage(using);
    for (Type type : typesOfPackage) {
        usedTypes.addAll(getLeafUsedTypes(type));
    }
    Set<Package> usedPackages = new HashSet<>();
    for (Type type : usedTypes) {
        Package used = classContext.getPackageOfType(type);
        if (!used.equals(using)) {
            usedPackages.add(used);
        }
    }
    return usedPackages;
}

From source file:org.javaan.model.CallGraph.java

/**
 * For each type contained in package retrieves the leave using types.
 * Returns set of packages of these leave types.
 *//*w  w w  . j  ava2  s . c  om*/
public Set<Package> getLeafUsingPackages(Package used) {
    Set<Type> usingTypes = new HashSet<>();
    Set<Type> typesOfPackage = classContext.getTypesOfPackage(used);
    for (Type type : typesOfPackage) {
        usingTypes.addAll(getLeafUsingTypes(type));
    }
    Set<Package> usingPackages = new HashSet<>();
    for (Type type : usingTypes) {
        Package using = classContext.getPackageOfType(type);
        if (!used.equals(using)) {
            usingPackages.add(using);
        }
    }
    return usingPackages;
}