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: Introduce a type registry as a si...
Date Mon, 02 Nov 2015 13:57:19 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/993#discussion_r43629895
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
---
    @@ -0,0 +1,152 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.core.typereg;
    +
    +import groovy.xml.Entity;
    +
    +import java.util.Set;
    +
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
    +import org.apache.brooklyn.api.objs.BrooklynObject;
    +import org.apache.brooklyn.api.objs.BrooklynObjectType;
    +import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
    +import org.apache.brooklyn.api.typereg.RegisteredTypeConstraint;
    +import org.apache.brooklyn.util.collections.MutableSet;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.google.common.collect.ImmutableSet;
    +
    +public class RegisteredTypeConstraints {
    +
    +    private static final Logger log = LoggerFactory.getLogger(RegisteredTypeConstraints.BasicRegisteredTypeConstraint.class);
    +    
    +    public final static class BasicRegisteredTypeConstraint implements RegisteredTypeConstraint
{
    +        private RegisteredTypeKind kind;
    +        private Class<?> javaSuperType;
    +        private Set<String> encounteredTypes;
    +        
    +        private BasicRegisteredTypeConstraint() {}
    +        
    +        public BasicRegisteredTypeConstraint(RegisteredTypeConstraint source) {
    +            if (source==null) return;
    +            
    +            this.kind = source.getKind();
    +            this.javaSuperType = source.getJavaSuperType();
    +            this.encounteredTypes = source.getEncounteredTypes();
    +        }
    +
    +        @Override
    +        public RegisteredTypeKind getKind() {
    +            return kind;
    +        }
    +        
    +        @Override
    +        public Class<?> getJavaSuperType() {
    +            if (javaSuperType==null) return Object.class;
    +            return javaSuperType;
    +        }
    +
    +        @Override
    +        public Set<String> getEncounteredTypes() {
    +            if (encounteredTypes==null) return ImmutableSet.of();
    +            return ImmutableSet.<String>copyOf(encounteredTypes);
    +        }
    +        
    +        @Override
    +        public String toString() {
    +            return super.toString()+"["+kind+","+javaSuperType+","+encounteredTypes+"]";
    +        }
    +    }
    +
    +    /** returns a constraint which allows anything */
    +    public static RegisteredTypeConstraint any() {
    +        return new BasicRegisteredTypeConstraint();
    +    }
    +
    +    public static RegisteredTypeConstraint alreadyVisited(Set<String> encounteredTypeSymbolicNames)
{
    +        BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
    +        result.encounteredTypes = encounteredTypeSymbolicNames;
    +        return result;
    +    }
    +    public static RegisteredTypeConstraint alreadyVisited(Set<String> encounteredTypeSymbolicNames,
String anotherEncounteredType) {
    +        BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
    +        result.encounteredTypes = MutableSet.copyOf(encounteredTypeSymbolicNames);
    +        if (anotherEncounteredType!=null) result.encounteredTypes.add(anotherEncounteredType);
    +        return result;
    +    }
    +    
    +    private static RegisteredTypeConstraint of(RegisteredTypeKind kind, Class<? extends
BrooklynObject> javaSuperType) {
    +        BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
    +        result.kind = kind;
    +        result.javaSuperType = javaSuperType;
    +        return result;
    +    }
    +
    +    public static RegisteredTypeConstraint spec(Class<? extends BrooklynObject>
javaSuperType) {
    +        return of(RegisteredTypeKind.SPEC, javaSuperType);
    +    }
    +
    +    public static <T extends AbstractBrooklynObjectSpec<?,?>> RegisteredTypeConstraint
extendedWithSpecSuperType(RegisteredTypeConstraint source, Class<T> specSuperType) {
    +        Class<?> superType = lookupTargetTypeForSpec(specSuperType);
    +        BasicRegisteredTypeConstraint constraint = new BasicRegisteredTypeConstraint(source);
    +        if (source==null) source = constraint;
    --- End diff --
    
    Mark `source` as `@Nullable`


---
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