这个没循环的地方怎么搞?

<?xml version="1.0" encoding="utf-8"?>

<Conf> 
  <global desc="预留"> 
    <processName alias="" desc="预留">GZTR</processName>  
    <ns_model desc="corba对象获取方式 ns-命名服务 ior-IOR字符串">ior</ns_model>  
    <channel_ip>10.45.7.22</channel_ip>  
    <channel_port>3001</channel_port>  
    <load_database desc="是否加载数据库 n-不加载">y</load_database>  
    <ior_server_url>http://10.45.32.30:80/NameService/Server</ior_server_url>  
    <dirverClass>com.mysql.jdbc.Driver</dirverClass>  
    <url>jdbc:mysql://10.45.7.23:3306/gztr_ema?autoReconnect=true</url>  
    <username>root</username>  
    <password>rootroot</password>  
    <maxPoolSize>15</maxPoolSize>  
    <minPoolSize>3</minPoolSize> 
  </global>  
  <channel desc="系统事件发送通道" name="SystemEventConsumer" type="supplier" trace="1" loglevel="0" status="load"> 
    <channel_name>Notifier</channel_name> 
  </channel>  
  <channel desc="ALE事件接收通道" name="ReaderToALEEventConsumer" type="consumer" trace="1" loglevel="0" status="unload"> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=READER1.0</channel_filter>  
    <processModule>ALEModule</processModule> 
  </channel>  
  <module desc="ALE模块" name="ALEModule" type="" trace="1" loglevel="0" status="unload" class="com.ztesoft.ale.ALEModule"> 
    <durationValue>2000</durationValue>  
    <intervalValue>0</intervalValue>  
    <channel_name>Notifier</channel_name> 
  </module>  
  <channel desc="ETL事件接收通道" name="ALEToETLEventConsumer" type="consumer" trace="1" loglevel="0" status="unload"> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=(ALE1.0|ETL_REQ1.0)</channel_filter>  
    <processModule>ETLModule</processModule> 
  </channel>  
  <module desc="ETL模块" name="ETLModule" type="" trace="1" loglevel="0" status="unload" class="com.ztesoft.etl.core.ETLModule"> 
    <channel_name>Notifier</channel_name>  
    <updateInterval>1000</updateInterval> 
  </module>  
  <channel desc="Schedule事件接收通道" name="ScheduleEventConsumer" type="consumer" trace="1" loglevel="0" status=""> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=SCHEDULE_REQ1.0</channel_filter>  
    <processModule>ScheduleModule</processModule> 
  </channel>  
  <module desc="Schedule模块" name="ScheduleModule" type="" trace="1" loglevel="-1" status="" class="com.ztesoft.schedule.ScheduleModule"> 
    <channel_name>Notifier</channel_name>  
    <dbModel desc="ONCE,ALWAY">ALWAYS</dbModel>  
    <dbInterval desc="second">10</dbInterval>  
    <schInterval desc="microsecond">2</schInterval> 
  </module>  
  <channel desc="GZTR接收通道" name="MobileEventConsumer" type="consumer" trace="1" loglevel="0" status="unload"> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=ETL1.0</channel_filter>  
    <processModule>GZTRModule</processModule> 
  </channel>  
  <module desc="GZTR处理模块" name="GZTRModule" type="" trace="1" loglevel="1" status="unload" class="com.ztesoft.customize.GZTRModule"> 
    <channel_name>Notifier</channel_name>  
    <updateInterval desc="检测周期/秒">10</updateInterval> 
  </module>  
  <channel desc="手持终端事件接收通道" name="MobileEventConsumer" type="consumer" trace="1" loglevel="0" status="unload"> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=MOBILE_REQ1.0</channel_filter>  
    <processModule>MobileEventModule</processModule> 
  </channel>  
  <module desc="手持终端消息处理模块" name="MobileEventModule" type="" trace="1" loglevel="0" status="unload" class="com.ztesoft.mobile.MobileEventModule"> 
    <channel_name>Notifier</channel_name> 
  </module>  
  <channel desc="TMF接收通道" name="MobileEventConsumer" type="consumer" trace="1" loglevel="0" status="unload"> 
    <channel_name>Notifier</channel_name>  
    <channel_filter>protocol=(ALE1.0|ETL1.0)</channel_filter>  
    <processModule>TMFModule</processModule> 
  </channel>  
  <module desc="TMF处理模块" name="TMFModule" type="" trace="1" loglevel="5" status="unload" class="com.ztesoft.customize.TMFModule"> 
    <channel_name>Notifier</channel_name>  
    <updateInterval desc="检测周期/秒">720</updateInterval>  
    <expireTime desc="过期时长/秒">1440</expireTime> 
  </module>  
  <module1 desc="预留" name="ALE" type="" trace="1" loglevel="0" status=""> 
    <initializer dll="" class="" trace="1" loglevel="0" threads="1" queuesize="10000"/>  
    <config></config> 
  </module1> 
