0001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
0002: * This code is licensed under the GPL 2.0 license, availible at the root
0003: * application directory.
0004: */
0005: package org.vfny.geoserver.config;
0006:
0007: import org.geotools.data.DataStore;
0008: import org.geotools.data.DefaultRepository;
0009: import org.geotools.data.Repository;
0010: import org.vfny.geoserver.global.Data;
0011: import org.vfny.geoserver.global.dto.CoverageInfoDTO;
0012: import org.vfny.geoserver.global.dto.CoverageStoreInfoDTO;
0013: import org.vfny.geoserver.global.dto.DataDTO;
0014: import org.vfny.geoserver.global.dto.DataStoreInfoDTO;
0015: import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
0016: import org.vfny.geoserver.global.dto.NameSpaceInfoDTO;
0017: import org.vfny.geoserver.global.dto.StyleDTO;
0018: import java.io.IOException;
0019: import java.util.ArrayList;
0020: import java.util.Arrays;
0021: import java.util.Collections;
0022: import java.util.HashMap;
0023: import java.util.Iterator;
0024: import java.util.List;
0025: import java.util.Map;
0026: import java.util.NoSuchElementException;
0027: import java.util.SortedSet;
0028: import java.util.TreeSet;
0029: import java.util.logging.Level;
0030: import java.util.logging.Logger;
0031: import javax.servlet.ServletContext;
0032:
0033: /**
0034: * Data purpose.
0035: *
0036: * <p>
0037: * Represents an instance of the catalog.xml file in the configuration of the
0038: * server, along with associated configuration files for the feature types.
0039: * </p>
0040: *
0041: * <p></p>
0042: *
0043: * @author dzwiers, Refractions Research, Inc.
0044: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last modification)
0045: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last modification)
0046: * @version $Id: DataConfig.java 8391 2008-02-13 16:44:23Z aaime $
0047: *
0048: * @see DataSource
0049: * @see FeatureTypeInfo
0050: * @see StyleConfig
0051: */
0052: public class DataConfig {
0053: public static final String CONFIG_KEY = "Config.Data";
0054: public static final String SEPARATOR = ":::";
0055: public static final String SELECTED_FEATURE_TYPE = "selectedFeatureType";
0056: public static final String SELECTED_ATTRIBUTE_TYPE = "selectedAttributeType";
0057: public static final String SELECTED_COVERAGE = "selectedCoverage";
0058: private Logger LOGGER = org.geotools.util.logging.Logging
0059: .getLogger(this .getClass().toString());
0060:
0061: /**
0062: * A set of dataFormatConfig by dataFormatId.
0063: *
0064: * @see org.vfny.geoserver.config.data.CoverageStoreInfo
0065: *
0066: * @uml.property name="dataFormats"
0067: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.CoverageStoreConfig"
0068: * multiplicity="(0 1)"
0069: */
0070: private Map dataFormats;
0071:
0072: /**
0073: * A set of dataStoreConfig by dataStoreId.
0074: *
0075: * @see org.vfny.geoserver.config.data.DataStoreInfo
0076: *
0077: * @uml.property name="dataStores"
0078: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.DataStoreConfig"
0079: * multiplicity="(0 1)"
0080: */
0081: private Map dataStores;
0082:
0083: /**
0084: * A set of namespaces and their names.
0085: *
0086: * @see org.vfny.geoserver.config.data.NameSpaceConfig
0087: *
0088: * @uml.property name="nameSpaces"
0089: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.NameSpaceConfig"
0090: * multiplicity="(0 1)"
0091: */
0092: private Map nameSpaces;
0093:
0094: /**
0095: * FeatureTypesInfoConfig referenced by key "<code>dataStoreID + SEPARATOR
0096: * + typeName</code>"
0097: *
0098: * @see org.vfny.geoserver.global.dto.FeatureTypeInfoConfig
0099: *
0100: * @uml.property name="featuresTypes"
0101: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.FeatureTypeConfig"
0102: * multiplicity="(0 1)"
0103: */
0104: private Map featuresTypes;
0105:
0106: /**
0107: *
0108: * @uml.property name="coverages"
0109: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.CoverageConfig"
0110: * multiplicity="(0 1)"
0111: */
0112: private Map coverages;
0113:
0114: /**
0115: * A set of styles and their names.
0116: *
0117: * @see org.vfny.geoserver.config.data.StyleConfig
0118: *
0119: * @uml.property name="styles"
0120: * @uml.associationEnd qualifier="key:java.lang.String org.vfny.geoserver.config.StyleConfig"
0121: * multiplicity="(0 1)"
0122: */
0123: private Map styles;
0124:
0125: /**
0126: * the default namespace for the server instance.
0127: *
0128: * @see org.vfny.geoserver.config.data.NameSpaceConfig
0129: *
0130: * @uml.property name="defaultNameSpace"
0131: * @uml.associationEnd multiplicity="(1 1)"
0132: */
0133: private NameSpaceConfig defaultNameSpace;
0134:
0135: /**
0136: * Data constructor.
0137: *
0138: * <p>
0139: * Creates a Data to represent an instance with default data.
0140: * </p>
0141: *
0142: * @see defaultSettings()
0143: */
0144: public DataConfig() {
0145: dataFormats = new HashMap();
0146: dataStores = new HashMap();
0147: nameSpaces = new HashMap();
0148: styles = new HashMap();
0149: featuresTypes = new HashMap();
0150: coverages = new HashMap();
0151: defaultNameSpace = new NameSpaceConfig();
0152: }
0153:
0154: /**
0155: * Data constructor.
0156: *
0157: * <p>
0158: * Creates a copy of the DataDTO provided. If the Data provided is null
0159: * then default values are used. All the datastructures are cloned.
0160: * </p>
0161: *
0162: * @param data The catalog to copy.
0163: */
0164: public DataConfig(DataDTO data) {
0165: // Iterator i = null;
0166: //
0167: // i = data.getDataStores().keySet().iterator();
0168: // dataStores = new HashMap();
0169: //
0170: // while (i.hasNext()) {
0171: // Object key = i.next();
0172: // dataStores.put(key,
0173: // new DataStoreConfig(
0174: // (DataStoreInfoDTO) data.getDataStores().get(key)));
0175: // }
0176: //
0177: // i = data.getNameSpaces().keySet().iterator();
0178: // nameSpaces = new HashMap();
0179: //
0180: // while (i.hasNext()) {
0181: // Object key = i.next();
0182: // nameSpaces.put(key,
0183: // new NameSpaceConfig(
0184: // (NameSpaceInfoDTO) data.getNameSpaces().get(key)));
0185: //
0186: // if (((NameSpaceConfig) nameSpaces.get(key)).isDefault()) {
0187: // defaultNameSpace = (NameSpaceConfig) nameSpaces.get(key);
0188: // }
0189: // }
0190: //
0191: // i = data.getFeaturesTypes().keySet().iterator();
0192: // featuresTypes = new HashMap();
0193: //
0194: // while (i.hasNext()) {
0195: // Object key = i.next();
0196: //
0197: // featuresTypes.put(key,
0198: // new FeatureTypeConfig(
0199: // (FeatureTypeInfoDTO) data.getFeaturesTypes().get(key)));
0200: // }
0201: //
0202: // i = data.getStyles().keySet().iterator();
0203: // styles = new HashMap();
0204: //
0205: // while (i.hasNext()) {
0206: // Object key = i.next();
0207: // styles.put(key,
0208: // new StyleConfig((StyleDTO) data.getStyles().get(key)));
0209: // }
0210: this ();
0211: update(data);
0212: }
0213:
0214: /**
0215: * Instantiates the data config from the data module.
0216: *
0217: * @param data The data module.
0218: */
0219: public DataConfig(Data data) {
0220: this ((DataDTO) data.toDTO());
0221: }
0222:
0223: /**
0224: * Implement loadDTO.
0225: *
0226: * <p>
0227: * Populates the object with the param passed.
0228: * </p>
0229: *
0230: * @param data An instance of DataDTO to populate this object
0231: *
0232: * @throws NullPointerException DOCUMENT ME!
0233: *
0234: * @see org.vfny.geoserver.config.DataStructure#loadDTO(java.lang.Object)
0235: */
0236: public synchronized void update(DataDTO data) {
0237: if (data == null) {
0238: throw new NullPointerException(
0239: "Data Data Transfer Object required");
0240: }
0241:
0242: Iterator i;
0243: Object key;
0244:
0245: ////
0246: //
0247: //
0248: //
0249: ////
0250: i = data.getFormats().keySet().iterator();
0251: dataFormats = new HashMap();
0252:
0253: while (i.hasNext()) {
0254: key = i.next();
0255: dataFormats.put(key, new CoverageStoreConfig(
0256: (CoverageStoreInfoDTO) data.getFormats().get(key)));
0257: }
0258:
0259: ////
0260: //
0261: //
0262: //
0263: ////
0264: i = data.getDataStores().keySet().iterator();
0265: dataStores = new HashMap();
0266:
0267: while (i.hasNext()) {
0268: key = i.next();
0269: dataStores.put(key, new DataStoreConfig(
0270: (DataStoreInfoDTO) data.getDataStores().get(key)));
0271: }
0272:
0273: ////
0274: //
0275: //
0276: //
0277: ////
0278: i = data.getNameSpaces().keySet().iterator();
0279: nameSpaces = new HashMap();
0280:
0281: while (i.hasNext()) {
0282: key = i.next();
0283: nameSpaces.put(key, new NameSpaceConfig(
0284: (NameSpaceInfoDTO) data.getNameSpaces().get(key)));
0285:
0286: if (((NameSpaceConfig) nameSpaces.get(key)).isDefault()) {
0287: defaultNameSpace = (NameSpaceConfig) nameSpaces
0288: .get(key);
0289: }
0290: }
0291:
0292: ////
0293: //
0294: //
0295: //
0296: ////
0297: i = data.getFeaturesTypes().keySet().iterator();
0298: featuresTypes = new HashMap();
0299:
0300: FeatureTypeInfoDTO f;
0301:
0302: while (i.hasNext()) {
0303: key = i.next();
0304:
0305: f = (FeatureTypeInfoDTO) data.getFeaturesTypes().get(key);
0306: if (f.getAlias() == null)
0307: featuresTypes.put(f.getDataStoreId() + ":"
0308: + f.getName(), new FeatureTypeConfig(f));
0309: else
0310: featuresTypes.put(f.getDataStoreId() + ":"
0311: + f.getAlias(), new FeatureTypeConfig(f));
0312: }
0313:
0314: ////
0315: //
0316: //
0317: //
0318: ////
0319: i = data.getCoverages().keySet().iterator();
0320: coverages = new HashMap();
0321:
0322: CoverageInfoDTO c;
0323:
0324: while (i.hasNext()) {
0325: key = i.next();
0326: c = (CoverageInfoDTO) data.getCoverages().get(key);
0327: coverages.put(c.getFormatId() + ":" + c.getName(),
0328: new CoverageConfig(c));
0329: }
0330:
0331: ////
0332: //
0333: //
0334: //
0335: ////
0336: i = data.getStyles().keySet().iterator();
0337: styles = new HashMap();
0338:
0339: while (i.hasNext()) {
0340: key = i.next();
0341: styles.put(key, new StyleConfig((StyleDTO) data.getStyles()
0342: .get(key)));
0343: }
0344: }
0345:
0346: public DataDTO toDTO() {
0347: DataDTO dt = new DataDTO();
0348: HashMap tmp = null;
0349: Iterator i = null;
0350:
0351: tmp = new HashMap();
0352: dt.setFormats(tmp);
0353: i = dataFormats.keySet().iterator();
0354:
0355: while (i.hasNext()) {
0356: Object key = i.next();
0357: tmp.put(key, ((CoverageStoreConfig) dataFormats.get(key))
0358: .toDTO());
0359: }
0360:
0361: tmp = new HashMap();
0362: dt.setDataStores(tmp);
0363: i = dataStores.keySet().iterator();
0364:
0365: while (i.hasNext()) {
0366: Object key = i.next();
0367: tmp.put(key, ((DataStoreConfig) dataStores.get(key))
0368: .toDTO());
0369: }
0370:
0371: tmp = new HashMap();
0372: dt.setFeaturesTypes(tmp);
0373: i = featuresTypes.keySet().iterator();
0374:
0375: while (i.hasNext()) {
0376: Object key = i.next();
0377: tmp.put(key, ((FeatureTypeConfig) featuresTypes.get(key))
0378: .toDTO());
0379: }
0380:
0381: tmp = new HashMap();
0382: dt.setCoverages(tmp);
0383: i = coverages.keySet().iterator();
0384:
0385: while (i.hasNext()) {
0386: Object key = i.next();
0387: tmp.put(key, ((CoverageConfig) coverages.get(key)).toDTO());
0388: }
0389:
0390: tmp = new HashMap();
0391: dt.setStyles(tmp);
0392: i = styles.keySet().iterator();
0393:
0394: while (i.hasNext()) {
0395: Object key = i.next();
0396: tmp.put(key, ((StyleConfig) styles.get(key)).toDTO());
0397: }
0398:
0399: tmp = new HashMap();
0400: dt.setNameSpaces(tmp);
0401: i = nameSpaces.keySet().iterator();
0402:
0403: while (i.hasNext()) {
0404: Object key = i.next();
0405: tmp.put(key, ((NameSpaceConfig) nameSpaces.get(key))
0406: .toDTO());
0407:
0408: if (((NameSpaceInfoDTO) tmp.get(key)).isDefault()) {
0409: dt.setDefaultNameSpacePrefix(((NameSpaceInfoDTO) tmp
0410: .get(key)).getPrefix());
0411: }
0412: }
0413:
0414: return dt;
0415: }
0416:
0417: public List getFeatureTypeConfigKeys() {
0418: return new ArrayList(featuresTypes.keySet());
0419: }
0420:
0421: /**
0422: * Lookup FeatureTypeConfig for things like WMS.
0423: *
0424: * @param key Key based on <code>dataStoreID.typeName</code>
0425: *
0426: * @return FeatureTypeInfo or null if not found
0427: *
0428: * @throws NoSuchElementException DOCUMENT ME!
0429: */
0430: public FeatureTypeConfig lookupFeatureTypeConfig(String key) {
0431: if (featuresTypes.containsKey(key)) {
0432: return (FeatureTypeConfig) featuresTypes.get(key);
0433: } else {
0434: throw new NoSuchElementException(
0435: "Could not find FeatureTypeConfig '" + key + "'.");
0436: }
0437: }
0438:
0439: /**
0440: * getDataFormats purpose.
0441: *
0442: * <p>
0443: * Description ...
0444: * </p>
0445: *
0446: * @return
0447: *
0448: * @uml.property name="dataFormats"
0449: */
0450: public Map getDataFormats() {
0451: return dataFormats;
0452: }
0453:
0454: /**
0455: * List of DataFormatIds
0456: *
0457: * @return DOCUMENT ME!
0458: */
0459: public List listDataFormatIds() {
0460: return new ArrayList(dataFormats.keySet());
0461: }
0462:
0463: public List getDataFormatIds() {
0464: return listDataFormatIds();
0465: }
0466:
0467: /**
0468: * getDataFormats purpose.
0469: *
0470: * <p>
0471: * Description ...
0472: * </p>
0473: *
0474: * @param key DOCUMENT ME!
0475: *
0476: * @return
0477: */
0478: public CoverageStoreConfig getDataFormat(String key) {
0479: return (CoverageStoreConfig) dataFormats.get(key);
0480: }
0481:
0482: /**
0483: * getDataStores purpose.
0484: *
0485: * <p>
0486: * Description ...
0487: * </p>
0488: *
0489: * @return
0490: *
0491: * @uml.property name="dataStores"
0492: */
0493: public Map getDataStores() {
0494: return dataStores;
0495: }
0496:
0497: /**
0498: * List of DataStoreIds
0499: *
0500: * @return DOCUMENT ME!
0501: */
0502: public List listDataStoreIds() {
0503: return new ArrayList(dataStores.keySet());
0504: }
0505:
0506: public List getDataStoreIds() {
0507: return listDataStoreIds();
0508: }
0509:
0510: /**
0511: * getDataStores purpose.
0512: *
0513: * <p>
0514: * Description ...
0515: * </p>
0516: *
0517: * @param key DOCUMENT ME!
0518: *
0519: * @return
0520: */
0521: public DataStoreConfig getDataStore(String key) {
0522: return (DataStoreConfig) dataStores.get(key);
0523: }
0524:
0525: /**
0526: * getDefaultNameSpace purpose.
0527: *
0528: * <p>
0529: * Description ...
0530: * </p>
0531: *
0532: * @return
0533: *
0534: * @uml.property name="defaultNameSpace"
0535: */
0536: public NameSpaceConfig getDefaultNameSpace() {
0537: return defaultNameSpace;
0538: }
0539:
0540: /**
0541: * getFeatures purpose.
0542: *
0543: * <p>
0544: * Description ...
0545: * </p>
0546: *
0547: * @return
0548: *
0549: * @uml.property name="featuresTypes"
0550: */
0551: public Map getFeaturesTypes() {
0552: return featuresTypes;
0553: }
0554:
0555: /**
0556: * getFeatures purpose.
0557: *
0558: * <p>
0559: * Description ...
0560: * </p>
0561: *
0562: * @param key DOCUMENT ME!
0563: *
0564: * @return
0565: */
0566: public FeatureTypeConfig getFeatureTypeConfig(String key) {
0567: return (FeatureTypeConfig) featuresTypes.get(key);
0568: }
0569:
0570: public CoverageConfig getCoverageConfig(String key) {
0571: return (CoverageConfig) coverages.get(key);
0572: }
0573:
0574: /**
0575: * getNameSpaces purpose.
0576: *
0577: * <p>
0578: * Description ...
0579: * </p>
0580: *
0581: * @return
0582: *
0583: * @uml.property name="nameSpaces"
0584: */
0585: public Map getNameSpaces() {
0586: return nameSpaces;
0587: }
0588:
0589: /**
0590: * getNameSpaces purpose.
0591: *
0592: * <p>
0593: * Description ...
0594: * </p>
0595: *
0596: * @param key DOCUMENT ME!
0597: *
0598: * @return
0599: */
0600: public NameSpaceConfig getNameSpace(String key) {
0601: return (NameSpaceConfig) nameSpaces.get(key);
0602: }
0603:
0604: /**
0605: * getStyles purpose.
0606: *
0607: * <p>
0608: * Description ...
0609: * </p>
0610: *
0611: * @return
0612: *
0613: * @uml.property name="styles"
0614: */
0615: public Map getStyles() {
0616: return styles;
0617: }
0618:
0619: /**
0620: * getStyles purpose.
0621: *
0622: * <p>
0623: * Description ...
0624: * </p>
0625: *
0626: * @param key DOCUMENT ME!
0627: *
0628: * @return
0629: */
0630: public StyleConfig getStyle(String key) {
0631: return (StyleConfig) styles.get(key);
0632: }
0633:
0634: /**
0635: * setFormats purpose.
0636: *
0637: * <p>
0638: * Description ...
0639: * </p>
0640: *
0641: * @param map
0642: */
0643: public void setFormats(Map map) {
0644: if (map != null) {
0645: dataFormats = map;
0646: }
0647: }
0648:
0649: /**
0650: * Add a new CoverageStoreConfig for the user to edit
0651: *
0652: * <p>
0653: * The DataFormatCondig will be added under its id name
0654: * </p>
0655: *
0656: * @param dataFormatConfig
0657: */
0658: public void addDataFormat(CoverageStoreConfig dataFormatConfig) {
0659: if (dataFormats == null) {
0660: dataFormats = new HashMap();
0661: }
0662:
0663: dataFormats.put(dataFormatConfig.getId(), dataFormatConfig);
0664: }
0665:
0666: /**
0667: * setDataFormats purpose.
0668: *
0669: * <p>
0670: * Description ...
0671: * </p>
0672: *
0673: * @param key
0674: *
0675: * @return DOCUMENT ME!
0676: */
0677: public CoverageStoreConfig removeDataFormat(String key) {
0678: if (dataFormats == null) {
0679: dataFormats = new HashMap();
0680: }
0681:
0682: return (CoverageStoreConfig) dataFormats.remove(key);
0683: }
0684:
0685: /**
0686: * setDataStores purpose.
0687: *
0688: * <p>
0689: * Description ...
0690: * </p>
0691: *
0692: * @param map
0693: *
0694: * @uml.property name="dataStores"
0695: */
0696: public void setDataStores(Map map) {
0697: if (map != null) {
0698: dataStores = map;
0699: }
0700: }
0701:
0702: /**
0703: * Add a new DataStoreConfig for the user to edit
0704: *
0705: * <p>
0706: * The DataStoreCondig will be added under its id name
0707: * </p>
0708: *
0709: * @param dataStoreConfig
0710: */
0711: public void addDataStore(DataStoreConfig dataStoreConfig) {
0712: if (dataStores == null) {
0713: dataStores = new HashMap();
0714: }
0715:
0716: dataStores.put(dataStoreConfig.getId(), dataStoreConfig);
0717: }
0718:
0719: /**
0720: * setDataStores purpose.
0721: *
0722: * <p>
0723: * Description ...
0724: * </p>
0725: *
0726: * @param key
0727: *
0728: * @return DOCUMENT ME!
0729: */
0730: public DataStoreConfig removeDataStore(String key) {
0731: if (dataStores == null) {
0732: dataStores = new HashMap();
0733: }
0734:
0735: return (DataStoreConfig) dataStores.remove(key);
0736: }
0737:
0738: /**
0739: * setDefaultNameSpace purpose.
0740: *
0741: * <p>
0742: * Description ...
0743: * </p>
0744: *
0745: * @param support
0746: *
0747: * @uml.property name="defaultNameSpace"
0748: */
0749: public void setDefaultNameSpace(NameSpaceConfig support) {
0750: if (support != null) {
0751: //first unset the old as default
0752: if (defaultNameSpace != null) {
0753: defaultNameSpace.setDefault(false);
0754: }
0755:
0756: defaultNameSpace = support;
0757:
0758: //set the new as default
0759: if (defaultNameSpace != null) {
0760: defaultNameSpace.setDefault(true);
0761: }
0762: }
0763: }
0764:
0765: /**
0766: * setFeatures purpose.
0767: *
0768: * <p>
0769: * Description ...
0770: * </p>
0771: *
0772: * @param map
0773: *
0774: * @uml.property name="featuresTypes"
0775: */
0776: public void setFeaturesTypes(Map map) {
0777: if (map != null) {
0778: featuresTypes = map;
0779: }
0780: }
0781:
0782: /**
0783: * setFeatures purpose.
0784: *
0785: * <p>
0786: * Description ...
0787: * </p>
0788: *
0789: * @param key
0790: * @param ft DOCUMENT ME!
0791: */
0792: public void addFeatureType(String key, FeatureTypeConfig ft) {
0793: if (featuresTypes == null) {
0794: featuresTypes = new HashMap();
0795: }
0796:
0797: if ((key != null) && (ft != null)) {
0798: featuresTypes.put(key, ft);
0799: }
0800: }
0801:
0802: public void addCoverage(String key, CoverageConfig cv) {
0803: if (coverages == null) {
0804: coverages = new HashMap();
0805: }
0806:
0807: if ((key != null) && (cv != null)) {
0808: coverages.put(key, cv);
0809: }
0810: }
0811:
0812: /**
0813: * setFeatures purpose.
0814: *
0815: * <p>
0816: * Description ...
0817: * </p>
0818: *
0819: * @param key
0820: *
0821: * @return DOCUMENT ME!
0822: */
0823: public FeatureTypeConfig removeFeatureType(String key) {
0824: if (featuresTypes == null) {
0825: featuresTypes = new HashMap();
0826: }
0827:
0828: return (FeatureTypeConfig) featuresTypes.remove(key);
0829: }
0830:
0831: public CoverageConfig removeCoverage(String key) {
0832: if (coverages == null) {
0833: coverages = new HashMap();
0834: }
0835:
0836: return (CoverageConfig) coverages.remove(key);
0837: }
0838:
0839: /**
0840: * setNameSpaces purpose.
0841: *
0842: * <p>
0843: * Description ...
0844: * </p>
0845: *
0846: * @param map
0847: *
0848: * @uml.property name="nameSpaces"
0849: */
0850: public void setNameSpaces(Map map) {
0851: if (map != null) {
0852: nameSpaces = map;
0853: }
0854: }
0855:
0856: /**
0857: * setNameSpaces purpose.
0858: *
0859: * <p>
0860: * Description ...
0861: * </p>
0862: *
0863: * @param key
0864: * @param ns DOCUMENT ME!
0865: */
0866: public void addNameSpace(String key, NameSpaceConfig ns) {
0867: if (nameSpaces == null) {
0868: nameSpaces = new HashMap();
0869: }
0870:
0871: if ((key != null) && (ns != null)) {
0872: nameSpaces.put(key, ns);
0873: }
0874: }
0875:
0876: /**
0877: * setNameSpaces purpose.
0878: *
0879: * <p>
0880: * Description ...
0881: * </p>
0882: *
0883: * @param key
0884: *
0885: * @return DOCUMENT ME!
0886: */
0887: public NameSpaceConfig removeNameSpace(String key) {
0888: if (nameSpaces == null) {
0889: nameSpaces = new HashMap();
0890: }
0891:
0892: return (NameSpaceConfig) nameSpaces.remove(key);
0893: }
0894:
0895: /**
0896: * setStyles purpose.
0897: *
0898: * <p>
0899: * Description ...
0900: * </p>
0901: *
0902: * @param map
0903: *
0904: * @uml.property name="styles"
0905: */
0906: public void setStyles(Map map) {
0907: if (map != null) {
0908: styles = map;
0909: }
0910: }
0911:
0912: /**
0913: * setStyles purpose.
0914: *
0915: * <p>
0916: * Description ...
0917: * </p>
0918: *
0919: * @param key
0920: * @param s DOCUMENT ME!
0921: */
0922: public void addStyle(String key, StyleConfig s) {
0923: if (styles == null) {
0924: styles = new HashMap();
0925: }
0926:
0927: if ((key != null) && (s != null)) {
0928: styles.put(key, s);
0929: }
0930: }
0931:
0932: /**
0933: * setStyles purpose.
0934: *
0935: * <p>
0936: * Description ...
0937: * </p>
0938: *
0939: * @param key
0940: *
0941: * @return DOCUMENT ME!
0942: */
0943: public StyleConfig removeStyle(String key) {
0944: if (styles == null) {
0945: styles = new HashMap();
0946: }
0947:
0948: return (StyleConfig) styles.remove(key);
0949: }
0950:
0951: /**
0952: * This is the list of all feature types
0953: *
0954: * @return a set of all "DataStoreId.TypeName"
0955: */
0956: public SortedSet getFeatureTypeIdentifiers(ServletContext sc) {
0957: TreeSet set = new TreeSet();
0958:
0959: for (Iterator iter = dataStores.values().iterator(); iter
0960: .hasNext();) {
0961: DataStoreConfig dataStoreConfig = (DataStoreConfig) iter
0962: .next();
0963:
0964: DataStore dataStore = null;
0965: try {
0966: dataStore = dataStoreConfig.findDataStore(sc);
0967:
0968: String[] typeNames = dataStore.getTypeNames();
0969:
0970: for (int i = 0; i < typeNames.length; i++) {
0971: typeNames[i] = dataStoreConfig.getId() + SEPARATOR
0972: + typeNames[i];
0973: }
0974:
0975: List typeNamesList = Arrays.asList(typeNames);
0976:
0977: set.addAll(typeNamesList);
0978: } catch (Throwable ignore) {
0979: LOGGER.warning("Could not use "
0980: + dataStoreConfig.getId()
0981: + " datastore was unavailable!");
0982: LOGGER.log(Level.WARNING, "", ignore);
0983:
0984: continue;
0985: } finally {
0986: if (dataStore != null)
0987: dataStore.dispose();
0988: }
0989: }
0990:
0991: return Collections.unmodifiableSortedSet(set);
0992: }
0993:
0994: public SortedSet getCoverageIdentifiers(ServletContext sc) {
0995: TreeSet set = new TreeSet();
0996:
0997: for (Iterator iter = dataFormats.values().iterator(); iter
0998: .hasNext();) {
0999: CoverageStoreConfig dataFormatConfig = (CoverageStoreConfig) iter
1000: .next();
1001:
1002: set.add(dataFormatConfig.getId());
1003: }
1004:
1005: return Collections.unmodifiableSortedSet(set);
1006: }
1007:
1008: /**
1009: * To DataRepository for ValidationProcessor.
1010: * <p>
1011: * This repository is limited to the FeatureTypes currently defined.
1012: * @throws IOException
1013: */
1014: public Repository toRepository(ServletContext context)
1015: throws IOException {
1016: DefaultRepository repository = new DefaultRepository();
1017:
1018: for (Iterator i = dataStores.entrySet().iterator(); i.hasNext();) {
1019: Map.Entry entry = (Map.Entry) i.next();
1020: String dataStoreId = (String) entry.getKey();
1021: DataStoreConfig dataStoreConfig = (DataStoreConfig) entry
1022: .getValue();
1023: repository.register(dataStoreId, dataStoreConfig
1024: .findDataStore(context));
1025: }
1026:
1027: return repository;
1028: }
1029:
1030: /**
1031: * @return Returns the coverages.
1032: *
1033: * @uml.property name="coverages"
1034: */
1035: public Map getCoverages() {
1036: return coverages;
1037: }
1038:
1039: /**
1040: * @param coverages The coverages to set.
1041: *
1042: * @uml.property name="coverages"
1043: */
1044: public void setCoverages(Map coverages) {
1045: this .coverages = coverages;
1046: }
1047:
1048: /**
1049: * @param dataFormats The dataFormats to set.
1050: *
1051: * @uml.property name="dataFormats"
1052: */
1053: public void setDataFormats(Map dataFormats) {
1054: this.dataFormats = dataFormats;
1055: }
1056: }
|