brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: OSGi/catalog improvements
Date Wed, 09 Jul 2014 19:57:59 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/47#discussion_r14732295
  
    --- Diff: usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
---
    @@ -168,25 +173,75 @@ protected String getJavaType() {
             
             return type;
         }
    +
    +    /** Returns the CatalogItem if there is one for the given type;
    +     * (if no type, callers should fall back to default classloading)
    +     */
    +    @Nullable
    +    public CatalogItem<Entity,EntitySpec<?>> getCatalogItem() {
    +        String type = getCatalogIdOrJavaType();
    +        if (type != null) {
    +            return loader.getManagementContext().getCatalog().getCatalogItem(Entity.class,
type);
    +        } else {
    +            return null;
    +        }
    +    }
         
    -    @SuppressWarnings("unchecked")
    -    public <T extends Entity> Class<T> loadEntityClass() {
    -        return (Class<T>) loader.type(getJavaType()).getType(Entity.class);
    +    public boolean canResolve() {
    +        if (getCatalogItem()!=null) 
    +            return true;
    +        if (loader.tryLoadClass(getCatalogIdOrJavaType(), Entity.class).isPresent())
    +            return true;
    +        return false;
         }
     
    -    public <T extends Entity> EntitySpec<T> resolveSpec() {
    -        return resolveSpec(this.<T>loadEntityClass(), null);
    +    /** returns the entity class, if needed in contexts which scan its statics for example
*/
    +    public Class<? extends Entity> loadEntityClass() {
    +        return tryLoadEntityClass().get();
    +    }
    +    
    +    /** tries to load the Java entity class */
    +    public Maybe<Class<? extends Entity>> tryLoadEntityClass() {
    +        CatalogItem<Entity, EntitySpec<?>> item = getCatalogItem();
    +        String typeName = getCatalogIdOrJavaType();
    +        
    +        if (item!=null) {
    +            // add additional bundles
    +            loader = new BrooklynClassLoadingContextSequential(mgmt, item.newClassLoadingContext(mgmt),
loader);
    +            
    +//            if (item.getPlanYaml()!=null) {
    +//                // TODO if yaml refers to *another* catalog item, or remote yaml reference,
or even have config
    +//                // then we will need to parse that YAML
    +//                // (but NB as it stands this code might cause infinite looping?)
    +//                CampPlatform platform = BrooklynServerConfig.getCampPlatform(mgmt).get();
    +//                AssemblyTemplate template2 = platform.pdp().registerDeploymentPlan(
new StringReader(item.getPlanYaml()) );
    +//                return ((AssemblyTemplateSpecInstantiator) template2.getInstantiator().newInstance()).createSpec(template2,
platform);
    +//            }
    --- End diff --
    
    already handled by the caller, remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message