</Conf>

如以上代码  global  只有一个所以不需要循环,然后就傻眼了..

package per.sww.eight.mideight;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="global")
public class Global {
    public Global(){
        super();
    }
    
    
    private String desc;
    private ProcessName processName;
    private Ns_model ns_model;
    private String channel_ip;
    private String channel_port;
    private Load_database load_database;
    private String ior_server_url;
    private String dirverClass;
    private String url;
    private String username;
    private String password;
    private String maxPoolSize;
    private String minPoolSize;
    
    @XmlAttribute(name="desc")
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    @XmlElement(name="processName")
    public ProcessName getProcessName() {
        return processName;
    }
    public void setProcessName(ProcessName processName) {
        this.processName = processName;
    }
    @XmlElement(name="ns_model")
    public Ns_model getNs_model() {
        return ns_model;
    }
    public void setNs_model(Ns_model ns_model) {
        this.ns_model = ns_model;
    }
    @XmlElement(name="channel_ip")
    public String getChannel_ip() {
        return channel_ip;
    }
    public void setChannel_ip(String channel_ip) {
        this.channel_ip = channel_ip;
    }
    @XmlElement(name="channel_port")
    public String getChannel_port() {
        return channel_port;
    }
    public void setChannel_port(String channel_port) {
        this.channel_port = channel_port;
    }
    @XmlElement(name="load_database")
    public Load_database getLoad_database() {
        return load_database;
    }
    public void setLoad_database(Load_database load_database) {
        this.load_database = load_database;
    }
    @XmlElement(name="ior_server_url")
    public String getIor_server_url() {
        return ior_server_url;
    }
    public void setIor_server_url(String ior_server_url) {
        this.ior_server_url = ior_server_url;
    }
    @XmlElement(name="dirverClass")
    public String getDirverClass() {
        return dirverClass;
    }
    public void setDirverClass(String dirverClass) {
        this.dirverClass = dirverClass;
    }
    @XmlElement(name="url")
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    @XmlElement(name="username")
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    @XmlElement(name="password")
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @XmlElement(name="maxPoolSize")
    public String getMaxPoolSize() {
        return maxPoolSize;
    }
    public void setMaxPoolSize(String maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }
    @XmlElement(name="minPoolSize")
    public String getMinPoolSize() {
        return minPoolSize;
    }
    public void setMinPoolSize(String minPoolSize) {
        this.minPoolSize = minPoolSize;
    }

    
    
}
 1 package per.sww.eight.mideight;
 2 
 3 import java.util.List;
 4 
 5 import javax.xml.bind.annotation.XmlElement;
 6 import javax.xml.bind.annotation.XmlElements;
 7 import javax.xml.bind.annotation.XmlRootElement;
 8 
 9 @XmlRootElement(name="Conf")
