1 23 24 package org.apache.slide.common; 25 26 import java.io.IOException ; 27 import java.io.Reader ; 28 import java.io.Writer ; 29 30 import javax.transaction.HeuristicMixedException ; 31 import javax.transaction.HeuristicRollbackException ; 32 import javax.transaction.NotSupportedException ; 33 import javax.transaction.RollbackException ; 34 import javax.transaction.SystemException ; 35 import javax.transaction.TransactionManager ; 36 import javax.xml.parsers.SAXParser ; 37 import javax.xml.parsers.SAXParserFactory ; 38 39 import org.apache.slide.content.Content; 40 import org.apache.slide.content.ContentImpl; 41 import org.apache.slide.event.EventDispatcher; 42 import org.apache.slide.event.TransactionEvent; 43 import org.apache.slide.event.VetoException; 44 import org.apache.slide.lock.Lock; 45 import org.apache.slide.lock.LockImpl; 46 import org.apache.slide.macro.Macro; 47 import org.apache.slide.macro.MacroImpl; 48 import org.apache.slide.search.Search; 49 import org.apache.slide.search.SearchImpl; 50 import org.apache.slide.security.ACLSecurityImpl; 51 import org.apache.slide.security.Security; 52 import org.apache.slide.security.SecurityImpl; 53 import org.apache.slide.security.SecurityImplAllGrant; 54 import org.apache.slide.structure.Structure; 55 import org.apache.slide.structure.StructureImpl; 56 import org.apache.slide.util.conf.Configuration; 57 import org.apache.slide.util.conf.ConfigurationElement; 58 import org.apache.slide.util.conf.ConfigurationException; 59 import org.apache.slide.util.conf.Populate; 60 import org.apache.slide.util.logger.Logger; 61 import org.xml.sax.InputSource ; 62 import org.xml.sax.SAXException ; 63 64 65 70 public final class NamespaceAccessTokenImpl implements NamespaceAccessToken { 71 72 73 75 private static String ACL_SEMANTICS = "acl_semantics"; 76 private static String ALL_GRANT_BEFORE_DENY = "all-grant-before-any-deny"; 77 private static String LEGACY_ALL_GRANT_BEFORE_DENY = "legacy-all-grant-before-any-deny"; 78 79 84 NamespaceAccessTokenImpl(Namespace namespace) { 85 this.namespace = namespace; 86 NamespaceConfig config = namespace.getConfig(); 87 if (config != null) { 88 String acl_semantics = config.getParameter(ACL_SEMANTICS); 89 if ((acl_semantics != null) && (acl_semantics.equals(LEGACY_ALL_GRANT_BEFORE_DENY ))) { 90 securityHelper = new SecurityImpl(namespace, namespace.getConfig()); 91 } else if((acl_semantics != null) && (acl_semantics.equals(ALL_GRANT_BEFORE_DENY ))) { 92 securityHelper = new SecurityImplAllGrant(namespace, namespace.getConfig()); 93 } else if (acl_semantics != null) { 94 try { 95 securityHelper = (Security) Class.forName(acl_semantics).newInstance(); 96 if (securityHelper != null) { 97 securityHelper.init(namespace, namespace.getConfig()); 98 } 99 }catch (Exception e) { 100 e.printStackTrace(); 101 } 102 } 103 } 104 if (securityHelper == null) { 105 securityHelper = new ACLSecurityImpl(namespace, namespace.getConfig()); 106 } 107 108 lockHelper = 109 new LockImpl(namespace, namespace.getConfig(), securityHelper); 110 111 structureHelper = 112 new StructureImpl(namespace, namespace.getConfig(), 113 securityHelper, lockHelper); 114 contentHelper = 115 new ContentImpl(namespace, namespace.getConfig(), securityHelper, 116 structureHelper, lockHelper); 117 searchHelper = 118 new SearchImpl (namespace, namespace.getConfig(), 119 structureHelper, contentHelper); 120 121 macroHelper = 122 new MacroImpl(namespace, namespace.getConfig(), securityHelper, 123 contentHelper, structureHelper, lockHelper); 124 } 125 126 127 129 130 133 Namespace namespace; 134 135 136 139 private Structure structureHelper; 140 141 142 145 private Content contentHelper; 146 147 148 151 private Lock lockHelper; 152 153 154 157 private Search searchHelper; 158 159 160 163 private Security securityHelper; 164 165 166 169 private Macro macroHelper; 170 171 172 174 175 180 public Structure getStructureHelper() { 181 return structureHelper; 182 } 183 184 185 190 public Content getContentHelper() { 191 return contentHelper; 192 } 193 194 195 200 public Lock getLockHelper() { 201 return lockHelper; 202 } 203 204 205 210 public Search getSearchHelper() { 211 return searchHelper; 212 } 213 214 215 220 public Security getSecurityHelper() { 221 return securityHelper; 222 } 223 224 225 230 public Macro getMacroHelper() { 231 return macroHelper; 232 } 233 234 235 240 public NamespaceConfig getNamespaceConfig() { 241 return namespace.getConfig(); 242 } 243 244 245 250 public Logger getLogger() { 251 return namespace.getApplicationLogger(); 252 } 253 254 255 257 258 268 public void importData(SlideToken token, Configuration dataConfiguration) 269 throws ConfigurationException, UnknownObjectClassException, 270 ServiceAccessException { 271 272 XMLUnmarshaller.unmarshal(this, token, dataConfiguration); 273 274 } 275 276 277 287 public void importData(SlideToken token, Reader reader) 288 throws ConfigurationException, UnknownObjectClassException, 289 ServiceAccessException, SAXException , IOException { 290 291 try { 292 293 SAXParserFactory factory = SAXParserFactory.newInstance(); 294 factory.setNamespaceAware(false); 295 factory.setValidating(false); 296 SAXParser parser = factory.newSAXParser(); 297 298 Populate pop = new Populate(); 299 Configuration configuration = new ConfigurationElement 300 (pop.load(new InputSource (reader), parser.getXMLReader())); 301 302 importData(token, configuration); 303 304 } catch (javax.xml.parsers.FactoryConfigurationError e) { 305 throw new SlideRuntimeException(e.getMessage()); 306 } catch (javax.xml.parsers.ParserConfigurationException e) { 307 throw new SlideRuntimeException(e.getMessage()); 308 } 311 312 } 313 314 315 321 public void exportData(SlideToken token, Writer writer) 322 throws SlideException { 323 exportData(token, writer, "/"); 324 } 325 326 327 334 public void exportData(SlideToken token, Writer writer, 335 String startNode) 336 throws SlideException { 337 338 XMLMarshaller.marshal(this, token, writer, startNode); 339 340 } 341 342 343 346 public void disconnect() { 347 try { 348 namespace.disconnectServices(); 349 } catch(SlideException e) { 350 e.printStackTrace(); 351 } 352 } 353 354 355 360 public String getName() { 361 return namespace.getName(); 362 } 363 364 371 public Uri getUri(SlideToken token, String uri) { 372 return namespace.getUri(token, uri); 373 } 374 375 376 378 379 388 public void begin() 389 throws NotSupportedException , SystemException { 390 if ( TransactionEvent.BEGIN.isEnabled() ) EventDispatcher.getInstance().fireEvent(TransactionEvent.BEGIN, new TransactionEvent(this)); 391 namespace.getTransactionManager().begin(); 392 } 393 394 395 414 public void commit() 415 throws RollbackException , HeuristicMixedException , 416 HeuristicRollbackException , SecurityException , IllegalStateException , 417 SystemException { 418 try { 419 if ( TransactionEvent.COMMIT.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(TransactionEvent.COMMIT, new TransactionEvent(this)); 420 } catch ( VetoException e ) { 421 throw new SystemException (e.getMessage()); 422 } 423 namespace.getTransactionManager().commit(); 424 if ( TransactionEvent.COMMITED.isEnabled() ) EventDispatcher.getInstance().fireEvent(TransactionEvent.COMMITED, new TransactionEvent(this)); 425 } 426 427 428 440 public void rollback() 441 throws SecurityException , IllegalStateException , SystemException { 442 if ( TransactionEvent.ROLLBACK.isEnabled() ) EventDispatcher.getInstance().fireEvent(TransactionEvent.ROLLBACK, new TransactionEvent(this)); 443 namespace.getTransactionManager().rollback(); 444 } 445 446 447 457 public void setRollbackOnly() 458 throws IllegalStateException , SystemException { 459 namespace.getTransactionManager().setRollbackOnly(); 460 } 461 462 463 471 public int getStatus() 472 throws SystemException { 473 return namespace.getTransactionManager().getStatus(); 474 } 475 476 477 489 public void setTransactionTimeout(int seconds) 490 throws SystemException { 491 namespace.getTransactionManager().setTransactionTimeout(seconds); 492 } 493 494 public TransactionManager getTransactionManager() { 495 return namespace.getTransactionManager(); 496 } 497 498 } 499 500 501 | Popular Tags |