public DependencyDescriptor getDescriptor(){ String filter = buildFilter(); return new DependencyDescriptor( myDependencyName, myDependencyClass, filter, myType); }
/** * Adds the description to the list of dependency to listen for. * @param descriptor dependency description to listen for * @throws IllegalStateException if the tracker has already been started * @throws IllegalArgumentException if the given dependencyId already exists */ public boolean addDependencyDescription(DependencyDescriptor descriptor){ if(descriptor == null){ throw new NullPointerException(); } return addDependencyDescription( descriptor.getServiceClass(), descriptor.getDependencyName(), descriptor.getServiceFilter(), descriptor.getDependencyType()); } /**
/** * Validates a DependencyDescriptor against a map of dependencies. A * descriptor is valid if there is an entry where the key and the * dependency's class matches the descriptor's fields. If there is no * dependency for the name, the descriptor is only valid if it is * optional. * If the dependecy's class does not match the descriptor, it is * invalid. * @param descriptor descriptor to check for * @param dependencies map of ids and dependencies to check against * @return true is a map entry matches the descriptor, false otherwise */ private static boolean checkDescriptor( DependencyDescriptor descriptor, Map<String,Object> dependencies){ String id = descriptor.getDependencyName(); Object req = dependencies.get(id); if(req == null){ return DependencyType.OPTIONAL == descriptor.getDependencyType(); } Class reqClass = descriptor.getServiceClass(); if(!reqClass.isAssignableFrom(req.getClass())){ return false; } return true; }
public void updateDisplay(Boolean status){ updateStatus(status); if(myDependency == null){ lblName.setText("--"); lblFilter.setText("--"); lblType.setText("--"); return; } String name = myDependency.getDependencyName(); String type = myDependency.getServiceClass().getName(); String filter = myDependency.getServiceFilter(); name = name == null ? "--" : name; type = type == null ? "--" : type; filter = filter == null ? "--" : filter; lblName.setText(name); lblFilter.setText(filter); lblType.setText(type); }
private DependencyDescriptor getRuntimeDescriptor(String name){ for(DependencyDescriptor d : myRuntimeDescriptors){ if(name.equals(d.getDependencyName())){ return d; } } return null; } }
".*" + f + ".*", Pattern.MULTILINE | Pattern.DOTALL); if(d.getDependencyName() != null && p.matcher(d.getDependencyName()).matches()){ return (myAvailability.equals("Available") && thals.isAvailable()) || !thals.isAvailable()) || myAvailability.equals("Both"); } else if(d.getServiceFilter() != null && p.matcher(d.getServiceFilter()).matches()){ return (myAvailability.equals("Available") && thals.isAvailable()) ||
/** * Validates an id and dependency against a list of * DependencyDescriptors. The id and dependency are valid if there is a * descriptor with a matching dependency id and class. * @param descriptors list of DependencyDescriptors to match against * @param dependencyId id for the dependency * @param dependency dependency to validate * @return true if a matching descriptor is found */ public static boolean validateService( List<DependencyDescriptor> descriptors, String dependencyId, Object dependency){ if(dependencyId == null || dependency == null){ theLogger.warning("Found null argument. Returning false."); return false; } for(DependencyDescriptor descriptor : descriptors){ String id = descriptor.getDependencyName(); Class reqClass = descriptor.getServiceClass(); if(dependencyId.equals(id) && reqClass.isAssignableFrom(dependency.getClass())){ return true; } } return false; }
/** * Start tracking dependencies. */ public void start(){ myListeningFlag = true; myRequiredCount = 0; for(DependencyDescriptor desc : myDependencyDescMap.values()){ if(DependencyType.REQUIRED == desc.getDependencyType()){ myRequiredCount++; } } for(SingleServiceListener ssl : myDependencyTrackers.values()){ ssl.start(); } }
public void updateDisplay(Boolean status){ updateStatus(status); if(myDependency == null){ lblName.setText("--"); lblFilter.setText("--"); lblType.setText("--"); return; } String name = myDependency.getDependencyName(); String type = myDependency.getServiceClass().getName(); String filter = myDependency.getServiceFilter(); name = name == null ? "--" : name; type = type == null ? "--" : type; filter = filter == null ? "--" : filter; lblName.setText(name); lblFilter.setText(filter); lblType.setText(type); }
public void removeDependency(DependencyDescriptor dep){ if(dep == null){ throw new NullPointerException(); } DependencyPanel panel = myPanelMap.remove(dep.getDependencyName()); if(panel == null){ return; } myPanelMap.remove(dep.getDependencyName()); remove(panel); }
".*" + f + ".*", Pattern.MULTILINE | Pattern.DOTALL); if(d.getDependencyName() != null && p.matcher(d.getDependencyName()).matches()){ return (myAvailability.equals("Available") && thals.isAvailable()) || !thals.isAvailable()) || myAvailability.equals("Both"); } else if(d.getServiceFilter() != null && p.matcher(d.getServiceFilter()).matches()){ return (myAvailability.equals("Available") && thals.isAvailable()) ||
private synchronized void dependencyChanged(String requirementId, Object req){ if(requirementId == null || req == null){ throw new NullPointerException(); }DependencyDescriptor desc = myDependencyDescMap.get(requirementId); if(desc == null){ return; }else if(DependencyType.REQUIRED == desc.getDependencyType()){ getLogger().info("Required dependency changed: {0}", requirementId); myRequiredDependencies.put(requirementId, req); }else{ getLogger().info("Optional dependency changed: {0}", requirementId); } myAvailableDependencies.put(requirementId, req); firePropertyChange(PROP_DEPENDENCY_CHANGED, requirementId, req); }
for(DependencyDescriptor dd : descriptors){ myDependenciesTracker.addDependencyDescription( dd.getServiceClass(), dd.getDependencyName(), dd.getServiceFilter(), dd.getDependencyType());
public void removeDependency(DependencyDescriptor dep){ if(dep == null){ throw new NullPointerException(); } DependencyPanel panel = myPanelMap.remove(dep.getDependencyName()); if(panel == null){ return; } myPanelMap.remove(dep.getDependencyName()); remove(panel); }
private static List<DependencyDescriptor> buildDescriptorList(SceneSpec spec){ List<String> chanURIs = getRequiredChannelURIs(spec); List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>(); for(String uri : chanURIs){ descriptors.add(new DependencyDescriptor(uri, Channel.class, OSGiUtils.createFilter(ChannelBindingLifecycle.URI_PROPERTY_NAME, uri), DependencyType.REQUIRED)); } return descriptors; }
private synchronized void dependencyLost(String requirementId){ if(requirementId == null){ throw new NullPointerException(); } DependencyDescriptor desc = myDependencyDescMap.get(requirementId); if(desc == null){ return; }else if(DependencyType.REQUIRED == desc.getDependencyType()){ myRequiredDependencies.remove(requirementId); getLogger().info("Lost required dependency: {0}", requirementId); }else{ getLogger().info("Lost optional dependency: {0}", requirementId); } myAvailableDependencies.remove(requirementId); firePropertyChange(PROP_DEPENDENCY_UNAVAILABLE, requirementId, null); }
public void updateDependnecyPanel(DependencyDescriptor dep, Boolean status){ if(dep == null){ throw new NullPointerException(); } DependencyPanel panel = myPanelMap.get(dep.getDependencyName()); if(panel == null){ return; } panel.updateDisplay(status); }
private static List<DependencyDescriptor> buildDescriptorList(SceneSpec spec){ List<String> chanURIs = getRequiredChannelURIs(spec); List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>(); for(String uri : chanURIs){ descriptors.add(new DependencyDescriptor(uri, Channel.class, OSGiUtils.createFilter(ChannelBindingLifecycle.URI_PROPERTY_NAME, uri), DependencyType.REQUIRED)); } return descriptors; }
}else if(depdendencies == null || depdendencies.isEmpty()){ for(DependencyDescriptor desc : descriptors){ if(DependencyType.REQUIRED == desc.getDependencyType()){ return false;
public void updateDependnecyPanel(DependencyDescriptor dep, Boolean status){ if(dep == null){ throw new NullPointerException(); } DependencyPanel panel = myPanelMap.get(dep.getDependencyName()); if(panel == null){ return; } panel.updateDisplay(status); }