1 /* 2 Copyright 2007 Ramon Servadei 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package fulmine.model.container.impl; 17 18 import fulmine.IDomain; 19 import fulmine.IType; 20 import fulmine.Type; 21 import fulmine.context.IFrameworkContext; 22 import fulmine.model.container.AbstractDynamicContainer; 23 import fulmine.model.container.ContainerFactory; 24 import fulmine.model.container.IContainerFactory; 25 import fulmine.model.field.containerdefinition.IContainerDefinitionField; 26 import fulmine.util.log.AsyncLog; 27 28 /** 29 * This is a dynamic container implementation. This implementation is thread 30 * safe. 31 * <p> 32 * A record can be used as a base-class or as an outright class. If used 33 * outright, it serves as a general purpose data construct that can be used in 34 * the event distribution framework with no extra user code required other than 35 * to populate the record. It is safe to simply construct the record instances 36 * using the {@link Record#Record(String)} constructor when used as a dynamic, 37 * general purpose, construct. 38 * <p> 39 * When used as a base-class, user code is required if the record sub-class is 40 * to participate in the event distribution framework. The appropriate user 41 * coded {@link IContainerFactory.IContainerBuilder} must be registered via the 42 * {@link ContainerFactory} for the record sub-class in the remote fulmine 43 * context instance. If this is not performed, the remote context will default 44 * to creating a standard record instance. Instances must also only be created 45 * using the {@link ContainerFactory#createContainer(String, int)} method. 46 * <p> 47 * A record can also be used as the base-class for a static container 48 * implementation. The {@link IContainerFactory.IContainerBuilder} will define 49 * the {@link IContainerDefinitionField}. The same base-class rules described in 50 * the preceding paragraph apply. 51 * 52 * @see ContainerFactory 53 * @author Ramon Servadei 54 */ 55 public class Record extends AbstractDynamicContainer 56 { 57 58 private final static AsyncLog LOG = new AsyncLog(Record.class); 59 60 /** 61 * Type specific constructor that allows the record to be constructed with a 62 * user defined type. By default, the {@link ContainerFactory} will 63 * construct a {@link Record} if no 64 * {@link IContainerFactory.IContainerBuilder} has been registered. This 65 * should be fine for use cases where a dynamic record of this type is 66 * required. When a static record of this type is required, a builder has to 67 * be registered in the remote context against the type argument, otherwise 68 * a dynamic version will be created. 69 * 70 * @param nativeContextIdentity 71 * the name of the context this record is native to; the name of 72 * its local context 73 * @param identity 74 * the identity for the record 75 * @param type 76 * the integer type for this record, must commence from 77 * {@link Type#RECORD}) 78 * @param domain 79 * the domain for the record 80 * @param hostContext 81 * the context hosting this record instance 82 * @param local 83 * <code>true</code> the container is local to this context 84 */ 85 public Record(String nativeContextIdentity, String identity, IType type, 86 IDomain domain, IFrameworkContext hostContext, boolean local) 87 { 88 super(nativeContextIdentity, identity, type, domain, hostContext, local); 89 if (type.value() != Type.SYSTEM.value() 90 && type.value() < Type.RECORD.value()) 91 { 92 throw new IllegalArgumentException("Types must start after " 93 + Type.RECORD + ", type was " + type); 94 } 95 } 96 97 @Override 98 protected AsyncLog getLog() 99 { 100 return LOG; 101 } 102 }