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 @ 40559
History | View | Annotate | Download (2.91 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 | |||
60 | @SuppressWarnings("unchecked") |
||
61 | public static void registerMetadataDefinition(String name, Class theClass, String filename) throws MetadataException { |
||
62 | MetadataManager manager = MetadataLocator.getMetadataManager(); |
||
63 | if( manager.getDefinition(name)==null ) { |
||
64 | InputStream resource = theClass.getResourceAsStream(filename);
|
||
65 | if( resource==null ) { |
||
66 | throw new IllegalArgumentException("File '"+ filename + "' not found as a resource of '"+theClass.getName()+"'."); |
||
67 | } |
||
68 | manager.addDefinition( |
||
69 | name, |
||
70 | theClass.getResourceAsStream(filename), |
||
71 | theClass.getClassLoader() |
||
72 | ); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | public static DynObject newParameters(String name) { |
||
77 | return ToolsLocator.getDynObjectManager()
|
||
78 | .createDynObject( |
||
79 | ToolsLocator.getPersistenceManager().getDefinition(name) |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | public static DynObject newMetadataContainer(String name) { |
||
84 | return ToolsLocator.getDynObjectManager()
|
||
85 | .createDynObject( |
||
86 | MetadataLocator.getMetadataManager().getDefinition(name) |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | } |