KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ir > ContainedImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.rmi.ir;
23
24 import org.omg.CORBA.ContainedPackage.Description;
25 import org.omg.CORBA.DefinitionKind JavaDoc;
26 import org.omg.CORBA.Container JavaDoc;
27 import org.omg.CORBA.ContainerHelper;
28 import org.omg.CORBA.Repository JavaDoc;
29 import org.omg.CORBA.RepositoryHelper;
30 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
31
32 import java.io.UnsupportedEncodingException JavaDoc;
33
34
35 /**
36  * Abstract base class for all contained IR entities.
37  *
38  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
39  * @version $Revision: 37459 $
40  */

41 abstract class ContainedImpl
42    extends IRObjectImpl
43    implements LocalContained
44 {
45    // Constants -----------------------------------------------------
46

47    // Attributes ----------------------------------------------------
48

49    // Static --------------------------------------------------------
50

51    private static final org.jboss.logging.Logger logger =
52                org.jboss.logging.Logger.getLogger(ContainedImpl.class);
53
54    // Constructors --------------------------------------------------
55

56    ContainedImpl(String JavaDoc id, String JavaDoc name, String JavaDoc version,
57                  LocalContainer defined_in,
58                  DefinitionKind JavaDoc def_kind, RepositoryImpl repository)
59    {
60       super(def_kind, repository);
61       this.id = id;
62       this.name = name;
63       this.version = version;
64       this.defined_in = defined_in;
65
66       if (defined_in instanceof LocalContained)
67         this.absolute_name = ((LocalContained)defined_in).absolute_name() +
68                              "::" + name;
69       else // must be Repository
70
this.absolute_name = "::" + name;
71    }
72
73    // Public --------------------------------------------------------
74

75    // Z implementation ----------------------------------------------
76

77    public java.lang.String JavaDoc id()
78    {
79       logger.trace("ContainedImpl[" + id + "].id() entered.");
80       return id;
81    }
82
83    public void id(java.lang.String JavaDoc id)
84    {
85       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
86    }
87
88    public java.lang.String JavaDoc name()
89    {
90       logger.trace("ContainedImpl[" + id + "].name() entered.");
91       return name;
92    }
93
94    public void name(java.lang.String JavaDoc name)
95    {
96       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
97    }
98
99    public java.lang.String JavaDoc version()
100    {
101       logger.trace("ContainedImpl[" + id + "].version() entered.");
102       return version;
103    }
104
105    public void version(java.lang.String JavaDoc version)
106    {
107       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
108    }
109
110    public Container JavaDoc defined_in()
111    {
112       logger.debug("ContainedImpl[" + id + "].defined_in() entered.");
113       return ContainerHelper.narrow(defined_in.getReference());
114    }
115
116    public java.lang.String JavaDoc absolute_name()
117    {
118       logger.trace("ContainedImpl[" + id + "].absolute_name() returning \"" +
119                    absolute_name + "\".");
120       return absolute_name;
121    }
122
123    public Repository JavaDoc containing_repository()
124    {
125       logger.debug("ContainedImpl[" + id +
126                    "].containing_repository() entered.");
127       return RepositoryHelper.narrow(repository.getReference());
128    }
129
130    public abstract Description describe();
131
132    public void move(Container JavaDoc new_container,
133                     String JavaDoc new_name, String JavaDoc new_version)
134    {
135       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
136    }
137
138    // Y overrides ---------------------------------------------------
139

140    // Package protected ---------------------------------------------
141

142    // Protected -----------------------------------------------------
143

144    /**
145     * The global repository ID of this object.
146     */

147    protected String JavaDoc id;
148
149    /**
150     * The name of this object within its container.
151     */

152    protected String JavaDoc name;
153
154    /**
155     * The version of this object. Defaults to 1.0.
156     */

157    protected String JavaDoc version = "1.0";
158
159    /**
160     * The container this is defined in.
161     * This may not be the same as the container this is contained in.
162     */

163    protected LocalContainer defined_in;
164
165    /**
166     * The absolute name of this object.
167     */

168    protected String JavaDoc absolute_name;
169
170
171    /**
172     * Return the POA object ID of this IR object.
173     * Contained objects use the UTF-8 encoding of their id, prefixed by
174     * "repository_name:".
175     */

176    protected byte[] getObjectId()
177    {
178       try {
179          return (getRepository().getObjectIdPrefix() + id).getBytes("UTF-8");
180       } catch (UnsupportedEncodingException JavaDoc ex) {
181          throw new RuntimeException JavaDoc("UTF-8 encoding not supported.");
182       }
183    }
184
185    // Private -------------------------------------------------------
186

187    // Inner classes -------------------------------------------------
188
}
189
Popular Tags