svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.lib / src / main / java / org / gvsig / fmap / dal / store / db / DBHelper.java @ 43020
History | View | Annotate | Download (3.86 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.store.db; |
25 | |||
26 | import java.io.InputStream; |
||
27 | |||
28 | import org.gvsig.metadata.MetadataLocator; |
||
29 | import org.gvsig.metadata.MetadataManager; |
||
30 | import org.gvsig.metadata.exceptions.MetadataException; |
||
31 | import org.gvsig.tools.ToolsLocator; |
||
32 | import org.gvsig.tools.dynobject.DynObject; |
||
33 | import org.gvsig.tools.persistence.PersistenceManager; |
||
34 | |||
35 | public final class DBHelper { |
||
36 | |||
37 | private DBHelper() {
|
||
38 | // Do nothing
|
||
39 | } |
||
40 | |||
41 | @SuppressWarnings("unchecked") |
||
42 | public static void registerParametersDefinition(String name, Class theClass, String filename) { |
||
43 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
44 | if (manager.getDefinition(name) == null) { |
||
45 | InputStream resource = theClass.getResourceAsStream(filename);
|
||
46 | if( resource==null ) { |
||
47 | throw new IllegalArgumentException("File '"+ filename + "' not found as a resource of '"+theClass.getName()+"'."); |
||
48 | } |
||
49 | manager.addDefinition( |
||
50 | theClass, |
||
51 | name, |
||
52 | resource, |
||
53 | theClass.getClassLoader(), |
||
54 | null,
|
||
55 | null
|
||
56 | ); |
||
57 | } |
||
58 | } |
||
59 | 43020 | jjdelcerro | |
60 | public static void registerParametersDefinition(String name, Class theClass, InputStream resource) { |
||
61 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
62 | if (manager.getDefinition(name) == null) { |
||
63 | if( resource==null ) { |
||
64 | throw new IllegalArgumentException("resource null not allowed."); |
||
65 | } |
||
66 | manager.addDefinition( |
||
67 | theClass, |
||
68 | name, |
||
69 | resource, |
||
70 | theClass.getClassLoader(), |
||
71 | null,
|
||
72 | null
|
||
73 | ); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | 40435 | jjdelcerro | @SuppressWarnings("unchecked") |
78 | public static void registerMetadataDefinition(String name, Class theClass, String filename) throws MetadataException { |
||
79 | MetadataManager manager = MetadataLocator.getMetadataManager(); |
||
80 | if( manager.getDefinition(name)==null ) { |
||
81 | InputStream resource = theClass.getResourceAsStream(filename);
|
||
82 | if( resource==null ) { |
||
83 | throw new IllegalArgumentException("File '"+ filename + "' not found as a resource of '"+theClass.getName()+"'."); |
||
84 | } |
||
85 | manager.addDefinition( |
||
86 | name, |
||
87 | 43020 | jjdelcerro | resource, |
88 | 40435 | jjdelcerro | theClass.getClassLoader() |
89 | ); |
||
90 | } |
||
91 | } |
||
92 | 43020 | jjdelcerro | @SuppressWarnings("unchecked") |
93 | public static void registerMetadataDefinition(String name, Class theClass, InputStream resource) throws MetadataException { |
||
94 | MetadataManager manager = MetadataLocator.getMetadataManager(); |
||
95 | if( manager.getDefinition(name)==null ) { |
||
96 | manager.addDefinition( |
||
97 | name, |
||
98 | resource, |
||
99 | theClass.getClassLoader() |
||
100 | ); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | 40435 | jjdelcerro | public static DynObject newParameters(String name) { |
105 | return ToolsLocator.getDynObjectManager()
|
||
106 | .createDynObject( |
||
107 | ToolsLocator.getPersistenceManager().getDefinition(name) |
||
108 | ); |
||
109 | } |
||
110 | |||
111 | public static DynObject newMetadataContainer(String name) { |
||
112 | return ToolsLocator.getDynObjectManager()
|
||
113 | .createDynObject( |
||
114 | MetadataLocator.getMetadataManager().getDefinition(name) |
||
115 | ); |
||
116 | } |
||
117 | |||
118 | } |