/[classpath]/classpath/gnu/CORBA/GIOP/ServiceContext.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/GIOP/ServiceContext.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.2 by gnu_andrew, Tue Aug 2 20:12:08 2005 UTC revision 1.1.2.3 by gnu_andrew, Sat Sep 10 15:31:35 2005 UTC
# Line 41  package gnu.CORBA.GIOP; Line 41  package gnu.CORBA.GIOP;
41  import gnu.CORBA.CDR.cdrInput;  import gnu.CORBA.CDR.cdrInput;
42  import gnu.CORBA.CDR.cdrOutput;  import gnu.CORBA.CDR.cdrOutput;
43    
44    import org.omg.CORBA.BAD_INV_ORDER;
45    import org.omg.CORBA.BAD_PARAM;
46    import org.omg.CORBA.CompletionStatus;
47  import org.omg.CORBA.portable.IDLEntity;  import org.omg.CORBA.portable.IDLEntity;
48    
49  /**  /**
# Line 53  public class ServiceContext Line 55  public class ServiceContext
55    implements IDLEntity    implements IDLEntity
56  {  {
57    /**    /**
58     * The context data.     * Use serialVersionUID for interoperability.
59     */     */
60    public byte[] context_data;    private static final long serialVersionUID = 1;
61    
62    /**    /**
63     * The context id.     * The context id (for instance, 0x1 for code sets context). At the moment of
64       * writing, the OMG defines 16 standard values and provides rules to register
65       * the vendor specific context ids. The range 0-4095 is reserved for the
66       * future standard OMG contexts.
67     */     */
68    public int context_id;    public int context_id;
69    
70    /**    /**
71       * The context_data.
72       */
73      public byte[] context_data;
74    
75      /**
76       * Crete unitialised instance.
77       */
78      public ServiceContext()
79      {
80      }
81    
82      /**
83       * Create from omg context.
84       */
85      public ServiceContext(org.omg.IOP.ServiceContext from)
86      {
87        context_id = from.context_id;
88        context_data = from.context_data;
89      }
90    
91      /**
92     * Read the context values from the stream.     * Read the context values from the stream.
93     *     *
94     * @param istream a stream to read from.     * @param istream a stream to read from.
# Line 73  public class ServiceContext Line 99  public class ServiceContext
99    
100      switch (id)      switch (id)
101        {        {
102          case cxCodeSet.ID :          case cxCodeSet.ID:
103    
104            cxCodeSet codeset = new cxCodeSet();            cxCodeSet codeset = new cxCodeSet();
105            codeset.readContext(istream);            codeset.readContext(istream);
106            return codeset;            return codeset;
107    
108          default :          default:
109    
110            ServiceContext ctx = new ServiceContext();            ServiceContext ctx = new ServiceContext();
111            ctx.context_id = id;            ctx.context_id = id;
# Line 94  public class ServiceContext Line 120  public class ServiceContext
120    public static ServiceContext[] readSequence(cdrInput istream)    public static ServiceContext[] readSequence(cdrInput istream)
121    {    {
122      int size = istream.read_long();      int size = istream.read_long();
123      ServiceContext[] value = new gnu.CORBA.GIOP.ServiceContext[ size ];      ServiceContext[] value = new gnu.CORBA.GIOP.ServiceContext[size];
124      for (int i = 0; i < value.length; i++)      for (int i = 0; i < value.length; i++)
125        value [ i ] = read(istream);        value[i] = read(istream);
126      return value;      return value;
127    }    }
128    
# Line 118  public class ServiceContext Line 144  public class ServiceContext
144    {    {
145      ostream.write_long(value.length);      ostream.write_long(value.length);
146      for (int i = 0; i < value.length; i++)      for (int i = 0; i < value.length; i++)
147        value [ i ].write(ostream);        value[i].write(ostream);
148      }
149    
150      /**
151       * Add context to the given array of contexts.
152       */
153      public static void add(org.omg.IOP.ServiceContext[] cx,
154        org.omg.IOP.ServiceContext service_context, boolean replace)
155      {
156        int exists = -1;
157    
158        for (int i = 0; i < cx.length; i++)
159          if (cx[i].context_id == service_context.context_id)
160            exists = i;
161    
162        if (exists < 0)
163          {
164            // Add context.
165            org.omg.IOP.ServiceContext[] n = new org.omg.IOP.ServiceContext[cx.length + 1];
166            for (int i = 0; i < cx.length; i++)
167              n[i] = cx[i];
168            n[cx.length] = service_context;
169          }
170        else
171          {
172            // Replace context.
173            if (!replace)
174              throw new BAD_INV_ORDER("Repetetive setting of the context "
175                                      + service_context.context_id, 15,
176                CompletionStatus.COMPLETED_NO);
177            else
178              cx[exists] = service_context;
179          }
180      }
181    
182      /**
183       * Add context to the given array of contexts.
184       */
185      public static ServiceContext[] add(ServiceContext[] cx,
186        org.omg.IOP.ServiceContext service_context, boolean replace)
187      {
188        int exists = -1;
189    
190        for (int i = 0; i < cx.length; i++)
191          if (cx[i].context_id == service_context.context_id)
192            exists = i;
193    
194        if (exists < 0)
195          {
196            // Add context.
197            ServiceContext[] n = new ServiceContext[cx.length + 1];
198            for (int i = 0; i < cx.length; i++)
199              n[i] = cx[i];
200            n[cx.length] = new ServiceContext(service_context);
201            return n;
202          }
203        else
204          {
205            // Replace context.
206            if (!replace)
207              throw new BAD_INV_ORDER("Repetetive setting of the context "
208                                      + service_context.context_id, 15,
209                CompletionStatus.COMPLETED_NO);
210            else
211              cx[exists] = new ServiceContext(service_context);
212            return cx;
213          }
214      }
215    
216    
217      /**
218       * Find context with the given name in the context array.
219       */
220      public static org.omg.IOP.ServiceContext findContext(int ctx_name,
221        org.omg.IOP.ServiceContext[] cx)
222      {
223        for (int i = 0; i < cx.length; i++)
224          if (cx[i].context_id == ctx_name)
225            return cx[i];
226        throw new BAD_PARAM("No context with id " + ctx_name);
227      }
228    
229      /**
230       * Find context with the given name in the context array,
231       * converting into org.omg.IOP.ServiceContext.
232       */
233      public static org.omg.IOP.ServiceContext findContext(int ctx_name,
234        ServiceContext[] cx)
235      {
236        for (int i = 0; i < cx.length; i++)
237          if (cx[i].context_id == ctx_name)
238            return new org.omg.IOP.ServiceContext(ctx_name, cx[i].context_data);
239        throw new BAD_PARAM("No context with id " + ctx_name);
240    }    }
241    
242    /**    /**
# Line 126  public class ServiceContext Line 244  public class ServiceContext
244     */     */
245    public String toString()    public String toString()
246    {    {
247      return "ctx "+context_id+", size "+context_data.length;      return "ctx " + context_id + ", size " + context_data.length;
248    }    }
249  }  }

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26