annotate artifact-database/src/main/java/de/intevation/artifactdatabase/LazyBackendUser.java @ 172:8ce06db80857

Added a new method to the ProtocolUtils that creates the necessary CREATE document for creating new artifact collections. artifacts/trunk@1397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Mar 2011 11:47:27 +0000
parents 81ad657569e1
children 16cd059945e5
rev   line source
165
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 /*
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 *
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 * Read the file LGPL.txt coming with the software for details
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 */
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 package de.intevation.artifactdatabase;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.User;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.UserFactory;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import org.w3c.dom.Document;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 public class LazyBackendUser
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 implements User
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 protected UserFactory factory;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 protected Backend backend;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 protected String identifier;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 protected User user;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 protected Object context;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public LazyBackendUser(
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 String identifier,
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 UserFactory factory,
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 Backend backend,
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 Object context
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 ) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this.identifier = identifier;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 this.factory = factory;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 this.backend = backend;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 this.context = context;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 protected User getUser() {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 if (user == null) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 user = backend.getUser(identifier, factory, context);
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 if (user == null) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 throw new IllegalStateException("loading user failed");
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 return user;
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public String identifier() {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 return getUser().identifier();
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public String getName() {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return getUser().getName();
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public void setName(String name) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 getUser().setName(name);
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 public void setIdentifier(String identifier) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 getUser().setIdentifier(identifier);
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 public Document getRole() {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 return getUser().getRole();
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 public void setRole(Document document) {
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 getUser().setRole(document);
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
81ad657569e1 Added Helper for lazy loading users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org