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; 17 18 import java.util.Collection; 19 20 import fulmine.IDomain; 21 import fulmine.ILifeCycle; 22 import fulmine.IType; 23 import fulmine.context.IFrameworkContext; 24 import fulmine.distribution.IDistributionManager; 25 import fulmine.event.listener.IEventListener; 26 import fulmine.model.container.ContainerFactory; 27 import fulmine.model.container.IContainer; 28 import fulmine.model.container.IContainerFactory; 29 30 /** 31 * Manages the data model structures in a context. The data structures are held 32 * in {@link IContainer} instances. These may be either local or remote 33 * instances. 34 * 35 * @see IFrameworkContext 36 * @author Ramon Servadei 37 */ 38 public interface IModelManager extends ILifeCycle 39 { 40 41 /** 42 * Get the container factory for the context. This factory is bound to this 43 * context. 44 * 45 * @return the container factory for the context 46 */ 47 IContainerFactory getContainerFactory(); 48 49 /** 50 * Get a <b>copy</b> of the collection of local containers in this context. 51 * 52 * @return a <b>copy</b> of the collection of all the local containers in 53 * this context 54 */ 55 Collection<IContainer> getLocalContainers(); 56 57 /** 58 * Get the identified local container. This container is native to this 59 * context. If it does not exist, it is created using the 60 * {@link ContainerFactory}. 61 * <p> 62 * If the {@link ContainerFactory} does not have a 63 * {@link IContainerFactory.IContainerBuilder} registered for the type 64 * argument, a standard container is created. 65 * <p> 66 * <b>This operation does not support any wildcards for the attributes (it 67 * does not have the same contract for the identity, type and domain as 68 * {@link IDistributionManager#subscribe(String, String, IType, IDomain, IEventListener)} 69 * .</b> 70 * 71 * @param identity 72 * the identity of the local container 73 * @param type 74 * the type of the local container 75 * @param domain 76 * the domain of the local container 77 * 78 * @return a {@link IContainer} native to this context and hosted in this 79 * context 80 */ 81 IContainer getLocalContainer(String identity, IType type, IDomain domain); 82 83 /** 84 * Identify if the local container exists in this context 85 * 86 * @param type 87 * the type of the container to find 88 * @param domain 89 * the domain of the container 90 * @param identity 91 * the identity of the local container to find 92 * 93 * @return <code>true</code> if the local container exists 94 */ 95 boolean containsLocalContainer(String identityRegularExpression, 96 IType type, IDomain domain); 97 98 /** 99 * Get the identified remote container. <u>This container is not native to 100 * this context.</u> If it does not exist, it is created using the 101 * {@link ContainerFactory} and its state is set to be 102 * {@link IContainer#STALE} until it receives an update. 103 * <p> 104 * This method just creates the 'proxy shell' for the remote events to be 105 * applied to. Use the 106 * {@link IDistributionManager#subscribe(String, String, IType, IDomain, IEventListener)} 107 * method to start receiving events for the container. 108 * <p> 109 * <b>This operation does not support any wildcards for the attributes (it 110 * does not have the same contract for the identity, type and domain as 111 * {@link IDistributionManager#subscribe(String, String, IType, IDomain, IEventListener)} 112 * .</b> 113 * 114 * @param remoteContextIdentity 115 * the identity of the remote context where the remote container 116 * originates from - this is only required if the remote 117 * container will be created. Use 118 * {@link #containsRemoteContainer(String, String, IType, IDomain)} 119 * to determine if the remote container exists. 120 * @param identity 121 * the identity of the remote container 122 * @param type 123 * the type of the remote container 124 * @param domain 125 * the domain of the remote container 126 * 127 * @return a {@link IContainer} native to the specified remote context and 128 * hosted in this context 129 */ 130 IContainer getRemoteContainer(String remoteContextIdentity, 131 String containerIdentity, IType type, IDomain domain); 132 133 /** 134 * Identify if the remote container exists in this context 135 * 136 * @param remoteContextIdentity 137 * the identity of the remote context where the remote container 138 * originated from 139 * @param type 140 * the type of the container to find 141 * @param domain 142 * the domain of the container 143 * @param identity 144 * the identity of the remote container to find 145 * 146 * @return <code>true</code> if the remote container exists 147 */ 148 boolean containsRemoteContainer(String remoteContextIdentity, 149 String containerIdentity, IType type, IDomain domain); 150 151 /** 152 * Get a <b>copy</b> of the collection of remote containers in this context. 153 * 154 * @param remoteContextIdentity 155 * the remote context identity that the remote containers 156 * originated from 157 * 158 * @return a <b>copy</b> of the collection of all the remote containers in 159 * this context 160 */ 161 Collection<IContainer> getRemoteContainers(String remoteContextIdentity); 162 163 /** 164 * Add a container to this context. 165 * 166 * @param container 167 * the container to add to this context 168 */ 169 void addContainer(IContainer container); 170 171 /** 172 * Remove a container from the context. This does not destroy the container 173 * but may leave the container with no references to it and thus it may be 174 * garbage collected. 175 * 176 * @param container 177 * the container to remove 178 * @return <code>true</code> if the container was removed, 179 * <code>false</code> if the container was not found 180 */ 181 boolean removeContainer(IContainer container); 182 183 }