KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > csiv2 > CSIv2Policy


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.csiv2;
23
24 import org.omg.CORBA.LocalObject JavaDoc;
25 import org.omg.CORBA.Policy JavaDoc;
26 import org.omg.CORBA.ORB JavaDoc;
27
28 import org.omg.IOP.Codec JavaDoc;
29 import org.omg.IOP.TaggedComponent JavaDoc;
30
31 import org.jboss.iiop.CorbaORBService;
32 import org.jboss.logging.Logger;
33 import org.jboss.metadata.IorSecurityConfigMetaData;
34
35 /**
36  * Implements <code>org.omg.CORBA.Policy</code> objects containing
37  * csiv2 ior security config info
38  *
39  * @author Dimitris.Andreadis@jboss.org
40  * @version $Revision: 37459 $
41  */

42 public class CSIv2Policy
43    extends LocalObject JavaDoc
44    implements Policy JavaDoc
45 {
46    // Static -----------------------------------------------------------------
47
private static final Logger log = Logger.getLogger(CSIv2Policy.class);
48    
49    // TODO: contact request@omg.org to get a policy type
50
public static final int TYPE = 0x87654321;
51    
52    // Private -----------------------------------------------------------------
53
private TaggedComponent JavaDoc sslTaggedComponent;
54    private TaggedComponent JavaDoc secTaggedComponent;
55    
56    // Constructor -------------------------------------------------------------
57
public CSIv2Policy(TaggedComponent JavaDoc sslTaggedComponent,
58                       TaggedComponent JavaDoc secTaggedComponent)
59    {
60       this.sslTaggedComponent = sslTaggedComponent;
61       this.secTaggedComponent = secTaggedComponent;
62    }
63    
64    public CSIv2Policy(IorSecurityConfigMetaData metadata, Codec JavaDoc codec)
65    {
66       log.debug(metadata);
67       
68       // convert the ior metadata to a cached security tagged component
69

70       try {
71          // get the singleton orb
72
ORB JavaDoc orb = ORB.init();
73
74          this.sslTaggedComponent =
75             CSIv2Util.createSSLTaggedComponent(
76                metadata,
77                codec,
78                CorbaORBService.getTheActualSSLPort(),
79                orb);
80
81          this.secTaggedComponent =
82             CSIv2Util.createSecurityTaggedComponent(
83                metadata,
84                codec,
85                CorbaORBService.getTheActualSSLPort(),
86                orb);
87       }
88       catch (Exception JavaDoc e) {
89          throw new RuntimeException JavaDoc("Unexpected exception " + e);
90       }
91    }
92
93    /**
94     * Return a copy of the cached SSL TaggedComponent
95    **/

96    public TaggedComponent JavaDoc getSSLTaggedComponent()
97    {
98       return CSIv2Util.createCopy(this.sslTaggedComponent);
99    }
100    
101    /**
102     * Return a copy of the cached CSI TaggedComponent
103    **/

104    public TaggedComponent JavaDoc getSecurityTaggedComponent()
105    {
106       return CSIv2Util.createCopy(this.secTaggedComponent);
107    }
108    
109    // org.omg.CORBA.Policy operations -----------------------------------------
110
/**
111     * Returns a copy of the Policy object.
112     */

113    public Policy JavaDoc copy()
114    {
115       return new CSIv2Policy(getSSLTaggedComponent(),
116                              getSecurityTaggedComponent());
117    }
118    
119    /**
120     * Destroys the Policy object.
121     */

122    public void destroy()
123    {
124       this.sslTaggedComponent = null;
125       this.secTaggedComponent = null;
126    }
127
128    /**
129     * Returns the constant value that corresponds to the type of the policy
130     * object.
131     */

132    public int policy_type()
133    {
134       return TYPE;
135    }
136
137     public String JavaDoc toString()
138     {
139         return "CSIv2Policy[" + this.sslTaggedComponent + ", "
140                               + this.secTaggedComponent + "]";
141     }
142 }
143
Popular Tags