| 1 | /* | 
| 2 | *  jDTAUS Core RI Client Container | 
| 3 | *  Copyright (C) 2005 Christian Schulte | 
| 4 | *  <cs@schulte.it> | 
| 5 | * | 
| 6 | *  This library is free software; you can redistribute it and/or | 
| 7 | *  modify it under the terms of the GNU Lesser General Public | 
| 8 | *  License as published by the Free Software Foundation; either | 
| 9 | *  version 2.1 of the License, or any later version. | 
| 10 | * | 
| 11 | *  This library is distributed in the hope that it will be useful, | 
| 12 | *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 13 | *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 14 | *  Lesser General Public License for more details. | 
| 15 | * | 
| 16 | *  You should have received a copy of the GNU Lesser General Public | 
| 17 | *  License along with this library; if not, write to the Free Software | 
| 18 | *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| 19 | * | 
| 20 | */ | 
| 21 | package org.jdtaus.core.container.ri.client; | 
| 22 |  | 
| 23 | import java.util.HashMap; | 
| 24 | import java.util.Map; | 
| 25 | import org.jdtaus.core.container.Dependency; | 
| 26 | import org.jdtaus.core.container.Implementation; | 
| 27 | import org.jdtaus.core.container.Messages; | 
| 28 | import org.jdtaus.core.container.Properties; | 
| 29 |  | 
| 30 | /** | 
| 31 | * Instance meta-data. | 
| 32 | * | 
| 33 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> | 
| 34 | * @version $JDTAUS: Instance.java 8641 2012-09-27 06:45:17Z schulte $ | 
| 35 | */ | 
| 36 | class Instance | 
| 37 | { | 
| 38 |  | 
| 39 | /** Scope the instance applies to. */ | 
| 40 | private int scope; | 
| 41 |  | 
| 42 | /** Class name of the instance. */ | 
| 43 | private String className; | 
| 44 |  | 
| 45 | /** Model version of the instance. */ | 
| 46 | private String modelVersion; | 
| 47 |  | 
| 48 | /** Name of the module defining the instance. */ | 
| 49 | private String moduleName; | 
| 50 |  | 
| 51 | /** Map of dependency objects of the instance. */ | 
| 52 | private Map dependencies; | 
| 53 |  | 
| 54 | /** Implementation meta-data of the instance. */ | 
| 55 | private Implementation implementation; | 
| 56 |  | 
| 57 | /** Dependency meta-data of the instance. */ | 
| 58 | private Dependency dependency; | 
| 59 |  | 
| 60 | /** The classloader loading the instance. */ | 
| 61 | private ClassLoader classLoader; | 
| 62 |  | 
| 63 | public Instance( final ClassLoader classLoader, final int scope, | 
| 64 | final String className, final String modelVersion, | 
| 65 | final String moduleName ) | 
| 66 | { | 
| 67 | this.classLoader = classLoader; | 
| 68 | this.scope = scope; | 
| 69 | this.className = className; | 
| 70 | this.modelVersion = modelVersion; | 
| 71 | this.moduleName = moduleName; | 
| 72 | } | 
| 73 |  | 
| 74 | public ClassLoader getClassLoader() | 
| 75 | { | 
| 76 | return this.classLoader; | 
| 77 | } | 
| 78 |  | 
| 79 | public int getScope() | 
| 80 | { | 
| 81 | return this.scope; | 
| 82 | } | 
| 83 |  | 
| 84 | public String getClassName() | 
| 85 | { | 
| 86 | return this.className; | 
| 87 | } | 
| 88 |  | 
| 89 | public String getModelVersion() | 
| 90 | { | 
| 91 | return this.modelVersion; | 
| 92 | } | 
| 93 |  | 
| 94 | public String getModuleName() | 
| 95 | { | 
| 96 | return this.moduleName; | 
| 97 | } | 
| 98 |  | 
| 99 | public Implementation getImplementation() | 
| 100 | { | 
| 101 | return this.implementation; | 
| 102 | } | 
| 103 |  | 
| 104 | public void setImplementation( final Implementation implementation ) | 
| 105 | { | 
| 106 | this.implementation = implementation; | 
| 107 | } | 
| 108 |  | 
| 109 | public Dependency getDependency() | 
| 110 | { | 
| 111 | return this.dependency; | 
| 112 | } | 
| 113 |  | 
| 114 | public void setDependency( final Dependency dependency ) | 
| 115 | { | 
| 116 | this.dependency = dependency; | 
| 117 | } | 
| 118 |  | 
| 119 | public Properties getProperties() | 
| 120 | { | 
| 121 | Properties properties = null; | 
| 122 |  | 
| 123 | if ( this.implementation != null ) | 
| 124 | { | 
| 125 | properties = this.implementation.getProperties(); | 
| 126 | } | 
| 127 | else if ( this.dependency != null ) | 
| 128 | { | 
| 129 | properties = this.dependency.getProperties(); | 
| 130 | } | 
| 131 |  | 
| 132 | return properties; | 
| 133 | } | 
| 134 |  | 
| 135 | public Messages getMessages() | 
| 136 | { | 
| 137 | Messages messages = null; | 
| 138 |  | 
| 139 | if ( this.implementation != null ) | 
| 140 | { | 
| 141 | messages = this.implementation.getMessages(); | 
| 142 | } | 
| 143 | else if ( this.dependency != null ) | 
| 144 | { | 
| 145 | messages = this.dependency.getImplementation().getMessages(); | 
| 146 | } | 
| 147 |  | 
| 148 | return messages; | 
| 149 | } | 
| 150 |  | 
| 151 | public Object getDependencyObject( | 
| 152 | final String dependencyName ) | 
| 153 | { | 
| 154 | if ( this.dependencies == null ) | 
| 155 | { | 
| 156 | this.dependencies = new HashMap(); | 
| 157 | } | 
| 158 |  | 
| 159 | return this.dependencies.get( dependencyName ); | 
| 160 | } | 
| 161 |  | 
| 162 | public void setDependencyObject( final String dependencyName, | 
| 163 | final Object object ) | 
| 164 | { | 
| 165 | if ( this.dependencies == null ) | 
| 166 | { | 
| 167 | this.dependencies = new HashMap(); | 
| 168 | } | 
| 169 |  | 
| 170 | this.dependencies.put( dependencyName, object ); | 
| 171 | } | 
| 172 |  | 
| 173 | } |