felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard S. Hall" <he...@ungoverned.org>
Subject Re: OBR: discover resources who have a particular host
Date Fri, 23 Aug 2013 13:34:34 GMT
It appears that RepositoryAdmin.discoverResources(filterStr) pretty much 
does the same thing as your code below, no?

     public synchronized Resource[] discoverResources(String filterExpr) throws InvalidSyntaxException
     {
         initialize();

         Filter filter = filterExpr != null ? m_helper.filter(filterExpr) : null;
         Resource[] resources;
         MapToDictionary dict = new MapToDictionary(null);
         Repository[] repos = listRepositories();
         List matchList = new ArrayList();
         for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++)
         {
             resources = repos[repoIdx].getResources();
             for (int resIdx = 0; (resources != null) && (resIdx < resources.length);
resIdx++)
             {
                 dict.setSourceMap(resources[resIdx].getProperties());
                 if (filter == null || filter.match(dict))
                 {
                     matchList.add(resources[resIdx]);
                 }
             }
         }

         // Convert matching resources to an array an sort them by name.
         resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
         Arrays.sort(resources, m_nameComparator);
         return resources;
     }

-> richard


On 8/23/13 09:16 , Roland wrote:
> I can show you my workaround to illustrate what I mean:
>
>        ...
>        repository = repoAdmin.addRepository(obrfile.toURI().toURL());
>        resources = repository.getResources();
>        for(Resource resource : resources) {
>          Capability[] capabilities = resource.getCapabilities();
>          for(Capability capability : capabilities) {
>            if(capability.getName().equals("fragment")) {
>              Map<String,Object> properties = capability.getPropertiesAsMap();
>              if(properties.containsKey("host")) {
>                Object value = capability.getPropertiesAsMap().get("host");
>                if(value instanceof String) {
>                  if(hostsymbolicname.equals(value)) {
>                    discoveredresources.add(resource);
>                  }
>                }
>              }
>            }
>          }
>        }
>        ...
>
> ...but it would be fine if it looks like this:
>
>      String filter = "(host=my.host)";
>      repoAdmin.discoverResources(filter);
>
>
> Regards
> Roland
>
>
>
> --
> View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-which-have-a-particular-host-tp5004680p5004686.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message