10 public class Conf {
11     public Conf(){
12         super();
13     }
14     
15     
16     //Channel
17     List<Channel> channelsList;
18     @XmlElements(value={@XmlElement(name="channel",type=Channel.class)})
19     public List<Channel> getChannelsList() {
20         return channelsList;
21     }
22     public void setChannelsList(List<Channel> channelsList) {
23         this.channelsList = channelsList;
24     }
25     
26     //Module
27     List<Module> modulesList;
28     @XmlElements(value={@XmlElement(name="module",type=Module.class)})
29     public List<Module> getModulesList() {
30         return modulesList;
31     }
32     public void setModulesList(List<Module> modulesList) {
33         this.modulesList = modulesList;
34     }
35     
36     List<Module1> module1sList;
37     @XmlElements(value={@XmlElement(name="module1",type=Module1.class)})
38     public List<Module1> getModule1sList() {
39         return module1sList;
40     }
41     public void setModule1sList(List<Module1> module1sList) {
42         this.module1sList = module1sList;
43     }
44     
45 }
package per.sww.eight.mideight;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement.GlobalScope;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class ReadConf {
    public static void main(String[] args) {
        try{
            JAXBContext jc=JAXBContext.newInstance(Conf.class);
            Unmarshaller u=jc.createUnmarshaller();
            Conf conf=(Conf)u.unmarshal(new File("D:"+File.separator+"middleware.conf.xml"));
            System.out.println("-------------------------------------------------");
                Global g=new Global();
                System.out.println(g.getProcessName().getAlias());
                System.out.println(g.getProcessName().getDesc());
                System.out.println(g.getProcessName().getText());
                System.out.println(g.getNs_model().getDesc());
                System.out.println(g.getNs_model().getTwotest());
                System.out.println(g.getChannel_ip());
                System.out.println(g.getChannel_port());
                System.out.println(g.getLoad_database().getDesc());
                System.out.println(g.getLoad_database().getThreetext());
                System.out.println(g.getIor_server_url());
                System.out.println(g.getDirverClass());
                System.out.println(g.getUrl());
                System.out.println(g.getUsername());
                System.out.println(g.getPassword());
                System.out.println(g.getMaxPoolSize());
                System.out.println(g.getMinPoolSize());
                System.out.println("**********************************************");
                
            for(Channel channel:conf.getChannelsList()){
                System.out.println(channel.getDesc());
                System.out.println(channel.getName());
                System.out.println(channel.getType());
                System.out.println(channel.getTrace());
                System.out.println(channel.getLoglevel());
                System.out.println(channel.getStatus());
                System.out.println(channel.getChannel_name());
                if(null!=channel.getChannel_filter()){
                    System.out.println(channel.getChannel_filter());
                }
                if(null!=channel.getProcessModule()){
                    System.out.println(channel.getProcessModule());
                }
                
                System.out.println("===============================================");
            }
            for(Module module:conf.getModulesList()){
                System.out.println(module.getDesc());
                System.out.println(module.getName());
                System.out.println(module.getType());
                System.out.println(module.getTrace());
                System.out.println(module.getLoglevel());
                System.out.println(module.getStatus());
                System.out.println(module.getClazz());
                System.out.println(module.getDurationValue());
                System.out.println(module.getChannel_name());
                if (null!=module.getUpdateInterval()) {
                    System.out.println(module.getUpdateInterval().getDesc());
                    System.out.println(module.getUpdateInterval().getFourtext());
                }
                if (null!=module.getDbModel()) {
                    System.out.println(module.getDbModel().getDesc());
                    System.out.println(module.getDbModel().getFivetext());
                }
                if (null!=module.getDbInterval()) {
                    System.out.println(module.getDbInterval().getDesc());
                    System.out.println(module.getDbInterval().getSextext());
                }
                if (null!=module.getSchInterval()) {
                    System.out.println(module.getSchInterval().getDesc());
                    System.out.println(module.getSchInterval().getSenventext());
                }
                if (null!=module.getExpireTime()) {
                    System.out.println(module.getExpireTime().getDesc());
                    System.out.println(module.getExpireTime().getEighttext());
                }
                System.out.println("|||||||||||||||||||||||||||||||||||||||||||||||||||||");
            }
            for(Module1 module1:conf.getModule1sList()){
                System.out.println(module1.getDesc());
                System.out.println(module1.getName());
                System.out.println(module1.getType());
                System.out.println(module1.getTrace());
                System.out.println(module1.getLoglevel());
                System.out.println(module1.getStatus());
                if(null!=module1.getInitializer()){
                    System.out.println(module1.getInitializer().getDll());
                    System.out.println(module1.getInitializer().getClazz());
                    System.out.println(module1.getInitializer().getTrace());
                    System.out.println(module1.getInitializer().getLoglevel());
                    System.out.println(module1.getInitializer().getThreads());
                    System.out.println(module1.getInitializer().getQueuesize());
                }
                System.out.println(module1.getConfig());
                System.out.println("-----------------------------------------------");
            }
        }catch(JAXBException e){
            e.printStackTrace();
        }
    }
}

本来是用List循环全取出来了(其他代码做好了就这第一块不让用循环懵住了),然后现在第一块不用循环怎么做?

GCT1015
浏览 538回答 1
1回答

子衿沉夜

什么意思。。。 你的global没用循环取呀
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java